org.ujac.util
Class BeanUtils

java.lang.Object
  extended by org.ujac.util.BeanUtils

public class BeanUtils
extends Object

Name: BeanUtils
Description: Class providing common utility methods for java bean access.

Author:
lauerc

Field Summary
static Class[] GETTER_ARG_TYPES
          The argument type list for a getter method.
static Object[] GETTER_ARGS
          The argument list for a getter method.
 
Constructor Summary
BeanUtils()
           
 
Method Summary
static boolean between(Comparable obj, Comparable from, Comparable to)
          Checks if the given object is between the last two parameter values.
static int compare(Comparable a, Comparable b)
          Compares the given values.
static boolean equals(Object a, Object b)
          Checks if the given objects are equal.
static boolean equals(Object a, Object b, boolean caseSensitive)
          Checks if the given objects are equal.
static Object getProperty(Object bean, String propertyName)
          Gets a property from the given bean.
static Object getProperty(Object bean, String propertyName, boolean lenient)
          Gets a property from the given bean.
static Class getPropertyType(Class clazz, String propertyName, boolean lenient)
          Gets a property from the given bean.
static Object invokeGetter(Object bean, Method getterMethod)
          Invokes a getter method with the given value.
static void invokeSetter(Object bean, Method setterMethod, Object value)
          Invokes a setter method with the given value.
static void invokeSetter(Object bean, Method setterMethod, Object value, TypeConverter typeConverter)
          Invokes a setter method with the given value.
static boolean isEmpty(String value)
          Checks if the given string is null or has zero length.
static void setProperty(Object bean, String propertyName, Object value)
          Sets a property at the given bean.
static String toString(Object obj)
          Gets the textual representation of the given object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GETTER_ARG_TYPES

public static final Class[] GETTER_ARG_TYPES
The argument type list for a getter method.


GETTER_ARGS

public static final Object[] GETTER_ARGS
The argument list for a getter method.

Constructor Detail

BeanUtils

public BeanUtils()
Method Detail

getProperty

public static final Object getProperty(Object bean,
                                       String propertyName)
                                throws BeanException
Gets a property from the given bean.

Parameters:
bean - The bean to read property from.
propertyName - The name of the property to read.
Returns:
The determined value.
Throws:
BeanException - In case the bean access failed.

getPropertyType

public static final Class getPropertyType(Class clazz,
                                          String propertyName,
                                          boolean lenient)
                                   throws BeanException
Gets a property from the given bean.

Parameters:
clazz - The class to determine the property type for.
propertyName - The name of the property to read.
lenient - If true is passed for this attribute, null will returned for in case no matching getter method is defined, else an Exception will be throw in this case.
Returns:
The determined value.
Throws:
BeanException - In case the bean access failed.

getProperty

public static final Object getProperty(Object bean,
                                       String propertyName,
                                       boolean lenient)
                                throws BeanException
Gets a property from the given bean.

Parameters:
bean - The bean to read property from.
propertyName - The name of the property to read.
lenient - If true is passed for this attribute, null will returned for in case no matching getter method is defined, else an Exception will be throw in this case.
Returns:
The determined value.
Throws:
BeanException - In case the bean access failed.

invokeGetter

public static final Object invokeGetter(Object bean,
                                        Method getterMethod)
                                 throws BeanException
Invokes a getter method with the given value.

Parameters:
bean - The bean to set a property at.
getterMethod - The setter method to invoke.
Returns:
The determined value.
Throws:
BeanException - In case the bean access failed.

setProperty

public static final void setProperty(Object bean,
                                     String propertyName,
                                     Object value)
                              throws BeanException
Sets a property at the given bean.

Parameters:
bean - The bean to set a property at.
propertyName - The name of the property to set.
value - The value to set for the property.
Throws:
BeanException - In case the bean access failed.

invokeSetter

public static final void invokeSetter(Object bean,
                                      Method setterMethod,
                                      Object value)
                               throws BeanException
Invokes a setter method with the given value.

Parameters:
bean - The bean to set a property at.
setterMethod - The setter method to invoke.
value - The value to set for the property.
Throws:
BeanException - In case the bean access failed.

invokeSetter

public static final void invokeSetter(Object bean,
                                      Method setterMethod,
                                      Object value,
                                      TypeConverter typeConverter)
                               throws BeanException
Invokes a setter method with the given value.

Parameters:
bean - The bean to set a property at.
setterMethod - The setter method to invoke.
value - The value to set for the property.
typeConverter - The TypeConverter to use.
Throws:
BeanException - In case the bean access failed.

isEmpty

public static final boolean isEmpty(String value)
Checks if the given string is null or has zero length.

Parameters:
value - The string to check.
Returns:
true if the given string is null or has zero length.

equals

public static final boolean equals(Object a,
                                   Object b)
Checks if the given objects are equal.

Parameters:
a - The object to compare with object b.
b - The object to compare with object a.
Returns:
true if the objects are equal or are both null.

equals

public static final boolean equals(Object a,
                                   Object b,
                                   boolean caseSensitive)
Checks if the given objects are equal.

Parameters:
a - The object to compare with object b.
b - The object to compare with object a.
caseSensitive - Tells whether or not to compare string values case sensitive. This parameter is only respected, in case a is a java.lang.String instance.
Returns:
true if the objects are equal or are both null.

compare

public static final int compare(Comparable a,
                                Comparable b)
Compares the given values.

Parameters:
a - The object to compare with object b.
b - The object to compare with object a.
Returns:
true if the objects are equal or are both null.

between

public static final boolean between(Comparable obj,
                                    Comparable from,
                                    Comparable to)
Checks if the given object is between the last two parameter values.

Parameters:
obj - The object to check.
from - The lower value to compare.
to - The upper value to compare.
Returns:
true if obj is between from and to.

toString

public static final String toString(Object obj)
Gets the textual representation of the given object.

Parameters:
obj - The object to get the extual representation of.
Returns:
The textual representation of the given object or null.


Copyright © 2003-2004 UJAC.org. All Rights Reserved.