org.apache.fulcrum.yaafi.framework.reflection
Class Clazz

java.lang.Object
  extended by org.apache.fulcrum.yaafi.framework.reflection.Clazz

public class Clazz
extends java.lang.Object

Helper clazz to do a little bit of reflection magic.

Author:
Siegfried Goeschl

Constructor Summary
Clazz()
           
 
Method Summary
static java.util.List getAllInterfaces(java.lang.Class cls)
          Gets a List of all interfaces implemented by the given class and its superclasses.
static java.lang.Class getClazz(java.lang.ClassLoader classLoader, java.lang.String clazzName)
          Loads a class with the given name.
static boolean hasClazz(java.lang.ClassLoader classLoader, java.lang.String clazzName)
          Determine if the class can be loaded.
static java.lang.Object invoke(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] signature, java.lang.Object[] args)
          Invokes a static method on a class.
static java.lang.Object invoke(java.lang.Object instance, java.lang.String methodName, java.lang.Class[] signature, java.lang.Object[] args)
          Invokes a given method on the instance.
static java.lang.Object newInstance(java.lang.Class clazz, java.lang.Class[] signature, java.lang.Object[] args)
          Creates a new instance of the class
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Clazz

public Clazz()
Method Detail

hasClazz

public static boolean hasClazz(java.lang.ClassLoader classLoader,
                               java.lang.String clazzName)
Determine if the class can be loaded.

Parameters:
classLoader - the classloader to be used
clazzName - the name of the class to be loaded
Returns:
true if the class was found

getClazz

public static java.lang.Class getClazz(java.lang.ClassLoader classLoader,
                                       java.lang.String clazzName)
                                throws java.lang.ClassNotFoundException
Loads a class with the given name.

Parameters:
classLoader - the class loader to be used
clazzName - the name of the clazz to be loaded
Returns:
the loaded class
Throws:
java.lang.ClassNotFoundException - the class was nout found

newInstance

public static java.lang.Object newInstance(java.lang.Class clazz,
                                           java.lang.Class[] signature,
                                           java.lang.Object[] args)
                                    throws java.lang.NoSuchMethodException,
                                           java.lang.reflect.InvocationTargetException,
                                           java.lang.InstantiationException,
                                           java.lang.IllegalAccessException
Creates a new instance of the class

Parameters:
clazz - the class to be instantiated
signature - the signature of the constructor
args - the arguments to be passed
Returns:
the newly created instance
Throws:
java.lang.NoSuchMethodException - the method was not found
java.lang.reflect.InvocationTargetException - an exception was thrown in the constructor
java.lang.InstantiationException - the target class could not be instantiated
java.lang.IllegalAccessException - an field couldn't be accessed

invoke

public static java.lang.Object invoke(java.lang.Object instance,
                                      java.lang.String methodName,
                                      java.lang.Class[] signature,
                                      java.lang.Object[] args)
                               throws java.lang.NoSuchMethodException,
                                      java.lang.reflect.InvocationTargetException,
                                      java.lang.IllegalAccessException
Invokes a given method on the instance.

Parameters:
instance - the instance
methodName - the name of the method to be invoked
signature - the signature of the method
args - the arguments for the method invocation
Returns:
the result of the method invocation
Throws:
java.lang.NoSuchMethodException - the method was not found
java.lang.reflect.InvocationTargetException - an exception was thrown in the constructor
java.lang.IllegalAccessException - an field couldn't be accessed

invoke

public static java.lang.Object invoke(java.lang.Class clazz,
                                      java.lang.String methodName,
                                      java.lang.Class[] signature,
                                      java.lang.Object[] args)
                               throws java.lang.NoSuchMethodException,
                                      java.lang.reflect.InvocationTargetException,
                                      java.lang.IllegalAccessException
Invokes a static method on a class.

Parameters:
clazz - the class instance to work on
methodName - the name of the method to be invoked
signature - the signature of the method
args - the arguments for the method invocation
Returns:
the result of the method invocation
Throws:
java.lang.NoSuchMethodException - the method was not found
java.lang.reflect.InvocationTargetException - an exception was thrown in the constructor
java.lang.IllegalAccessException - an field couldn't be accessed

getAllInterfaces

public static java.util.List getAllInterfaces(java.lang.Class cls)

Gets a List of all interfaces implemented by the given class and its superclasses.

The order is determined by looking through each interface in turn as declared in the source file and following its hierarchy up. Then each superclass is considered in the same way. Later duplicates are ignored, so the order is maintained.

Parameters:
cls - the class to look up, may be null
Returns:
the List of interfaces in order, null if null input


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.