List of usage examples for java.lang InstantiationException printStackTrace
public void printStackTrace()
From source file:com.ricemap.spateDB.mapred.SpatialRecordReader.java
/** * Reads all shapes left in the current block in one shot. * @param shapes/*from w w w.ja v a2 s. co m*/ * @return * @throws IOException */ protected boolean nextShapes(ArrayWritable shapes) throws IOException { // Prepare a vector that will hold all objects in this Vector<Shape> vshapes = new Vector<Shape>(); try { Shape stockObject = (Shape) shapes.getValueClass().newInstance(); // Reached the end of this split if (getPos() >= end) return false; long initialReadPos = getPos(); long readBytes = 0; // Read all shapes in this block while (vshapes.size() < maxShapesInOneRead && readBytes < maxBytesInOneRead && nextShape(stockObject)) { vshapes.add(stockObject.clone()); readBytes = getPos() - initialReadPos; } // Store them in the return value shapes.set(vshapes.toArray(new Shape[vshapes.size()])); return vshapes.size() > 0; } catch (InstantiationException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } catch (OutOfMemoryError e) { LOG.error("Error reading shapes. Stopped with " + vshapes.size() + " shapes"); throw e; } return false; }
From source file:cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl.java
/** * Create a HardwareAddress object from its XML representation. * * @param pElement DOM element containing the XML representation of a HardwareAddress object, as created by the * toConfigXML() method. * @throws RuntimeException if unable to instantiate the Hardware address * @see cern.c2mon.shared.common.datatag.address.HardwareAddress#toConfigXML() *//*from ww w . j ava 2 s. c o m*/ public final synchronized HardwareAddress fromConfigXML(Element pElement) { Class hwAddressClass = null; HardwareAddressImpl hwAddress = null; try { hwAddressClass = Class.forName(pElement.getAttribute("class")); hwAddress = (HardwareAddressImpl) hwAddressClass.newInstance(); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); throw new RuntimeException("Exception caught when instantiating a hardware address from XML", cnfe); } catch (IllegalAccessException iae) { iae.printStackTrace(); throw new RuntimeException("Exception caught when instantiating a hardware address from XML", iae); } catch (InstantiationException ie) { ie.printStackTrace(); throw new RuntimeException("Exception caught when instantiating a hardware address from XML", ie); } NodeList fields = pElement.getChildNodes(); Node fieldNode = null; int fieldsCount = fields.getLength(); String fieldName; String fieldValueString; String fieldTypeName = ""; for (int i = 0; i < fieldsCount; i++) { fieldNode = fields.item(i); if (fieldNode.getNodeType() == Node.ELEMENT_NODE) { fieldName = fieldNode.getNodeName(); if (fieldNode.getFirstChild() != null) { fieldValueString = fieldNode.getFirstChild().getNodeValue(); } else { fieldValueString = ""; } try { Field field = hwAddressClass.getDeclaredField(decodeFieldName(fieldName)); fieldTypeName = field.getType().getName(); if (fieldTypeName.equals("short")) { field.setShort(hwAddress, Short.parseShort(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Short")) { field.set(hwAddress, new Integer(Integer.parseInt(fieldValueString))); } else if (fieldTypeName.equals("int")) { field.setInt(hwAddress, Integer.parseInt(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Integer")) { field.set(hwAddress, new Integer(Integer.parseInt(fieldValueString))); } else if (fieldTypeName.equals("float")) { field.setFloat(hwAddress, Float.parseFloat(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Float")) { field.set(hwAddress, new Float(Float.parseFloat(fieldValueString))); } else if (fieldTypeName.equals("double")) { field.setDouble(hwAddress, Double.parseDouble(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Double")) { field.set(hwAddress, new Double(Double.parseDouble(fieldValueString))); } else if (fieldTypeName.equals("long")) { field.setLong(hwAddress, Long.parseLong(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Long")) { field.set(hwAddress, new Long(Long.parseLong(fieldValueString))); } else if (fieldTypeName.equals("byte")) { field.setByte(hwAddress, Byte.parseByte(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Byte")) { field.set(hwAddress, new Byte(Byte.parseByte(fieldValueString))); } else if (fieldTypeName.equals("char")) { field.setChar(hwAddress, fieldValueString.charAt(0)); } else if (fieldTypeName.equals("java.lang.Character")) { field.set(hwAddress, new Character(fieldValueString.charAt(0))); } else if (fieldTypeName.equals("boolean")) { field.setBoolean(hwAddress, Boolean.getBoolean(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Boolean")) { field.set(hwAddress, new Boolean(Boolean.getBoolean(fieldValueString))); } else if (fieldTypeName.equals("java.util.HashMap")) { field.set(hwAddress, SimpleXMLParser.domNodeToMap(fieldNode)); } else if (field.getType().isEnum()) { Object[] enumConstants = field.getType().getEnumConstants(); for (Object enumConstant : enumConstants) { if (enumConstant.toString().equals(fieldValueString)) { field.set(hwAddress, enumConstant); } } } else { field.set(hwAddress, fieldValueString); } } catch (NoSuchFieldException nsfe) { String errorMsg = "fromConfigXML(...) - Error occured while parsing XML <HardwareAddress> tag. " + "The following variable does not exist in " + hwAddressClass.toString() + ": \"" + decodeFieldName(fieldName) + "\""; log.error(errorMsg); throw new IllegalArgumentException(errorMsg); } catch (IllegalAccessException iae) { iae.printStackTrace(); throw new RuntimeException(iae); } catch (NumberFormatException npe) { String errorMsg = "fromConfigXML(...) - Error occured while parsing XML <HardwareAddress> tag. Field \"" + fieldName + "\" shall not be empty since we expect a \"" + fieldTypeName + "\" value. Please correct the XML configuration for " + hwAddressClass.toString(); log.error(errorMsg); throw new IllegalArgumentException(errorMsg); } } } return hwAddress; }
From source file:com.wit.and.dialog.internal.xml.XmlDialogInflater.java
/** * Returns parser for the requested XML dialog root tag. * * @param rootTag XML dialog root tag./*from ww w. j av a2 s . c om*/ * @return Xml dialog parser or <code>null</code> if there is no parser registered for * the requested root tag. */ private XmlDialogParser getParser(String rootTag) { // Check if there is cached parser for requested tag. XmlDialogParser parser = CACHED_PARSERS.get(rootTag); if (parser == null) { final Class<? extends XmlDialogParser> parserClass = PARSERS.get(rootTag); if (parserClass != null) { try { // Create new parser. parser = parserClass.newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } finally { if (parser != null) { // Set up and add parser into cache. parser.dispatchSetUp(mResources); // Clear cached parsers if needed. if (CACHED_PARSERS.size() > MAX_CACHED_PARSERS) { CACHED_PARSERS.clear(); } CACHED_PARSERS.put(rootTag, parser); } } } } return parser; }
From source file:com.concentricsky.android.khanacademy.app.HomeActivity.java
private void setListForTopic(final Topic topic, final Class<? extends AbstractListFragment<?>> fragmentClass, final boolean forward) { this.requestDataService(new ObjectCallback<KADataService>() { @Override/*from w w w .ja va 2 s . c o m*/ public void call(KADataService dataService) { try { final Fragment frag = fragmentClass.newInstance(); Bundle args = new Bundle(); args.putString(PARAM_TOPIC_ID, topic.getId()); frag.setArguments(args); // transition the fragments FragmentTransaction tx = getFragmentManager().beginTransaction() .setBreadCrumbTitle(topic.getTitle()); tx.replace(R.id.activity_home_list_container, frag, TAG_LIST_FRAGMENT).commit(); } catch (InstantiationException e) { // Swallow this; we know that both AbstractListFragment subclasses have zero-arg constructors. e.printStackTrace(); } catch (IllegalAccessException e) { // Swallow this; we know that both AbstractListFragment subclasses are visible here. e.printStackTrace(); } } }); }
From source file:any.Linker.java
/** * initialise with properties/*from w ww .j ava2 s . c o m*/ * * @param properties */ public Linker(Properties properties) { this.properties = properties; final LoopConnection loop = new LoopConnection(this); // namedCon.put("host", loop); namedCon.put("loop", loop); // FIXME // setup services from properties file ClassLoader cl; cl = Linker.class.getClassLoader(); try { for (Map.Entry<Object, Object> p : properties.entrySet()) { String key = p.getKey().toString(); if (key.startsWith("serve.")) { String name = key.substring(6); String classstr = p.getValue().toString(); if (logger.isDebugEnabled()) logger.debug("setup servable with name: " + name + " and " + classstr); Servable s = (Servable) cl.loadClass(classstr).newInstance(); servableMap.put(name, s); s.init(properties, loop.getOutQueue(), this); } } } catch (InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ConfigServable configServable = new ConfigServable(); servableMap.put("config", configServable); configServable.init(properties, null, null); }
From source file:net.semanticmetadata.lire.solr.ParallelSolrIndexer.java
private void addFeatures(List features) { for (Iterator<Class> iterator = listOfFeatures.iterator(); iterator.hasNext();) { Class next = iterator.next(); try {/*w w w . j a va2 s. c o m*/ features.add(next.newInstance()); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } }
From source file:org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory.java
public TemplateElement getProcessor(final Node nodeElement, final CompilationContext componentBean) throws CompilationException { TemplateElement returnValue = null;//from w w w. ja v a 2 s . c o m short nodeType = nodeElement.getNodeType(); if (Node.CDATA_SECTION_NODE == nodeType) { returnValue = new CDATAElement(nodeElement, componentBean); } else if (Node.TEXT_NODE == nodeType) { returnValue = new TextElement(nodeElement, componentBean); } else if (Node.COMMENT_NODE == nodeType) { returnValue = new CommentElement(nodeElement, componentBean); } else if (Node.PROCESSING_INSTRUCTION_NODE == nodeType) { returnValue = new PIElement(nodeElement, componentBean); } else if (Node.ELEMENT_NODE == nodeType) { String className = (String) mapClasses.get(nodeElement.getNodeName()); if (className == null) { className = DEFAULT_CLASS_ELEMENT_PROCESSOR; } if (!className.equals("")) { Class class1; try { log.debug("loading class: " + className); class1 = Class.forName(className); Object[] objects = new Object[2]; objects[0] = nodeElement; objects[1] = componentBean; returnValue = (TemplateElement) class1.getConstructor(paramClasses).newInstance(objects); } catch (InstantiationException e) { throw new CompilationException("InstantiationException: " + e.getLocalizedMessage(), e); } catch (IllegalAccessException e) { throw new CompilationException("IllegalAccessException: " + e.getLocalizedMessage(), e); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); throw new CompilationException("InvocationTargetException: " + e.getMessage(), e); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { throw new CompilationException(" error loading class: " + e.getLocalizedMessage()); } } } return returnValue; }
From source file:com.google.code.facebook.graph.sna.applet.TreeCollapseDemo.java
@SuppressWarnings("unchecked") public TreeCollapseDemo() { // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();// w w w .j a v a 2 s. co m layout = new TreeLayout<String, Integer>(graph); collapser = new TreeCollapser(); radialLayout = new RadialTreeLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<String, Integer>(layout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); rings = new Rings(); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Radial"); radial.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { // layout.setRadial(true); vv.setGraphLayout(radialLayout); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { // layout.setRadial(false); vv.setGraphLayout(layout); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() == 1) { Object root = picked.iterator().next(); Forest inGraph = (Forest) layout.getGraph(); try { collapser.collapse(vv.getGraphLayout(), inGraph, root); } catch (InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); for (Object v : picked) { if (v instanceof Forest) { Forest inGraph = (Forest) layout.getGraph(); collapser.expand(inGraph, (Forest) v); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); controls.add(collapse); controls.add(expand); content.add(controls, BorderLayout.SOUTH); }
From source file:demos.TreeCollapse.java
@SuppressWarnings("unchecked") public TreeCollapse() { // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();/*from w ww .j av a 2 s . co m*/ layout = new TreeLayout<String, Integer>(graph); collapser = new TreeCollapser(); radialLayout = new RadialTreeLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<String, Integer>(layout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); rings = new Rings(); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Radial"); radial.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { // layout.setRadial(true); vv.setGraphLayout(radialLayout); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { // layout.setRadial(false); vv.setGraphLayout(layout); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection<?> picked = new HashSet<Object>(vv.getPickedVertexState().getPicked()); if (picked.size() == 1) { Object root = picked.iterator().next(); Forest<?, ?> inGraph = (Forest<?, ?>) layout.getGraph(); try { collapser.collapse(vv.getGraphLayout(), inGraph, root); } catch (InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); for (Object v : picked) { if (v instanceof Forest) { Forest inGraph = (Forest) layout.getGraph(); collapser.expand(inGraph, (Forest) v); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); controls.add(collapse); controls.add(expand); content.add(controls, BorderLayout.SOUTH); }
From source file:zodicSign.treeLayout.java
@SuppressWarnings("unchecked") public treeLayout() { // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();// w w w.j a va 2 s . c om layout = new TreeLayout<String, Integer>(graph); collapser = new TreeCollapser(); radialLayout = new RadialTreeLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<String, Integer>(layout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); rings = new Rings(); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Radial"); radial.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { // layout.setRadial(true); vv.setGraphLayout(radialLayout); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { // layout.setRadial(false); vv.setGraphLayout(layout); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() == 1) { Object root = picked.iterator().next(); Forest inGraph = (Forest) layout.getGraph(); try { collapser.collapse(vv.getGraphLayout(), inGraph, root); } catch (InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); for (Object v : picked) { if (v instanceof Forest) { Forest inGraph = (Forest) layout.getGraph(); collapser.expand(inGraph, (Forest) v); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); controls.add(collapse); controls.add(expand); content.add(controls, BorderLayout.SOUTH); }