public class ClassRegistry<T>
extends java.lang.Object
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
protected void |
assertArgNotNull(java.lang.String methodName,
java.lang.String argName,
java.lang.Object arg) |
protected void |
assertClassFound(ClassInfo<T> classInfo) |
protected void |
assertInstanceCreation(ClassInfo classInfo) |
protected void |
assertValidType(ClassInfo classInfo) |
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.
|
protected java.util.List |
collect(boolean collectNames)
Returns all class objects or all class names that are currently
in this registry.
|
protected 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.
|
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() |
ClassInfo |
getFirst()
Returns the first class info object of null if the registry is empty.
|
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,
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,ClassInfo<T>> |
registry() |
protected void |
registry(java.util.Map<java.lang.String,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(ClassInfo<T> classInfo) |
ClassInfo[] |
values()
Returns all class info objects that are currently in this registry.
|
public ClassRegistry()
public ClassRegistry(java.lang.Class<T> typeOfRegisteredClasses)
typeOfRegisteredClasses
- The type to which the classes that can be
registered must be compatible topublic java.lang.String getClassName(java.lang.Object key)
key
- The key under which the class is registeredpublic java.lang.Class<T> getClass(java.lang.String key)
key
- The key under which the class is registeredpublic T newInstance(java.lang.String key)
key
- The key under which the class is registered.public boolean register(java.lang.String key, java.lang.String className)
key
- The key under which the class is registeredclassName
- The fully qualified name of the classpublic void put(java.lang.String key, java.lang.String className) throws ClassRegistryException
key
- The key under which the class is registered.className
- The fully qualified name of the class.ClassRegistryException
- If the class can't be found or if it is of
the wrong type or can't be instantiated.public boolean register(java.lang.String key, java.lang.Class<T> aClass)
key
- The key under which the class is registeredaClass
- The class to be registeredpublic void put(java.lang.String key, java.lang.Class<T> aClass) throws ClassRegistryException
key
- The key under which the class is registeredaClass
- The class to be registeredClassRegistryException
- If the class is of the wrong type or
can't be instantiatedpublic boolean remove(java.lang.Object key)
public java.lang.String[] keys()
public ClassInfo[] values()
public ClassInfo getFirst()
public java.lang.Class[] classes()
public java.lang.String[] classNames()
public ClassInfo<T> getClassInfo(java.lang.String key)
public boolean isValidType(java.lang.Class<?> type)
type
- The type to be checked.public int size()
public boolean isEmpty()
protected void put(java.lang.String key, ClassInfo<T> classInfo) throws ClassRegistryException
ClassRegistryException
protected void validate(ClassInfo<T> classInfo) throws ClassRegistryException
ClassRegistryException
protected void assertClassFound(ClassInfo<T> classInfo) throws ClassRegistryException
ClassRegistryException
protected void assertValidType(ClassInfo classInfo) throws ClassRegistryException
ClassRegistryException
protected void assertInstanceCreation(ClassInfo classInfo) throws ClassRegistryException
ClassRegistryException
protected boolean isTyped()
protected void assertArgNotNull(java.lang.String methodName, java.lang.String argName, java.lang.Object arg)
protected void illegalArgumentException(java.lang.String methodName, java.lang.String argName)
protected java.util.List collect(boolean collectNames)
collectNames
- If true, the names are returned, otherwise the Class objectsprotected java.lang.Class<T> getEntryType()
protected void setEntryType(java.lang.Class<T> newValue)