Top Description Fields Methods
org.springframework.beans

public Interface PropertyAccessor

Known Direct Subinterfaces
org.springframework.beans.ConfigurablePropertyAccessor
Imports
java.util.Map, org.springframework.core.convert.TypeDescriptor, org.springframework.lang.Nullable

Common interface for classes that can access named properties (such as bean properties of an object or fields in an object).

Serves as base interface for BeanWrapper.

Author
Juergen Hoeller
Since
1.1
See Also
BeanWrapper, PropertyAccessorFactory#forBeanPropertyAccess, PropertyAccessorFactory#forDirectFieldAccess

Field Summary

Modifier and TypeField and Description
public static final String
NESTED_PROPERTY_SEPARATOR

Path separator for nested properties.

public static final char
NESTED_PROPERTY_SEPARATOR_CHAR

Path separator for nested properties.

public static final String
PROPERTY_KEY_PREFIX

Marker that indicates the start of a property key for an indexed or mapped property like "person.addresses[0]".

public static final char
PROPERTY_KEY_PREFIX_CHAR

Marker that indicates the start of a property key for an indexed or mapped property like "person.addresses[0]".

public static final String
PROPERTY_KEY_SUFFIX

Marker that indicates the end of a property key for an indexed or mapped property like "person.addresses[0]".

public static final char
PROPERTY_KEY_SUFFIX_CHAR

Marker that indicates the end of a property key for an indexed or mapped property like "person.addresses[0]".

Method Summary

Modifier and TypeMethod and Description
public Class<?>

Returns:

the property type for the particular property, or null if not determinable
getPropertyType
(String
the property to check (may be a nested path and/or an indexed/mapped property)
propertyName
)

Determine the property type for the specified property, either checking the property descriptor or checking the value in case of an indexed or mapped element.

public TypeDescriptor

Returns:

the property type for the particular property, or null if not determinable
getPropertyTypeDescriptor
(String
the property to check (may be a nested path and/or an indexed/mapped property)
propertyName
)

Return a type descriptor for the specified property: preferably from the read method, falling back to the write method.

public Object

Returns:

the value of the property
getPropertyValue
(String
the name of the property to get the value of (may be a nested path and/or an indexed/mapped property)
propertyName
)

Get the current value of the specified property.

public boolean

Returns:

whether the property is readable
isReadableProperty
(String
the property to check (may be a nested path and/or an indexed/mapped property)
propertyName
)

Determine whether the specified property is readable.

public boolean

Returns:

whether the property is writable
isWritableProperty
(String
the property to check (may be a nested path and/or an indexed/mapped property)
propertyName
)

Determine whether the specified property is writable.

public void
setPropertyValue(String
the name of the property to set the value of (may be a nested path and/or an indexed/mapped property)
propertyName
,
Object
the new value
value
)

Set the specified value as current property value.

public void
setPropertyValue(PropertyValue
an object containing the new property value
pv
)

Set the specified value as current property value.

public void
setPropertyValues(Map<?, ?>
a Map to take properties from. Contains property value objects, keyed by property name
map
)

Perform a batch update from a Map.

public void
setPropertyValues(PropertyValues
a PropertyValues to set on the target object
pvs
)

The preferred way to perform a batch update.

public void
setPropertyValues(PropertyValues
a PropertyValues to set on the target object
pvs
,
boolean
should we ignore unknown properties (not found in the bean)
ignoreUnknown
)

Perform a batch update with more control over behavior.

public void
setPropertyValues(PropertyValues
a PropertyValues to set on the target object
pvs
,
boolean
should we ignore unknown properties (not found in the bean)
ignoreUnknown
,
boolean
should we ignore invalid properties (found but not accessible)
ignoreInvalid
)

Perform a batch update with full control over behavior.

Field Detail

NESTED_PROPERTY_SEPARATORback to summary
public static final String NESTED_PROPERTY_SEPARATOR

Path separator for nested properties. Follows normal Java conventions: getFoo().getBar() would be "foo.bar".

NESTED_PROPERTY_SEPARATOR_CHARback to summary
public static final char NESTED_PROPERTY_SEPARATOR_CHAR

Path separator for nested properties. Follows normal Java conventions: getFoo().getBar() would be "foo.bar".

PROPERTY_KEY_PREFIXback to summary
public static final String PROPERTY_KEY_PREFIX

Marker that indicates the start of a property key for an indexed or mapped property like "person.addresses[0]".

PROPERTY_KEY_PREFIX_CHARback to summary
public static final char PROPERTY_KEY_PREFIX_CHAR

Marker that indicates the start of a property key for an indexed or mapped property like "person.addresses[0]".

PROPERTY_KEY_SUFFIXback to summary
public static final String PROPERTY_KEY_SUFFIX

Marker that indicates the end of a property key for an indexed or mapped property like "person.addresses[0]".

PROPERTY_KEY_SUFFIX_CHARback to summary
public static final char PROPERTY_KEY_SUFFIX_CHAR

Marker that indicates the end of a property key for an indexed or mapped property like "person.addresses[0]".

Method Detail

getPropertyTypeback to summary
public Class<?> getPropertyType(String propertyName) throws BeansException

Determine the property type for the specified property, either checking the property descriptor or checking the value in case of an indexed or mapped element.

Parameters
propertyName:String

the property to check (may be a nested path and/or an indexed/mapped property)

Returns:Class<?>

the property type for the particular property, or null if not determinable

Annotations
@Nullable
Exceptions
PropertyAccessException:
if the property was valid but the accessor method failed
getPropertyTypeDescriptorback to summary
public TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException

Return a type descriptor for the specified property: preferably from the read method, falling back to the write method.

Parameters
propertyName:String

the property to check (may be a nested path and/or an indexed/mapped property)

Returns:TypeDescriptor

the property type for the particular property, or null if not determinable

Annotations
@Nullable
Exceptions
PropertyAccessException:
if the property was valid but the accessor method failed
getPropertyValueback to summary
public Object getPropertyValue(String propertyName) throws BeansException

Get the current value of the specified property.

Parameters
propertyName:String

the name of the property to get the value of (may be a nested path and/or an indexed/mapped property)

Returns:Object

the value of the property

Annotations
@Nullable
Exceptions
InvalidPropertyException:
if there is no such property or if the property isn't readable
PropertyAccessException:
if the property was valid but the accessor method failed
isReadablePropertyback to summary
public boolean isReadableProperty(String propertyName)

Determine whether the specified property is readable.

Returns false if the property doesn't exist.

Parameters
propertyName:String

the property to check (may be a nested path and/or an indexed/mapped property)

Returns:boolean

whether the property is readable

isWritablePropertyback to summary
public boolean isWritableProperty(String propertyName)

Determine whether the specified property is writable.

Returns false if the property doesn't exist.

Parameters
propertyName:String

the property to check (may be a nested path and/or an indexed/mapped property)

Returns:boolean

whether the property is writable

setPropertyValueback to summary
public void setPropertyValue(String propertyName, Object value) throws BeansException

Set the specified value as current property value.

Parameters
propertyName:String

the name of the property to set the value of (may be a nested path and/or an indexed/mapped property)

value:Object

the new value

Exceptions
InvalidPropertyException:
if there is no such property or if the property isn't writable
PropertyAccessException:
if the property was valid but the accessor method failed or a type mismatch occurred
setPropertyValueback to summary
public void setPropertyValue(PropertyValue pv) throws BeansException

Set the specified value as current property value.

Parameters
pv:PropertyValue

an object containing the new property value

Exceptions
InvalidPropertyException:
if there is no such property or if the property isn't writable
PropertyAccessException:
if the property was valid but the accessor method failed or a type mismatch occurred
setPropertyValuesback to summary
public void setPropertyValues(Map<?, ?> map) throws BeansException

Perform a batch update from a Map.

Bulk updates from PropertyValues are more powerful: This method is provided for convenience. Behavior will be identical to that of the setPropertyValues(PropertyValues) method.

Parameters
map:Map<?, ?>

a Map to take properties from. Contains property value objects, keyed by property name

Exceptions
InvalidPropertyException:
if there is no such property or if the property isn't writable
PropertyBatchUpdateException:
if one or more PropertyAccessExceptions occurred for specific properties during the batch update. This exception bundles all individual PropertyAccessExceptions. All other properties will have been successfully updated.
setPropertyValuesback to summary
public void setPropertyValues(PropertyValues pvs) throws BeansException

The preferred way to perform a batch update.

Note that performing a batch update differs from performing a single update, in that an implementation of this class will continue to update properties if a recoverable error (such as a type mismatch, but not an invalid field name or the like) is encountered, throwing a PropertyBatchUpdateException containing all the individual errors. This exception can be examined later to see all binding errors. Properties that were successfully updated remain changed.

Does not allow unknown fields or invalid fields.

Parameters
pvs:PropertyValues

a PropertyValues to set on the target object

Exceptions
InvalidPropertyException:
if there is no such property or if the property isn't writable
PropertyBatchUpdateException:
if one or more PropertyAccessExceptions occurred for specific properties during the batch update. This exception bundles all individual PropertyAccessExceptions. All other properties will have been successfully updated.
See Also
setPropertyValues(PropertyValues, boolean, boolean)
setPropertyValuesback to summary
public void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown) throws BeansException

Perform a batch update with more control over behavior.

Note that performing a batch update differs from performing a single update, in that an implementation of this class will continue to update properties if a recoverable error (such as a type mismatch, but not an invalid field name or the like) is encountered, throwing a PropertyBatchUpdateException containing all the individual errors. This exception can be examined later to see all binding errors. Properties that were successfully updated remain changed.

Parameters
pvs:PropertyValues

a PropertyValues to set on the target object

ignoreUnknown:boolean

should we ignore unknown properties (not found in the bean)

Exceptions
InvalidPropertyException:
if there is no such property or if the property isn't writable
PropertyBatchUpdateException:
if one or more PropertyAccessExceptions occurred for specific properties during the batch update. This exception bundles all individual PropertyAccessExceptions. All other properties will have been successfully updated.
See Also
setPropertyValues(PropertyValues, boolean, boolean)
setPropertyValuesback to summary
public void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown, boolean ignoreInvalid) throws BeansException

Perform a batch update with full control over behavior.

Note that performing a batch update differs from performing a single update, in that an implementation of this class will continue to update properties if a recoverable error (such as a type mismatch, but not an invalid field name or the like) is encountered, throwing a PropertyBatchUpdateException containing all the individual errors. This exception can be examined later to see all binding errors. Properties that were successfully updated remain changed.

Parameters
pvs:PropertyValues

a PropertyValues to set on the target object

ignoreUnknown:boolean

should we ignore unknown properties (not found in the bean)

ignoreInvalid:boolean

should we ignore invalid properties (found but not accessible)

Exceptions
InvalidPropertyException:
if there is no such property or if the property isn't writable
PropertyBatchUpdateException:
if one or more PropertyAccessExceptions occurred for specific properties during the batch update. This exception bundles all individual PropertyAccessExceptions. All other properties will have been successfully updated.