public class ClassInfo<T>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.Object[] |
EMPTY_OBJECT_ARRAY |
Constructor and Description |
---|
ClassInfo(java.lang.Class<T> aClass)
Initialize the new instance with a class.
|
ClassInfo(java.lang.Class<T> aClass,
boolean singleton)
Initialize the new instance with a class.
|
ClassInfo(java.lang.String className)
Initialize the new instance with a class name.
|
ClassInfo(java.lang.String className,
boolean singleton)
Initialize the new instance with a class name and a flag if it is a
singleton.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
className() |
protected void |
className(java.lang.String newValue) |
protected java.lang.Class<T> |
classObject() |
protected void |
classObject(java.lang.Class<T> newValue) |
T |
createInstance()
Returns a new instance of the class or null in any case of error.
|
static <T> ClassInfo<T> |
createSingleton(T instance)
Creates a new instance with a singleton.
|
java.lang.String |
getClassName()
Returns the name of the class, this object represents.
|
java.lang.Class<T> |
getClassObject()
Returns the the class object.
|
T |
getInstance()
Returns either a new instance of the underlying class or always the
identical instance if it is defined to be a singleton.
|
protected T |
getSoleInstance() |
protected void |
handleException(java.lang.Exception exception) |
protected void |
initClassObject() |
boolean |
isAssignableFrom(java.lang.Class<?> type)
Determines if the class or interface represented by this ClassInfo object is
either the same as, or is a superclass or superinterface of, the class
or interface represented by the specified Class parameter.
|
boolean |
isAssignableTo(java.lang.Class<?> type)
Determines if the class or interface represented by the specified class parameter is
either the same as, or is a superclass or super interface of, the class
or interface represented by this ClassInfo object.
|
boolean |
isInstance(java.lang.Object object)
Determines if the specified Object is assignment-compatible with the object
represented by this ClassInfo.
|
boolean |
isSingleton() |
T[] |
newArray(int size)
Returns a new array of the type represented by this ClassInfo.
|
T |
newInstance()
Returns a new instance of the class.
|
void |
setClassName(java.lang.String className)
Set the name of the class this object should represent.
|
void |
setClassObject(java.lang.Class<T> aClass)
Set the class object.
|
void |
setIsSingleton(boolean newValue) |
protected void |
setSoleInstance(T newValue) |
java.lang.String |
toString() |
public ClassInfo(java.lang.String className)
className
- The name of the class the new object should represent.public ClassInfo(java.lang.String className, boolean singleton)
className
- The name of the class the new object should represent.singleton
- if true method getInstance() will return always the identical instancepublic ClassInfo(java.lang.Class<T> aClass)
aClass
- The class the new object should represent.public ClassInfo(java.lang.Class<T> aClass, boolean singleton)
aClass
- The class the new object should represent.singleton
- if true method getInstance() will return always the identical instancepublic static <T> ClassInfo<T> createSingleton(T instance)
instance
- The instance to be used as singleton (must not be null).java.lang.IllegalArgumentException
- If the given instance is null.public boolean isSingleton()
public void setIsSingleton(boolean newValue)
public boolean isAssignableFrom(java.lang.Class<?> type)
type
- the Class object to be checkedpublic boolean isAssignableTo(java.lang.Class<?> type)
type
- the Class object to be checkedpublic boolean isInstance(java.lang.Object object)
object
- the object to checkpublic java.lang.String getClassName()
public void setClassName(java.lang.String className)
className
- A fully qualified class namepublic java.lang.Class<T> getClassObject()
public void setClassObject(java.lang.Class<T> aClass)
aClass
- A classpublic T getInstance()
isSingleton()
,
setIsSingleton(boolean)
public T createInstance()
newInstance
.newInstance()
public T newInstance() throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException
java.lang.ClassNotFoundException
- If the class represented by this object can't be foundjava.lang.InstantiationException
- If no none-argument constructor is available/visiblejava.lang.IllegalAccessException
- If for security reasons the instance creation of this class prohibitedcreateInstance()
public T[] newArray(int size)
size
- The number of elements the new array whould have (must not be negative)java.lang.NullPointerException
- if the specified componentType parameter is nulljava.lang.IllegalArgumentException
- if componentType is Void.TYPEjava.lang.NegativeArraySizeException
- if the specified length is negativepublic java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
protected void initClassObject()
protected void handleException(java.lang.Exception exception)
protected java.lang.String className()
protected void className(java.lang.String newValue)
protected java.lang.Class<T> classObject()
protected void classObject(java.lang.Class<T> newValue)
protected T getSoleInstance()
protected void setSoleInstance(T newValue)