|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.taco.lang.reflect.ReflectionUtilities
public class ReflectionUtilities
A utility class that contains useful methods dealing with reflection.
Constructor Summary | |
---|---|
protected |
ReflectionUtilities()
Since this class is a static utility class, its sole constructor is protected. |
Method Summary | |
---|---|
static java.lang.String |
computeGetMethodName(java.lang.String propertyName)
Compute the name of the get method that used to get the property value, based on the name of property. |
static java.lang.String |
computeSetMethodName(java.lang.String propertyName)
Compute the name of the set method that used to set the property value, based on the name of property. |
static java.util.Map |
createEmptyMap(java.util.Map map)
Create an empty map with the same type as the argument. |
static java.util.Map |
createMapCopy(java.util.Map map)
Create a clone of the argument map, preferrably using the single map argument constructor of the argument map's class. |
static java.lang.reflect.Method |
findSetMethod(java.lang.Class compositeClass,
java.lang.String setMethodName,
java.lang.Object propertyValue,
boolean unwrap)
Given the class object of an object which has a settable property, the name of the set method, and new property value, return the method that sets the value. |
static java.lang.reflect.Method |
findSetMethodForNonNullValue(java.lang.Class compositeClass,
java.lang.String setMethodName,
java.lang.Object propertyValue,
boolean unwrap)
Find the method to set a non-null value. |
static java.lang.reflect.Method |
findSetMethodForNullValue(java.lang.Class compositeClass,
java.lang.String setMethodName)
Find the method to set a null value. |
static java.lang.Object |
forceClone(java.lang.Object obj)
Using reflection, try to clone obj . |
static boolean |
isPrimitiveWrapperClass(java.lang.Class c)
Return true if c is a class that wraps on of the primitive
types. |
static java.lang.Class |
primitiveTypeForWrapperClass(java.lang.Class c)
If c is a primitive wrapper class, return the class object
for the type it wraps. |
static void |
setProperty(java.lang.Object composite,
java.lang.String propertyName,
java.lang.Object propertyValue,
boolean unwrap)
Set a property of a bean. |
static java.lang.Class |
wrapperClassToPrimitiveType(java.lang.Class c)
If c is a class object for a primitive type, return the
class object for the corresponding wrapper class. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected ReflectionUtilities()
Method Detail |
---|
public static final java.lang.Object forceClone(java.lang.Object obj) throws java.lang.CloneNotSupportedException
obj
. If obj
is
null
, return null
. If obj does not implement
Cloneable
or an exception occurs invoking
clone()
, throw a CloneNotSupportedException
.
obj
- The object to clone
java.lang.NullPointerException
- if obj
is null
java.lang.CloneNotSupportedException
- if the argument map doesn't have a
default constructor or the constructor throws an exception, and the map
cannot be cloned using clone()
.public static final java.util.Map createEmptyMap(java.util.Map map) throws java.lang.CloneNotSupportedException
forceClone()
and clear the map before returning it to the
caller.
map
- The map to clone
java.lang.NullPointerException
- if map
is null
java.lang.CloneNotSupportedException
- if the argument map doesn't have a
default constructor or the constructor throws an exception, and the map
cannot be cloned using clone()
.public static final java.util.Map createMapCopy(java.util.Map map) throws java.lang.CloneNotSupportedException
forceClone()
.
map
- The map to clone
java.lang.NullPointerException
- if map
is null
java.lang.CloneNotSupportedException
- if the argument map doesn't have a
single map argument constructor or the constructor throws an exception,
and the map cannot be cloned using clone()
.public static final void setProperty(java.lang.Object composite, java.lang.String propertyName, java.lang.Object propertyValue, boolean unwrap) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
unwrap
is true and
propertyValue
is an instance of a wrapper class for a
primitive type, look for a method that has a single argument with the
corresponding primitive type.
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static final java.lang.String computeGetMethodName(java.lang.String propertyName)
propertyName
- the name of the property to get
java.lang.NullPointerException
- if propertyName
is
null
public static final java.lang.String computeSetMethodName(java.lang.String propertyName)
propertyName
- the name of the property to set
java.lang.NullPointerException
- if propertyName
is
null
public static final java.lang.reflect.Method findSetMethod(java.lang.Class compositeClass, java.lang.String setMethodName, java.lang.Object propertyValue, boolean unwrap) throws java.lang.NoSuchMethodException
unwrap
is true and propertyValue
is an
instance of a wrapper class for a primitive type, look for a method
that has a single argument with the corresponding primitive type.
java.lang.NoSuchMethodException
public static final java.lang.reflect.Method findSetMethodForNullValue(java.lang.Class compositeClass, java.lang.String setMethodName) throws java.lang.NoSuchMethodException
NoSuchMethodException
.
java.lang.NoSuchMethodException
public static final java.lang.reflect.Method findSetMethodForNonNullValue(java.lang.Class compositeClass, java.lang.String setMethodName, java.lang.Object propertyValue, boolean unwrap) throws java.lang.NoSuchMethodException
propertyValue
. If found, it returns it immediately.
Otherwise, it repeats using the superclass of
propertyValue
's type as the argument type. If no
method can be found, throw a NoSuchMethodException
.
java.lang.NoSuchMethodException
public static final boolean isPrimitiveWrapperClass(java.lang.Class c)
c
is a class that wraps on of the primitive
types.
public static final java.lang.Class primitiveTypeForWrapperClass(java.lang.Class c)
c
is a primitive wrapper class, return the class object
for the type it wraps. Otherwise, return null
.
c
- The class to get the primitive class for
null
if the argument class is not a primitive wrapper
class
java.lang.NullPointerException
- if c
is null
public static final java.lang.Class wrapperClassToPrimitiveType(java.lang.Class c)
c
is a class object for a primitive type, return the
class object for the corresponding wrapper class. Otherwise, return
null
.
c
- The class to get the primitive wrapper class for
null
if the argument class is not a primitive class
java.lang.NullPointerException
- if c
is null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |