org.jaffa.util
Class BeanHelper

java.lang.Object
  extended byorg.jaffa.util.BeanHelper

public class BeanHelper
extends Object

This has convenience methods for dealing with Java Beans.


Constructor Summary
BeanHelper()
           
 
Method Summary
static Object convertDataType(Class beanClass, String propertyName, String propertyValue)
          This method will introspect the beanClass & get the getter method for the input propertyName.
static Object getField(Object bean, String field)
          This will inspect the specified java bean, and extract an Object from the beans getXxx() method, where 'xxx' is the field name passed in.
static String getReaderName(String field)
          Get the name of the reader method for the specified string.
static boolean setField(Object bean, String propertyName, String propertyValue)
          This method will introspect the bean & get the setter method for the input propertyName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanHelper

public BeanHelper()
Method Detail

getField

public static Object getField(Object bean,
                              String field)
                       throws NoSuchMethodException
This will inspect the specified java bean, and extract an Object from the beans getXxx() method, where 'xxx' is the field name passed in. A null will be returned in case there is any error in invoking the getter.

Parameters:
bean - The Java Bean.
field - The field.
Returns:
the output of the getter for the field.
Throws:
NoSuchMethodException - if there is no getter for the input field.

getReaderName

public static String getReaderName(String field)
Get the name of the reader method for the specified string. For example 'hello' will return 'getHello'

Parameters:
field - The field.
Returns:
the name of the reader/getter method for the specified string.

setField

public static boolean setField(Object bean,
                               String propertyName,
                               String propertyValue)
                        throws IntrospectionException,
                               IllegalAccessException,
                               InvocationTargetException
This method will introspect the bean & get the setter method for the input propertyName. It will then try & convert the propertyValue to the appropriate datatype. Finally it will invoke the setter.

Parameters:
bean - The bean class to be introspected.
propertyName - The Property being searched for.
propertyValue - The value to be set.
Returns:
A true indicates, the property was succesfully set to the passed value. A false indicates the property doesn't exist or the propertyValue passed is not compatible with the setter.
Throws:
IntrospectionException - if an exception occurs during introspection.
IllegalAccessException - if the underlying method is inaccessible.
InvocationTargetException - if the underlying method throws an exception.

convertDataType

public static Object convertDataType(Class beanClass,
                                     String propertyName,
                                     String propertyValue)
                              throws IntrospectionException,
                                     IllegalArgumentException
This method will introspect the beanClass & get the getter method for the input propertyName. It will then try & convert the propertyValue to the appropriate datatype.

Parameters:
beanClass - The bean class to be introspected.
propertyName - The Property being searched for.
propertyValue - The value to be converted.
Returns:
a converted propertyValue compatible with the getter.
Throws:
IntrospectionException - if an exception occurs during introspection.
IllegalArgumentException - if the propertyValue cannot be converted to the appropriate datatype.


Copyright © 2002-2004 JAFFA Project.