org.osesb.utilities.language
Class ClassUtilities

java.lang.Object
  extended by org.osesb.utilities.language.ClassUtilities

public final class ClassUtilities
extends java.lang.Object

This Class contains utilities for handling files.

Since:
Version .9

Field Summary
protected static org.apache.commons.logging.Log log
          The logging implementation for this class.
 
Constructor Summary
ClassUtilities()
           
 
Method Summary
static java.lang.Class getApplicationAncestor(java.lang.Class theClass)
          Returns the ancestor of the specified Class immediately below java.lang.Object.
static java.lang.String getApplicationAncestor(java.lang.String className)
          Returns the ancestor of the specified Class immediately below java.lang.Object.
static java.lang.Class getClass(java.lang.String className)
          Returns the specified Class.
static java.lang.reflect.Constructor getConstructor(java.lang.String theClassName, java.lang.Class[] constructorSignature)
          Returns the Constructor with the specified signature for the named Class.
static java.lang.reflect.Constructor getConstructor(java.lang.String theClassName, java.lang.Class[] constructorSignature, java.lang.Class ancestorClass, java.lang.Class interfaceClass)
          Returns the Constructor with the specified signature for the named Class with optional checks to insure that the Class extends another Class or implements an Interface.
static java.lang.reflect.Constructor[] getConstructors(java.lang.String theClassName)
          Gets an array of Constructor(s) for the named Class.
static java.lang.reflect.Constructor[] getConstructors(java.lang.String theClassName, java.lang.Class ancestorClass, java.lang.Class interfaceClass)
          Gets an array of Constructor(s) for the named Class with optional checks to insure that the Class extends another Class or implements an Interface.
static java.lang.String getPackageName(java.lang.Class theClass)
          returns the package name for the specified Class.
static boolean implementsInterface(java.lang.Class theClass, java.lang.Class theInterface)
          Checks of a Class implements the specified interface.
static boolean implementsInterface(java.lang.String theClassName, java.lang.String theInterfaceName)
          Checks of a Class implements the specified interface.
static boolean isdescendantOf(java.lang.Class descendantClass, java.lang.Class ancestorClass)
          Checks of one Class is a descendant of another Class.
static boolean isdescendantOf(java.lang.String descendantClassName, java.lang.Class ancestorClass)
          Checks of one Class is a descendant of another Class.
static boolean isdescendantOf(java.lang.String descendantClassName, java.lang.String ancestorClassName)
          Checks of one Class is a descendant of another Class.
static void main(java.lang.String[] args)
          Main method for testing and sandboxing.
static java.lang.Object newInstance(java.lang.String theClassName, java.lang.Object[] constructorArguments)
          Create a newInstance of the specified Class using the Constructor signature that matches the constructorArguments.
static java.lang.Object newInstance(java.lang.String theClassName, java.lang.Object[] constructorArguments, java.lang.Class[] constructorSignature)
          Create a newInstance of the specified Class using the Constructor signature that matches the constructorArguments.
static java.lang.Object newInstance(java.lang.String theClassName, java.lang.Object[] constructorArguments, java.lang.Class[] constructorSignature, java.lang.Class ancestorClass, java.lang.Class interfaceClass)
          Create a newInstance of the specified Class using the Constructor specified by constructorSignature, passing it constructorArguments with optional checks to insure that the Class extends another Class or implements an Interface.
static java.lang.Object newInstance(java.lang.String theClassName, java.lang.Object[] constructorArguments, java.lang.Class ancestorClass, java.lang.Class interfaceClass)
          Create a newInstance of the specified Class using the Constructor signature that matches the constructor Arguments with optional checks to insure that the Class extends another Class or implements an Interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log
The logging implementation for this class.

Constructor Detail

ClassUtilities

public ClassUtilities()
Method Detail

getClass

public static java.lang.Class getClass(java.lang.String className)
                                throws java.lang.Exception
Returns the specified Class.

Parameters:
className - The name of the Class to get.
Returns:
The specified Class.
Throws:
java.lang.Exception - if the Class cannot be found.

getPackageName

public static java.lang.String getPackageName(java.lang.Class theClass)
returns the package name for the specified Class.

Parameters:
theClass - The Class to get the package name of.
Returns:
The package name for the Class.

getApplicationAncestor

public static java.lang.String getApplicationAncestor(java.lang.String className)
Returns the ancestor of the specified Class immediately below java.lang.Object.

Parameters:
className - The name of the Class to get the ancestor of.
Returns:
The ancestor className of theClass that is immediately below java.lang.Object. Note that this will be theClassName if theClass has no ancestor besides java.lang.Object.

getApplicationAncestor

public static java.lang.Class getApplicationAncestor(java.lang.Class theClass)
Returns the ancestor of the specified Class immediately below java.lang.Object.

Parameters:
theClass - The Class to get the ancestor of.
Returns:
The ancestor Class of theClass that is immediately below java.lang.Object. Note that this will be theClass if theClass has no ancestor besides java.lang.Object.

isdescendantOf

public static boolean isdescendantOf(java.lang.String descendantClassName,
                                     java.lang.Class ancestorClass)
Checks of one Class is a descendant of another Class.

Parameters:
descendantClassName - The name of the Class to check.
ancestorClass - The Class to check against.
Returns:
true, if descendantClass is a descendant of ancestorClass.

isdescendantOf

public static boolean isdescendantOf(java.lang.String descendantClassName,
                                     java.lang.String ancestorClassName)
Checks of one Class is a descendant of another Class.

Parameters:
descendantClassName - The name of the Class to check.
ancestorClassName - The name of the Class to check against.
Returns:
true, if descendantClass is a descendant of ancestorClass.

isdescendantOf

public static boolean isdescendantOf(java.lang.Class descendantClass,
                                     java.lang.Class ancestorClass)
Checks of one Class is a descendant of another Class.

Parameters:
descendantClass - The Class to check.
ancestorClass - The Class to check against.
Returns:
true, if 'descendantClass' is a descendant of 'ancestorClass'.

implementsInterface

public static boolean implementsInterface(java.lang.String theClassName,
                                          java.lang.String theInterfaceName)
Checks of a Class implements the specified interface.

Parameters:
theClassName - The name of the Class to check.
theInterfaceName - The name of the Interface Class to check against.
Returns:
true, if the Class implements the Interface.

implementsInterface

public static boolean implementsInterface(java.lang.Class theClass,
                                          java.lang.Class theInterface)
Checks of a Class implements the specified interface.

Parameters:
theClass - The Class to check.
theInterface - The Interface Class to check against.
Returns:
true, if 'theClass' implements 'theInterface'.

newInstance

public static java.lang.Object newInstance(java.lang.String theClassName,
                                           java.lang.Object[] constructorArguments)
                                    throws java.lang.Exception
Create a newInstance of the specified Class using the Constructor signature that matches the constructorArguments.

Parameters:
theClassName - The name of the Class to get a newInstance of.
constructorArguments - The arguments for the Constructor to use as an Object[]. If omitted, a no argument constructor is used.
Returns:
a new instance of theClass.
Throws:
java.lang.Exception - if the Class cannot be instantiated.

newInstance

public static java.lang.Object newInstance(java.lang.String theClassName,
                                           java.lang.Object[] constructorArguments,
                                           java.lang.Class[] constructorSignature)
                                    throws java.lang.Exception
Create a newInstance of the specified Class using the Constructor signature that matches the constructorArguments.

Parameters:
theClassName - The name of the Class to get a newInstance of.
constructorArguments - The arguments for the Constructor to use as an Object[]. If omitted, a no argument constructor is used.
constructorSignature - The parameter types for the Constructor as a Class[]. If omitted, the constructorSignature is derived from the constructorArguments.
Returns:
a new instance of theClass.
Throws:
java.lang.Exception - if the Class cannot be instantiated.

newInstance

public static java.lang.Object newInstance(java.lang.String theClassName,
                                           java.lang.Object[] constructorArguments,
                                           java.lang.Class ancestorClass,
                                           java.lang.Class interfaceClass)
                                    throws java.lang.Exception
Create a newInstance of the specified Class using the Constructor signature that matches the constructor Arguments with optional checks to insure that the Class extends another Class or implements an Interface.

Parameters:
theClassName - The name of the Class to get a newInstance of.
constructorArguments - The arguments for the Constructor to use as an Object[]. If omitted, a no argument constructor is used.
ancestorClass - If specified, checks that theClass is a descendant of ancestorClass.
interfaceClass - If specified, checks that theClass implements interfaceClass.
Returns:
a new instance of theClass.
Throws:
java.lang.Exception - if the Class cannot be instantiated.

newInstance

public static java.lang.Object newInstance(java.lang.String theClassName,
                                           java.lang.Object[] constructorArguments,
                                           java.lang.Class[] constructorSignature,
                                           java.lang.Class ancestorClass,
                                           java.lang.Class interfaceClass)
                                    throws java.lang.Exception
Create a newInstance of the specified Class using the Constructor specified by constructorSignature, passing it constructorArguments with optional checks to insure that the Class extends another Class or implements an Interface.

Parameters:
theClassName - The name of the Class to get a newInstance of.
constructorArguments - The arguments for the Constructor to use as an Object[]. If omitted, a no argument constructor is used.
constructorSignature - The parameter types for the Constructor as a Class[]. If omitted, the constructorSignature is derived from the constructorArguments.
ancestorClass - If specified, checks that theClass is a descendant of ancestorClass.
interfaceClass - If specified, checks that theClass implements interfaceClass.
Returns:
a new instance of theClass.
Throws:
java.lang.Exception - if the Class cannot be instantiated or if ancestor or interface implementation tests fail.

getConstructor

public static java.lang.reflect.Constructor getConstructor(java.lang.String theClassName,
                                                           java.lang.Class[] constructorSignature)
                                                    throws java.lang.Exception
Returns the Constructor with the specified signature for the named Class.

Parameters:
theClassName - The name of the Class to get a the Constructor for.
constructorSignature - The constructor signature as a Class[]. If omitted, this method looks for a no-argument constructor.
Throws:
java.lang.Exception - if the Class cannot be loaded or if the constructor cannot be found.

getConstructor

public static java.lang.reflect.Constructor getConstructor(java.lang.String theClassName,
                                                           java.lang.Class[] constructorSignature,
                                                           java.lang.Class ancestorClass,
                                                           java.lang.Class interfaceClass)
                                                    throws java.lang.Exception
Returns the Constructor with the specified signature for the named Class with optional checks to insure that the Class extends another Class or implements an Interface.

Parameters:
theClassName - The name of the Class to get the Constructor for.
constructorSignature - The constructor signature as a Class[]. If omitted, this method looks for a no-argument constructor.
ancestorClass - If specified, checks that theClass is a descendant of ancestorClass.
interfaceClass - If specified, checks that theClass implements interfaceClass.
Returns:
The Constructor with the specified signature for the named Class.
Throws:
java.lang.Exception - if the Class cannot be loaded, the constructor cannot be found, or if ancestor or interface implementation tests fail.

getConstructors

public static java.lang.reflect.Constructor[] getConstructors(java.lang.String theClassName)
                                                       throws java.lang.Exception
Gets an array of Constructor(s) for the named Class.

Parameters:
theClassName - The name of the Class to get the Constructor(s) for.
Returns:
The Constructor with the specified signature for the named Class.
Throws:
java.lang.Exception - if the Class cannot be loaded, the constructor cannot be found, or if ancestor or interface implementation tests fail.

getConstructors

public static java.lang.reflect.Constructor[] getConstructors(java.lang.String theClassName,
                                                              java.lang.Class ancestorClass,
                                                              java.lang.Class interfaceClass)
                                                       throws java.lang.Exception
Gets an array of Constructor(s) for the named Class with optional checks to insure that the Class extends another Class or implements an Interface.

Parameters:
theClassName - The name of the Class to get the Constructor(s) for.
ancestorClass - If specified, checks that theClass is a descendant of another ancestorClass.
interfaceClass - If specified, checks that theClass implements interfaceClass.
Returns:
The Constructor with the specified signature for the named Class.
Throws:
java.lang.Exception - if the Class cannot be loaded, the constructor cannot be found, or if ancestor or interface implementation tests fail.

main

public static void main(java.lang.String[] args)
Main method for testing and sandboxing.

Parameters:
args - commandline arguments