JXTA

net.jxta.util
Class ClassFactory<K,I>

java.lang.Object
  extended by net.jxta.util.ClassFactory<K,I>
Direct Known Subclasses:
AdvertisementFactory, IDFactory, StructuredDocumentFactory, WireFormatMessageFactory

public abstract class ClassFactory<K,I>
extends Object

This util class provides methods needed by class construction factories.

See Also:
StructuredDocumentFactory, AdvertisementFactory, IDFactory, WireFormatMessageFactory

Constructor Summary
protected ClassFactory()
          Standard constructor.
 
Method Summary
protected abstract  Map<K,I> getAssocTable()
          Used by ClassFactory methods to get the mapping of keys to constructors.
 Iterator<K> getAvailableKeys()
          Return all of the available keys for this factory.
protected abstract  Class<K> getClassForKey()
          Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.
protected abstract  Class<I> getClassOfInstantiators()
          Used by ClassFactory methods to ensure that all of the instance classes which register with this factory have the correct base class
 Set<Map.Entry<K,I>> getEntrySet()
          Returns an unmodifiable Set containing all of the associations stored in this ClassFactory.
protected  I getInstantiator(K key)
          Return the instantiator associated with the provided key.
protected  boolean registerAssoc(K key, I 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 registerFromFile(URI providerList)
          Register instance classes given a URI to a file containing class names which must be found on the current class path.
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.
protected  boolean registerProviders(String interfaceName)
          Given an provider interface name register instance classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFactory

protected ClassFactory()
Standard constructor.

Method Detail

getAssocTable

protected abstract Map<K,I> getAssocTable()
Used by ClassFactory methods to get the mapping of keys to constructors.

Returns:
the map containing the mappings.

getClassForKey

protected abstract Class<K> 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<K> getAvailableKeys()
Return all of the available keys for this factory.

Returns:
Iterator of all the available keys for this factory.

getEntrySet

public Set<Map.Entry<K,I>> getEntrySet()
Returns an unmodifiable Set containing all of the associations stored in this ClassFactory.

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

getClassOfInstantiators

protected abstract Class<I> 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 separated 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 separated by spaces.

Parameters:
classNamesString - The class name list
Returns:
boolean true if at least one of the instance classes could be registered otherwise false.

registerProviders

protected boolean registerProviders(String interfaceName)
Given an provider interface name register instance classes. The class path is searched for service provider lists as described by the JAR File specification for service providers

Parameters:
interfaceName - name of the implemented interface.
Returns:
boolean true if at least one instance class could be registered with this factory.

registerFromFile

protected boolean registerFromFile(URI providerList)
Register instance classes given a URI to a file containing class names which must be found on the current class path. The class names are listed on separate lines. Comments are marked with a '#', the pound sign and any following text on any line in the file are ignored.

Parameters:
providerList - the URI to a file containing a list of providers
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 registered.
Returns:
boolean true if the class was registered otherwise false.
Throws:
Exception - when an error occurs.

registerAssoc

protected boolean registerAssoc(K key,
                                I 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 I getInstantiator(K 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 registered.

JXSE