util
Class Reflection

java.lang.Object
  extended by util.Reflection

public class Reflection
extends Object

Helper methods for the package java.lang.reflect


Constructor Summary
Reflection()
           
 
Method Summary
static boolean containsAnnotation(String className, Class<? extends Annotation> annotationClass)
           
static Object createObject(String className)
          Creates an object of the given class, using the default constructor
static
<A extends Annotation>
A
getAnnotation(String className, Class<A> annotationClass)
           
static
<A extends Annotation>
A
getPackageAnnotation(String className, Class<A> annotationClass)
           
static Object invokeMethod(Object o, String methodName, Object[] params)
          Invokes a instance method (of any visibility) of a given object.
static Object invokeStaticMethod(String className, String methodName, Object[] params)
          Invokes a static method (of any visibility) of a given class.
static boolean packageContainsAnnotation(String className, Class<? extends Annotation> annotationClass)
          Tests whether the package a class belongs to contains a given annotation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reflection

public Reflection()
Method Detail

packageContainsAnnotation

public static boolean packageContainsAnnotation(String className,
                                                Class<? extends Annotation> annotationClass)
Tests whether the package a class belongs to contains a given annotation. Annotations in packages are not automatically added by the compiler to the classes belonging to the package.

Parameters:
className - the fully qualified name of the class
annotationClass - annotation in question
Returns:
true if the package to which the class belongs has been marked with the given annotation.

getPackageAnnotation

public static <A extends Annotation> A getPackageAnnotation(String className,
                                                            Class<A> annotationClass)

containsAnnotation

public static boolean containsAnnotation(String className,
                                         Class<? extends Annotation> annotationClass)

getAnnotation

public static <A extends Annotation> A getAnnotation(String className,
                                                     Class<A> annotationClass)

createObject

public static Object createObject(String className)
Creates an object of the given class, using the default constructor

Parameters:
className - the fully qualified name of the class
Returns:
an instance of the class

invokeMethod

public static Object invokeMethod(Object o,
                                  String methodName,
                                  Object[] params)
Invokes a instance method (of any visibility) of a given object. If there is more than one method with the given name in the class the instance belongs to, we invoke any of them in a non-deterministic fashion.

Parameters:
o - object in which to invoke the given method
methodName - the name of the method to invoke
params - actual parameters
Returns:
Object return value of callee

invokeStaticMethod

public static Object invokeStaticMethod(String className,
                                        String methodName,
                                        Object[] params)
Invokes a static method (of any visibility) of a given class. If there is more than one static method with the given name in the class, we invoke one of them in non-deterministic fashion.

Parameters:
className - the fully qualified name of the class
methodName - the name of the method to invoke
params - actual parameters
Returns:
Object return value of callee