org.apache.commons.beanutils

Class PropertyUtils

public class PropertyUtils extends Object

Utility methods for using Java Reflection APIs to facilitate generic property getter and setter operations on Java objects.

The implementations for these methods are provided by PropertyUtilsBean. For more details see PropertyUtilsBean.

Version: $Revision: 644137 $ $Date: 2008-04-03 03:30:23 +0100 (Thu, 03 Apr 2008) $

Author: Craig R. McClanahan Ralph Schaer Chris Audley Rey Francois Gregor Rayman Jan Sorensen Scott Sanders

See Also: PropertyUtilsBean Resolver

Field Summary
static charINDEXED_DELIM
The delimiter that preceeds the zero-relative subscript for an indexed reference.
static charINDEXED_DELIM2
The delimiter that follows the zero-relative subscript for an indexed reference.
static charMAPPED_DELIM
The delimiter that preceeds the key of a mapped property.
static charMAPPED_DELIM2
The delimiter that follows the key of a mapped property.
static charNESTED_DELIM
The delimiter that separates the components of a nested reference.
Method Summary
static voidclearDescriptors()
Clear any cached property descriptors information for all classes loaded by any class loaders.
static voidcopyProperties(Object dest, Object orig)

Copy property values from the "origin" bean to the "destination" bean for all cases where the property names are the same (even though the actual getter and setter methods might have been customized via BeanInfo classes).

For more details see PropertyUtilsBean.

static Mapdescribe(Object bean)

Return the entire set of properties for which the specified bean provides a read method.

For more details see PropertyUtilsBean.

static intgetDebug()
The debug static property is no longer used
static ObjectgetIndexedProperty(Object bean, String name)

Return the value of the specified indexed property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

static ObjectgetIndexedProperty(Object bean, String name, int index)

Return the value of the specified indexed property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

static ObjectgetMappedProperty(Object bean, String name)

Return the value of the specified mapped property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

static ObjectgetMappedProperty(Object bean, String name, String key)

Return the value of the specified mapped property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

static FastHashMapgetMappedPropertyDescriptors(Class beanClass)

Return the mapped property descriptors for this bean class.

For more details see PropertyUtilsBean.

static FastHashMapgetMappedPropertyDescriptors(Object bean)

Return the mapped property descriptors for this bean.

For more details see PropertyUtilsBean.

static ObjectgetNestedProperty(Object bean, String name)

Return the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

static ObjectgetProperty(Object bean, String name)

Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

For more details see PropertyUtilsBean.

static PropertyDescriptorgetPropertyDescriptor(Object bean, String name)

Retrieve the property descriptor for the specified property of the specified bean, or return null if there is no such descriptor.

For more details see PropertyUtilsBean.

static PropertyDescriptor[]getPropertyDescriptors(Class beanClass)

Retrieve the property descriptors for the specified class, introspecting and caching them the first time a particular bean class is encountered.

For more details see PropertyUtilsBean.

static PropertyDescriptor[]getPropertyDescriptors(Object bean)

Retrieve the property descriptors for the specified bean, introspecting and caching them the first time a particular bean class is encountered.

For more details see PropertyUtilsBean.

static ClassgetPropertyEditorClass(Object bean, String name)

Return the Java Class repesenting the property editor class that has been registered for this property (if any).

For more details see PropertyUtilsBean.

static ClassgetPropertyType(Object bean, String name)

Return the Java Class representing the property type of the specified property, or null if there is no such property for the specified bean.

For more details see PropertyUtilsBean.

static MethodgetReadMethod(PropertyDescriptor descriptor)

Return an accessible property getter method for this property, if there is one; otherwise return null.

For more details see PropertyUtilsBean.

static ObjectgetSimpleProperty(Object bean, String name)

Return the value of the specified simple property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

static MethodgetWriteMethod(PropertyDescriptor descriptor)

Return an accessible property setter method for this property, if there is one; otherwise return null.

For more details see PropertyUtilsBean.

static booleanisReadable(Object bean, String name)

Return true if the specified property name identifies a readable property on the specified bean; otherwise, return false.

For more details see PropertyUtilsBean.

static booleanisWriteable(Object bean, String name)

Return true if the specified property name identifies a writeable property on the specified bean; otherwise, return false.

For more details see PropertyUtilsBean.

static voidsetDebug(int newDebug)
The debug static property is no longer used
static voidsetIndexedProperty(Object bean, String name, Object value)

Sets the value of the specified indexed property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

static voidsetIndexedProperty(Object bean, String name, int index, Object value)

Sets the value of the specified indexed property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

static voidsetMappedProperty(Object bean, String name, Object value)

Sets the value of the specified mapped property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

static voidsetMappedProperty(Object bean, String name, String key, Object value)

Sets the value of the specified mapped property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

static voidsetNestedProperty(Object bean, String name, Object value)

Sets the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

static voidsetProperty(Object bean, String name, Object value)

Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

For more details see PropertyUtilsBean.

static voidsetSimpleProperty(Object bean, String name, Object value)

Set the value of the specified simple property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Field Detail

INDEXED_DELIM

public static final char INDEXED_DELIM

Deprecated: The notation used for property name expressions is now dependant on the Resolver implementation being used.

The delimiter that preceeds the zero-relative subscript for an indexed reference.

INDEXED_DELIM2

public static final char INDEXED_DELIM2

Deprecated: The notation used for property name expressions is now dependant on the Resolver implementation being used.

The delimiter that follows the zero-relative subscript for an indexed reference.

MAPPED_DELIM

public static final char MAPPED_DELIM

Deprecated: The notation used for property name expressions is now dependant on the Resolver implementation being used.

The delimiter that preceeds the key of a mapped property.

MAPPED_DELIM2

public static final char MAPPED_DELIM2

Deprecated: The notation used for property name expressions is now dependant on the Resolver implementation being used.

The delimiter that follows the key of a mapped property.

NESTED_DELIM

public static final char NESTED_DELIM

Deprecated: The notation used for property name expressions is now dependant on the Resolver implementation being used.

The delimiter that separates the components of a nested reference.

Method Detail

clearDescriptors

public static void clearDescriptors()
Clear any cached property descriptors information for all classes loaded by any class loaders. This is useful in cases where class loaders are thrown away to implement class reloading.

For more details see PropertyUtilsBean.

See Also: PropertyUtilsBean

copyProperties

public static void copyProperties(Object dest, Object orig)

Copy property values from the "origin" bean to the "destination" bean for all cases where the property names are the same (even though the actual getter and setter methods might have been customized via BeanInfo classes).

For more details see PropertyUtilsBean.

Parameters: dest Destination bean whose properties are modified orig Origin bean whose properties are retrieved

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if the dest or orig argument is null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

describe

public static Map describe(Object bean)

Return the entire set of properties for which the specified bean provides a read method.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose properties are to be extracted

Returns: The set of properties for the bean

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean is null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

getDebug

public static int getDebug()

Deprecated: The debug static property is no longer used

The debug static property is no longer used

Returns: debug property

getIndexedProperty

public static Object getIndexedProperty(Object bean, String name)

Return the value of the specified indexed property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be extracted name propertyname[index] of the property value to be extracted

Returns: the indexed property value

Throws: IndexOutOfBoundsException if the specified index is outside the valid range for the underlying property IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: getIndexedProperty

getIndexedProperty

public static Object getIndexedProperty(Object bean, String name, int index)

Return the value of the specified indexed property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be extracted name Simple property name of the property value to be extracted index Index of the property value to be extracted

Returns: the indexed property value

Throws: IndexOutOfBoundsException if the specified index is outside the valid range for the underlying property IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

getMappedProperty

public static Object getMappedProperty(Object bean, String name)

Return the value of the specified mapped property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be extracted name propertyname(key) of the property value to be extracted

Returns: the mapped property value

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: getMappedProperty

getMappedProperty

public static Object getMappedProperty(Object bean, String name, String key)

Return the value of the specified mapped property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be extracted name Mapped property name of the property value to be extracted key Key of the property value to be extracted

Returns: the mapped property value

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

getMappedPropertyDescriptors

public static FastHashMap getMappedPropertyDescriptors(Class beanClass)

Deprecated: This method should not be exposed

Return the mapped property descriptors for this bean class.

For more details see PropertyUtilsBean.

Parameters: beanClass Bean class to be introspected

Returns: the mapped property descriptors

See Also: getMappedPropertyDescriptors

getMappedPropertyDescriptors

public static FastHashMap getMappedPropertyDescriptors(Object bean)

Deprecated: This method should not be exposed

Return the mapped property descriptors for this bean.

For more details see PropertyUtilsBean.

Parameters: bean Bean to be introspected

Returns: the mapped property descriptors

See Also: getMappedPropertyDescriptors

getNestedProperty

public static Object getNestedProperty(Object bean, String name)

Return the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be extracted name Possibly nested name of the property to be extracted

Returns: the nested property value

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null NestedNullException if a nested reference to a property returns null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

getProperty

public static Object getProperty(Object bean, String name)

Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be extracted name Possibly indexed and/or nested name of the property to be extracted

Returns: the property value

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

getPropertyDescriptor

public static PropertyDescriptor getPropertyDescriptor(Object bean, String name)

Retrieve the property descriptor for the specified property of the specified bean, or return null if there is no such descriptor.

For more details see PropertyUtilsBean.

Parameters: bean Bean for which a property descriptor is requested name Possibly indexed and/or nested name of the property for which a property descriptor is requested

Returns: the property descriptor

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null IllegalArgumentException if a nested reference to a property returns null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

getPropertyDescriptors

public static PropertyDescriptor[] getPropertyDescriptors(Class beanClass)

Retrieve the property descriptors for the specified class, introspecting and caching them the first time a particular bean class is encountered.

For more details see PropertyUtilsBean.

Parameters: beanClass Bean class for which property descriptors are requested

Returns: the property descriptors

Throws: IllegalArgumentException if beanClass is null

See Also: getPropertyDescriptors

getPropertyDescriptors

public static PropertyDescriptor[] getPropertyDescriptors(Object bean)

Retrieve the property descriptors for the specified bean, introspecting and caching them the first time a particular bean class is encountered.

For more details see PropertyUtilsBean.

Parameters: bean Bean for which property descriptors are requested

Returns: the property descriptors

Throws: IllegalArgumentException if bean is null

See Also: getPropertyDescriptors

getPropertyEditorClass

public static Class getPropertyEditorClass(Object bean, String name)

Return the Java Class repesenting the property editor class that has been registered for this property (if any).

For more details see PropertyUtilsBean.

Parameters: bean Bean for which a property descriptor is requested name Possibly indexed and/or nested name of the property for which a property descriptor is requested

Returns: the property editor class

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null IllegalArgumentException if a nested reference to a property returns null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: getPropertyEditorClass

getPropertyType

public static Class getPropertyType(Object bean, String name)

Return the Java Class representing the property type of the specified property, or null if there is no such property for the specified bean.

For more details see PropertyUtilsBean.

Parameters: bean Bean for which a property descriptor is requested name Possibly indexed and/or nested name of the property for which a property descriptor is requested

Returns: The property type

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null IllegalArgumentException if a nested reference to a property returns null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

getReadMethod

public static Method getReadMethod(PropertyDescriptor descriptor)

Return an accessible property getter method for this property, if there is one; otherwise return null.

For more details see PropertyUtilsBean.

Parameters: descriptor Property descriptor to return a getter for

Returns: The read method

See Also: getReadMethod

getSimpleProperty

public static Object getSimpleProperty(Object bean, String name)

Return the value of the specified simple property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be extracted name Name of the property to be extracted

Returns: The property value

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null IllegalArgumentException if the property name is nested or indexed InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

getWriteMethod

public static Method getWriteMethod(PropertyDescriptor descriptor)

Return an accessible property setter method for this property, if there is one; otherwise return null.

For more details see PropertyUtilsBean.

Parameters: descriptor Property descriptor to return a setter for

Returns: The write method

See Also: getWriteMethod

isReadable

public static boolean isReadable(Object bean, String name)

Return true if the specified property name identifies a readable property on the specified bean; otherwise, return false.

For more details see PropertyUtilsBean.

Parameters: bean Bean to be examined (may be a DynaBean name Property name to be evaluated

Returns: true if the property is readable, otherwise false

Throws: IllegalArgumentException if bean or name is null

Since: BeanUtils 1.6

See Also: PropertyUtilsBean

isWriteable

public static boolean isWriteable(Object bean, String name)

Return true if the specified property name identifies a writeable property on the specified bean; otherwise, return false.

For more details see PropertyUtilsBean.

Parameters: bean Bean to be examined (may be a DynaBean name Property name to be evaluated

Returns: true if the property is writeable, otherwise false

Throws: IllegalArgumentException if bean or name is null

Since: BeanUtils 1.6

See Also: PropertyUtilsBean

setDebug

public static void setDebug(int newDebug)

Deprecated: The debug static property is no longer used

The debug static property is no longer used

Parameters: newDebug debug property

setIndexedProperty

public static void setIndexedProperty(Object bean, String name, Object value)

Sets the value of the specified indexed property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be modified name propertyname[index] of the property value to be modified value Value to which the specified property element should be set

Throws: IndexOutOfBoundsException if the specified index is outside the valid range for the underlying property IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

setIndexedProperty

public static void setIndexedProperty(Object bean, String name, int index, Object value)

Sets the value of the specified indexed property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be set name Simple property name of the property value to be set index Index of the property value to be set value Value to which the indexed property element is to be set

Throws: IndexOutOfBoundsException if the specified index is outside the valid range for the underlying property IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

setMappedProperty

public static void setMappedProperty(Object bean, String name, Object value)

Sets the value of the specified mapped property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be set name propertyname(key) of the property value to be set value The property value to be set

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

setMappedProperty

public static void setMappedProperty(Object bean, String name, String key, Object value)

Sets the value of the specified mapped property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be set name Mapped property name of the property value to be set key Key of the property value to be set value The property value to be set

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

setNestedProperty

public static void setNestedProperty(Object bean, String name, Object value)

Sets the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be modified name Possibly nested name of the property to be modified value Value to which the property is to be set

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null IllegalArgumentException if a nested reference to a property returns null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

setProperty

public static void setProperty(Object bean, String name, Object value)

Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be modified name Possibly indexed and/or nested name of the property to be modified value Value to which this property is to be set

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

setSimpleProperty

public static void setSimpleProperty(Object bean, String name, Object value)

Set the value of the specified simple property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Parameters: bean Bean whose property is to be modified name Name of the property to be modified value Value to which the property should be set

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if bean or name is null IllegalArgumentException if the property name is nested or indexed InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

See Also: PropertyUtilsBean

Copyright © 2000-2010 Apache Software Foundation. All Rights Reserved.