private void processGenericObjects(Collection objects) { Iterator i = objects.iterator() ; while (i.hasNext()) { ConfigObject o = (ConfigObject)i.next() ; o.targetObject = o.createTargetObject() ; } // Process properties only after all target objects are instantiated. i = objects.iterator() ; while (i.hasNext()) ((ConfigObject)i.next()).processProperties() ; }
/** * Return an instance of the class specified by the given class object. * * @param objectClass the object representing the class * @return a new instance of the class */ protected Object getNewInstance(ConfigCommand cmd, Class objectClass) { try { return objectClass.newInstance() ; } catch (IllegalAccessException e) { throw new IllegalArgumentException (errorMessage(cmd, "Illegal access to object class")) ; } catch (InstantiationException e) { throw new IllegalArgumentException (errorMessage(cmd, "Instantiation error for object class")) ; } }
/** * Evaluate properties for the the given class instance. The property * names are used as the names of methods to be invoked by the instance. * Each such method takes an array of Objects as its only parameter. The * array will contain Objects corresponding to the property values. */ protected void processProperties() { evaluateProperties(this.targetClass, this.targetObject, this.properties) ; // Potentially holds a lot of references, and not needed anymore. this.properties.clear() ; }
/** * Instantiates the target object. */ protected Object createTargetObject() { if (targetClassName == null) return null ; targetClass = getClassForName(creatingCommand, targetClassName) ; targetObject = getNewInstance(creatingCommand, targetClass) ; return targetObject ; }
syntaxError("Wrong number of arguments to " + c.commandName) ; if (!isName(c.argv[1])) { syntaxError("The first argument to " + c.commandName + " must be the instance name") ; if (!isName(c.argv[2])) { syntaxError("The second argument to " + c.commandName + " must be the class name") ;
configObject.setClassLoader(classLoader); configObject.initialize(cmd) ; return configObject ;
case ConfigCommand.PROPERTY: co = findConfigObject(cmd.baseName, cmd.instanceName) ; co.setProperty(cmd) ; break ; case ConfigCommand.INCLUDE:
syntaxError("Wrong number of arguments to " + c.commandName) ; if (!isName(c.argv[1])) { syntaxError("The first argument to " + c.commandName + " must be the instance name") ; if (!isName(c.argv[2])) { syntaxError("The second argument to " + c.commandName + " must be the property name") ;
/** * Return the class for the specified class name string. * * @param className the name of the class * @return the object representing the class */ protected Class getClassForName(ConfigCommand cmd, String className) { try { // Use the system class loader. If the Java 3D jar files are // installed directly in the JVM's lib/ext directory, then the // default class loader won't find user classes outside ext. // // From 1.3.2 we use the classLoader supplied to this object, // normally this will be the system class loader, but for webstart // apps the user can supply another class loader. return Class.forName(className, true, classLoader) ; } catch (ClassNotFoundException e) { throw new IllegalArgumentException (errorMessage(cmd, "Class \"" + className + "\" not found")) ; } }
/** * Returns the ConfigObject associated with the name in the given * ConfigCommand. This is used for evaluating retained built-in commands * after the config file has already been parsed. The parser won't catch * any of the exceptions generated by this method, so the error messages * are wrapped accordingly. * * @param basename base name of the config object * @param cmd command containing the name in argv[1] * @return the found ConfigObject */ private ConfigObject findConfigObject(String baseName, ConfigCommand cmd) { if (cmd.argc != 2 || !(cmd.argv[1] instanceof String)) throw new IllegalArgumentException (ConfigObject.errorMessage (cmd, "Parameter must be a single string")) ; try { return findConfigObject(baseName, (String)cmd.argv[1]) ; } catch (IllegalArgumentException e) { throw new IllegalArgumentException (ConfigObject.errorMessage(cmd, e.getMessage())) ; } }
(errorMessage (cmd, "Unknown property \"" + methodName + "\"")) ; (errorMessage (cmd, "Illegal access to \"" + methodName + "\"")) ; (errorMessage(cmd, e.getTargetException().getMessage())) ;
(ConfigObject.errorMessage(cmd, "Unknown built-in command \"" + cmd.commandName + "\"")) ;