02/28/2005
 

com.vignette.portal.util
Class ReflectionUtils

java.lang.Object
  |
  +--com.vignette.portal.util.ReflectionUtils

public final class ReflectionUtils
extends Object

Utilities for examining and manipulating classes and objects.


Constructor Summary
ReflectionUtils()
           
 
Method Summary
static Object convertToType(Object object, Class type)
          Return the specified object (either an Object or String) in the form of the specified type.
static Boolean getBoolean(Object object)
          Convert the specified object into it's Boolean equivalent.
static Byte getByte(Object object)
          Convert the specified object into it's Byte equivalent.
static Character getCharacter(Object object)
          Convert the specified object into it's Character equivalent.
static Double getDouble(Object object)
          Convert the specified object into it's Double equivalent.
static Float getFloat(Object object)
          Convert the specified object into it's Float equivalent.
static Integer getInteger(Object object)
          Convert the specified object into it's Integer equivalent.
static Integer getInteger(Object object, int default_value)
          Convert the specified object into it's Integer equivalent.
static Long getLong(Object object)
          Convert the specified object into it's Long equivalent.
static Method getMethod(Class thisClass, String methodName, Class[] paramClasses)
          One of a handful of getMethod implementations, designed to get a method to invoke with a single call.
static Method getMethod(Object anyInstance, String methodName, Object[] params)
          One of a handful of getMethod implementations, designed to get a method to invoke with a single call.
static Method getMethod(String fullClassName, String methodName, String[] paramClassNames)
          One of a handful of getMethod implementations, designed to get a method to invoke with a single call.
static String getProperty(Object obj, String property)
          Get property from standard accessor method.
static Short getShort(Object object)
          Convert the specified object into it's Short equivalent.
static Class getType(String type)
          Return the type Class object of the specified type.
static Method lookupReadMethod(Object obj, String name)
          Get the standard accessor given name of property.
static Method lookupReadOrWriteMethod(Object obj, String name, boolean isRead)
          Lookup either the get or set accessor method for the specified property on the specified object.
static Method lookupWriteMethod(Object obj, String name)
          Get the standard mutator given name of property.
static void setProperty(Object obj, String property, Object value)
          Use the standard mutator method: set(property) to set the value.
 
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

getProperty

public static String getProperty(Object obj,
                                 String property)
Get property from standard accessor method.
Parameters:
property - if "object", method must be getObject()
obj - The object from which to retrieve the specified property.
Returns:
The string value of the specified property of object obj.

setProperty

public static void setProperty(Object obj,
                               String property,
                               Object value)
Use the standard mutator method: set(property) to set the value.
Parameters:
value - is value to set. If the set(property) method's argument is primitive, it must be wrapped in the corresponding Object wrapper (e.g. Integer for an int).
property - is name, and set(property) must be defined ... Note that the first character of property will be changed to upper case to make the name. For details, see JavaBean specification.
obj - The object on which to set the specified property with the designated value.

lookupReadMethod

public static Method lookupReadMethod(Object obj,
                                      String name)
Get the standard accessor given name of property.
Parameters:
name - if "object", accessor method must be "getObject()"
obj - The object for which to retrieve the accessor method for the specified property (name).
Returns:
the standard accessor for the specified property on the given object (obj).

lookupWriteMethod

public static Method lookupWriteMethod(Object obj,
                                       String name)
Get the standard mutator given name of property.
Parameters:
name - if "object", mutator method must be "setObject(value)"
obj - The object on which to retrieve the write method.
Returns:
The write Method (or "setter") for the specified property (name).

lookupReadOrWriteMethod

public static Method lookupReadOrWriteMethod(Object obj,
                                             String name,
                                             boolean isRead)
Lookup either the get or set accessor method for the specified property on the specified object.
Parameters:
obj - The object on which to retrieve an accessor method.
name - The name of the property for which to retrieve an accessor method.
isRead - true if the read accessor (usually the 'getter') is to be retrieved.
Returns:
The Method used to read or write the specified property (name).

getBoolean

public static Boolean getBoolean(Object object)
Convert the specified object into it's Boolean equivalent.
Parameters:
object - The Object to be converted.
Returns:
a Boolean equivalent of the specified object.

getByte

public static Byte getByte(Object object)
Convert the specified object into it's Byte equivalent.
Parameters:
object - The Object to be converted.
Returns:
a Byte equilvalent of the specified object or 0 if no equalvalent can be determined.

getShort

public static Short getShort(Object object)
Convert the specified object into it's Short equivalent.
Parameters:
object - The Object to be converted.
Returns:
a Short equilvalent of the specified object.

getCharacter

public static Character getCharacter(Object object)
Convert the specified object into it's Character equivalent.
Parameters:
object - The Object to be converted.
Returns:
a Character equilvalent of the specified object or space (' ') if no equivalent can be determined.

getInteger

public static Integer getInteger(Object object)
Convert the specified object into it's Integer equivalent.
Parameters:
object - The Object to be converted.
Returns:
a Integer equilvalent of the specified object.

getInteger

public static Integer getInteger(Object object,
                                 int default_value)
Convert the specified object into it's Integer equivalent.
Parameters:
object - The Object to be converted.
default_value - The value to be returned if the specified object cannot be converted into an Integer.
Returns:
a Integer equalvalent of the specified object or the specified default_value if convertion results in a NumberFormatException.

getLong

public static Long getLong(Object object)
Convert the specified object into it's Long equivalent.
Parameters:
object - The Object to be converted.
Returns:
a Long equalvalent of the specified object.

getFloat

public static Float getFloat(Object object)
Convert the specified object into it's Float equivalent.
Parameters:
object - The Object to be converted.
Returns:
a Float equalvalent of the specified object.

getDouble

public static Double getDouble(Object object)
Convert the specified object into it's Double equivalent.
Parameters:
object - The Object to be converted.
Returns:
a Double equalvalent of the specified object.

convertToType

public static Object convertToType(Object object,
                                   Class type)
Return the specified object (either an Object or String) in the form of the specified type. For example, the String "true" will return a Boolean object with the value true if the specified type is either Boolean.class or Boolean.TYPE.
Parameters:
object - The object to be converted into the specified type.
type - The type (Class) to which the specified object is to be converted.
Returns:
The specified object in the form of the specified type.

getType

public static Class getType(String type)
Return the type Class object of the specified type. If the specified type is not a primitive (e.g. "int", "boolean", "long", etc...), then an attempt to find the type by fully qualified class name will occur. If this fails, an attempt to find the class in package java.lang will occur. If this also fails, type java.lang.String will be returned.
Parameters:
type - The String representation of a primitive type.
Returns:
The type Class object of the specified type primitive.

getMethod

public static Method getMethod(Object anyInstance,
                               String methodName,
                               Object[] params)
                        throws NoSuchMethodException
One of a handful of getMethod implementations, designed to get a method to invoke with a single call.
Parameters:
anyInstance - instance upon which to invoke method.
methodName -  
params - An array of objects that form the parameters to the method call.
Returns:
Method

getMethod

public static Method getMethod(String fullClassName,
                               String methodName,
                               String[] paramClassNames)
                        throws ClassNotFoundException,
                               NoSuchMethodException
One of a handful of getMethod implementations, designed to get a method to invoke with a single call.
Parameters:
fullClassName - (must include package)
methodName -  
paramClassNames - full class names of parameters
Returns:
method

getMethod

public static Method getMethod(Class thisClass,
                               String methodName,
                               Class[] paramClasses)
                        throws NoSuchMethodException
One of a handful of getMethod implementations, designed to get a method to invoke with a single call. This is the core method, which actually interrogates the class for the method.
Parameters:
thisClass - class upon which to invoke method.
methodName -  
paramClasses - An array of classes that are arguments to the method call.
Returns:
The method as specified in the given parameters.

02/28/2005
 

Copyright and Trademark Notices