Package org.apache.openjpa.enhance
Class Reflection
- java.lang.Object
 - 
- org.apache.openjpa.enhance.Reflection
 
 
- 
public class Reflection extends Object
Reflection utilities used to support and augment enhancement. Used both at enhancement time and at runtime.- Author:
 - Abe White
 
 
- 
- 
Constructor Summary
Constructors Constructor Description Reflection() 
- 
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FieldfindField(Class cls, String name, boolean mustExist)Return the field with the given name, optionally throwing an exception if none.static MethodfindGetter(Class cls, String prop, boolean mustExist)Return the getter method matching the given property name, optionally throwing an exception if none.static MethodfindSetter(Class cls, String prop, boolean mustExist)Return the setter method matching the given property name, optionally throwing an exception if none.static MethodfindSetter(Class cls, String prop, Class param, boolean mustExist)Return the setter method matching the given property name, optionally throwing an exception if none.static Objectget(Object target, Field field)Return the value of the given field in the given object.static Objectget(Object target, Method getter)Return the return value of the given getter in the given object.static Set<String>getBeanStylePropertyNames(Class<?> c)Gets all bean-style property names of the given Class or its superclass.static booleangetBoolean(Object target, Field field)Return the value of the given field in the given object.static booleangetBoolean(Object target, Method getter)Return the return value of the given getter in the given object.static bytegetByte(Object target, Field field)Return the value of the given field in the given object.static bytegetByte(Object target, Method getter)Return the return value of the given getter in the given object.static chargetChar(Object target, Field field)Return the value of the given field in the given object.static chargetChar(Object target, Method getter)Return the return value of the given getter in the given object.static ClassgetDeclaringClass(Method m)Gets the declaring class of the given method signature but also checks if the method is declared in an interface.static MethodgetDeclaringMethod(Class c, Method m)Gets the method in the given class that has the same signature of the given method, if exists.static doublegetDouble(Object target, Field field)Return the value of the given field in the given object.static doublegetDouble(Object target, Method getter)Return the return value of the given getter in the given object.static <T> Set<T>getFieldValues(Class c, int mods, Class<T> t)Gets values of all field f the given class such that f exactly match the given modifiers and are of given type (Object implies any type) unless f is annotated asReflectable.static floatgetFloat(Object target, Field field)Return the value of the given field in the given object.static floatgetFloat(Object target, Method getter)Return the return value of the given getter in the given object.static intgetInt(Object target, Field field)Return the value of the given field in the given object.static intgetInt(Object target, Method getter)Return the return value of the given getter in the given object.static longgetLong(Object target, Field field)Return the value of the given field in the given object.static longgetLong(Object target, Method getter)Return the return value of the given getter in the given object.static Set<String>getPublicFieldNames(Class c)Gets all public field names of the given Class.static shortgetShort(Object target, Field field)Return the value of the given field in the given object.static shortgetShort(Object target, Method getter)Return the return value of the given getter in the given object.static ObjectgetValue(Object obj, String prop, boolean mustExist)Get the value of the given named field or a corresponding getter method.static voidset(Object target, boolean value, Field field)Set the value of the given field in the given object.static voidset(Object target, byte value, Field field)Set the value of the given field in the given object.static voidset(Object target, char value, Field field)Set the value of the given field in the given object.static voidset(Object target, double value, Field field)Set the value of the given field in the given object.static voidset(Object target, float value, Field field)Set the value of the given field in the given object.static voidset(Object target, int value, Field field)Set the value of the given field in the given object.static voidset(Object target, long value, Field field)Set the value of the given field in the given object.static voidset(Object target, short value, Field field)Set the value of the given field in the given object.static voidset(Object target, Object value, Field field)Set the value of the given field in the given object.static voidset(Object target, Field field, boolean value)Set the value of the given field in the given object.static voidset(Object target, Field field, byte value)Set the value of the given field in the given object.static voidset(Object target, Field field, char value)Set the value of the given field in the given object.static voidset(Object target, Field field, double value)Set the value of the given field in the given object.static voidset(Object target, Field field, float value)Set the value of the given field in the given object.static voidset(Object target, Field field, int value)Set the value of the given field in the given object.static voidset(Object target, Field field, long value)Set the value of the given field in the given object.static voidset(Object target, Field field, short value)Set the value of the given field in the given object.static voidset(Object target, Field field, Object value)Set the value of the given field in the given object.static voidset(Object target, Method setter, boolean value)Invoke the given setter on the given object.static voidset(Object target, Method setter, byte value)Invoke the given setter on the given object.static voidset(Object target, Method setter, char value)Invoke the given setter on the given object.static voidset(Object target, Method setter, double value)Invoke the given setter on the given object.static voidset(Object target, Method setter, float value)Invoke the given setter on the given object.static voidset(Object target, Method setter, int value)Invoke the given setter on the given object.static voidset(Object target, Method setter, long value)Invoke the given setter on the given object.static voidset(Object target, Method setter, short value)Invoke the given setter on the given object.static voidset(Object target, Method setter, Object value)Invoke the given setter on the given object. 
 - 
 
- 
- 
Method Detail
- 
findGetter
public static Method findGetter(Class cls, String prop, boolean mustExist)
Return the getter method matching the given property name, optionally throwing an exception if none. 
- 
findSetter
public static Method findSetter(Class cls, String prop, boolean mustExist)
Return the setter method matching the given property name, optionally throwing an exception if none. The property must also have a getter. 
- 
findSetter
public static Method findSetter(Class cls, String prop, Class param, boolean mustExist)
Return the setter method matching the given property name, optionally throwing an exception if none. 
- 
findField
public static Field findField(Class cls, String name, boolean mustExist)
Return the field with the given name, optionally throwing an exception if none. 
- 
get
public static Object get(Object target, Field field)
Return the value of the given field in the given object. 
- 
getValue
public static Object getValue(Object obj, String prop, boolean mustExist)
Get the value of the given named field or a corresponding getter method.- Returns:
 - null if the field does not exist and mustExist is set to false or the given target is null.
 - Throws:
 UserException- if mustExist is true and the field or getter method is non-existent
 
- 
getBoolean
public static boolean getBoolean(Object target, Field field)
Return the value of the given field in the given object. 
- 
getByte
public static byte getByte(Object target, Field field)
Return the value of the given field in the given object. 
- 
getChar
public static char getChar(Object target, Field field)
Return the value of the given field in the given object. 
- 
getDouble
public static double getDouble(Object target, Field field)
Return the value of the given field in the given object. 
- 
getFloat
public static float getFloat(Object target, Field field)
Return the value of the given field in the given object. 
- 
getInt
public static int getInt(Object target, Field field)
Return the value of the given field in the given object. 
- 
getLong
public static long getLong(Object target, Field field)
Return the value of the given field in the given object. 
- 
getShort
public static short getShort(Object target, Field field)
Return the value of the given field in the given object. 
- 
get
public static Object get(Object target, Method getter)
Return the return value of the given getter in the given object. 
- 
getBoolean
public static boolean getBoolean(Object target, Method getter)
Return the return value of the given getter in the given object. 
- 
getByte
public static byte getByte(Object target, Method getter)
Return the return value of the given getter in the given object. 
- 
getChar
public static char getChar(Object target, Method getter)
Return the return value of the given getter in the given object. 
- 
getDouble
public static double getDouble(Object target, Method getter)
Return the return value of the given getter in the given object. 
- 
getFloat
public static float getFloat(Object target, Method getter)
Return the return value of the given getter in the given object. 
- 
getInt
public static int getInt(Object target, Method getter)
Return the return value of the given getter in the given object. 
- 
getLong
public static long getLong(Object target, Method getter)
Return the return value of the given getter in the given object. 
- 
getShort
public static short getShort(Object target, Method getter)
Return the return value of the given getter in the given object. 
- 
set
public static void set(Object target, Field field, Object value)
Set the value of the given field in the given object. 
- 
set
public static void set(Object target, Field field, boolean value)
Set the value of the given field in the given object. 
- 
set
public static void set(Object target, Field field, byte value)
Set the value of the given field in the given object. 
- 
set
public static void set(Object target, Field field, char value)
Set the value of the given field in the given object. 
- 
set
public static void set(Object target, Field field, double value)
Set the value of the given field in the given object. 
- 
set
public static void set(Object target, Field field, float value)
Set the value of the given field in the given object. 
- 
set
public static void set(Object target, Field field, int value)
Set the value of the given field in the given object. 
- 
set
public static void set(Object target, Field field, long value)
Set the value of the given field in the given object. 
- 
set
public static void set(Object target, Field field, short value)
Set the value of the given field in the given object. 
- 
set
public static void set(Object target, Object value, Field field)
Set the value of the given field in the given object. Same behavior as above methods, but parameter ordering is rearranged to simplify usage from generated bytecodes.- Since:
 - 1.0.0
 
 
- 
set
public static void set(Object target, boolean value, Field field)
Set the value of the given field in the given object. Same behavior as above methods, but parameter ordering is rearranged to simplify usage from generated bytecodes.- Since:
 - 1.0.0
 
 
- 
set
public static void set(Object target, byte value, Field field)
Set the value of the given field in the given object. Same behavior as above methods, but parameter ordering is rearranged to simplify usage from generated bytecodes.- Since:
 - 1.0.0
 
 
- 
set
public static void set(Object target, char value, Field field)
Set the value of the given field in the given object. Same behavior as above methods, but parameter ordering is rearranged to simplify usage from generated bytecodes.- Since:
 - 1.0.0
 
 
- 
set
public static void set(Object target, double value, Field field)
Set the value of the given field in the given object. Same behavior as above methods, but parameter ordering is rearranged to simplify usage from generated bytecodes.- Since:
 - 1.0.0
 
 
- 
set
public static void set(Object target, float value, Field field)
Set the value of the given field in the given object. Same behavior as above methods, but parameter ordering is rearranged to simplify usage from generated bytecodes.- Since:
 - 1.0.0
 
 
- 
set
public static void set(Object target, int value, Field field)
Set the value of the given field in the given object. Same behavior as above methods, but parameter ordering is rearranged to simplify usage from generated bytecodes.- Since:
 - 1.0.0
 
 
- 
set
public static void set(Object target, long value, Field field)
Set the value of the given field in the given object. Same behavior as above methods, but parameter ordering is rearranged to simplify usage from generated bytecodes.- Since:
 - 1.0.0
 
 
- 
set
public static void set(Object target, short value, Field field)
Set the value of the given field in the given object. Same behavior as above methods, but parameter ordering is rearranged to simplify usage from generated bytecodes.- Since:
 - 1.0.0
 
 
- 
set
public static void set(Object target, Method setter, Object value)
Invoke the given setter on the given object. 
- 
set
public static void set(Object target, Method setter, boolean value)
Invoke the given setter on the given object. 
- 
set
public static void set(Object target, Method setter, byte value)
Invoke the given setter on the given object. 
- 
set
public static void set(Object target, Method setter, char value)
Invoke the given setter on the given object. 
- 
set
public static void set(Object target, Method setter, double value)
Invoke the given setter on the given object. 
- 
set
public static void set(Object target, Method setter, float value)
Invoke the given setter on the given object. 
- 
set
public static void set(Object target, Method setter, int value)
Invoke the given setter on the given object. 
- 
set
public static void set(Object target, Method setter, long value)
Invoke the given setter on the given object. 
- 
set
public static void set(Object target, Method setter, short value)
Invoke the given setter on the given object. 
- 
getBeanStylePropertyNames
public static Set<String> getBeanStylePropertyNames(Class<?> c)
Gets all bean-style property names of the given Class or its superclass. A bean-style property 'abc' exists in Class C iff C has declared following pair of methods: public void setAbc(Y y) or public C setAbc(Y y) public Y getAbc(); If a getter property is annotated withReflectable, then it is ignored. 
- 
getPublicFieldNames
public static Set<String> getPublicFieldNames(Class c)
Gets all public field names of the given Class. 
- 
getFieldValues
public static <T> Set<T> getFieldValues(Class c, int mods, Class<T> t)
Gets values of all field f the given class such that f exactly match the given modifiers and are of given type (Object implies any type) unless f is annotated asReflectable. 
- 
getDeclaringClass
public static Class getDeclaringClass(Method m)
Gets the declaring class of the given method signature but also checks if the method is declared in an interface. If yes, then returns the interface. 
 - 
 
 -