org.pfsw.reflect
Class ClassInfo<T>

java.lang.Object
  extended by org.pfsw.reflect.ClassInfo<T>

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

Contains the name of a class and the class itself. It can create new instances.


Field Summary
static java.lang.Object[] EMPTY_OBJECT_ARRAY
           
 
Constructor Summary
ClassInfo(java.lang.Class aClass)
          Initialize the new instance with a class.
ClassInfo(java.lang.Class 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.
 
Method Summary
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.
 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 superinterface 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_OBJECT_ARRAY

public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
Constructor Detail

ClassInfo

public ClassInfo(java.lang.String className)
Initialize the new instance with a class name.

Parameters:
className - The name of the class the new object should represent.

ClassInfo

public ClassInfo(java.lang.String className,
                 boolean singleton)
Initialize the new instance with a class name and a flag if it is a singleton.

Parameters:
className - The name of the class the new object should represent.
singleton - if true method getInstance() will return always the identical instance

ClassInfo

public ClassInfo(java.lang.Class aClass)
Initialize the new instance with a class.

Parameters:
aClass - The class the new object should represent.

ClassInfo

public ClassInfo(java.lang.Class aClass,
                 boolean singleton)
Initialize the new instance with a class.

Parameters:
aClass - The class the new object should represent.
singleton - if true method getInstance() will return always the identical instance
Method Detail

className

protected java.lang.String className()

className

protected void className(java.lang.String newValue)

classObject

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

classObject

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

isSingleton

public boolean isSingleton()

setIsSingleton

public void setIsSingleton(boolean newValue)

getSoleInstance

protected T getSoleInstance()

setSoleInstance

protected void setSoleInstance(T newValue)

isAssignableFrom

public 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. It returns true if so; otherwise it returns false. If this ClassInfo object represents a primitive type, this method returns true if the specified Class parameter is exactly this Class object; otherwise it returns false.

Parameters:
type - the Class object to be checked

isAssignableTo

public 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 superinterface of, the class or interface represented by this ClassInfo object. It returns true if so; otherwise it returns false. If specified class parameter is a primitive type, this method returns true if this ClassInfo object rerpresents exactly the same Class object; otherwise it returns false.

Parameters:
type - the Class object to be checked

isInstance

public boolean isInstance(java.lang.Object object)
Determines if the specified Object is assignment-compatible with the object represented by this ClassInfo. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this ClassInfo object without raising a ClassCastException. It returns false otherwise.

Parameters:
object - the object to check

getClassName

public java.lang.String getClassName()
Returns the name of the class, this object represents.


setClassName

public void setClassName(java.lang.String className)
Set the name of the class this object should represent. Additionally the corresponding class object is set to null.

Parameters:
className - A fully qualified class name

getClassObject

public java.lang.Class<T> getClassObject()
Returns the the class object. If the class can't be found by the class loader, null will be returned.


setClassObject

public void setClassObject(java.lang.Class<T> aClass)
Set the class object. The name will be set automatically to the given class's name.

Parameters:
aClass - A class

getInstance

public T getInstance()
Returns either a new instance of the underlying class or always the identical instance if it is defined to be a singleton.

Returns:
An instance of the underlying class
See Also:
isSingleton(), setIsSingleton(boolean)

createInstance

public T createInstance()
Returns a new instance of the class or null in any case of error. If more detailed information about a failed instance creation is necessary, the better method is newInstance.

See Also:
newInstance()

newInstance

public T newInstance()
              throws java.lang.ClassNotFoundException,
                     java.lang.InstantiationException,
                     java.lang.IllegalAccessException
Returns a new instance of the class.

Throws:
java.lang.ClassNotFoundException - If the class represented by this object can't be found
java.lang.InstantiationException - If no none-argument constructor is available/visible
java.lang.IllegalAccessException - If for security reasons the instance creation of this class prohibited
See Also:
createInstance()

newArray

public T[] newArray(int size)
Returns a new array of the type represented by this ClassInfo. Returns Object[0] if this ClassInfo does not represent a valid and loadable class.

Parameters:
size - The number of elements the new array whould have (must not be negative)
Returns:
the new array
Throws:
java.lang.NullPointerException - if the specified componentType parameter is null
java.lang.IllegalArgumentException - if componentType is Void.TYPE
java.lang.NegativeArraySizeException - if the specified length is negative

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

initClassObject

protected void initClassObject()

handleException

protected void handleException(java.lang.Exception exception)