com.acsinet_solutions.util
Class ReflectionUtils

java.lang.Object
  extended by com.acsinet_solutions.util.ReflectionUtils

public final class ReflectionUtils
extends java.lang.Object

Useful reflection utility methods

Author:
Santiago Arriaga

Method Summary
static void addValue(java.lang.Object bean, java.lang.String property, java.lang.Object value)
          Add a property to a bean object.
static boolean correspond(java.lang.reflect.Method method1, java.lang.reflect.Method method2)
          Check if the methods correspond to the same name and arguments.
static java.lang.Class getClassFor(java.lang.String className)
           
static java.util.Set<java.lang.Object> getConstantSet(java.lang.Class c, java.lang.String suffix)
          Create a Set of the constants included in the given class that end with the provided suffix.
static java.lang.reflect.Constructor getConstructor(java.lang.Class c, java.lang.Class[] args)
          Get the a constructor for the given class; throws a runtime exception
static java.lang.Object getProperty(java.lang.Object bean, java.lang.String property)
          Get a maybe-nested property of a bean object.
static java.lang.String getPropertyFromGetterName(java.lang.String name)
          Get a property name from a getter name.
static boolean hasReadProperty(java.lang.Object bean, java.lang.String property)
          Thin wrapper around BeanUtils to check if a read property exists
static boolean hasWriteProperty(java.lang.Object bean, java.lang.String property)
          Thin wrapper around BeanUtils to check if a write property exists
static java.lang.Object newInstance(java.lang.String className, java.lang.Class paramClass, java.lang.Object param)
          Create a new instance of the given class name using a single-parameter constructor
static void setProperty(java.lang.Object bean, java.lang.String property, java.lang.Object value)
          Set a property to a bean object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getClassFor

public static final java.lang.Class getClassFor(java.lang.String className)
                                         throws java.lang.ClassNotFoundException
Parameters:
className - A not-null valid Class FQN avalable to the class loader. Primitive names are valid values for this method ( in contrast to Class.forName() ).
Returns:
A not-null Class instance
Throws:
java.lang.ClassNotFoundException - Thrown if the class instance could not be obtained

newInstance

public static final java.lang.Object newInstance(java.lang.String className,
                                                 java.lang.Class paramClass,
                                                 java.lang.Object param)
                                          throws java.lang.Exception
Create a new instance of the given class name using a single-parameter constructor

Parameters:
className - The not-null valid name of the class to be instanciated
paramClass - The not-null class type of the constructor parameter
param - The valid not-null single-parameter of the class constructor
Throws:
java.lang.Exception

getConstructor

public static final java.lang.reflect.Constructor getConstructor(java.lang.Class c,
                                                                 java.lang.Class[] args)
Get the a constructor for the given class; throws a runtime exception

Parameters:
c - A not-null class
args - A not-null class array
Returns:
A not-null Constructor instance

getConstantSet

public static final java.util.Set<java.lang.Object> getConstantSet(java.lang.Class c,
                                                                   java.lang.String suffix)
Create a Set of the constants included in the given class that end with the provided suffix. May not be pretty but works.


hasReadProperty

public static final boolean hasReadProperty(java.lang.Object bean,
                                            java.lang.String property)
Thin wrapper around BeanUtils to check if a read property exists


hasWriteProperty

public static final boolean hasWriteProperty(java.lang.Object bean,
                                             java.lang.String property)
Thin wrapper around BeanUtils to check if a write property exists


getProperty

public static final java.lang.Object getProperty(java.lang.Object bean,
                                                 java.lang.String property)
                                          throws java.lang.RuntimeException
Get a maybe-nested property of a bean object. Commons BeanUtils is internally used for this task.

Throws:
java.lang.RuntimeException

setProperty

public static final void setProperty(java.lang.Object bean,
                                     java.lang.String property,
                                     java.lang.Object value)
                              throws java.lang.RuntimeException
Set a property to a bean object. Properties may be nested. Commons BeanUtils is internally used for this task.

Throws:
java.lang.RuntimeException

addValue

public static final void addValue(java.lang.Object bean,
                                  java.lang.String property,
                                  java.lang.Object value)
                           throws java.lang.RuntimeException
Add a property to a bean object. No nested properties currently supported; this may change if needed.

Throws:
java.lang.RuntimeException

getPropertyFromGetterName

public static final java.lang.String getPropertyFromGetterName(java.lang.String name)
Get a property name from a getter name. The get prefix is eliminated and the first character is passed to lowercase.


correspond

public static final boolean correspond(java.lang.reflect.Method method1,
                                       java.lang.reflect.Method method2)
Check if the methods correspond to the same name and arguments.