public class PropertyUtilsBean
extends java.lang.Object
BeanUtils
, but has been
separated because of the volume of code involved.
In general, the objects that are examined and modified using these
methods are expected to conform to the property getter and setter method
naming conventions described in the JavaBeans Specification (Version 1.0.1).
No data type conversions are performed, and there are no usage of any
PropertyEditor
classes that have been registered, although
a convenient way to access the registered classes themselves is included.
For the purposes of this class, five formats for referencing a particular
property value of a bean are defined, with the default layout of an
identifying String in parentheses. However the notation for these formats
and how they are resolved is now (since BeanUtils 1.8.0) controlled by
the configured Resolver
implementation:
name
) - The specified
name
identifies an individual property of a particular
JavaBean. The name of the actual getter or setter method to be used
is determined using standard JavaBeans instrospection, so that (unless
overridden by a BeanInfo
class, a property named "xyz"
will have a getter method named getXyz()
or (for boolean
properties only) isXyz()
, and a setter method named
setXyz()
.name1.name2.name3
) The first
name element is used to select a property getter, as for simple
references above. The object returned for this property is then
consulted, using the same approach, for a property getter for a
property named name2
, and so on. The property value that
is ultimately retrieved or modified is the one identified by the
last name element.name[index]
) - The underlying
property value is assumed to be an array, or this JavaBean is assumed
to have indexed property getter and setter methods. The appropriate
(zero-relative) entry in the array is selected. List
objects are now also supported for read/write. You simply need to define
a getter that returns the List
name(key)
) - The JavaBean
is assumed to have an property getter and setter methods with an
additional attribute of type java.lang.String
.name1.name2[index].name3(key)
) -
Combining mapped, nested, and indexed references is also
supported.Resolver
,
PropertyUtils
Modifier and Type | Field and Description |
---|---|
private WeakFastHashMap<java.lang.Class<?>,BeanIntrospectionData> |
descriptorsCache
The cache of PropertyDescriptor arrays for beans we have already
introspected, keyed by the java.lang.Class of this object.
|
private static java.lang.Object[] |
EMPTY_OBJECT_ARRAY
An empty object array
|
private java.util.List<BeanIntrospector> |
introspectors
The list with BeanIntrospector objects.
|
private org.apache.commons.logging.Log |
log
Log instance
|
private WeakFastHashMap<java.lang.Class<?>,org.apache.commons.collections.FastHashMap> |
mappedDescriptorsCache |
private Resolver |
resolver |
Constructor and Description |
---|
PropertyUtilsBean()
Base constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addBeanIntrospector(BeanIntrospector introspector)
Adds a
BeanIntrospector . |
void |
clearDescriptors()
Clear any cached property descriptors information for all classes
loaded by any class loaders.
|
void |
copyProperties(java.lang.Object dest,
java.lang.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). |
java.util.Map<java.lang.String,java.lang.Object> |
describe(java.lang.Object bean)
Return the entire set of properties for which the specified bean
provides a read method.
|
private BeanIntrospectionData |
fetchIntrospectionData(java.lang.Class<?> beanClass)
Performs introspection on the specified class.
|
java.lang.Object |
getIndexedProperty(java.lang.Object bean,
java.lang.String name)
Return the value of the specified indexed property of the specified
bean, with no type conversions.
|
java.lang.Object |
getIndexedProperty(java.lang.Object bean,
java.lang.String name,
int index)
Return the value of the specified indexed property of the specified
bean, with no type conversions.
|
protected static PropertyUtilsBean |
getInstance()
Return the PropertyUtils bean instance.
|
private BeanIntrospectionData |
getIntrospectionData(java.lang.Class<?> beanClass)
Obtains the
BeanIntrospectionData object describing the specified bean
class. |
java.lang.Object |
getMappedProperty(java.lang.Object bean,
java.lang.String name)
Return the value of the specified mapped property of the
specified bean, with no type conversions.
|
java.lang.Object |
getMappedProperty(java.lang.Object bean,
java.lang.String name,
java.lang.String key)
Return the value of the specified mapped property of the specified
bean, with no type conversions.
|
org.apache.commons.collections.FastHashMap |
getMappedPropertyDescriptors(java.lang.Class<?> beanClass)
Deprecated.
This method should not be exposed
|
org.apache.commons.collections.FastHashMap |
getMappedPropertyDescriptors(java.lang.Object bean)
Deprecated.
This method should not be exposed
|
java.lang.Object |
getNestedProperty(java.lang.Object bean,
java.lang.String name)
Return the value of the (possibly nested) property of the specified
name, for the specified bean, with no type conversions.
|
java.lang.Object |
getProperty(java.lang.Object bean,
java.lang.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.
|
java.beans.PropertyDescriptor |
getPropertyDescriptor(java.lang.Object bean,
java.lang.String name)
Retrieve the property descriptor for the specified property of the
specified bean, or return
null if there is no such
descriptor. |
java.beans.PropertyDescriptor[] |
getPropertyDescriptors(java.lang.Class<?> beanClass)
Retrieve the property descriptors for the specified class,
introspecting and caching them the first time a particular bean class
is encountered.
|
java.beans.PropertyDescriptor[] |
getPropertyDescriptors(java.lang.Object bean)
Retrieve the property descriptors for the specified bean,
introspecting and caching them the first time a particular bean class
is encountered.
|
java.lang.Class<?> |
getPropertyEditorClass(java.lang.Object bean,
java.lang.String name)
Return the Java Class repesenting the property editor class that has
been registered for this property (if any).
|
protected java.lang.Object |
getPropertyOfMapBean(java.util.Map<?,?> bean,
java.lang.String propertyName)
This method is called by getNestedProperty and setNestedProperty to
define what it means to get a property from an object which implements
Map.
|
java.lang.Class<?> |
getPropertyType(java.lang.Object bean,
java.lang.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. |
(package private) java.lang.reflect.Method |
getReadMethod(java.lang.Class<?> clazz,
java.beans.PropertyDescriptor descriptor)
Return an accessible property getter method for this property,
if there is one; otherwise return
null . |
java.lang.reflect.Method |
getReadMethod(java.beans.PropertyDescriptor descriptor)
Return an accessible property getter method for this property,
if there is one; otherwise return
null . |
Resolver |
getResolver()
Return the configured
Resolver implementation used by BeanUtils. |
java.lang.Object |
getSimpleProperty(java.lang.Object bean,
java.lang.String name)
Return the value of the specified simple property of the specified
bean, with no type conversions.
|
java.lang.reflect.Method |
getWriteMethod(java.lang.Class<?> clazz,
java.beans.PropertyDescriptor descriptor)
Return an accessible property setter method for this property,
if there is one; otherwise return
null . |
java.lang.reflect.Method |
getWriteMethod(java.beans.PropertyDescriptor descriptor)
Return an accessible property setter method for this property,
if there is one; otherwise return
null . |
private java.lang.Object |
invokeMethod(java.lang.reflect.Method method,
java.lang.Object bean,
java.lang.Object[] values)
This just catches and wraps IllegalArgumentException.
|
boolean |
isReadable(java.lang.Object bean,
java.lang.String name)
Return
true if the specified property name identifies
a readable property on the specified bean; otherwise, return
false . |
boolean |
isWriteable(java.lang.Object bean,
java.lang.String name)
Return
true if the specified property name identifies
a writeable property on the specified bean; otherwise, return
false . |
boolean |
removeBeanIntrospector(BeanIntrospector introspector)
Removes the specified
BeanIntrospector . |
void |
resetBeanIntrospectors()
Resets the
BeanIntrospector objects registered at this instance. |
void |
setIndexedProperty(java.lang.Object bean,
java.lang.String name,
int index,
java.lang.Object value)
Set the value of the specified indexed property of the specified
bean, with no type conversions.
|
void |
setIndexedProperty(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
Set the value of the specified indexed property of the specified
bean, with no type conversions.
|
void |
setMappedProperty(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
Set the value of the specified mapped property of the
specified bean, with no type conversions.
|
void |
setMappedProperty(java.lang.Object bean,
java.lang.String name,
java.lang.String key,
java.lang.Object value)
Set the value of the specified mapped property of the specified
bean, with no type conversions.
|
void |
setNestedProperty(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
Set the value of the (possibly nested) property of the specified
name, for the specified bean, with no type conversions.
|
void |
setProperty(java.lang.Object bean,
java.lang.String name,
java.lang.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.
|
protected void |
setPropertyOfMapBean(java.util.Map<java.lang.String,java.lang.Object> bean,
java.lang.String propertyName,
java.lang.Object value)
This method is called by method setNestedProperty when the current bean
is found to be a Map object, and defines how to deal with setting
a property on a Map.
|
void |
setResolver(Resolver resolver)
Configure the
Resolver implementation used by BeanUtils. |
void |
setSimpleProperty(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
Set the value of the specified simple property of the specified bean,
with no type conversions.
|
private static java.util.List<java.lang.Object> |
toObjectList(java.lang.Object obj)
Converts an object to a list of objects.
|
private static java.util.Map<java.lang.String,java.lang.Object> |
toPropertyMap(java.lang.Object obj)
Converts an object to a map with property values.
|
private Resolver resolver
private WeakFastHashMap<java.lang.Class<?>,BeanIntrospectionData> descriptorsCache
private WeakFastHashMap<java.lang.Class<?>,org.apache.commons.collections.FastHashMap> mappedDescriptorsCache
private static final java.lang.Object[] EMPTY_OBJECT_ARRAY
private final org.apache.commons.logging.Log log
private final java.util.List<BeanIntrospector> introspectors
protected static PropertyUtilsBean getInstance()
public Resolver getResolver()
Resolver
implementation used by BeanUtils.
The Resolver
handles the property name
expressions and the implementation in use effectively
controls the dialect of the expression language
that BeanUtils recongnises.
DefaultResolver
is the default implementation used.
public void setResolver(Resolver resolver)
Resolver
implementation used by BeanUtils.
The Resolver
handles the property name
expressions and the implementation in use effectively
controls the dialect of the expression language
that BeanUtils recongnises.
DefaultResolver
is the default implementation used.
resolver
- The property expression resolver.public final void resetBeanIntrospectors()
BeanIntrospector
objects registered at this instance. After this
method was called, only the default BeanIntrospector
is registered.public void addBeanIntrospector(BeanIntrospector introspector)
BeanIntrospector
. This object is invoked when the
property descriptors of a class need to be obtained.introspector
- the BeanIntrospector
to be added (must
not be nulljava.lang.IllegalArgumentException
- if the argument is nullpublic boolean removeBeanIntrospector(BeanIntrospector introspector)
BeanIntrospector
.introspector
- the BeanIntrospector
to be removedBeanIntrospector
existed and
could be removed, false otherwisepublic void clearDescriptors()
public void copyProperties(java.lang.Object dest, java.lang.Object orig) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
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). No conversions are performed on the
actual property values -- it is assumed that the values retrieved from
the origin bean are assignment-compatible with the types expected by
the destination bean.
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 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.
Note, that this method will not copy a List to a List, or an Object[] to an Object[]. It's specifically for copying JavaBean properties.
dest
- Destination bean whose properties are modifiedorig
- Origin bean whose properties are retrievedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if the dest
or
orig
argument is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic java.util.Map<java.lang.String,java.lang.Object> describe(java.lang.Object bean) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
Return the entire set of properties for which the specified bean
provides a read method. This map contains the unconverted property
values for all properties for which a read method is provided
(i.e. where the getReadMethod()
returns non-null).
FIXME - Does not account for mapped properties.
bean
- Bean whose properties are to be extractedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic java.lang.Object getIndexedProperty(java.lang.Object bean, java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
IllegalArgumentException
will be
thrown. In addition to supporting the JavaBeans specification, this
method has been extended to support List
objects as well.bean
- Bean whose property is to be extractedname
- propertyname[index]
of the property value
to be extractedjava.lang.IndexOutOfBoundsException
- if the specified index
is outside the valid range for the underlying array or Listjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic java.lang.Object getIndexedProperty(java.lang.Object bean, java.lang.String name, int index) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
List
objects as well.bean
- Bean whose property is to be extractedname
- Simple property name of the property value to be extractedindex
- Index of the property value to be extractedjava.lang.IndexOutOfBoundsException
- if the specified index
is outside the valid range for the underlying propertyjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic java.lang.Object getMappedProperty(java.lang.Object bean, java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
IllegalArgumentException
will be
thrown.bean
- Bean whose property is to be extractedname
- propertyname(key)
of the property value
to be extractedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic java.lang.Object getMappedProperty(java.lang.Object bean, java.lang.String name, java.lang.String key) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
bean
- Bean whose property is to be extractedname
- Mapped property name of the property value to be extractedkey
- Key of the property value to be extractedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be found@Deprecated public org.apache.commons.collections.FastHashMap getMappedPropertyDescriptors(java.lang.Class<?> beanClass)
Return the mapped property descriptors for this bean class.
FIXME - Does not work with DynaBeans.
beanClass
- Bean class to be introspected@Deprecated public org.apache.commons.collections.FastHashMap getMappedPropertyDescriptors(java.lang.Object bean)
Return the mapped property descriptors for this bean.
FIXME - Does not work with DynaBeans.
bean
- Bean to be introspectedpublic java.lang.Object getNestedProperty(java.lang.Object bean, java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
bean
- Bean whose property is to be extractedname
- Possibly nested name of the property to be extractedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nullNestedNullException
- if a nested reference to a
property returns nulljava.lang.reflect.InvocationTargetException
- if the property accessor method throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundprotected java.lang.Object getPropertyOfMapBean(java.util.Map<?,?> bean, java.lang.String propertyName) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
bean
- Map beanpropertyName
- The property namejava.lang.IllegalArgumentException
- when the propertyName is regarded as
being invalid.java.lang.IllegalAccessException
- just in case subclasses override this
method to try to access real getter methods and find permission is denied.java.lang.reflect.InvocationTargetException
- just in case subclasses override this
method to try to access real getter methods, and find it throws an
exception when invoked.java.lang.NoSuchMethodException
- just in case subclasses override this
method to try to access real getter methods, and want to fail if
no simple method is available.public java.lang.Object getProperty(java.lang.Object bean, java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
bean
- Bean whose property is to be extractedname
- Possibly indexed and/or nested name of the property
to be extractedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Object bean, java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
Retrieve the property descriptor for the specified property of the
specified bean, or return null
if there is no such
descriptor. This method resolves indexed and nested property
references in the same manner as other methods in this class, except
that if the last (or only) name element is indexed, the descriptor
for the last resolved property itself is returned.
FIXME - Does not work with DynaBeans.
Note that for Java 8 and above, this method no longer return
IndexedPropertyDescriptor for List
-typed properties, only for
properties typed as native array. (BEANUTILS-492).
bean
- Bean for which a property descriptor is requestedname
- Possibly indexed and/or nested name of the property for
which a property descriptor is requestedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.IllegalArgumentException
- if a nested reference to a
property returns nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Class<?> beanClass)
Retrieve the property descriptors for the specified class, introspecting and caching them the first time a particular bean class is encountered.
FIXME - Does not work with DynaBeans.
beanClass
- Bean class for which property descriptors are requestedjava.lang.IllegalArgumentException
- if beanClass
is nullpublic java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Object bean)
Retrieve the property descriptors for the specified bean, introspecting and caching them the first time a particular bean class is encountered.
FIXME - Does not work with DynaBeans.
bean
- Bean for which property descriptors are requestedjava.lang.IllegalArgumentException
- if bean
is nullpublic java.lang.Class<?> getPropertyEditorClass(java.lang.Object bean, java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
Return the Java Class repesenting the property editor class that has
been registered for this property (if any). This method follows the
same name resolution rules used by getPropertyDescriptor()
,
so if the last element of a name reference is indexed, the property
editor for the underlying property's class is returned.
Note that null
will be returned if there is no property,
or if there is no registered property editor class. Because this
return value is ambiguous, you should determine the existence of the
property itself by other means.
FIXME - Does not work with DynaBeans.
bean
- Bean for which a property descriptor is requestedname
- Possibly indexed and/or nested name of the property for
which a property descriptor is requestedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.IllegalArgumentException
- if a nested reference to a
property returns nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic java.lang.Class<?> getPropertyType(java.lang.Object bean, java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
null
if there is no such property for the
specified bean. This method follows the same name resolution rules
used by getPropertyDescriptor()
, so if the last element
of a name reference is indexed, the type of the property itself will
be returned. If the last (or only) element has no property with the
specified name, null
is returned.
If the property is an indexed property (e.g. String[]
),
this method will return the type of the items within that array.
Note that from Java 8 and newer, this method do not support
such index types from items within an Collection, and will
instead return the collection type (e.g. java.util.List) from the
getter mtethod.
bean
- Bean for which a property descriptor is requestedname
- Possibly indexed and/or nested name of the property for
which a property descriptor is requestedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.IllegalArgumentException
- if a nested reference to a
property returns nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic java.lang.reflect.Method getReadMethod(java.beans.PropertyDescriptor descriptor)
Return an accessible property getter method for this property,
if there is one; otherwise return null
.
FIXME - Does not work with DynaBeans.
descriptor
- Property descriptor to return a getter forjava.lang.reflect.Method getReadMethod(java.lang.Class<?> clazz, java.beans.PropertyDescriptor descriptor)
Return an accessible property getter method for this property,
if there is one; otherwise return null
.
FIXME - Does not work with DynaBeans.
clazz
- The class of the read method will be invoked ondescriptor
- Property descriptor to return a getter forpublic java.lang.Object getSimpleProperty(java.lang.Object bean, java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
bean
- Bean whose property is to be extractedname
- Name of the property to be extractedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.IllegalArgumentException
- if the property name
is nested or indexedjava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic java.lang.reflect.Method getWriteMethod(java.beans.PropertyDescriptor descriptor)
Return an accessible property setter method for this property,
if there is one; otherwise return null
.
Note: This method does not work correctly with custom bean
introspection under certain circumstances. It may return null
even if a write method is defined for the property in question. Use
getWriteMethod(Class, PropertyDescriptor)
to be sure that the
correct result is returned.
FIXME - Does not work with DynaBeans.
descriptor
- Property descriptor to return a setter forpublic java.lang.reflect.Method getWriteMethod(java.lang.Class<?> clazz, java.beans.PropertyDescriptor descriptor)
Return an accessible property setter method for this property,
if there is one; otherwise return null
.
FIXME - Does not work with DynaBeans.
clazz
- The class of the read method will be invoked ondescriptor
- Property descriptor to return a setter forpublic boolean isReadable(java.lang.Object bean, java.lang.String name)
Return true
if the specified property name identifies
a readable property on the specified bean; otherwise, return
false
.
bean
- Bean to be examined (may be a DynaBean
name
- Property name to be evaluatedtrue
if the property is readable,
otherwise false
java.lang.IllegalArgumentException
- if bean
or name
is null
public boolean isWriteable(java.lang.Object bean, java.lang.String name)
Return true
if the specified property name identifies
a writeable property on the specified bean; otherwise, return
false
.
bean
- Bean to be examined (may be a DynaBean
name
- Property name to be evaluatedtrue
if the property is writeable,
otherwise false
java.lang.IllegalArgumentException
- if bean
or name
is null
public void setIndexedProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
IllegalArgumentException
will be
thrown. In addition to supporting the JavaBeans specification, this
method has been extended to support List
objects as well.bean
- Bean whose property is to be modifiedname
- propertyname[index]
of the property value
to be modifiedvalue
- Value to which the specified property element
should be setjava.lang.IndexOutOfBoundsException
- if the specified index
is outside the valid range for the underlying propertyjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic void setIndexedProperty(java.lang.Object bean, java.lang.String name, int index, java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
List
objects as well.bean
- Bean whose property is to be setname
- Simple property name of the property value to be setindex
- Index of the property value to be setvalue
- Value to which the indexed property element is to be setjava.lang.IndexOutOfBoundsException
- if the specified index
is outside the valid range for the underlying propertyjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic void setMappedProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
IllegalArgumentException
will be
thrown.bean
- Bean whose property is to be setname
- propertyname(key)
of the property value
to be setvalue
- The property value to be setjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic void setMappedProperty(java.lang.Object bean, java.lang.String name, java.lang.String key, java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
bean
- Bean whose property is to be setname
- Mapped property name of the property value to be setkey
- Key of the property value to be setvalue
- The property value to be setjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic void setNestedProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
Example values for parameter "name" are:
bean
- Bean whose property is to be modifiedname
- Possibly nested name of the property to be modifiedvalue
- Value to which the property is to be setjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.IllegalArgumentException
- if a nested reference to a
property returns nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundprotected void setPropertyOfMapBean(java.util.Map<java.lang.String,java.lang.Object> bean, java.lang.String propertyName, java.lang.Object value) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
The standard implementation here is to:
The default behaviour of beanutils 1.7.1 or later is for assigning to "a.b" to mean a.put(b, obj) always. However the behaviour of beanutils version 1.6.0, 1.6.1, 1.7.0 was for "a.b" to mean a.setB(obj) if such a method existed, and a.put(b, obj) otherwise. In version 1.5 it meant a.put(b, obj) always (ie the same as the behaviour in the current version). In versions prior to 1.5 it meant a.setB(obj) always. [yes, this is all very unfortunate]
Users who would like to customise the meaning of "a.b" in method setNestedProperty when a is a Map can create a custom subclass of this class and override this method to implement the behaviour of their choice, such as restoring the pre-1.4 behaviour of this class if they wish. When overriding this method, do not forget to deal with MAPPED_DELIM and INDEXED_DELIM characters in the propertyName.
Note, however, that the recommended solution for objects that implement Map but want their simple properties to come first is for those objects to override their get/put methods to implement that behaviour, and not to solve the problem by modifying the default behaviour of the PropertyUtilsBean class by overriding this method.
bean
- Map beanpropertyName
- The property namevalue
- the property valuejava.lang.IllegalArgumentException
- when the propertyName is regarded as
being invalid.java.lang.IllegalAccessException
- just in case subclasses override this
method to try to access real setter methods and find permission is denied.java.lang.reflect.InvocationTargetException
- just in case subclasses override this
method to try to access real setter methods, and find it throws an
exception when invoked.java.lang.NoSuchMethodException
- just in case subclasses override this
method to try to access real setter methods, and want to fail if
no simple method is available.public void setProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
bean
- Bean whose property is to be modifiedname
- Possibly indexed and/or nested name of the property
to be modifiedvalue
- Value to which this property is to be setjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundpublic void setSimpleProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
bean
- Bean whose property is to be modifiedname
- Name of the property to be modifiedvalue
- Value to which the property should be setjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.IllegalArgumentException
- if the property name is
nested or indexedjava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
propety cannot be foundprivate java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object bean, java.lang.Object[] values) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
private BeanIntrospectionData getIntrospectionData(java.lang.Class<?> beanClass)
BeanIntrospectionData
object describing the specified bean
class. This object is looked up in the internal cache. If necessary, introspection
is performed now on the affected bean class, and the results object is created.beanClass
- the bean class in questionBeanIntrospectionData
object for this classjava.lang.IllegalArgumentException
- if the bean class is nullprivate BeanIntrospectionData fetchIntrospectionData(java.lang.Class<?> beanClass)
BeanIntrospector
objects that were
added to this instance.beanClass
- the class to be inspectedprivate static java.util.List<java.lang.Object> toObjectList(java.lang.Object obj)
obj
- the object to be convertedprivate static java.util.Map<java.lang.String,java.lang.Object> toPropertyMap(java.lang.Object obj)
obj
- the object to be convertedCopyright (c) 2000-2008 - Apache Software Foundation