com.ebasetech.ufs.utility
Class ReflectionUtil

java.lang.Object
  extended bycom.ebasetech.ufs.utility.ReflectionUtil

public class ReflectionUtil
extends java.lang.Object

Handy functions for dealing with reflection. Notably - access to their privates


Constructor Summary
ReflectionUtil()
           
 
Method Summary
static java.lang.reflect.Constructor findConstructor(java.lang.Class cls, java.lang.Class[] parameterTypes, boolean makeAccessible)
           
static java.lang.reflect.Field findField(java.lang.Class cls, java.lang.String fieldName, boolean makeAccessible)
           
static java.lang.reflect.Method findMethod(java.lang.Class cls, java.lang.String methodName, java.lang.Class[] parameterTypes, boolean makeAccessible)
           
static java.lang.Object instantiateConstructor(java.lang.reflect.Constructor constr, java.lang.Object[] arguments)
          make a new instance using the provided constructor.
static java.lang.Object instantiateConstructorAndCheckCast(java.lang.String clsname, java.lang.Class[] castTo)
          instantiate a class and check it can be cast into required interfaces/classes
static java.lang.Object instantiatePrivateConstructor(java.lang.Class cls, java.lang.Class[] parameterTypes, java.lang.Object[] arguments)
           
static java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object obj, java.lang.Object[] args)
           
static java.lang.Object invokePrivateMethod(java.lang.Object obj, java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Object[] args)
           
static void multiCast(java.lang.Class cls, java.lang.Class[] castTo)
          check that an instance of a class could be cast to a bunch of classes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtil

public ReflectionUtil()
Method Detail

findConstructor

public static java.lang.reflect.Constructor findConstructor(java.lang.Class cls,
                                                            java.lang.Class[] parameterTypes,
                                                            boolean makeAccessible)
                                                     throws java.lang.NoSuchMethodException
Throws:
java.lang.NoSuchMethodException

instantiateConstructor

public static java.lang.Object instantiateConstructor(java.lang.reflect.Constructor constr,
                                                      java.lang.Object[] arguments)
                                               throws java.lang.IllegalAccessException,
                                                      java.lang.reflect.InvocationTargetException,
                                                      java.lang.InstantiationException
make a new instance using the provided constructor.

Parameters:
constr - Constructor to use to instantiate
arguments - arguments for the constructor.
Returns:
ne instance
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException

instantiatePrivateConstructor

public static java.lang.Object instantiatePrivateConstructor(java.lang.Class cls,
                                                             java.lang.Class[] parameterTypes,
                                                             java.lang.Object[] arguments)
                                                      throws java.lang.NoSuchMethodException,
                                                             java.lang.IllegalAccessException,
                                                             java.lang.reflect.InvocationTargetException,
                                                             java.lang.InstantiationException
Throws:
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException

instantiateConstructorAndCheckCast

public static java.lang.Object instantiateConstructorAndCheckCast(java.lang.String clsname,
                                                                  java.lang.Class[] castTo)
                                                           throws java.lang.ClassNotFoundException,
                                                                  java.lang.IllegalAccessException,
                                                                  java.lang.InstantiationException
instantiate a class and check it can be cast into required interfaces/classes

Parameters:
clsname - the class to instantiate
castTo - the interfaces to check
Returns:
a new instance
Throws:
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException

multiCast

public static void multiCast(java.lang.Class cls,
                             java.lang.Class[] castTo)
check that an instance of a class could be cast to a bunch of classes

Parameters:
cls - the class to test
castTo - array of class to check
Throws:
java.lang.ClassCastException - is one of the casts fails

findMethod

public static java.lang.reflect.Method findMethod(java.lang.Class cls,
                                                  java.lang.String methodName,
                                                  java.lang.Class[] parameterTypes,
                                                  boolean makeAccessible)
                                           throws java.lang.NoSuchMethodException
Throws:
java.lang.NoSuchMethodException

invokeMethod

public static java.lang.Object invokeMethod(java.lang.reflect.Method method,
                                            java.lang.Object obj,
                                            java.lang.Object[] args)
                                     throws java.lang.IllegalAccessException,
                                            java.lang.reflect.InvocationTargetException
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

invokePrivateMethod

public static java.lang.Object invokePrivateMethod(java.lang.Object obj,
                                                   java.lang.String methodName,
                                                   java.lang.Class[] parameterTypes,
                                                   java.lang.Object[] args)
                                            throws java.lang.IllegalAccessException,
                                                   java.lang.reflect.InvocationTargetException,
                                                   java.lang.NoSuchMethodException
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

findField

public static java.lang.reflect.Field findField(java.lang.Class cls,
                                                java.lang.String fieldName,
                                                boolean makeAccessible)
                                         throws java.lang.NoSuchFieldException
Throws:
java.lang.NoSuchFieldException