com.objectwave.utility
Class ReflectiveHelper

java.lang.Object
  |
  +--com.objectwave.utility.ReflectiveHelper

public class ReflectiveHelper
extends java.lang.Object

A collection of functions that may assist when working with java's reflective capabilities.

Version:
$Id: ReflectiveHelper.java,v 2.1 2001/08/02 16:27:11 dave_hoag Exp $
Author:
dhoag

Constructor Summary
ReflectiveHelper()
          Constructor for the ReflectiveHelper object
 
Method Summary
protected  java.lang.reflect.Method findMethod(java.lang.String fieldName, java.lang.Class targetClass)
          Find the method called get so we can set the value.
protected  java.lang.reflect.Method findMethod(java.lang.String fieldName, java.lang.Class fieldType, java.lang.Class targetClass)
          Find the method called set so we can set the value.
 java.lang.Object getValue(java.lang.reflect.Field field, java.lang.Object obj)
          Use the getMethod to get the value of the provided field.
protected  void initialize()
          Establish the object formatter for converting string properties to their actuall class type.
 void setValue(java.lang.reflect.Field field, java.lang.Object valueToSet, java.lang.Object obj)
          Use the setMethod to set a field property.
 void setValue(java.lang.reflect.Field field, java.lang.String valueToSet, java.lang.Object obj)
          Use the setMethod to set a field property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectiveHelper

public ReflectiveHelper()
Constructor for the ReflectiveHelper object

Method Detail

setValue

public void setValue(java.lang.reflect.Field field,
                     java.lang.String valueToSet,
                     java.lang.Object obj)
              throws java.lang.reflect.InvocationTargetException,
                     java.lang.IllegalAccessException
Use the setMethod to set a field property. The property is originally a string and it is converted to the correct field type before the set method is called. If no set method exists, nothing is done.

Parameters:
valueToSet - String The value to set.
field - The field that will ultimately have the set value.
obj - The object upon which the setProperty method will be called.
Throws:
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException

setValue

public void setValue(java.lang.reflect.Field field,
                     java.lang.Object valueToSet,
                     java.lang.Object obj)
              throws java.lang.reflect.InvocationTargetException,
                     java.lang.IllegalAccessException
Use the setMethod to set a field property. If no set method exists, nothing is done.

Parameters:
field - The new Value value
valueToSet - The new Value value
obj - The new Value value
Throws:
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException

getValue

public java.lang.Object getValue(java.lang.reflect.Field field,
                                 java.lang.Object obj)
                          throws java.lang.reflect.InvocationTargetException,
                                 java.lang.IllegalAccessException
Use the getMethod to get the value of the provided field.

Parameters:
field -
obj -
Returns:
The Value value
Throws:
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException

initialize

protected void initialize()
Establish the object formatter for converting string properties to their actuall class type.


findMethod

protected java.lang.reflect.Method findMethod(java.lang.String fieldName,
                                              java.lang.Class fieldType,
                                              java.lang.Class targetClass)
Find the method called set so we can set the value. Property is the uppercase name of the fieldName parameter.

Parameters:
fieldType - The class of the field. This should be the set method's argument type.
fieldName - The name of a field on the target class.
targetClass -
Returns:
java.lang.reflect.Method The reflected method object found on the target class.

findMethod

protected java.lang.reflect.Method findMethod(java.lang.String fieldName,
                                              java.lang.Class targetClass)
Find the method called get so we can set the value. Property is the uppercase name of the fieldName parameter.

Parameters:
fieldName - The name of a field on the target class.
targetClass -
Returns:
java.lang.reflect.Method The reflected method object found on the target class.