org.pf.plugin
Class ClassRegistry<T>

java.lang.Object
  extended by org.pf.plugin.ClassRegistry<T>

public class ClassRegistry<T>
extends java.lang.Object

A class registry is a container that keeps classes registered under a logical key. For a query by key it can return

Version:
1.2
Author:
Manfred Duchrow

Constructor Summary
ClassRegistry()
          Initialize the new instance with default values.
ClassRegistry(java.lang.Class<T> typeOfRegisteredClasses)
          Initialize the new instance with a type all classes that are registered must comply to.
 
Method Summary
 java.lang.Class[] classes()
          Returns all class objects that are currently in this registry.
 java.lang.String[] classNames()
          Returns all class names of the classes that are currently in this registry.
 java.lang.Class<T> getClass(java.lang.Object key)
          Returns the class which is registered under the given key.
 ClassInfo<T> getClassInfo(java.lang.String key)
          Returns the class information object stored under the given key or null if nothing is found.
 java.lang.String getClassName(java.lang.Object key)
          Returns the name of the class which is registered under the given key.
 java.lang.String[] keys()
          Returns all keys known in this registry.
 T newInstance(java.lang.Object key)
          Returns a new instance of the class which is registered under the given key.
 void put(java.lang.Object key, java.lang.Class<T> aClass)
          Registers the given class under the specified key.
 void put(java.lang.Object key, java.lang.String className)
          Registers the class with the given name under the specified key.
 boolean register(java.lang.Object key, java.lang.Class<T> aClass)
          Registers the class under the specified key.
 boolean register(java.lang.Object key, java.lang.String className)
          Registers the class with the given name under the specified key.
 boolean remove(java.lang.Object key)
          Removes the entry in the registry which is defined by the given key.
 ClassInfo[] values()
          Returns all class info objects that are currently in this registry.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassRegistry

public ClassRegistry()
Initialize the new instance with default values.


ClassRegistry

public ClassRegistry(java.lang.Class<T> typeOfRegisteredClasses)
Initialize the new instance with a type all classes that are registered must comply to. That is, they must be the identical class, a subclass of this type or an implementer of this type if it is an interface.

Parameters:
typeOfRegisteredClasses - The type to which the classes that can be registered must be compatible to
Method Detail

getClassName

public java.lang.String getClassName(java.lang.Object key)
Returns the name of the class which is registered under the given key. If nothing is registered under the key this method returns null.

Parameters:
key - The key under which the class is registered

getClass

public java.lang.Class<T> getClass(java.lang.Object key)
Returns the class which is registered under the given key. If nothing is registered under the key this method returns null.

Parameters:
key - The key under which the class is registered

newInstance

public T newInstance(java.lang.Object key)
Returns a new instance of the class which is registered under the given key. If nothing is registered under the key this method returns null.

Parameters:
key - The key under which the class is registered

register

public boolean register(java.lang.Object key,
                        java.lang.String className)
Registers the class with the given name under the specified key.

Parameters:
key - The key under which the class is registered
className - The fully qualified name of the class
Returns:
true, if the class was found, successfully validated and registered

put

public void put(java.lang.Object key,
                java.lang.String className)
         throws ClassRegistryException
Registers the class with the given name under the specified key.

Parameters:
key - The key under which the class is registered
className - The fully qualified name of the class
Throws:
ClassRegistryException - If the class can't be found or if it is of the wrong type or can't be instantiated

register

public boolean register(java.lang.Object key,
                        java.lang.Class<T> aClass)
Registers the class under the specified key.

Parameters:
key - The key under which the class is registered
aClass - The class to be registered
Returns:
true, if the class was successfully validated and registered

put

public void put(java.lang.Object key,
                java.lang.Class<T> aClass)
         throws ClassRegistryException
Registers the given class under the specified key.

Parameters:
key - The key under which the class is registered
aClass - The class to be registered
Throws:
ClassRegistryException - If the class is of the wrong type or can't be instantiated

remove

public boolean remove(java.lang.Object key)
Removes the entry in the registry which is defined by the given key.

Returns:
true, if anything has been found and removed, otherwise false.

keys

public java.lang.String[] keys()
Returns all keys known in this registry.


values

public ClassInfo[] values()
Returns all class info objects that are currently in this registry.


classes

public java.lang.Class[] classes()
Returns all class objects that are currently in this registry.


classNames

public java.lang.String[] classNames()
Returns all class names of the classes that are currently in this registry.


getClassInfo

public ClassInfo<T> getClassInfo(java.lang.String key)
Returns the class information object stored under the given key or null if nothing is found.