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

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

public class Clazz
extends Object

Helper clazz to do a little bit of reflection magic.

Author:
Siegfried Goeschl

Constructor Summary
Clazz()
           
 
Method Summary
static List getAllInterfaces(Class cls)
          Gets a List of all interfaces implemented by the given class and its superclasses.
static Class getClazz(ClassLoader classLoader, String clazzName)
          Loads a class with the given name.
static boolean hasClazz(ClassLoader classLoader, String clazzName)
          Determine if the class can be loaded.
static Object invoke(Class clazz, String methodName, Class[] signature, Object[] args)
          Invokes a static method on a class.
static Object invoke(Object instance, String methodName, Class[] signature, Object[] args)
          Invokes a given method on the instance.
static Object newInstance(Class clazz, Class[] signature, 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(ClassLoader classLoader,
                               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 Class getClazz(ClassLoader classLoader,
                             String clazzName)
                      throws 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:
ClassNotFoundException - the class was nout found

newInstance

public static Object newInstance(Class clazz,
                                 Class[] signature,
                                 Object[] args)
                          throws NoSuchMethodException,
                                 InvocationTargetException,
                                 InstantiationException,
                                 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:
NoSuchMethodException - the method was not found
InvocationTargetException - an exception was thrown in the constructor
InstantiationException - the target class could not be instantiated
IllegalAccessException - an field couldn't be accessed

invoke

public static Object invoke(Object instance,
                            String methodName,
                            Class[] signature,
                            Object[] args)
                     throws NoSuchMethodException,
                            InvocationTargetException,
                            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:
NoSuchMethodException - the method was not found
InvocationTargetException - an exception was thrown in the constructor
IllegalAccessException - an field couldn't be accessed

invoke

public static Object invoke(Class clazz,
                            String methodName,
                            Class[] signature,
                            Object[] args)
                     throws NoSuchMethodException,
                            InvocationTargetException,
                            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:
NoSuchMethodException - the method was not found
InvocationTargetException - an exception was thrown in the constructor
IllegalAccessException - an field couldn't be accessed

getAllInterfaces

public static List getAllInterfaces(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 © 2004-2012 The Apache Software Foundation. All Rights Reserved.