Project JXTA

net.jxta.util
Class ClassFactory

java.lang.Object
  extended by net.jxta.util.ClassFactory
Direct Known Subclasses:
AdvertisementFactory, IDFactory, StructuredDocumentFactory

public abstract class ClassFactory
extends Object

This util class provides methods needed by class construction factories.

See Also:
StructuredDocumentFactory, AdvertisementFactory, IDFactory, net.jxta.impl.endpoint.WireFormatMessageFactory

Constructor Summary
protected ClassFactory()
          Constructor for ClassFactory.
 
Method Summary
protected abstract  Map getAssocTable()
          Used by ClassFactory methods to get the mapping of keys to constructors.
 Iterator getAvailableKeys()
          Return all of the available keys for this factory.
protected abstract  Class getClassForKey()
          Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.
protected abstract  Class getClassOfInstantiators()
          Used by ClassFactory methods to ensure that all of the instance classes which register with this factory have the correct base class
 Set getEntrySet()
          Returns an umodifiable Set containing all of the associations stored in this ClassFactory.
protected  Object getInstantiator(Object key)
          Return the instantiator associated with the provided key.
protected  boolean registerAssoc(Object key, Object instantiator)
          Register a key and instance class with the factory.
protected  boolean registerAssoc(String className)
          Register a class with the factory from its class name.
protected  boolean registerFromResources(String resourceName, String propertyName)
          Given a resource bundle identifier and a property name register instance classes.
protected  boolean registerFromString(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

protected ClassFactory()
Constructor for ClassFactory. Instances of ClassFactory are created only by the singleton subclasses.

Method Detail

getAssocTable

protected abstract Map getAssocTable()
Used by ClassFactory methods to get the mapping of keys to constructors.

Returns:
the hashtable containing the mappings.

getClassForKey

protected abstract 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.

getAvailableKeys

public Iterator getAvailableKeys()
Return all of the available keys for this factory. All elements will be of the same type as the result as getClassForKey.

Returns:
Iterator containing all of the available keys for this factory. All elements will be of the same type as the result as getClassForKey.

getEntrySet

public Set getEntrySet()
Returns an umodifiable Set containing all of the associations stored in this ClassFactory. Each entry is of type Map.Entry.

Returns:
Set Containing all of the available entries for this factory.

getClassOfInstantiators

protected abstract Class getClassOfInstantiators()
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.

registerFromResources

protected boolean registerFromResources(String resourceName,
                                        String propertyName)
                                 throws 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:
MissingResourceException - if the resource bundle or property cannot be located.

registerFromString

protected boolean registerFromString(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.

registerAssoc

protected boolean registerAssoc(String className)
                         throws 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.
Throws:
Exception - when an error occurs.

registerAssoc

protected boolean registerAssoc(Object key,
                                Object instantiator)
Register a key and instance class with the factory.

Parameters:
key - The key to register.
instantiator - The instantiator object which will be registered for this key.
Returns:
boolean true if the key was successfully registered otherwise false.

getInstantiator

protected Object getInstantiator(Object key)
                          throws NoSuchElementException
Return the instantiator associated with the provided key.

Parameters:
key - The identifier for the Instantiator class to be returned.
Returns:
Instantiator Instantiator matching the provided key
Throws:
NoSuchElementException - if the key has not been registerd.

JXTA J2SE