private void initStringClass(Class<E> clazz) { this.dialogInputs = new JComponent[] {new JLabel("ID"), getTextField()}; try { this.constructor = clazz.getConstructor(String.class); } catch (NoSuchMethodException ignored) { } }
public static void invoke(String aClass, String aMethod, Class[] params, Object[] args) throws Exception { Class c = Class.forName(aClass); Constructor constructor = c.getConstructor(params); Method m = c.getDeclaredMethod(aMethod, params); Object i = constructor.newInstance(args); Object r = m.invoke(i, args); }
public static Object loadFrame( JopSession session, String className, String instance, boolean scrollbar) throws ClassNotFoundException { if (className.indexOf(".pwg") != -1) { GrowFrame frame = new GrowFrame( className, session.getGdh(), instance, new GrowFrameCb(session), session.getRoot()); frame.validate(); frame.setVisible(true); } else { Object frame; if (instance == null) instance = ""; JopLog.log( "JopSpider.loadFrame: Loading frame \"" + className + "\" instance \"" + instance + "\""); try { Class clazz = Class.forName(className); try { Class argTypeList[] = new Class[] {session.getClass(), instance.getClass(), boolean.class}; Object argList[] = new Object[] {session, instance, new Boolean(scrollbar)}; System.out.println("JopSpider.loadFrame getConstructor"); Constructor constructor = clazz.getConstructor(argTypeList); try { frame = constructor.newInstance(argList); } catch (Exception e) { System.out.println( "Class instanciation error: " + className + " " + e.getMessage() + " " + constructor); return null; } // frame = clazz.newInstance(); JopLog.log("JopSpider.loadFrame openFrame"); openFrame(frame); return frame; } catch (NoSuchMethodException e) { System.out.println("NoSuchMethodException: Unable to get frame constructor " + className); } catch (Exception e) { System.out.println( "Exception: Unable to get frame class " + className + " " + e.getMessage()); } } catch (ClassNotFoundException e) { System.out.println("Class not found: " + className); throw new ClassNotFoundException(); } return null; } return null; }
/** * This function is called when we want to create a Plugin with a File accepted by the * PluginFilter * * @param file the file found * @return the Plugin created */ protected Plugin createPlugin(File file) { Class<?> c = null; Plugin plugin = null; try { c = Class.forName("plugins." + file.getName().substring(0, file.getName().length() - 6)); plugin = (Plugin) c.getConstructor().newInstance(); } catch (Exception e) { e.printStackTrace(); return null; } return plugin; }
/** * Create the default projection for the default class * * @return a default projection */ private ProjectionImpl makeDefaultProjection() { // the default constructor try { Constructor c = projClass.getConstructor(VOIDCLASSARG); return (ProjectionImpl) c.newInstance(VOIDOBJECTARG); } catch (Exception ee) { System.err.println( "ProjectionManager makeDefaultProjection failed to construct class " + projClass); System.err.println(" " + ee); return null; } }
protected void initObjectClass(Class<E> clazz) { Field[] fields = clazz.getDeclaredFields(); this.dialogInputs = new JComponent[fields.length * 2]; for (int i = 0; i < fields.length; i++) { this.dialogInputs[2 * i] = new JLabel(fields[i].getName()); this.dialogInputs[2 * i + 1] = (i == 0) ? getTextField() : getTextArea(); } this.dialogInputs[1].setEnabled(false); Class[] classes = new Class[fields.length]; for (int i = 0; i < classes.length; i++) { classes[i] = String.class; } try { this.constructor = clazz.getConstructor(classes); } catch (NoSuchMethodException ignored) { } }
public Object getBean(String beanfactory) throws BeanFactoryException { // For backwards compatibility beanfactory = mapNewClass(beanfactory); BeanFactory bf = m_aBeanFactories.get(beanfactory); if (bf == null) { // testing sripts if (beanfactory.startsWith("/")) { bf = new BeanFactoryScript(beanfactory); } else { // Class BeanFactory try { Class bfclass = Class.forName(beanfactory); if (BeanFactory.class.isAssignableFrom(bfclass)) { bf = (BeanFactory) bfclass.newInstance(); } else { // the old construction for beans... Constructor constMyView = bfclass.getConstructor(new Class[] {AppView.class}); Object bean = constMyView.newInstance(new Object[] {this}); bf = new BeanFactoryObj(bean); } } catch (Exception e) { // ClassNotFoundException, InstantiationException, IllegalAccessException, // NoSuchMethodException, InvocationTargetException throw new BeanFactoryException(e); } } // cache the factory m_aBeanFactories.put(beanfactory, bf); // Initialize if it is a BeanFactoryApp if (bf instanceof BeanFactoryApp) { ((BeanFactoryApp) bf).init(this); } } return bf.getBean(); }
private void addTool(String key, Class tool) { Class[] constructArgs = null; if (key.equals("XMLToolPanel")) { constructArgs = new Class[3]; constructArgs[0] = vnmr.ui.SessionShare.class; constructArgs[1] = String.class; constructArgs[2] = String.class; } else { constructArgs = new Class[1]; constructArgs[0] = vnmr.ui.SessionShare.class; } try { Constructor c = tool.getConstructor(constructArgs); vobjs.put(key, c); } catch (NoSuchMethodException nse) { Messages.postError("Problem initiating " + key + " area."); Messages.writeStackTrace(nse, tool + " not found."); } catch (SecurityException se) { Messages.postError("Problem initiating " + key + " area."); Messages.writeStackTrace(se); } }
/** Look on disk for an editor with the class name 'ocName'. */ PluggableEditor loadEditorFromDisk(String ocName) { // if here, we need to look on disk for a pluggable editor class... log.finer("looking for ocName: " + ocName); try { Class c = myLoader.loadClass(ocName); Constructor constructor = c.getConstructor(new Class[0]); // XXX If the pluggable editor has an error in the constructor, under some // XXX circumstances it can fail so badly that this call never returns, and // XXX the thread hangs! It doesn't even get to the exception handler below... // XXX but sometimes if the constructor fails everything works as expected. Wierd. PluggableEditor editor = (PluggableEditor) constructor.newInstance(new Object[0]); editors.put(ocName, editor); // add the new editor to our list return editor; } catch (Exception e) // expected condition - just means no pluggable editor available { if (e instanceof InvocationTargetException) // rare exception - an error was encountered in the plugin's // constructor. { log.warning("unable to load special editor for: '" + ocName + "' " + e); if (JXConfig.debugLevel >= 1) { log.warning("Error loading plugin class: "); ((InvocationTargetException) e).getTargetException().printStackTrace(); } } log.log(Level.FINEST, "'Expected' Error loading " + ocName, e); editors.put(ocName, NONE); // add a blank place holder - we can't load // an editor for this, and there's no point looking again. (change if want dynamic loading, // i.e. look *every* time) } return null; // only here if an error has occured. }
private Action tryDefaultConstructor(final Class aClass) throws Exception { final Constructor constructor = aClass.getConstructor(EditorCoreAPI.class); return (Action) constructor.newInstance(myCoreAPI); }