java.lang.Object | |
↳ | org.apache.commons.beanutils.BeanUtilsBean |
Known Direct Subclasses |
JavaBean property population methods.
This class provides implementations for the utility methods in
BeanUtils
.
Different instances can be used to isolate caches between classloaders
and to vary the value converters registered.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs an instance using new property and conversion instances. | |||||||||||
Constructs an instance using given conversion instances
and new | |||||||||||
Constructs an instance using given property and conversion instances. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Clone a bean based on the available property getters and setters, even if the bean class itself does not implement Cloneable. | |||||||||||
Copy property values from the origin bean to the destination bean for all cases where the property names are the same. | |||||||||||
Copy the specified property value to the specified destination bean, performing any type conversion that is required. | |||||||||||
Return the entire set of properties for which the specified bean provides a read method. | |||||||||||
Return the value of the specified array property of the specified
bean, as a String array.
| |||||||||||
Gets the
ConvertUtilsBean instance used to perform the conversions. | |||||||||||
Return the value of the specified indexed property of the specified
bean, as a String.
| |||||||||||
Return the value of the specified indexed property of the specified
bean, as a String.
| |||||||||||
Gets the instance which provides the functionality for
BeanUtils . | |||||||||||
Return the value of the specified mapped property of the specified
bean, as a String.
| |||||||||||
Return the value of the specified indexed property of the specified
bean, as a String.
| |||||||||||
Return the value of the (possibly nested) property of the specified
name, for the specified bean, as a String.
| |||||||||||
Return the value of the specified property of the specified bean,
no matter which property reference format is used, as a String.
| |||||||||||
Gets the
PropertyUtilsBean instance used to access properties. | |||||||||||
Return the value of the specified simple property of the specified
bean, converted to a String.
| |||||||||||
If we're running on JDK 1.4 or later, initialize the cause for the given throwable.
| |||||||||||
Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs. | |||||||||||
Sets the instance which provides the functionality for
BeanUtils . | |||||||||||
Set the specified property value, performing type conversions as required to conform to the type of the destination property. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Convert the value to an object of the specified class (if possible). |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Constructs an instance using new property and conversion instances.
Constructs an instance using given conversion instances
and new PropertyUtilsBean
instance.
convertUtilsBean | use this ConvertUtilsBean
to perform conversions from one object to another |
---|
Constructs an instance using given property and conversion instances.
convertUtilsBean | use this ConvertUtilsBean
to perform conversions from one object to another |
---|---|
propertyUtilsBean | use this PropertyUtilsBean
to access properties
|
Clone a bean based on the available property getters and setters, even if the bean class itself does not implement Cloneable.
Note: this method creates a shallow clone. In other words, any objects referred to by the bean are shared with the clone rather than being cloned in turn.
bean | Bean to be cloned |
---|
IllegalAccessException | if the caller does not have access to the property accessor method |
---|---|
InstantiationException | if a new instance of the bean's class cannot be instantiated |
InvocationTargetException | if the property accessor method throws an exception |
NoSuchMethodException | if an accessor method for this property cannot be found |
Copy property values from the origin bean to the destination bean for all cases where the property names are the same. For each property, a conversion is attempted as necessary. All combinations of standard JavaBeans and DynaBeans as origin and destination are supported. Properties that exist in the origin bean, but do not exist in the destination bean (or are read-only in the destination bean) are silently ignored.
If the origin "bean" is actually a Map
, it is assumed
to contain String-valued simple property names as the keys, pointing at
the corresponding property values that will be converted (if necessary)
and set in the destination bean. Note that this method
is intended to perform a "shallow copy" of the properties and so complex
properties (for example, nested ones) will not be copied.
This method differs from populate()
, which
was primarily designed for populating JavaBeans from the map of request
parameters retrieved on an HTTP request, is that no scalar->indexed
or indexed->scalar manipulations are performed. If the origin property
is indexed, the destination property must be also.
If you know that no type conversions are required, the
copyProperties()
method in PropertyUtils
will
execute faster than this method.
FIXME - Indexed and mapped properties that do not have getter and setter methods for the underlying array or Map are not copied by this method.
dest | Destination bean whose properties are modified |
---|---|
orig | Origin bean whose properties are retrieved |
IllegalAccessException | if the caller does not have access to the property accessor method |
---|---|
IllegalArgumentException | if the dest or
orig argument is null or if the dest
property type is different from the source type and the relevant
converter has not been registered. |
InvocationTargetException | if the property accessor method throws an exception |
Copy the specified property value to the specified destination bean,
performing any type conversion that is required. If the specified
bean does not have a property of the specified name, or the property
is read only on the destination bean, return without
doing anything. If you have custom destination property types, register
Converter
s for them by calling the register()
method of ConvertUtils
.
IMPLEMENTATION RESTRICTIONS:
bean | Bean on which setting is to be performed |
---|---|
name | Property name (can be nested/indexed/mapped/combo) |
value | Value to be set |
IllegalAccessException | if the caller does not have access to the property accessor method |
---|---|
InvocationTargetException | if the property accessor method throws an exception |
Return the entire set of properties for which the specified bean
provides a read method. This map contains the to String
converted property values for all properties for which a read method
is provided (i.e. where the getReadMethod() returns non-null).
This map can be fed back to a call to
BeanUtils.populate()
to reconsitute the same set of
properties, modulo differences for read-only and write-only
properties, but only if there are no indexed properties.
Warning: if any of the bean property implementations
contain (directly or indirectly) a call to this method then
a stack overflow may result. For example:
will result in an infinite regression when
class MyBean
{
public Map getParameterMap()
{
BeanUtils.describe(this);
}
}
getParametersMap
is called. It is recommended that such methods are given alternative
names (for example, parametersMap
).
bean | Bean whose properties are to be extracted |
---|
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 property cannot be found |
Return the value of the specified array property of the specified bean, as a String array.
bean | Bean whose property is to be extracted |
---|---|
name | Name of the property to be extracted |
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 property cannot be found |
Gets the ConvertUtilsBean
instance used to perform the conversions.
Return the value of the specified indexed property of the specified
bean, as a String. The zero-relative index of the
required value must be included (in square brackets) as a suffix to
the property name, or IllegalArgumentException
will be
thrown.
bean | Bean whose property is to be extracted |
---|---|
name | propertyname[index] of the property value
to be extracted |
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 property cannot be found |
Return the value of the specified indexed property of the specified bean, as a String. The index is specified as a method parameter and must *not* be included in the property name expression
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 |
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 property cannot be found |
Gets the instance which provides the functionality for BeanUtils
.
This is a pseudo-singleton - an single instance is provided per (thread) context classloader.
This mechanism provides isolation for web apps deployed in the same container.
Return the value of the specified mapped property of the specified bean, as a String. The key is specified as a method parameter and must *not* be included in the property name expression
bean | Bean whose property is to be extracted |
---|---|
name | Simple property name of the property value to be extracted |
key | Lookup key of the property value to be extracted |
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 property cannot be found |
Return the value of the specified indexed property of the specified
bean, as a String. The String-valued key of the required value
must be included (in parentheses) as a suffix to
the property name, or IllegalArgumentException
will be
thrown.
bean | Bean whose property is to be extracted |
---|---|
name | propertyname(index) of the property value
to be extracted |
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 property cannot be found |
Return the value of the (possibly nested) property of the specified name, for the specified bean, as a String.
bean | Bean whose property is to be extracted |
---|---|
name | Possibly nested name of the property to be extracted |
IllegalAccessException | if the caller does not have access to the property accessor method |
---|---|
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 property cannot be found |
Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.
bean | Bean whose property is to be extracted |
---|---|
name | Possibly indexed and/or nested name of the property to be extracted |
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 property cannot be found |
Gets the PropertyUtilsBean
instance used to access properties.
Return the value of the specified simple property of the specified bean, converted to a String.
bean | Bean whose property is to be extracted |
---|---|
name | Name of the property to be extracted |
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 property cannot be found |
If we're running on JDK 1.4 or later, initialize the cause for the given throwable.
throwable | The throwable. |
---|---|
cause | The cause of the throwable. |
Populate the JavaBeans properties of the specified bean, based on
the specified name/value pairs. This method uses Java reflection APIs
to identify corresponding "property setter" method names, and deals
with setter arguments of type String
, boolean
,
int
, long
, float
, and
double
. In addition, array setters for these types (or the
corresponding primitive types) can also be identified.
The particular setter method to be called for each property is determined using the usual JavaBeans introspection mechanisms. Thus, you may identify custom setter methods using a BeanInfo class that is associated with the class of the bean itself. If no such BeanInfo class is available, the standard method name conversion ("set" plus the capitalized name of the property in question) is used.
NOTE: It is contrary to the JavaBeans Specification to have more than one setter method (with different argument signatures) for the same property.
WARNING - The logic of this method is customized
for extracting String-based request parameters from an HTTP request.
It is probably not what you want for general property copying with
type conversion. For that purpose, check out the
copyProperties()
method instead.
bean | JavaBean whose properties are being populated |
---|---|
properties | Map keyed by property name, with the corresponding (String or String[]) value(s) to be set |
IllegalAccessException | if the caller does not have access to the property accessor method |
---|---|
InvocationTargetException | if the property accessor method throws an exception |
Sets the instance which provides the functionality for BeanUtils
.
This is a pseudo-singleton - an single instance is provided per (thread) context classloader.
This mechanism provides isolation for web apps deployed in the same container.
newInstance | The (pseudo-singleton) BeanUtils bean instance |
---|
Set the specified property value, performing type conversions as required to conform to the type of the destination property.
If the property is read only then the method returns without throwing an exception.
If null
is passed into a property expecting a primitive value,
then this will be converted as if it were a null
string.
WARNING - The logic of this method is customized
to meet the needs of populate()
, and is probably not what
you want for general property copying with type conversion. For that
purpose, check out the copyProperty()
method instead.
WARNING - PLEASE do not modify the behavior of this method without consulting with the Struts developer community. There are some subtleties to its functionality that are not documented in the Javadoc description above, yet are vital to the way that Struts utilizes this method.
bean | Bean on which setting is to be performed |
---|---|
name | Property name (can be nested/indexed/mapped/combo) |
value | Value to be set |
IllegalAccessException | if the caller does not have access to the property accessor method |
---|---|
InvocationTargetException | if the property accessor method throws an exception |
Convert the value to an object of the specified class (if possible).
value | Value to be converted (may be null) |
---|---|
type | Class of the value to be converted to |
ConversionException | if thrown by an underlying Converter |
---|