com.ebmwebsourcing.easycommons.lang.reflect
Class ReflectionHelper

java.lang.Object
  extended by com.ebmwebsourcing.easycommons.lang.reflect.ReflectionHelper

public final class ReflectionHelper
extends java.lang.Object


Method Summary
static java.util.Set<java.lang.Class<?>> findAllImplementedInterfaces(java.lang.Class<?> clazz)
          Find all implemented interfaces recursively.
static java.util.Collection<java.lang.reflect.Method> findMethodsThatReturnType(java.lang.Class<?> clazz, java.lang.Class<?> returnType)
           
static java.lang.reflect.Method getDeclaredMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
          Get a declared method and wrap exceptions into unchecked exceptions.
static java.lang.Object getFieldValue(java.lang.Object obj, java.lang.reflect.Field field)
           
static java.util.List<java.lang.reflect.Method> getPublicDeclaredMethods(java.lang.Class<?> clazz)
          Get all public declared methods and wrap exceptions into unchecked exceptions.
static java.lang.reflect.Method getPublicMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
          Get a public method and wrap exceptions into unchecked exceptions.
static java.lang.Object invokeMethod(java.lang.Object obj, java.lang.reflect.Method method, java.lang.Object... args)
          Invoke a method by reflection.
static java.lang.Object invokePrivateMethod(java.lang.Object obj, java.lang.String methodName, java.lang.Object... args)
          Invoke a private method by reflection.
static boolean isOrInheritedFrom(java.lang.Class<?> clazz, java.lang.String canonicalName)
          Test if the specified class is or inherited from the class with the specified canonical name
static
<T> T
newInstance(java.lang.Class<T> clazz, java.lang.Object... args)
           
static void setFieldValue(java.lang.Object obj, java.lang.reflect.Field field, java.lang.Object newValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

findAllImplementedInterfaces

public static final java.util.Set<java.lang.Class<?>> findAllImplementedInterfaces(java.lang.Class<?> clazz)
Find all implemented interfaces recursively.

Parameters:
clazz - Class for which we want to know all implemented interfaces.
Returns:
An unmodifiable set of implemented interfaces.

getPublicMethod

public static final java.lang.reflect.Method getPublicMethod(java.lang.Class<?> clazz,
                                                             java.lang.String methodName,
                                                             java.lang.Class<?>... parameterTypes)
Get a public method and wrap exceptions into unchecked exceptions.

Parameters:
clazz -
methodName -
parameterTypes -
Returns:

getPublicDeclaredMethods

public static final java.util.List<java.lang.reflect.Method> getPublicDeclaredMethods(java.lang.Class<?> clazz)
Get all public declared methods and wrap exceptions into unchecked exceptions.

Parameters:
clazz -
Returns:

getDeclaredMethod

public static final java.lang.reflect.Method getDeclaredMethod(java.lang.Class<?> clazz,
                                                               java.lang.String methodName,
                                                               java.lang.Class<?>... parameterTypes)
Get a declared method and wrap exceptions into unchecked exceptions.

Parameters:
clazz -
methodName -
parameterTypes -
Returns:

invokeMethod

public static final java.lang.Object invokeMethod(java.lang.Object obj,
                                                  java.lang.reflect.Method method,
                                                  java.lang.Object... args)
                                           throws java.lang.reflect.InvocationTargetException
Invoke a method by reflection. This is a convenience method, wrapping all related exceptions into an unchecked exception.

Parameters:
obj - Object on which to invoke method.
method - Method to be invoked.
args - Method arguments.
Returns:
Result of invoked method.
Throws:
java.lang.reflect.InvocationTargetException

invokePrivateMethod

public static final java.lang.Object invokePrivateMethod(java.lang.Object obj,
                                                         java.lang.String methodName,
                                                         java.lang.Object... args)
                                                  throws java.lang.reflect.InvocationTargetException
Invoke a private method by reflection. This method can be used only in experimental projects This is a convenience method, wrapping all related exceptions into an unchecked exception.

Parameters:
obj - Object on which to invoke method.
method - Method to be invoked.
args - Method arguments.
Returns:
Result of invoked method.
Throws:
java.lang.reflect.InvocationTargetException

newInstance

public static final <T> T newInstance(java.lang.Class<T> clazz,
                                      java.lang.Object... args)
                           throws java.lang.reflect.InvocationTargetException
Throws:
java.lang.reflect.InvocationTargetException

findMethodsThatReturnType

public static final java.util.Collection<java.lang.reflect.Method> findMethodsThatReturnType(java.lang.Class<?> clazz,
                                                                                             java.lang.Class<?> returnType)

getFieldValue

public static final java.lang.Object getFieldValue(java.lang.Object obj,
                                                   java.lang.reflect.Field field)

setFieldValue

public static final void setFieldValue(java.lang.Object obj,
                                       java.lang.reflect.Field field,
                                       java.lang.Object newValue)

isOrInheritedFrom

public static final boolean isOrInheritedFrom(java.lang.Class<?> clazz,
                                              java.lang.String canonicalName)
Test if the specified class is or inherited from the class with the specified canonical name

Parameters:
clazz - the class to check
superClassName - the class name to look for
Returns:
true if the


Copyright © 2011 Petals Link. All Rights Reserved.