com.jdroid.java.utils
Class ReflectionUtils

java.lang.Object
  extended by com.jdroid.java.utils.ReflectionUtils

public abstract class ReflectionUtils
extends Object

Reflection related utilities


Constructor Summary
ReflectionUtils()
           
 
Method Summary
static Object get(Field field, Object object)
           
static Object get(Object object, String fieldName)
           
static Field getField(Class<?> clazz, String fieldName)
          Returns a Field from a class or any of its super classes.
static Field getField(Object object, String fieldName)
           
static
<T> T
getFieldValue(Object object, String fieldName)
          Returns the value of a given Field from an Object.
static Class<?> getType(Object object, String fieldName)
           
static
<T> T
newInstance(Class<T> clazz)
          Create a class for the specified type,.
static
<T> T
newInstance(Class<T> clazz, Collection<Class<?>> parameterTypes, Collection<Object> parameterValues)
          Create a class for the specified type, using the specified constructor with the passed parameters.
static void set(Object object, String expression, Object value)
          Set a value in the given object without using getters or setters
static void setId(Identifiable identifiable, Long id)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtils

public ReflectionUtils()
Method Detail

newInstance

public static <T> T newInstance(Class<T> clazz)
Create a class for the specified type,.

Type Parameters:
T - the class to instantiate to be returned
Parameters:
clazz - the class to be instantiated
Returns:
an instance of the class specified

newInstance

public static <T> T newInstance(Class<T> clazz,
                                Collection<Class<?>> parameterTypes,
                                Collection<Object> parameterValues)
Create a class for the specified type, using the specified constructor with the passed parameters.

Type Parameters:
T - the class to instantiate to be returned
Parameters:
clazz - the class to be instantiated
parameterTypes - a constructor with this parameters will be used to instantiate the class
parameterValues - parameter values to be used when instantiating
Returns:
an instance of the class specified

set

public static void set(Object object,
                       String expression,
                       Object value)
Set a value in the given object without using getters or setters

Parameters:
object - The object where we want to null the expression
expression - The expression we want to null
value - The new value to set

get

public static Object get(Field field,
                         Object object)
Parameters:
field -
object -
Returns:
Object

get

public static Object get(Object object,
                         String fieldName)
Parameters:
object -
fieldName -
Returns:
Object

getField

public static Field getField(Object object,
                             String fieldName)
Parameters:
object -
fieldName -
Returns:
Field

getField

public static Field getField(Class<?> clazz,
                             String fieldName)
Returns a Field from a class or any of its super classes.

Parameters:
clazz - The Class whose Field is looked for
fieldName - The name of the Field to get
Returns:
The Field

getFieldValue

public static <T> T getFieldValue(Object object,
                                  String fieldName)
Returns the value of a given Field from an Object. Or null if the Object doesn't have a Field with the given name.

Type Parameters:
T - The type of the value
Parameters:
object - The Object whose value is being retrieved
fieldName - The name of the Field
Returns:
The value of the Field

getType

public static Class<?> getType(Object object,
                               String fieldName)
Parameters:
object -
fieldName -
Returns:
Class

setId

public static void setId(Identifiable identifiable,
                         Long id)


Copyright © 2014. All rights reserved.