com.sun.j3d.utils.universe
Class ConfigObject

java.lang.Object
  extended by com.sun.j3d.utils.universe.ConfigObject
Direct Known Subclasses:
ConfigContainer.ConfigAlias, ConfigDevice, ConfigPhysicalBody, ConfigPhysicalEnvironment, ConfigScreen, ConfigSensor, ConfigView, ConfigViewPlatform, ConfigViewPlatformBehavior

 class ConfigObject
extends java.lang.Object

Base class for all configuration objects. A ConfigObject processes configuration parameters for a target object, which is instantiated after the configuration file is parsed. The ConfigObject then applies its configuration properties to the target object.

Generic base implementations are provided for the initialize(), setProperty(), and processProperties() methods. These implementations assume target objects that are unknown and thus instantiated via introspection. Property names are assumed to be method names that take an array of Objects as a parameter; they are invoked through introspection as well.

Most ConfigObjects target concrete Java 3D core classes, so these implementations are usually overridden to instantiate those objects and call their methods directly.


Field Summary
(package private)  java.util.List aliases
          List of alias Strings for this object if it's not an alias itself.
(package private)  java.lang.String baseName
          The base name of this object, derived from the configuration command which created it.
protected  java.lang.ClassLoader classLoader
           
(package private)  ConfigContainer configContainer
          The ConfigContainer in which this ConfigObject is contained.
(package private)  ConfigCommand creatingCommand
          The command that created this class.
(package private)  java.lang.String instanceName
          The instance name of this object, as specified in the configuration file.
(package private)  boolean isAlias
          If true, this object is an alias to another.
(package private)  ConfigObject original
          If isAlias is true, this references the original object.
(package private)  java.util.List properties
          Configurable properties gathered by this object, represented by the ConfigCommands that set them.
(package private)  java.lang.Class targetClass
          The Class object for the target.
(package private)  java.lang.String targetClassName
          The name of the target class this object is configuring.
(package private)  java.lang.Object targetObject
          The corresponding target object which this ConfigObject is configuring.
 
Constructor Summary
ConfigObject()
           
 
Method Summary
protected  java.lang.Object createTargetObject()
          Instantiates the target object.
(package private) static java.lang.String errorMessage(ConfigCommand cmd, java.lang.String s)
          Constructs an error message from the given string and file information from the given command.
protected  void evaluateProperties(java.lang.Class objectClass, java.lang.Object objectInstance, java.util.List properties)
          Evaluate properties for the the given class instance.
protected  java.lang.Class getClassForName(ConfigCommand cmd, java.lang.String className)
          Return the class for the specified class name string.
protected  java.lang.Object getNewInstance(ConfigCommand cmd, java.lang.Class objectClass)
          Return an instance of the class specified by the given class object.
protected  void initialize(ConfigCommand c)
          The base initialize() implementation.
protected  boolean isName(java.lang.Object o)
          Check if the argument is a name string.
protected  void processProperties()
          Evaluate properties for the the given class instance.
(package private)  void setClassLoader(java.lang.ClassLoader classLoader)
           
protected  void setProperty(ConfigCommand c)
          The base setProperty() implementation.
protected  void syntaxError(java.lang.String s)
          Throws an IllegalArgumentException with the specified description.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

baseName

java.lang.String baseName
The base name of this object, derived from the configuration command which created it. This is constructed by stripping off the leading "New" prefix or the trailing "Attribute", "Property", or "Alias" suffix of the command name. The name of the ConfigObject subclass which handles the command is derived by adding "Config" as a prefix to the base name.


instanceName

java.lang.String instanceName
The instance name of this object, as specified in the configuration file.


targetObject

java.lang.Object targetObject
The corresponding target object which this ConfigObject is configuring.


targetClassName

java.lang.String targetClassName
The name of the target class this object is configuring.


targetClass

java.lang.Class targetClass
The Class object for the target.


properties

java.util.List properties
Configurable properties gathered by this object, represented by the ConfigCommands that set them.


configContainer

ConfigContainer configContainer
The ConfigContainer in which this ConfigObject is contained.


creatingCommand

ConfigCommand creatingCommand
The command that created this class.


isAlias

boolean isAlias
If true, this object is an alias to another.


original

ConfigObject original
If isAlias is true, this references the original object.


aliases

java.util.List aliases
List of alias Strings for this object if it's not an alias itself.


classLoader

protected java.lang.ClassLoader classLoader
Constructor Detail

ConfigObject

ConfigObject()
Method Detail

setClassLoader

void setClassLoader(java.lang.ClassLoader classLoader)
Parameters:
classLoader - the ClassLoader to use when loading the implementation class for this object

initialize

protected void initialize(ConfigCommand c)
The base initialize() implementation. This takes a ConfigCommand with three arguments: the command name, the instance name, and the name of the target class this ConfigObject is configuring. The command in the configuration file should have the form:

(New{configType} {instanceName} {className})

For example, (NewDevice tracker com.sun.j3d.input.LogitechTracker) will first cause ConfigDevice to be instantiated, which will then be initialized with this method. After all the properties are collected, ConfigDevice will instantiate com.sun.j3d.input.LogitechTracker, evaluate its properties, and allow references to it in the configuration file by the name "tracker".

It's assumed the target class will be instantiated through introspection and its properties set through introspection as well. Most config objects (ConfigScreen, ConfigView, ConfigViewPlatform, ConfigPhysicalBody, and ConfigPhysicalEnvironment) target a concrete core Java 3D class and will instantiate them directly, so they override this method.

Parameters:
c - the command that created this ConfigObject

setProperty

protected void setProperty(ConfigCommand c)
The base setProperty() implementation. This implementation assumes the property needs to be set by introspection on the property name as a method that accepts an array of Objects. That is, the command in the configuration file is of the form:

({type}Property {instance name} {method name} {arg0} ... {argn})

For example, (DeviceProperty tracker SerialPort "/dev/ttya") will invoke the method named "SerialPort" in the object referenced by "tracker" with an array of 1 Object containing the String "/dev/ttya".

The property is stored as the original ConfigCommand and is evaluated after the configuration file has been parsed. It is overridden by subclasses that instantiate concrete core Java 3D classes with known method names.

Parameters:
c - the command that invoked this method

createTargetObject

protected java.lang.Object createTargetObject()
Instantiates the target object.


getClassForName

protected java.lang.Class getClassForName(ConfigCommand cmd,
                                          java.lang.String className)
Return the class for the specified class name string.

Parameters:
className - the name of the class
Returns:
the object representing the class

getNewInstance

protected java.lang.Object getNewInstance(ConfigCommand cmd,
                                          java.lang.Class objectClass)
Return an instance of the class specified by the given class object.

Parameters:
objectClass - the object representing the class
Returns:
a new instance of the class

processProperties

protected void processProperties()
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.


evaluateProperties

protected void evaluateProperties(java.lang.Class objectClass,
                                  java.lang.Object objectInstance,
                                  java.util.List properties)
Evaluate properties for the the given class instance.

Parameters:
objectClass - the class object representing the given class
objectInstance - the class instance whose methods will be invoked
properties - list of property setting commands

syntaxError

protected void syntaxError(java.lang.String s)
Throws an IllegalArgumentException with the specified description. This is caught by the parser which prints out error diagnostics and continues parsing if it can.

Parameters:
s - string describing the syntax error

errorMessage

static java.lang.String errorMessage(ConfigCommand cmd,
                                     java.lang.String s)
Constructs an error message from the given string and file information from the given command.


isName

protected boolean isName(java.lang.Object o)
Check if the argument is a name string.

Parameters:
o - the object to be checked
Returns:
true if the object is an instance of String


Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.