public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyAccessor
ConfigurablePropertyAccessor
that provides the necessary
infrastructure for all typical use cases.
This accessor will convert collection and array values to the corresponding
target collections or arrays, if necessary. Custom property editors that deal
with collections or arrays can either be written via PropertyEditor's
setValue
, or against a comma-delimited String via setAsText
,
as String arrays are converted in such a format if the array itself is not
assignable.
PropertyEditorRegistrySupport.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)
,
AbstractPropertyAccessor.setPropertyValues(java.util.Map<?, ?>)
,
setPropertyValue(java.lang.String, java.lang.Object)
,
getPropertyValue(java.lang.String)
,
getPropertyType(java.lang.String)
,
BeanWrapper
,
PropertyEditorRegistrySupport
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractNestablePropertyAccessor.PropertyHandler
Handle a given property.
|
protected static class |
AbstractNestablePropertyAccessor.PropertyTokenHolder |
NESTED_PROPERTY_SEPARATOR, NESTED_PROPERTY_SEPARATOR_CHAR, PROPERTY_KEY_PREFIX, PROPERTY_KEY_PREFIX_CHAR, PROPERTY_KEY_SUFFIX, PROPERTY_KEY_SUFFIX_CHAR
Modifier | Constructor and Description |
---|---|
protected |
AbstractNestablePropertyAccessor()
Create a new empty accessor.
|
protected |
AbstractNestablePropertyAccessor(boolean registerDefaultEditors)
Create a new empty accessor.
|
protected |
AbstractNestablePropertyAccessor(Class<?> clazz)
Create a new accessor, wrapping a new instance of the specified class.
|
protected |
AbstractNestablePropertyAccessor(Object object)
Create a new accessor for the given object.
|
protected |
AbstractNestablePropertyAccessor(Object object,
String nestedPath,
AbstractNestablePropertyAccessor parent)
Create a new accessor for the given object,
registering a nested path that the object is in.
|
protected |
AbstractNestablePropertyAccessor(Object object,
String nestedPath,
Object rootObject)
Create a new accessor for the given object,
registering a nested path that the object is in.
|
Modifier and Type | Method and Description |
---|---|
protected Object |
convertForProperty(String propertyName,
Object oldValue,
Object newValue,
TypeDescriptor td) |
protected abstract NotWritablePropertyException |
createNotWritablePropertyException(String propertyName)
Create a
NotWritablePropertyException for the specified property. |
int |
getAutoGrowCollectionLimit()
Return the limit for array and collection auto-growing.
|
protected String |
getFinalPath(AbstractNestablePropertyAccessor pa,
String nestedPath)
Get the last component of the path.
|
protected abstract AbstractNestablePropertyAccessor.PropertyHandler |
getLocalPropertyHandler(String propertyName)
Return a
AbstractNestablePropertyAccessor.PropertyHandler for the specified local propertyName . |
String |
getNestedPath()
Return the nested path of the object wrapped by this accessor.
|
protected AbstractNestablePropertyAccessor |
getPropertyAccessorForPropertyPath(String propertyPath)
Recursively navigate to return a property accessor for the nested property path.
|
protected AbstractNestablePropertyAccessor.PropertyHandler |
getPropertyHandler(String propertyName)
Return the
AbstractNestablePropertyAccessor.PropertyHandler for the specified propertyName , navigating
if necessary. |
Class<?> |
getPropertyType(String propertyName)
Determine the property type for the given property path.
|
TypeDescriptor |
getPropertyTypeDescriptor(String propertyName)
Return a type descriptor for the specified property:
preferably from the read method, falling back to the write method.
|
protected Object |
getPropertyValue(AbstractNestablePropertyAccessor.PropertyTokenHolder tokens) |
Object |
getPropertyValue(String propertyName)
Actually get the value of a property.
|
Class<?> |
getRootClass()
Return the class of the root object at the top of the path of this accessor.
|
Object |
getRootInstance()
Return the root object at the top of the path of this accessor.
|
Class<?> |
getWrappedClass() |
Object |
getWrappedInstance() |
boolean |
isReadableProperty(String propertyName)
Determine whether the specified property is readable.
|
boolean |
isWritableProperty(String propertyName)
Determine whether the specified property is writable.
|
protected abstract AbstractNestablePropertyAccessor |
newNestedPropertyAccessor(Object object,
String nestedPath)
Create a new nested property accessor instance.
|
void |
setAutoGrowCollectionLimit(int autoGrowCollectionLimit)
Specify a limit for array and collection auto-growing.
|
protected void |
setPropertyValue(AbstractNestablePropertyAccessor.PropertyTokenHolder tokens,
PropertyValue pv) |
void |
setPropertyValue(PropertyValue pv)
Set the specified value as current property value.
|
void |
setPropertyValue(String propertyName,
Object value)
Actually set a property value.
|
void |
setWrappedInstance(Object object)
Switch the target object, replacing the cached introspection results only
if the class of the new object is different to that of the replaced object.
|
void |
setWrappedInstance(Object object,
String nestedPath,
Object rootObject)
Switch the target object, replacing the cached introspection results only
if the class of the new object is different to that of the replaced object.
|
String |
toString() |
isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setExtractOldValueForEditor, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues
convertIfNecessary, convertIfNecessary, convertIfNecessary
copyCustomEditorsTo, copyDefaultEditorsTo, findCustomEditor, getConversionService, getDefaultEditor, guessPropertyTypeFromEditors, hasCustomEditorForElement, overrideDefaultEditor, registerCustomEditor, registerCustomEditor, registerDefaultEditors, setConversionService, useConfigValueEditors
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getConversionService, setConversionService
findCustomEditor, registerCustomEditor, registerCustomEditor
convertIfNecessary, convertIfNecessary, convertIfNecessary
protected AbstractNestablePropertyAccessor()
setWrappedInstance(java.lang.Object)
protected AbstractNestablePropertyAccessor(boolean registerDefaultEditors)
registerDefaultEditors
- whether to register default editors
(can be suppressed if the accessor won't need any type conversion)setWrappedInstance(java.lang.Object)
protected AbstractNestablePropertyAccessor(Object object)
object
- object wrapped by this accessorprotected AbstractNestablePropertyAccessor(Class<?> clazz)
clazz
- class to instantiate and wrapprotected AbstractNestablePropertyAccessor(Object object, String nestedPath, Object rootObject)
object
- object wrapped by this accessornestedPath
- the nested path of the objectrootObject
- the root object at the top of the pathprotected AbstractNestablePropertyAccessor(Object object, String nestedPath, AbstractNestablePropertyAccessor parent)
object
- object wrapped by this accessornestedPath
- the nested path of the objectparent
- the containing accessor (must not be null
)public void setAutoGrowCollectionLimit(int autoGrowCollectionLimit)
Default is unlimited on a plain accessor.
public int getAutoGrowCollectionLimit()
public void setWrappedInstance(Object object)
object
- the new target objectpublic void setWrappedInstance(Object object, String nestedPath, Object rootObject)
object
- the new target objectnestedPath
- the nested path of the objectrootObject
- the root object at the top of the pathpublic final Object getWrappedInstance()
public final Class<?> getWrappedClass()
public final String getNestedPath()
public final Object getRootInstance()
getNestedPath()
public final Class<?> getRootClass()
getNestedPath()
public void setPropertyValue(String propertyName, Object value) throws BeansException
AbstractPropertyAccessor
setPropertyValue
in interface PropertyAccessor
setPropertyValue
in class AbstractPropertyAccessor
propertyName
- name of the property to set value ofvalue
- the new valueInvalidPropertyException
- if there is no such property or
if the property isn't writablePropertyAccessException
- if the property was valid but the
accessor method failed or a type mismatch occuredBeansException
public void setPropertyValue(PropertyValue pv) throws BeansException
PropertyAccessor
setPropertyValue
in interface PropertyAccessor
setPropertyValue
in class AbstractPropertyAccessor
pv
- an object containing the new property valueInvalidPropertyException
- if there is no such property or
if the property isn't writablePropertyAccessException
- if the property was valid but the
accessor method failed or a type mismatch occuredBeansException
protected void setPropertyValue(AbstractNestablePropertyAccessor.PropertyTokenHolder tokens, PropertyValue pv) throws BeansException
BeansException
public Class<?> getPropertyType(String propertyName) throws BeansException
PropertyEditorRegistrySupport
Called by PropertyEditorRegistrySupport.findCustomEditor(java.lang.Class<?>, java.lang.String)
if no required type has been specified,
to be able to find a type-specific editor even if just given a property path.
The default implementation always returns null
.
BeanWrapperImpl overrides this with the standard getPropertyType
method as defined by the BeanWrapper interface.
getPropertyType
in interface PropertyAccessor
getPropertyType
in class AbstractPropertyAccessor
propertyName
- the property path to determine the type fornull
if not determinableInvalidPropertyException
- if there is no such property or
if the property isn't readablePropertyAccessException
- if the property was valid but the
accessor method failedBeansException
PropertyAccessor.getPropertyType(String)
public TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException
PropertyAccessor
propertyName
- the property to check
(may be a nested path and/or an indexed/mapped property)null
if not determinableInvalidPropertyException
- if there is no such property or
if the property isn't readableBeansException
public boolean isReadableProperty(String propertyName)
PropertyAccessor
Returns false
if the property doesn't exist.
propertyName
- the property to check
(may be a nested path and/or an indexed/mapped property)public boolean isWritableProperty(String propertyName)
PropertyAccessor
Returns false
if the property doesn't exist.
propertyName
- the property to check
(may be a nested path and/or an indexed/mapped property)protected Object convertForProperty(String propertyName, Object oldValue, Object newValue, TypeDescriptor td) throws TypeMismatchException
TypeMismatchException
public Object getPropertyValue(String propertyName) throws BeansException
AbstractPropertyAccessor
getPropertyValue
in interface PropertyAccessor
getPropertyValue
in class AbstractPropertyAccessor
propertyName
- name of the property to get the value ofInvalidPropertyException
- if there is no such property or
if the property isn't readablePropertyAccessException
- if the property was valid but the
accessor method failedBeansException
protected Object getPropertyValue(AbstractNestablePropertyAccessor.PropertyTokenHolder tokens) throws BeansException
BeansException
protected AbstractNestablePropertyAccessor.PropertyHandler getPropertyHandler(String propertyName) throws BeansException
AbstractNestablePropertyAccessor.PropertyHandler
for the specified propertyName
, navigating
if necessary. Return null
if not found rather than throwing an exception.propertyName
- the property to obtain the descriptor fornull
if not foundBeansException
- in case of introspection failureprotected abstract AbstractNestablePropertyAccessor.PropertyHandler getLocalPropertyHandler(String propertyName)
AbstractNestablePropertyAccessor.PropertyHandler
for the specified local propertyName
. Only
used to reach a property available in the current context.propertyName
- the name of a local propertynull
if it has not been foundprotected abstract AbstractNestablePropertyAccessor newNestedPropertyAccessor(Object object, String nestedPath)
object
- object wrapped by this PropertyAccessornestedPath
- the nested path of the objectprotected abstract NotWritablePropertyException createNotWritablePropertyException(String propertyName)
NotWritablePropertyException
for the specified property.protected String getFinalPath(AbstractNestablePropertyAccessor pa, String nestedPath)
pa
- property accessor to work onnestedPath
- property path we know is nestedprotected AbstractNestablePropertyAccessor getPropertyAccessorForPropertyPath(String propertyPath)
propertyPath
- property property path, which may be nested