com.bbn.openmap.util
Class ComponentFactory

java.lang.Object
  extended by com.bbn.openmap.util.ComponentFactory

public class ComponentFactory
extends java.lang.Object

The OpenMap ComponentFactory is a class that can construct objects from class names, with the added capability of passing the new object a Properties object to initialize itself. The new object may also receive a property prefix to use to scope its properties from the Properties object. It is sensitive to the OpenMap paradigm of marker names in a list: That a list of objects can be defined as a space separated names (marker names) within a String. Those marker names can serve as a prefix for other properties within a Properties object, as well as the prefix for a '.class' property to define the class name for the new object.


Field Summary
static java.lang.String ClassNameProperty
          A property to use for the class name of new objects - "class".
static java.lang.String DotClassNameProperty
          The property to use for the class name of new objects - ".class".
static java.util.logging.Logger logger
           
 
Constructor Summary
protected ComponentFactory()
           
 
Method Summary
protected  java.lang.Object _create(java.lang.String className, java.lang.Object[] constructorArgs, java.lang.Class<?>[] argClasses, java.lang.String prefix, java.util.Properties properties)
          Create a single object.
protected  java.util.Vector<?> _create(java.util.Vector<java.lang.String> markerNames, java.lang.String prefix, java.util.Properties properties, ProgressSupport progressSupport, boolean matchInOutVectorSize)
          Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object.
static java.lang.Object create(java.lang.String className)
          Create a single object.
static java.lang.Object create(java.lang.String className, java.lang.Object[] constructorArgs)
          Create a single object.
static java.lang.Object create(java.lang.String className, java.lang.Object[] constructorArgs, java.lang.Class<?>[] argClasses)
          Create a single object.
static java.lang.Object create(java.lang.String className, java.lang.Object[] constructorArgs, java.lang.Class<?>[] argClasses, java.lang.String prefix, java.util.Properties properties)
          Create a single object.
static java.lang.Object create(java.lang.String className, java.lang.Object[] constructorArgs, java.lang.String prefix, java.util.Properties properties)
          Create a single object.
static java.lang.Object create(java.lang.String className, java.util.Properties properties)
          Create a single object.
static java.lang.Object create(java.lang.String className, java.lang.String prefix, java.util.Properties properties)
          Create a single object.
static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames, java.util.Properties properties)
          Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object.
static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames, java.util.Properties properties, ProgressSupport progressSupport)
          Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object.
static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames, java.util.Properties properties, ProgressSupport progressSupport, boolean matchInOutVectorSize)
          Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object.
static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames, java.lang.String prefix, java.util.Properties properties)
          Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object.
static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames, java.lang.String prefix, java.util.Properties properties, ProgressSupport progressSupport)
          Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object.
static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames, java.lang.String prefix, java.util.Properties properties, ProgressSupport progressSupport, boolean matchInOutVectorSize)
          Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object.
protected  java.lang.Object createWithSubclassConstructorArgs(java.lang.Class<?> newObjClass, java.lang.Class<?>[] argClasses, java.lang.Object[] constructorArgs)
          Method to create Object with arguments.
protected static ComponentFactory getInstance()
          Method call to retrieve the singleton instance of the ComponentFactory.
protected static void setInstance(ComponentFactory cf)
          Set the singleton instance of the ComponentFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public static java.util.logging.Logger logger

DotClassNameProperty

public static final java.lang.String DotClassNameProperty
The property to use for the class name of new objects - ".class". Expects that a prefix will be prepended to it.

See Also:
Constant Field Values

ClassNameProperty

public static final java.lang.String ClassNameProperty
A property to use for the class name of new objects - "class". Can be used with the PropUtils.objectsFromProperties method as the defining property.

See Also:
Constant Field Values
Constructor Detail

ComponentFactory

protected ComponentFactory()
Method Detail

getInstance

protected static ComponentFactory getInstance()
Method call to retrieve the singleton instance of the ComponentFactory.

Returns:
ComponentFactory.

setInstance

protected static void setInstance(ComponentFactory cf)
Set the singleton instance of the ComponentFactory.

Parameters:
cf -

create

public static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames,
                                         java.util.Properties properties)
Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object. Then, if the new objects are PropertyConsumers, use the marker name as a property prefix to get properties for that object out of the Properties.

Parameters:
markerNames - String of space separated marker names.
properties - Properties object containing the details.
Returns:
Vector containing the new Objects.

create

public static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames,
                                         java.lang.String prefix,
                                         java.util.Properties properties)
Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object. Then, if the new objects are PropertyConsumers, use the marker name as a property prefix to get properties for that object out of the Properties.

Parameters:
markerNames - String of space separated marker names.
prefix - The prefix that should be prepended to the marker names.
properties - Properties object containing the details.
Returns:
Vector containing the new Objects.

create

public static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames,
                                         java.lang.String prefix,
                                         java.util.Properties properties,
                                         ProgressSupport progressSupport)
Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object. Then, if the new objects are PropertyConsumers, use the marker name as a property prefix to get properties for that object out of the Properties.

Parameters:
markerNames - String of space separated marker names.
prefix - The prefix that should be prepended to the marker names.
properties - Properties object containing the details.
progressSupport - ProgressSupport object to provide progress updates to. It's OK if this is null to not have progress events sent.
Returns:
Vector containing the new Objects.

create

public static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames,
                                         java.util.Properties properties,
                                         ProgressSupport progressSupport)
Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object. Then, if the new objects are PropertyConsumers, use the marker name as a property prefix to get properties for that object out of the Properties.

Parameters:
markerNames - String of space separated marker names.
properties - Properties object containing the details.
progressSupport - ProgressSupport object to provide progress updates to. It's OK if this is null to not have progress events sent.
Returns:
Vector containing the new Objects.

create

public static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames,
                                         java.util.Properties properties,
                                         ProgressSupport progressSupport,
                                         boolean matchInOutVectorSize)
Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object. Then, if the new objects are PropertyConsumers, use the marker name as a property prefix to get properties for that object out of the Properties.

Parameters:
markerNames - String of space separated marker names.
properties - Properties object containing the details.
progressSupport - ProgressSupport object to provide progress updates to. It's OK if this is null to not have progress events sent.
matchInOutVectorSize - if true, then if there is any trouble creating an object, it's marker name will be placed in the returned vector instead of a component. If false, only valid objects will be returned in the vector.
Returns:
Vector containing the new Objects. If a component could not be created, the markerName is returned in its place, so you can figure out which one couldn't be created. In any case, the size of the returned vector is the same size as the markerNames vector, so you can figure out which markerNames go with which objects.

create

public static java.util.Vector<?> create(java.util.Vector<java.lang.String> markerNames,
                                         java.lang.String prefix,
                                         java.util.Properties properties,
                                         ProgressSupport progressSupport,
                                         boolean matchInOutVectorSize)
Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object. Then, if the new objects are PropertyConsumers, use the marker name as a property prefix to get properties for that object out of the Properties.

Parameters:
markerNames - String of space separated marker names.
prefix - The prefix that should be prepended to the marker names.
properties - Properties object containing the details.
progressSupport - ProgressSupport object to provide progress updates to. It's OK if this is null to not have progress events sent.
matchInOutVectorSize - if true, then if there is any trouble creating an object, it's marker name will be placed in the returned vector instead of a component. If false, only valid objects will be returned in the vector.
Returns:
Vector containing the new Objects. If a component could not be created, the markerName is returned in its place, so you can figure out which one couldn't be created. In any case, the size of the returned vector is the same size as the markerNames vector, so you can figure out which markerNames go with which objects.

_create

protected java.util.Vector<?> _create(java.util.Vector<java.lang.String> markerNames,
                                      java.lang.String prefix,
                                      java.util.Properties properties,
                                      ProgressSupport progressSupport,
                                      boolean matchInOutVectorSize)
Given a Vector of marker name Strings, and a Properties object, look in the Properties object for the markerName.class property to get a class name to create each object. Then, if the new objects are PropertyConsumers, use the marker name as a property prefix to get properties for that object out of the Properties.

Parameters:
markerNames - String of space separated marker names.
prefix - The prefix that should be prepended to the marker names.
properties - Properties object containing the details.
progressSupport - ProgressSupport object to provide progress updates to. It's OK if this is null to not have progress events sent.
matchInOutVectorSize - if true, then if there is any trouble creating an object, it's marker name will be placed in the returned vector instead of a component. If false, only valid objects will be returned in the vector.
Returns:
Vector containing the new Objects. If a component could not be created, the markerName is returned in its place, so you can figure out which one couldn't be created. In any case, the size of the returned vector is the same size as the markerNames vector, so you can figure out which markerNames go with which objects.

create

public static java.lang.Object create(java.lang.String className)
Create a single object.

Parameters:
className - Class name to instantiate, empty constructor.
Returns:
object if all goes well, null if not.

create

public static java.lang.Object create(java.lang.String className,
                                      java.util.Properties properties)
Create a single object.

Parameters:
className - Class name to instantiate.
properties - Properties to use to initialize the object, if the object is a PropertyConsumer.
Returns:
object if all goes well, null if not.

create

public static java.lang.Object create(java.lang.String className,
                                      java.lang.String prefix,
                                      java.util.Properties properties)
Create a single object. If you want it to complain about classes it can't find, then set the 'basic' debug flag.

Parameters:
className - Class name to instantiate.
prefix - Properties prefix to use by the object to scope its properties.
properties - Properties to use to initialize the object, if the object is a PropertyConsumer.
Returns:
Object or null if it couldn't be created

create

public static java.lang.Object create(java.lang.String className,
                                      java.lang.Object[] constructorArgs)
Create a single object. If you want it to complain about classes it can't find, then set the 'basic' debug flag.

Parameters:
className - Class name to instantiate.
constructorArgs - an Object array of arguments to use in the constructor of the component.
Returns:
object if all goes well, null if anything bad happens.

create

public static java.lang.Object create(java.lang.String className,
                                      java.lang.Object[] constructorArgs,
                                      java.lang.Class<?>[] argClasses)
Create a single object. If you want it to complain about classes it can't find, then set the 'basic' debug flag.

Parameters:
className - Class name to instantiate.
constructorArgs - an Object array of arguments to use in the constructor of the component.
argClasses - an array of classes to use to scope which constructor to use. If null, then an array will be built from the constructorArgs.
Returns:
object if all goes well, null if anything bad happens.

create

public static java.lang.Object create(java.lang.String className,
                                      java.lang.Object[] constructorArgs,
                                      java.lang.String prefix,
                                      java.util.Properties properties)
Create a single object. If you want it to complain about classes it can't find, then set the 'basic' debug flag.

Parameters:
className - Class name to instantiate.
constructorArgs - an Object array of arguments to use in the constructor of the component.
prefix - Properties prefix to use by the object to scope its properties.
properties - Properties to use to initialize the object, if the object is a PropertyConsumer.
Returns:
object if all goes well, null if anything bad happens.

create

public static java.lang.Object create(java.lang.String className,
                                      java.lang.Object[] constructorArgs,
                                      java.lang.Class<?>[] argClasses,
                                      java.lang.String prefix,
                                      java.util.Properties properties)
Create a single object. If you want it to complain about classes it can't find, then set the 'basic' debug flag.

Parameters:
className - Class name to instantiate.
constructorArgs - an Object array of arguments to use in the constructor of the component.
argClasses - an array of classes to use to scope which constructor to use. If null, then an array will be built from the constructorArgs.
prefix - Properties prefix to use by the object to scope its properties.
properties - Properties to use to initialize the object, if the object is a PropertyConsumer.
Returns:
object if all goes well, null if anything bad happens.

_create

protected java.lang.Object _create(java.lang.String className,
                                   java.lang.Object[] constructorArgs,
                                   java.lang.Class<?>[] argClasses,
                                   java.lang.String prefix,
                                   java.util.Properties properties)
Create a single object. If you want it to complain about classes it can't find, then set the 'basic' debug flag.

Parameters:
className - Class name to instantiate.
constructorArgs - an Object array of arguments to use in the constructor of the component.
argClasses - an array of classes to use to scope which constructor to use. If null, then an array will be built from the constructorArgs.
prefix - Properties prefix to use by the object to scope its properties.
properties - Properties to use to initialize the object, if the object is a PropertyConsumer.
Returns:
object if all goes well, null if anything bad happens.

createWithSubclassConstructorArgs

protected java.lang.Object createWithSubclassConstructorArgs(java.lang.Class<?> newObjClass,
                                                             java.lang.Class<?>[] argClasses,
                                                             java.lang.Object[] constructorArgs)
                                                      throws java.lang.NoSuchMethodException,
                                                             java.lang.InstantiationException,
                                                             java.lang.IllegalAccessException,
                                                             java.lang.IllegalArgumentException,
                                                             java.lang.reflect.InvocationTargetException
Method to create Object with arguments.

Parameters:
newObjClass - the Class to be created.
argClasses - an array of Classes describing the arguments.
constructorArgs - an array of Objects for arguments.
Returns:
Object created from the Class and arguments.
Throws:
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details