org.pfsw.plugin
Class ClassRegistry<T>

java.lang.Object
  extended by org.pfsw.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


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
protected  void assertArgNotNull(java.lang.String methodName, java.lang.String argName, java.lang.Object arg)
           
protected  void assertClassFound(org.pfsw.reflect.ClassInfo<T> classInfo)
           
protected  void assertInstanceCreation(org.pfsw.reflect.ClassInfo<T> classInfo)
           
protected  void assertValidType(org.pfsw.reflect.ClassInfo<T> classInfo)
           
 java.lang.Class<T>[] 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.
protected  java.util.List<java.lang.Class<T>> collectClasses()
          Returns all classes that are currently in this registry.
protected  java.util.List<java.lang.String> collectNames()
          Returns all class names that are currently in this registry.
protected  org.pfsw.reflect.ClassInfo<T> get(java.lang.Object key)
           
 java.lang.Class<T> getClass(java.lang.String key)
          Returns the class which is registered under the given key.
 org.pfsw.reflect.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.
protected  java.lang.Class<T> getEntryType()
           
 org.pfsw.reflect.ClassInfo<T> getFirst()
          Returns the first class info object of null if the registry is empty.
protected  void handleException(java.lang.Exception ex)
           
protected  void illegalArgumentException(java.lang.String methodName, java.lang.String argName)
           
 boolean isEmpty()
           
protected  boolean isTyped()
           
 boolean isValidType(java.lang.Class<?> type)
          Returns true if the given type is compatible to the underlying entry type.
 java.lang.String[] keys()
          Returns all keys known in this registry.
 T newInstance(java.lang.String key)
          Returns a new instance of the class which is registered under the given key.
 void put(java.lang.String key, java.lang.Class<T> aClass)
          Registers the given class under the specified key.
protected  void put(java.lang.String key, org.pfsw.reflect.ClassInfo<T> classInfo)
           
 void put(java.lang.String key, java.lang.String className)
          Registers the class with the given name under the specified key.
 boolean register(java.lang.String key, java.lang.Class<T> aClass)
          Registers the class under the specified key.
 boolean register(java.lang.String key, java.lang.String className)
          Registers the class with the given name under the specified key.
protected  java.util.Map<java.lang.String,org.pfsw.reflect.ClassInfo<T>> registry()
           
protected  void registry(java.util.Map<java.lang.String,org.pfsw.reflect.ClassInfo<T>> newValue)
           
 boolean remove(java.lang.Object key)
          Removes the entry in the registry which is defined by the given key.
protected  void setEntryType(java.lang.Class<T> newValue)
           
 int size()
           
protected  void validate(org.pfsw.reflect.ClassInfo<T> classInfo)
           
 org.pfsw.reflect.ClassInfo<T>[] values()
          Returns all class info objects that are currently in this registry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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.String 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.String 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.String 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.String 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.String 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.String 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 org.pfsw.reflect.ClassInfo<T>[] values()
Returns all class info objects that are currently in this registry.


getFirst

public org.pfsw.reflect.ClassInfo<T> getFirst()
Returns the first class info object of null if the registry is empty.


classes

public java.lang.Class<T>[] 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 org.pfsw.reflect.ClassInfo<T> getClassInfo(java.lang.String key)
Returns the class information object stored under the given key or null if nothing is found.


isValidType

public boolean isValidType(java.lang.Class<?> type)
Returns true if the given type is compatible to the underlying entry type. If no underlying entry type exists all types are assumed valid and true will be returned.

Parameters:
type - The type to be checked.

size

public int size()

isEmpty

public boolean isEmpty()

get

protected org.pfsw.reflect.ClassInfo<T> get(java.lang.Object key)

put

protected void put(java.lang.String key,
                   org.pfsw.reflect.ClassInfo<T> classInfo)
            throws ClassRegistryException
Throws:
ClassRegistryException

validate

protected void validate(org.pfsw.reflect.ClassInfo<T> classInfo)
                 throws ClassRegistryException
Throws:
ClassRegistryException

assertClassFound

protected void assertClassFound(org.pfsw.reflect.ClassInfo<T> classInfo)
                         throws ClassRegistryException
Throws:
ClassRegistryException

assertValidType

protected void assertValidType(org.pfsw.reflect.ClassInfo<T> classInfo)
                        throws ClassRegistryException
Throws:
ClassRegistryException

assertInstanceCreation

protected void assertInstanceCreation(org.pfsw.reflect.ClassInfo<T> classInfo)
                               throws ClassRegistryException
Throws:
ClassRegistryException

isTyped

protected boolean isTyped()

assertArgNotNull

protected void assertArgNotNull(java.lang.String methodName,
                                java.lang.String argName,
                                java.lang.Object arg)

illegalArgumentException

protected void illegalArgumentException(java.lang.String methodName,
                                        java.lang.String argName)

collectNames

protected java.util.List<java.lang.String> collectNames()
Returns all class names that are currently in this registry.


collectClasses

protected java.util.List<java.lang.Class<T>> collectClasses()
Returns all classes that are currently in this registry.


handleException

protected void handleException(java.lang.Exception ex)

getEntryType

protected java.lang.Class<T> getEntryType()

setEntryType

protected void setEntryType(java.lang.Class<T> newValue)

registry

protected java.util.Map<java.lang.String,org.pfsw.reflect.ClassInfo<T>> registry()

registry

protected void registry(java.util.Map<java.lang.String,org.pfsw.reflect.ClassInfo<T>> newValue)