org.yestech.lib.lang
Class Clazz

java.lang.Object
  extended by org.yestech.lib.lang.Clazz

public final class Clazz
extends java.lang.Object

Utility Class for Dealing with Class and Reflection.


Method Summary
static java.lang.Class getClass(java.lang.String classFqn)
          Looks up and retrieves an Initialized class.
static java.lang.reflect.Constructor getConstructor(java.lang.Class clazz, java.lang.Class[] ctorTypes)
          Returns a Cached Constructor associated with the Class.
static java.lang.reflect.Method getMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] argTypes)
          Returns a Cached Method associated by the methodName.
static java.lang.reflect.Method getMethod(java.lang.String classFQN, java.lang.String methodName, java.lang.Class[] params)
          Returns the Method that is a associated with the FQN class.
static
<I> I
instantiateClass(java.lang.Class clazz)
          Instantiates a Class from a Class.
static
<I> I
instantiateClass(java.lang.String classFQN)
          Instantiates a Class from a Fully Qualified Name.
static java.lang.Object invoke(java.lang.reflect.Method method, java.lang.Object[] methodArgs, java.lang.Object instance)
          Dynamically invokes a method using the supplied params as the parameters for the call.
static java.lang.Object invoke(java.lang.String classFQN, java.lang.String methodName, java.lang.Class[] params, java.lang.Object[] methodArgs, java.lang.Object instance)
          Dynamically invokes a method using the supplied params as the parameters for the call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getClass

public static java.lang.Class getClass(java.lang.String classFqn)
Looks up and retrieves an Initialized class. This means that the class with only load it's static block!

Parameters:
classFqn - FQN of the class to initialize
Returns:
The initialized Class
Throws:
java.lang.RuntimeException - If error happens Loading or Initializing

instantiateClass

public static <I> I instantiateClass(java.lang.String classFQN)
Instantiates a Class from a Fully Qualified Name. It assumes that there is a default Constructor.

Parameters:
classFQN - FQN of the class to Instantiate
Returns:
The Instantiated Class
Throws:
java.lang.RuntimeException - If error happens Instantiating

instantiateClass

public static <I> I instantiateClass(java.lang.Class clazz)
Instantiates a Class from a Class. It assumes that there is a default Constructor.

Parameters:
clazz - Class to Instantiate
Returns:
The Instantiated Class
Throws:
java.lang.RuntimeException - If error happens Instantiating

getMethod

public static java.lang.reflect.Method getMethod(java.lang.String classFQN,
                                                 java.lang.String methodName,
                                                 java.lang.Class[] params)
Returns the Method that is a associated with the FQN class.

Parameters:
classFQN - The FQN of the class method is a member of
methodName - The method name
params - Array of Class the are in the method parameter list
Returns:
the Method found
Throws:
java.lang.RuntimeException - If error happens Loading Method

invoke

public static java.lang.Object invoke(java.lang.reflect.Method method,
                                      java.lang.Object[] methodArgs,
                                      java.lang.Object instance)
Dynamically invokes a method using the supplied params as the parameters for the call. If the method being invoked is static, the instance should be null.

Parameters:
method - Method to invoke
methodArgs - Parameters that will be passed to the method
instance - Instance of the Onject to invoke method on. (null if method is static)
Returns:
The result of the method call
Throws:
java.lang.RuntimeException - If error happens Invoking Method

invoke

public static java.lang.Object invoke(java.lang.String classFQN,
                                      java.lang.String methodName,
                                      java.lang.Class[] params,
                                      java.lang.Object[] methodArgs,
                                      java.lang.Object instance)
Dynamically invokes a method using the supplied params as the parameters for the call. If the method being invoked is static, the instance should be null.

Parameters:
classFQN - The FQN of the class method is a member of
methodName - The method name
params - Array of Class the are in the method parameter list
methodArgs - Parameters that will be passed to the method
instance - Instance of the Onject to invoke method on. (null if method is static)
Returns:
The result of the method call
Throws:
java.lang.RuntimeException - If error happens Invoking Method

getMethod

public static java.lang.reflect.Method getMethod(java.lang.Class clazz,
                                                 java.lang.String methodName,
                                                 java.lang.Class[] argTypes)
Returns a Cached Method associated by the methodName. If the method isn't in the cache a new one is created and added to the cache. There will ALWAYS be only one method instance in the cache.

Parameters:
clazz - Class method associated with
methodName - Name of the method
argTypes - Class Array of argument types in method signature
Returns:
The Method

getConstructor

public static java.lang.reflect.Constructor getConstructor(java.lang.Class clazz,
                                                           java.lang.Class[] ctorTypes)
Returns a Cached Constructor associated with the Class. If the Constructor isn't in the cache a new one is created and added to the cache. There will ALWAYS be only one Constructor instance in the cache.

Parameters:
clazz - Class Constructor associated with
ctorTypes - Class Array of argument types in Constructors signature
Returns:
The Constructor


Copyright © 2009 YES Technology Association. All Rights Reserved.