com.opensymphony.util
Class BeanUtils

java.lang.Object
  extended bycom.opensymphony.util.BeanUtils

public class BeanUtils
extends Object

Convenience methods for manipulating the getter/setter properties of JavaBeans (well any kind of Object).

These methods are provided purely for convenience to frequent operations. No exceptions are thrown from the methods.

Version:
$Revision: 1.1.1.1 $
Author:
Joe Walnes

Constructor Summary
BeanUtils()
           
 
Method Summary
static String[] getPropertyNames(Object obj)
          Get list of property names of bean.
static Object getValue(Object obj, String property)
          Get a single property of the bean.
static Map getValues(Object obj, String[] allowedProperties)
          Get Map of property values from a bean.
static boolean setValue(Object obj, String property, Object value)
          Set a single property of the bean.
static void setValues(Object obj, Map valueMap, String[] allowedProperties)
          Set multiple properties of a bean at once using a Map.
static void setValues(Object obj, Object src, String[] allowedProperties)
          Set multiple properties of a bean at once using properties of another bean.
static void setValues(Object obj, javax.servlet.ServletRequest request, String[] allowedProperties)
          Set multiple properties of a bean at once using the params passed across from the ServletRequest (useful for mapping HTML forms to beans).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanUtils

public BeanUtils()
Method Detail

getPropertyNames

public static final String[] getPropertyNames(Object obj)
Get list of property names of bean.

Parameters:
obj - Object to query for property names.
Returns:
Array of property names, or null if an error occurred.

setValue

public static final boolean setValue(Object obj,
                                     String property,
                                     Object value)
Set a single property of the bean.

Parameters:
obj - The object to be manipulated.
property - Name of property to set.
value - Value to set property to.
Returns:
Boolean indicating success.

getValue

public static final Object getValue(Object obj,
                                    String property)
Get a single property of the bean.

Parameters:
obj - The object to be accessed.
property - Name of property to get.
Returns:
Value of property. If property was not found, null is returned.

setValues

public static final void setValues(Object obj,
                                   Map valueMap,
                                   String[] allowedProperties)
Set multiple properties of a bean at once using a Map. Any unknown properties shall be ignored.

Parameters:
obj - The object to be manipulated.
valueMap - Map containing property-name (String) / property-value (Object) pairs to set in the object.
allowedProperties - If array is NOT null, only the properties matching names passed here shall be set.

setValues

public static final void setValues(Object obj,
                                   Object src,
                                   String[] allowedProperties)
Set multiple properties of a bean at once using properties of another bean. The beans may be of different types and any properties not common to both types shall be ignored.

Parameters:
obj - The object to be manipulated.
src - The object containing the properties to be copied.
allowedProperties - If array is NOT null, only the properties matching names passed here shall be set.

setValues

public static final void setValues(Object obj,
                                   javax.servlet.ServletRequest request,
                                   String[] allowedProperties)
Set multiple properties of a bean at once using the params passed across from the ServletRequest (useful for mapping HTML forms to beans). Any properties not known shall be ignored.

Parameters:
obj - The object to be manipulated.
request - ServletRequest to get params from.
allowedProperties - If array is NOT null, only the properties matching names passed here shall be set.

getValues

public static final Map getValues(Object obj,
                                  String[] allowedProperties)
Get Map of property values from a bean.

Parameters:
obj - Object to query for properties.
allowedProperties - If array is NOT null, only the properties matching names passed here shall be retrieved.
Returns:
Map containing property-name (String) / property-value (Object) pairs.

OSCore Project Page