Project JXTA

net.jxta.util
Class ClassFactory

java.lang.Object
  |
  +--net.jxta.util.ClassFactory
Direct Known Subclasses:
AdvertisementFactory, IDFactory, StructuredDocumentFactory

public abstract class ClassFactory
extends java.lang.Object

This util class provides methods needed by class construction factories. FIXME bondolo@jxta.org 20010223 This implementation needs a way to return the list of key -> class associations

Since:
JXTA 1.0
See Also:
StructuredDocumentFactory, AdvertisementFactory, IDFactory

Constructor Summary
ClassFactory()
           
 
Method Summary
protected  java.lang.Object callStaticMethod(java.lang.Object key, java.lang.String name, java.lang.Class[] paramSet, java.lang.Object[] params)
          Call a static method of the class associated with the provided key.
protected abstract  java.util.Hashtable getAssocTable()
          Used by ClassFactory methods to get the mapping of keys to constructors.
protected abstract  java.lang.Class getBaseClassForFactory()
          Used by ClassFactory methods to ensure that all of the instance classes which register with this factory have the correct base class
protected abstract  java.lang.Class getClassForKey()
          Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.
protected abstract  java.lang.Class[][] getRequiredConstructors()
          Used by ClassFactory methods to determine the required set of constructors needed by the instance classes generated by this factory.
protected abstract  java.lang.Object[][] getRequiredStaticMethods()
          Used by ClassFactory methods to determine the required set of static methods needed by classes registering with this factory.
protected  java.lang.Object newInstance(java.lang.Object key, java.lang.Class[] constructorMatching, java.lang.Object[] params)
          Create a new instance of the class associated with the provided key.
protected  boolean registerAssoc(java.lang.Object key, java.lang.Class instanceClass)
          Register a key and instance class with the factory.
protected  boolean registerAssoc(java.lang.String className)
          Register a class with the factory from its class name.
protected  boolean registerFromResources(java.lang.String resourceName, java.lang.String propertyName)
          Given a resource bundle identifier and a property name register instance classes.
protected  boolean registerFromString(java.lang.String classNamesString)
          Register instance classes given a string containing class names which must be found on the current class path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFactory

public ClassFactory()
Method Detail

getAssocTable

protected abstract java.util.Hashtable getAssocTable()
Used by ClassFactory methods to get the mapping of keys to constructors.
Returns:
the hashtable containing the mappings.
Since:
JXTA 1.0

getClassForKey

protected abstract java.lang.Class getClassForKey()
Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.
Returns:
Class object of the key type.
Since:
JXTA 1.0

getBaseClassForFactory

protected abstract java.lang.Class getBaseClassForFactory()
Used by ClassFactory methods to ensure that all of the instance classes which register with this factory have the correct base class
Returns:
Class object of the "Factory" type.
Since:
JXTA 1.0

getRequiredConstructors

protected abstract java.lang.Class[][] getRequiredConstructors()
Used by ClassFactory methods to determine the required set of constructors needed by the instance classes generated by this factory.
Since:
JXTA 1.0

getRequiredStaticMethods

protected abstract java.lang.Object[][] getRequiredStaticMethods()
Used by ClassFactory methods to determine the required set of static methods needed by classes registering with this factory.
Returns:
Object
Since:
JXTA 1.0

registerFromResources

protected boolean registerFromResources(java.lang.String resourceName,
                                        java.lang.String propertyName)
                                 throws java.util.MissingResourceException
Given a resource bundle identifier and a property name register instance classes. The property must be a string containing class names which must be found on the current class path. The class names are seperated by spaces.
Parameters:
resourceName - name of the resource bundle
propertyName - name of the property.
Returns:
boolean true if at least one instance class could be registered with this factory.
Throws:
java.util.MissingResourceException - if the resource bundle or property cannot be located.
Since:
JXTA 1.0

registerFromString

protected boolean registerFromString(java.lang.String classNamesString)
Register instance classes given a string containing class names which must be found on the current class path. The class names are seperated by spaces.
Parameters:
classNamesString - The class name list
Returns:
boolean true if at least one of the instance classes could be registered otherwise false.
Since:
JXTA 1.0

registerAssoc

protected boolean registerAssoc(java.lang.String className)
                         throws java.lang.Exception
Register a class with the factory from its class name. Since class name doesn't tell us much, we just load the class and hope that something happens as a result of the class loading. This class is often overridden in class factories to interogate the instance class before registering the instance class.
Parameters:
className - The class name which will be regiestered.
Returns:
boolean true if the class was registered otherwise false.
Since:
JXTA 1.0

registerAssoc

protected boolean registerAssoc(java.lang.Object key,
                                java.lang.Class instanceClass)
                         throws java.lang.NoSuchMethodException,
                                java.lang.SecurityException
Register a key and instance class with the factory.
Parameters:
key - The key to register.
instanceClass - The class which will be registered for this key.
Returns:
booelan true if the key was successfully registered otherwise false.
Throws:
java.lang.NoSuchMethodException - If one one of the required constructors or methods is not present in the instance class.
java.lang.SecurityException - If the instance class cannot be registered because either it or one of its methods is inaccesssible due to a security service.
Since:
JXTA 1.0

newInstance

protected java.lang.Object newInstance(java.lang.Object key,
                                       java.lang.Class[] constructorMatching,
                                       java.lang.Object[] params)
                                throws java.lang.reflect.InvocationTargetException
Create a new instance of the class associated with the provided key.
Parameters:
key - The identifier for the instance class to be created.
constructorMatching - identifies which constructor is needed for the parameter set provided.
params - the parameters which will be provided to the constructor.
Returns:
Object The new instance.
Throws:
java.lang.reflect.InvocationTargetException - If there is an error in the execution of the constructor for the instance class.
Since:
JXTA 1.0

callStaticMethod

protected java.lang.Object callStaticMethod(java.lang.Object key,
                                            java.lang.String name,
                                            java.lang.Class[] paramSet,
                                            java.lang.Object[] params)
                                     throws java.lang.reflect.InvocationTargetException
Call a static method of the class associated with the provided key.
Parameters:
key - The identifier for the instance class to be created.
name - identifies the method name
params - the parameters which will be provided to the method.
Returns:
Object ots result.
Throws:
java.lang.reflect.InvocationTargetException - If there is an error in the execution of the constructor for the instance class.
Since:
JXTA 1.0

Project JXTA