List of usage examples for java.lang InstantiationException printStackTrace
public void printStackTrace()
From source file:org.java.plugin.boot.Boot.java
private static Application initApplication(final BootErrorHandler errorHandler, final ExtendedProperties props, final String[] args) throws Exception { ApplicationInitializer appInitializer = null; String className = props.getProperty(PARAM_APP_INITIALIZER); if (className != null) { try {/*w w w. j a va2s. co m*/ appInitializer = (ApplicationInitializer) Class.forName(className).newInstance(); } catch (InstantiationException ie) { System.err.println("failed instantiating application initializer " //$NON-NLS-1$ + className); ie.printStackTrace(); } catch (IllegalAccessException iae) { System.err.println("failed instantiating application initializer " //$NON-NLS-1$ + className); iae.printStackTrace(); } catch (ClassNotFoundException cnfe) { System.err.println("failed instantiating application initializer " //$NON-NLS-1$ + className); cnfe.printStackTrace(); } } if (appInitializer == null) { appInitializer = new DefaultApplicationInitializer(); } appInitializer.configure(props); Application result = appInitializer.initApplication(errorHandler, args); if (result == null) { throw new Exception(ResourceManager.getMessage(Boot.PACKAGE_NAME, "bootAppInitFailed")); //$NON-NLS-1$ } return result; }
From source file:com.genentech.chemistry.tool.sdfAggregator.SDFAggregator.java
private static AggInterface[] createAggregationFunction(String[] funcStrs) { String outTag = null;// w w w . j av a 2 s . c om String resFormat = null; String functionName = null; String fnargs = null; AggInterface[] ret = new AggInterface[funcStrs.length]; for (int i = 0; i < funcStrs.length; i++) { String funcstr = funcStrs[i]; Pattern pat = Pattern.compile(" *([^:]+)(:.*)? *= *(\\w+) *\\( *(.*)\\) *"); Matcher mat = pat.matcher(funcstr); if (mat.matches()) { outTag = mat.group(1); resFormat = mat.group(2); functionName = mat.group(3); fnargs = mat.group(4); if (resFormat != null) resFormat = resFormat.substring(1); } else // no output name given => construct from function name { pat = Pattern.compile(" *(\\w+) *\\( *(.+) *\\) *"); mat = pat.matcher(funcstr); if (mat.matches()) { functionName = mat.group(2); fnargs = mat.group(3); outTag = functionName + '-' + fnargs; } else if (funcstr.matches(" *count\\( *\\) *")) { functionName = "count"; // for backward compatibility fnargs = groups.get(0); // just first group by column outTag = "ClusterCount"; } else { System.err.printf("Invalid aggregation function: %s\n", funcstr); exitWithHelp(options); } } try { @SuppressWarnings("unchecked") Class<AggInterface> aFunctClass = (Class<AggInterface>) Class .forName(PACKAGEName + "." + functionName); Constructor<AggInterface> constr = aFunctClass.getConstructor(String.class, String.class, String.class, String.class); ret[i] = constr.newInstance(outTag, resFormat, functionName, fnargs); } catch (InstantiationException e) { System.err.println(e.getMessage()); System.err.println("Function does not exist: " + functionName); exitWithHelp(options); } catch (IllegalAccessException e) { System.err.println(e.getMessage()); System.err.println("Function does not exist: " + functionName); exitWithHelp(options); } catch (ClassNotFoundException e) { e.printStackTrace(); System.err.println(e.getMessage()); System.err.println("Function does not exist: " + functionName); exitWithHelp(options); } catch (NoSuchMethodException e) { System.err.println("Function is not implemented correctly: " + functionName); System.err.println(e.getMessage()); exitWithHelp(options); } catch (InvocationTargetException e) { System.err.println(e.getTargetException().getMessage()); exitWithHelp(options); } catch (Throwable e) { System.err.println(e.getMessage()); exitWithHelp(options); } } return ret; }
From source file:com.helpinput.utils.Utils.java
public static <T> T constructorNewInstance(Class<T> classType, Object... agrs) { if (agrs == null) { try {/*from www . j av a 2s . c o m*/ return classType.newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; } Constructor<?> cst = findConstructor(classType, agrs); if (cst != null) { try { @SuppressWarnings("unchecked") T instance = (T) cst.newInstance(agrs); return instance; } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } return null; }
From source file:com.helpinput.core.Utils.java
public static <T> T newInstance(Class<T> classType, Object... args) { if (!hasLength(args)) { try {//from w ww. j av a 2s .co m return classType.newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; } Constructor<?> cst = findConstructor(classType, args); if (cst != null) { try { @SuppressWarnings("unchecked") T instance = (T) cst.newInstance(args); return instance; } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } return null; }
From source file:com.incon.common.pdf.app.utils.ObjectUtils.java
/** * // w w w . j a v a2s .c om * @Title: newInstance * @Description: * @param obj * @param clazz * @return * @author lihengjun * 20131115 2:37:41 * */ public static <T> T newInstance(T obj, Class<T> clazz) { if (obj == null) { try { obj = clazz.newInstance(); return obj; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } return obj; }
From source file:edu.umn.cs.spatialHadoop.visualization.MultilevelPlot.java
private static void plotLocal(Path[] inFiles, final Path outPath, final Class<? extends Plotter> plotterClass, final OperationsParams params) throws IOException, InterruptedException, ClassNotFoundException { final boolean vflip = params.getBoolean("vflip", true); OperationsParams mbrParams = new OperationsParams(params); mbrParams.setBoolean("background", false); final Rectangle inputMBR = params.get("mbr") != null ? params.getShape("mbr").getMBR() : FileMBR.fileMBR(inFiles, mbrParams); OperationsParams.setShape(params, InputMBR, inputMBR); // Retrieve desired output image size and keep aspect ratio if needed int tileWidth = params.getInt("tilewidth", 256); int tileHeight = params.getInt("tileheight", 256); // Adjust width and height if aspect ratio is to be kept if (params.getBoolean("keepratio", true)) { // Expand input file to a rectangle for compatibility with the pyramid // structure if (inputMBR.getWidth() > inputMBR.getHeight()) { inputMBR.y1 -= (inputMBR.getWidth() - inputMBR.getHeight()) / 2; inputMBR.y2 = inputMBR.y1 + inputMBR.getWidth(); } else {/* ww w.ja v a 2 s . c o m*/ inputMBR.x1 -= (inputMBR.getHeight() - inputMBR.getWidth()) / 2; inputMBR.x2 = inputMBR.x1 + inputMBR.getHeight(); } } String outFName = outPath.getName(); int extensionStart = outFName.lastIndexOf('.'); final String extension = extensionStart == -1 ? ".png" : outFName.substring(extensionStart); // Start reading input file Vector<InputSplit> splits = new Vector<InputSplit>(); final SpatialInputFormat3<Rectangle, Shape> inputFormat = new SpatialInputFormat3<Rectangle, Shape>(); for (Path inFile : inFiles) { FileSystem inFs = inFile.getFileSystem(params); if (!OperationsParams.isWildcard(inFile) && inFs.exists(inFile) && !inFs.isDirectory(inFile)) { if (SpatialSite.NonHiddenFileFilter.accept(inFile)) { // Use the normal input format splitter to add this non-hidden file Job job = Job.getInstance(params); SpatialInputFormat3.addInputPath(job, inFile); splits.addAll(inputFormat.getSplits(job)); } else { // A hidden file, add it immediately as one split // This is useful if the input is a hidden file which is automatically // skipped by FileInputFormat. We need to plot a hidden file for the case // of plotting partition boundaries of a spatial index splits.add(new FileSplit(inFile, 0, inFs.getFileStatus(inFile).getLen(), new String[0])); } } else { Job job = Job.getInstance(params); SpatialInputFormat3.addInputPath(job, inFile); splits.addAll(inputFormat.getSplits(job)); } } try { Plotter plotter = plotterClass.newInstance(); plotter.configure(params); String[] strLevels = params.get("levels", "7").split("\\.\\."); int minLevel, maxLevel; if (strLevels.length == 1) { minLevel = 0; maxLevel = Integer.parseInt(strLevels[0]); } else { minLevel = Integer.parseInt(strLevels[0]); maxLevel = Integer.parseInt(strLevels[1]); } GridInfo bottomGrid = new GridInfo(inputMBR.x1, inputMBR.y1, inputMBR.x2, inputMBR.y2); bottomGrid.rows = bottomGrid.columns = 1 << maxLevel; TileIndex key = new TileIndex(); // All canvases in the pyramid, one per tile Map<TileIndex, Canvas> canvases = new HashMap<TileIndex, Canvas>(); for (InputSplit split : splits) { FileSplit fsplit = (FileSplit) split; RecordReader<Rectangle, Iterable<Shape>> reader = inputFormat.createRecordReader(fsplit, null); if (reader instanceof SpatialRecordReader3) { ((SpatialRecordReader3) reader).initialize(fsplit, params); } else if (reader instanceof RTreeRecordReader3) { ((RTreeRecordReader3) reader).initialize(fsplit, params); } else if (reader instanceof HDFRecordReader) { ((HDFRecordReader) reader).initialize(fsplit, params); } else { throw new RuntimeException("Unknown record reader"); } while (reader.nextKeyValue()) { Rectangle partition = reader.getCurrentKey(); if (!partition.isValid()) partition.set(inputMBR); Iterable<Shape> shapes = reader.getCurrentValue(); for (Shape shape : shapes) { Rectangle shapeMBR = shape.getMBR(); if (shapeMBR == null) continue; java.awt.Rectangle overlappingCells = bottomGrid.getOverlappingCells(shapeMBR); // Iterate over levels from bottom up for (key.level = maxLevel; key.level >= minLevel; key.level--) { for (key.x = overlappingCells.x; key.x < overlappingCells.x + overlappingCells.width; key.x++) { for (key.y = overlappingCells.y; key.y < overlappingCells.y + overlappingCells.height; key.y++) { Canvas canvas = canvases.get(key); if (canvas == null) { Rectangle tileMBR = new Rectangle(); int gridSize = 1 << key.level; tileMBR.x1 = (inputMBR.x1 * (gridSize - key.x) + inputMBR.x2 * key.x) / gridSize; tileMBR.x2 = (inputMBR.x1 * (gridSize - (key.x + 1)) + inputMBR.x2 * (key.x + 1)) / gridSize; tileMBR.y1 = (inputMBR.y1 * (gridSize - key.y) + inputMBR.y2 * key.y) / gridSize; tileMBR.y2 = (inputMBR.y1 * (gridSize - (key.y + 1)) + inputMBR.y2 * (key.y + 1)) / gridSize; canvas = plotter.createCanvas(tileWidth, tileHeight, tileMBR); canvases.put(key.clone(), canvas); } plotter.plot(canvas, shape); } } // Update overlappingCells for the higher level int updatedX1 = overlappingCells.x / 2; int updatedY1 = overlappingCells.y / 2; int updatedX2 = (overlappingCells.x + overlappingCells.width - 1) / 2; int updatedY2 = (overlappingCells.y + overlappingCells.height - 1) / 2; overlappingCells.x = updatedX1; overlappingCells.y = updatedY1; overlappingCells.width = updatedX2 - updatedX1 + 1; overlappingCells.height = updatedY2 - updatedY1 + 1; } } } reader.close(); } // Done with all splits. Write output to disk LOG.info("Done with plotting. Now writing the output"); final FileSystem outFS = outPath.getFileSystem(params); LOG.info("Writing default empty image"); // Write a default empty image to be displayed for non-generated tiles BufferedImage emptyImg = new BufferedImage(tileWidth, tileHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g = new SimpleGraphics(emptyImg); g.setBackground(new Color(0, 0, 0, 0)); g.clearRect(0, 0, tileWidth, tileHeight); g.dispose(); // Write HTML file to browse the mutlielvel image OutputStream out = outFS.create(new Path(outPath, "default.png")); ImageIO.write(emptyImg, "png", out); out.close(); // Add an HTML file that visualizes the result using Google Maps LOG.info("Writing the HTML viewer file"); LineReader templateFileReader = new LineReader( MultilevelPlot.class.getResourceAsStream("/zoom_view.html")); PrintStream htmlOut = new PrintStream(outFS.create(new Path(outPath, "index.html"))); Text line = new Text(); while (templateFileReader.readLine(line) > 0) { String lineStr = line.toString(); lineStr = lineStr.replace("#{TILE_WIDTH}", Integer.toString(tileWidth)); lineStr = lineStr.replace("#{TILE_HEIGHT}", Integer.toString(tileHeight)); lineStr = lineStr.replace("#{MAX_ZOOM}", Integer.toString(maxLevel)); lineStr = lineStr.replace("#{MIN_ZOOM}", Integer.toString(minLevel)); lineStr = lineStr.replace("#{TILE_URL}", "'tile-' + zoom + '-' + coord.x + '-' + coord.y + '" + extension + "'"); htmlOut.println(lineStr); } templateFileReader.close(); htmlOut.close(); // Write the tiles final Entry<TileIndex, Canvas>[] entries = canvases.entrySet().toArray(new Map.Entry[canvases.size()]); // Clear the hash map to save memory as it is no longer needed canvases.clear(); int parallelism = params.getInt("parallel", Runtime.getRuntime().availableProcessors()); Parallel.forEach(entries.length, new RunnableRange<Object>() { @Override public Object run(int i1, int i2) { boolean output = params.getBoolean("output", true); try { Plotter plotter = plotterClass.newInstance(); plotter.configure(params); for (int i = i1; i < i2; i++) { Map.Entry<TileIndex, Canvas> entry = entries[i]; TileIndex key = entry.getKey(); if (vflip) key.y = ((1 << key.level) - 1) - key.y; Path imagePath = new Path(outPath, key.getImageFileName() + extension); // Write this tile to an image DataOutputStream outFile = output ? outFS.create(imagePath) : new DataOutputStream(new NullOutputStream()); plotter.writeImage(entry.getValue(), outFile, vflip); outFile.close(); // Remove entry to allows GC to collect it entries[i] = null; } return null; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } }, parallelism); } catch (InstantiationException e) { throw new RuntimeException("Error creating rastierizer", e); } catch (IllegalAccessException e) { throw new RuntimeException("Error creating rastierizer", e); } }
From source file:com.chaincloud.chaincloudv.adapter.MFragmentPagerAdapter.java
@Override public Fragment getItem(int arg0) { try {/*from ww w .ja va2 s . c o m*/ return (Fragment) fragments[arg0].newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; }
From source file:net.bither.adapter.hot.HotFragmentPagerAdapter.java
@Override public Fragment getItem(int index) { try {/*from w w w .ja va2 s . c o m*/ return (Fragment) fragments[index].newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; }
From source file:com.seedform.dfatester.app.SectionsPagerAdapter.java
@Override public Fragment getItem(int i) { try {/*from ww w . j a v a 2s .c o m*/ return mFragments[i].newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; }
From source file:org.voidsink.anewjkuapp.base.SlidingTabItem.java
/** * @return A new {@link Fragment} to be displayed by a {@link android.support.v4.view.ViewPager} *//*from w w w .j av a 2 s . c om*/ public Fragment createFragment() { try { Fragment f = mFragment.newInstance(); Bundle b = getArguments(); if (b != null) { f.setArguments(b); } return f; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; }