|
||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||
概要: 内部クラス | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |
java.lang.Object | +--org.apache.commons.beanutils.PropertyUtils
Utility methods for using Java Reflection APIs to facilitate generic
property getter and setter operations on Java objects. Much of this
code was originally included in 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 layout of an identifying String in parentheses:
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.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.
フィールドの概要 | |
private static int |
debug
The debugging detail level for this component. |
private static org.apache.commons.collections.FastHashMap |
descriptorsCache
The cache of PropertyDescriptor arrays for beans we have already introspected, keyed by the java.lang.Class of this object. |
static char |
INDEXED_DELIM
The delimiter that preceeds the zero-relative subscript for an indexed reference. |
static char |
INDEXED_DELIM2
The delimiter that follows the zero-relative subscript for an indexed reference. |
static char |
MAPPED_DELIM
The delimiter that preceeds the key of a mapped property. |
static char |
MAPPED_DELIM2
The delimiter that follows the key of a mapped property. |
private static org.apache.commons.collections.FastHashMap |
mappedDescriptorsCache
|
static char |
NESTED_DELIM
The delimiter that separates the components of a nested reference. |
コンストラクタの概要 | |
PropertyUtils()
|
メソッドの概要 | |
(パッケージプライベート) static void |
|
static void |
clearDescriptors()
Clear any cached property descriptors information for all classes loaded by any class loaders. |
static 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). |
static java.util.Map |
describe(java.lang.Object bean)
Return the entire set of properties for which the specified bean provides a read method. |
static int |
getDebug()
|
static 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. |
static 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. |
static 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. |
static 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. |
static org.apache.commons.collections.FastHashMap |
getMappedPropertyDescriptors(java.lang.Object bean)
Return the mapped property descriptors for this bean. |
static 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. |
static 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. |
static 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. |
static 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. |
static 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). |
static 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. |
static 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 . |
static 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. |
static 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 . |
static void |
setDebug(int newDebug)
|
static 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. |
static 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. |
static 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. |
static 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. |
static 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. |
static 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. |
static 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. |
クラス java.lang.Object から継承したメソッド |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
フィールドの詳細 |
public static final char INDEXED_DELIM
public static final char INDEXED_DELIM2
public static final char MAPPED_DELIM
public static final char MAPPED_DELIM2
public static final char NESTED_DELIM
private static int debug
private static org.apache.commons.collections.FastHashMap descriptorsCache
private static org.apache.commons.collections.FastHashMap mappedDescriptorsCache
コンストラクタの詳細 |
public PropertyUtils()
メソッドの詳細 |
public static int getDebug()
public static void setDebug(int newDebug)
static void()
public static void clearDescriptors()
public static void copyProperties(java.lang.Object dest, java.lang.Object orig) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
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.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 static java.util.Map describe(java.lang.Object bean) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
getReadMethod()
returns non-null).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 static 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.bean
- Bean whose property is to be extractedname
- propertyname[index]
of the property value
to be extractedjava.lang.ArrayIndexOutOfBoundsException
- if the specified index
is outside the valid range for the underlying arrayjava.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 static 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
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.ArrayIndexOutOfBoundsException
- if the specified index
is outside the valid range for the underlying arrayjava.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 static 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 static 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 foundpublic static org.apache.commons.collections.FastHashMap getMappedPropertyDescriptors(java.lang.Object bean)
bean
- Bean to be introspectedpublic static 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 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 static 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 static java.beans.PropertyDescriptor getPropertyDescriptor(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
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.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 static java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Object bean)
bean
- Bean for which property descriptors are requestedjava.lang.IllegalArgumentException
- if bean
is nullpublic static java.lang.Class getPropertyEditorClass(java.lang.Object bean, java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
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.
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 static 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.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 static java.lang.reflect.Method getReadMethod(java.beans.PropertyDescriptor descriptor)
null
.descriptor
- Property descriptor to return a getter forpublic static 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 static java.lang.reflect.Method getWriteMethod(java.beans.PropertyDescriptor descriptor)
null
.descriptor
- Property descriptor to return a setter forpublic static 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.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.ArrayIndexOutOfBoundsException
- if the specified index
is outside the valid range for the underlying arrayjava.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 static 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
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.ArrayIndexOutOfBoundsException
- if the specified index
is outside the valid range for the underlying arrayjava.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 static 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 static 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 static 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
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 foundpublic static 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 static 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 found
|
||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||
概要: 内部クラス | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |