Top Description Inners Fields Constructors Methods
org.springframework.beans

public abstract Class AbstractNestablePropertyAccessor

extends AbstractPropertyAccessor
Class Inheritance
Known Direct Subclasses
org.springframework.beans.BeanWrapperImpl, org.springframework.beans.DirectFieldAccessor
Imports
java.beans.PropertyChangeEvent, java.lang.reflect.Array, .Constructor, .InvocationTargetException, .Modifier, .UndeclaredThrowableException, java.security.PrivilegedActionException, java.util.ArrayList, .Collection, .HashMap, .Iterator, .List, .Map, .Optional, org.apache.commons.logging.Log, .LogFactory, org.springframework.core.CollectionFactory, .ResolvableType, org.springframework.core.convert.ConversionException, .ConverterNotFoundException, .TypeDescriptor, org.springframework.lang.Nullable, org.springframework.util.Assert, .ObjectUtils, .StringUtils

A basic 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.

Authors
Juergen Hoeller, Stephane Nicoll, Rod Johnson, Rob Harrop, Sam Brannen
Since
4.2
See Also
registerCustomEditor, setPropertyValues, setPropertyValue, getPropertyValue, getPropertyType, BeanWrapper, PropertyEditorRegistrySupport

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected abstract static class
AbstractNestablePropertyAccessor.PropertyHandler

A handler for a specific property.

protected static class
AbstractNestablePropertyAccessor.PropertyTokenHolder

Holder class used to store property tokens.

Field Summary

Modifier and TypeField and Description
private int
private static final Log
logger

We'll create a lot of these objects, so we don't want a new logger every time.

private String
private Map<String, AbstractNestablePropertyAccessor>
nestedPropertyAccessors

Map with cached nested Accessors: nested path -> Accessor instance.

pack-priv Object
pack-priv Object
Inherited from org.springframework.beans.AbstractPropertyAccessor:
suppressNotWritablePropertyException

Constructor Summary

AccessConstructor and Description
protected
AbstractNestablePropertyAccessor()

Create a new empty accessor.

protected
AbstractNestablePropertyAccessor(boolean
whether to register default editors (can be suppressed if the accessor won't need any type conversion)
registerDefaultEditors
)

Create a new empty accessor.

protected
AbstractNestablePropertyAccessor(Object
the object wrapped by this accessor
object
)

Create a new accessor for the given object.

protected
AbstractNestablePropertyAccessor(Class<?>
class to instantiate and wrap
clazz
)

Create a new accessor, wrapping a new instance of the specified class.

protected
AbstractNestablePropertyAccessor(Object
the object wrapped by this accessor
object
,
String
the nested path of the object
nestedPath
,
Object
the root object at the top of the path
rootObject
)

Create a new accessor for the given object, registering a nested path that the object is in.

protected
AbstractNestablePropertyAccessor(Object
the object wrapped by this accessor
object
,
String
the nested path of the object
nestedPath
,
AbstractNestablePropertyAccessor
the containing accessor (must not be null)
parent
)

Create a new accessor for the given object, registering a nested path that the object is in.

Method Summary

Modifier and TypeMethod and Description
protected Object
convertForProperty(String propertyName, Object oldValue, Object newValue, TypeDescriptor td)

private Object
convertIfNecessary(String propertyName, Object oldValue, Object newValue, Class<?> requiredType, TypeDescriptor td)

private PropertyValue
protected abstract NotWritablePropertyException
createNotWritablePropertyException(String propertyName)

Create a NotWritablePropertyException for the specified property.

public int
getAutoGrowCollectionLimit()

Return the limit for array and collection auto-growing.

protected String

Returns:

last component of the path (the property on the target bean)
getFinalPath
(AbstractNestablePropertyAccessor
property accessor to work on
pa
,
String
property path we know is nested
nestedPath
)

Get the last component of the path.

protected abstract AbstractNestablePropertyAccessor.PropertyHandler

Returns:

the handler for that property, or null if it has not been found
getLocalPropertyHandler
(String
the name of a local property
propertyName
)

Return a PropertyHandler for the specified local propertyName.

public final String
getNestedPath()

Return the nested path of the object wrapped by this accessor.

private AbstractNestablePropertyAccessor

Returns:

the PropertyAccessor instance, either cached or newly created
getNestedPropertyAccessor
(String
property to create the PropertyAccessor for
nestedProperty
)

Retrieve a Property accessor for the given nested property.

protected AbstractNestablePropertyAccessor

Returns:

a property accessor for the target bean
getPropertyAccessorForPropertyPath
(String
property path, which may be nested
propertyPath
)

Recursively navigate to return a property accessor for the nested property path.

protected AbstractNestablePropertyAccessor.PropertyHandler

Returns:

the property descriptor for the specified property, or null if not found
getPropertyHandler
(String
the property to obtain the descriptor for
propertyName
)

Return the PropertyHandler for the specified propertyName, navigating if necessary.

private Object
private int
getPropertyNameKeyEnd(String propertyName, int startIndex)

private AbstractNestablePropertyAccessor.PropertyTokenHolder

Returns:

representation of the parsed property tokens
getPropertyNameTokens
(String
the property name to parse
propertyName
)

Parse the given property name into the corresponding property name tokens.

public Class<?>
getPropertyType(String
the property to check (may be a nested path and/or an indexed/mapped property)
propertyName
)

Overrides org.springframework.beans.AbstractPropertyAccessor.getPropertyType.

Implements org.springframework.beans.PropertyAccessor.getPropertyType.

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
getPropertyTypeDescriptor(String
the property to check (may be a nested path and/or an indexed/mapped property)
propertyName
)

Implements org.springframework.beans.PropertyAccessor.getPropertyTypeDescriptor.

Return a type descriptor for the specified property: preferably from the read method, falling back to the write method.
public Object
getPropertyValue(String
name of the property to get the value of
propertyName
)

Implements abstract org.springframework.beans.AbstractPropertyAccessor.getPropertyValue.

Implements org.springframework.beans.PropertyAccessor.getPropertyValue.

Actually get the value of a property.
protected Object
public final Class<?>
getRootClass()

Return the class of the root object at the top of the path of this accessor.

public final Object
getRootInstance()

Return the root object at the top of the path of this accessor.

public final Class<?>
public final Object
private Object
growArrayIfNecessary(Object array, int index, String name)

private void
public boolean
isReadableProperty(String
the property to check (may be a nested path and/or an indexed/mapped property)
propertyName
)

Implements org.springframework.beans.PropertyAccessor.isReadableProperty.

Determine whether the specified property is readable.
public boolean
isWritableProperty(String
the property to check (may be a nested path and/or an indexed/mapped property)
propertyName
)

Implements org.springframework.beans.PropertyAccessor.isWritableProperty.

Determine whether the specified property is writable.
protected abstract AbstractNestablePropertyAccessor

Returns:

the nested PropertyAccessor instance
newNestedPropertyAccessor
(Object
the object wrapped by this PropertyAccessor
object
,
String
the nested path of the object
nestedPath
)

Create a new nested property accessor instance.

private Object
newValue(Class<?> type, TypeDescriptor desc, String name)

private void
private void
public void
setAutoGrowCollectionLimit(int autoGrowCollectionLimit)

Specify a limit for array and collection auto-growing.

private Object
public void
setPropertyValue(String
name of the property to set value of
propertyName
,
Object
the new value
value
)

Implements abstract org.springframework.beans.AbstractPropertyAccessor.setPropertyValue.

Implements org.springframework.beans.PropertyAccessor.setPropertyValue.

Actually set a property value.
public void
setPropertyValue(PropertyValue
an object containing the new property value
pv
)

Overrides org.springframework.beans.AbstractPropertyAccessor.setPropertyValue.

Implements org.springframework.beans.PropertyAccessor.setPropertyValue.

Set the specified value as current property value.
protected void
public void
setWrappedInstance(Object
the new target 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.

public void
setWrappedInstance(Object
the new target object
object
,
String
the nested path of the object
nestedPath
,
Object
the root object at the top of the path
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.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.springframework.beans.AbstractPropertyAccessor:
isAutoGrowNestedPathsisExtractOldValueForEditorsetAutoGrowNestedPathssetExtractOldValueForEditorsetPropertyValuessetPropertyValuessetPropertyValuessetPropertyValues

Field Detail

autoGrowCollectionLimitback to summary
private int autoGrowCollectionLimit
loggerback to summary
private static final Log logger

We'll create a lot of these objects, so we don't want a new logger every time.

nestedPathback to summary
private String nestedPath
nestedPropertyAccessorsback to summary
private Map<String, AbstractNestablePropertyAccessor> nestedPropertyAccessors

Map with cached nested Accessors: nested path -> Accessor instance.

Annotations
@Nullable
rootObjectback to summary
pack-priv Object rootObject
Annotations
@Nullable
wrappedObjectback to summary
pack-priv Object wrappedObject
Annotations
@Nullable

Constructor Detail

AbstractNestablePropertyAccessorback to summary
protected AbstractNestablePropertyAccessor()

Create a new empty accessor. Wrapped instance needs to be set afterwards. Registers default editors.

See Also
setWrappedInstance
AbstractNestablePropertyAccessorback to summary
protected AbstractNestablePropertyAccessor(boolean registerDefaultEditors)

Create a new empty accessor. Wrapped instance needs to be set afterwards.

Parameters
registerDefaultEditors:boolean

whether to register default editors (can be suppressed if the accessor won't need any type conversion)

See Also
setWrappedInstance
AbstractNestablePropertyAccessorback to summary
protected AbstractNestablePropertyAccessor(Object object)

Create a new accessor for the given object.

Parameters
object:Object

the object wrapped by this accessor

AbstractNestablePropertyAccessorback to summary
protected AbstractNestablePropertyAccessor(Class<?> clazz)

Create a new accessor, wrapping a new instance of the specified class.

Parameters
clazz:Class<?>

class to instantiate and wrap

AbstractNestablePropertyAccessorback to summary
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.

Parameters
object:Object

the object wrapped by this accessor

nestedPath:String

the nested path of the object

rootObject:Object

the root object at the top of the path

AbstractNestablePropertyAccessorback to summary
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.

Parameters
object:Object

the object wrapped by this accessor

nestedPath:String

the nested path of the object

parent:AbstractNestablePropertyAccessor

the containing accessor (must not be null)

Method Detail

convertForPropertyback to summary
protected Object convertForProperty(String propertyName, Object oldValue, Object newValue, TypeDescriptor td) throws TypeMismatchException
Annotations
@Nullable
convertIfNecessaryback to summary
private Object convertIfNecessary(String propertyName, Object oldValue, Object newValue, Class<?> requiredType, TypeDescriptor td) throws TypeMismatchException
Annotations
@Nullable
createDefaultPropertyValueback to summary
private PropertyValue createDefaultPropertyValue(AbstractNestablePropertyAccessor.PropertyTokenHolder tokens)
createNotWritablePropertyExceptionback to summary
protected abstract NotWritablePropertyException createNotWritablePropertyException(String propertyName)

Create a NotWritablePropertyException for the specified property.

getAutoGrowCollectionLimitback to summary
public int getAutoGrowCollectionLimit()

Return the limit for array and collection auto-growing.

getFinalPathback to summary
protected String getFinalPath(AbstractNestablePropertyAccessor pa, String nestedPath)

Get the last component of the path. Also works if not nested.

Parameters
pa:AbstractNestablePropertyAccessor

property accessor to work on

nestedPath:String

property path we know is nested

Returns:String

last component of the path (the property on the target bean)

getLocalPropertyHandlerback to summary
protected abstract AbstractNestablePropertyAccessor.PropertyHandler getLocalPropertyHandler(String propertyName)

Return a PropertyHandler for the specified local propertyName. Only used to reach a property available in the current context.

Parameters
propertyName:String

the name of a local property

Returns:AbstractNestablePropertyAccessor.PropertyHandler

the handler for that property, or null if it has not been found

Annotations
@Nullable
getNestedPathback to summary
public final String getNestedPath()

Return the nested path of the object wrapped by this accessor.

getNestedPropertyAccessorback to summary
private AbstractNestablePropertyAccessor getNestedPropertyAccessor(String nestedProperty)

Retrieve a Property accessor for the given nested property. Create a new one if not found in the cache.

Note

Caching nested PropertyAccessors is necessary now, to keep registered custom editors for nested properties.

Parameters
nestedProperty:String

property to create the PropertyAccessor for

Returns:AbstractNestablePropertyAccessor

the PropertyAccessor instance, either cached or newly created

getPropertyAccessorForPropertyPathback to summary
protected AbstractNestablePropertyAccessor getPropertyAccessorForPropertyPath(String propertyPath)

Recursively navigate to return a property accessor for the nested property path.

Parameters
propertyPath:String

property path, which may be nested

Returns:AbstractNestablePropertyAccessor

a property accessor for the target bean

getPropertyHandlerback to summary
protected AbstractNestablePropertyAccessor.PropertyHandler getPropertyHandler(String propertyName) throws BeansException

Return the PropertyHandler for the specified propertyName, navigating if necessary. Return null if not found rather than throwing an exception.

Parameters
propertyName:String

the property to obtain the descriptor for

Returns:AbstractNestablePropertyAccessor.PropertyHandler

the property descriptor for the specified property, or null if not found

Annotations
@Nullable
Exceptions
BeansException:
in case of introspection failure
getPropertyHoldingValueback to summary
private Object getPropertyHoldingValue(AbstractNestablePropertyAccessor.PropertyTokenHolder tokens)
getPropertyNameKeyEndback to summary
private int getPropertyNameKeyEnd(String propertyName, int startIndex)
getPropertyNameTokensback to summary
private AbstractNestablePropertyAccessor.PropertyTokenHolder getPropertyNameTokens(String propertyName)

Parse the given property name into the corresponding property name tokens.

Parameters
propertyName:String

the property name to parse

Returns:AbstractNestablePropertyAccessor.PropertyTokenHolder

representation of the parsed property tokens

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

Overrides org.springframework.beans.AbstractPropertyAccessor.getPropertyType.

Implements org.springframework.beans.PropertyAccessor.getPropertyType.

Doc from org.springframework.beans.PropertyAccessor.getPropertyType.

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
@Override
@Nullable
getPropertyTypeDescriptorback to summary
public TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException

Implements org.springframework.beans.PropertyAccessor.getPropertyTypeDescriptor.

Doc from org.springframework.beans.PropertyAccessor.getPropertyTypeDescriptor.

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
@Override
@Nullable
getPropertyValueback to summary
public Object getPropertyValue(String propertyName) throws BeansException

Implements abstract org.springframework.beans.AbstractPropertyAccessor.getPropertyValue.

Implements org.springframework.beans.PropertyAccessor.getPropertyValue.

Doc from org.springframework.beans.AbstractPropertyAccessor.getPropertyValue.

Actually get the value of a property.

Parameters
propertyName:String

name of the property to get the value of

Returns:Object

the value of the property

Annotations
@Override
@Nullable
getPropertyValueback to summary
protected Object getPropertyValue(AbstractNestablePropertyAccessor.PropertyTokenHolder tokens) throws BeansException
Annotations
@SuppressWarnings:rawtypes, unchecked
@Nullable
getRootClassback to summary
public final Class<?> getRootClass()

Return the class of the root object at the top of the path of this accessor.

See Also
getNestedPath
getRootInstanceback to summary
public final Object getRootInstance()

Return the root object at the top of the path of this accessor.

See Also
getNestedPath
getWrappedClassback to summary
public final Class<?> getWrappedClass()
getWrappedInstanceback to summary
public final Object getWrappedInstance()
growArrayIfNecessaryback to summary
private Object growArrayIfNecessary(Object array, int index, String name)
growCollectionIfNecessaryback to summary
private void growCollectionIfNecessary(Collection<Object> collection, int index, String name, AbstractNestablePropertyAccessor.PropertyHandler ph, int nestingLevel)
isReadablePropertyback to summary
public boolean isReadableProperty(String propertyName)

Implements org.springframework.beans.PropertyAccessor.isReadableProperty.

Doc from org.springframework.beans.PropertyAccessor.isReadableProperty.

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

Annotations
@Override
isWritablePropertyback to summary
public boolean isWritableProperty(String propertyName)

Implements org.springframework.beans.PropertyAccessor.isWritableProperty.

Doc from org.springframework.beans.PropertyAccessor.isWritableProperty.

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

Annotations
@Override
newNestedPropertyAccessorback to summary
protected abstract AbstractNestablePropertyAccessor newNestedPropertyAccessor(Object object, String nestedPath)

Create a new nested property accessor instance. Can be overridden in subclasses to create a PropertyAccessor subclass.

Parameters
object:Object

the object wrapped by this PropertyAccessor

nestedPath:String

the nested path of the object

Returns:AbstractNestablePropertyAccessor

the nested PropertyAccessor instance

newValueback to summary
private Object newValue(Class<?> type, TypeDescriptor desc, String name)
processKeyedPropertyback to summary
private void processKeyedProperty(AbstractNestablePropertyAccessor.PropertyTokenHolder tokens, PropertyValue pv)
Annotations
@SuppressWarnings:rawtypes, unchecked
processLocalPropertyback to summary
private void processLocalProperty(AbstractNestablePropertyAccessor.PropertyTokenHolder tokens, PropertyValue pv)
setAutoGrowCollectionLimitback to summary
public void setAutoGrowCollectionLimit(int autoGrowCollectionLimit)

Specify a limit for array and collection auto-growing.

Default is unlimited on a plain accessor.

setDefaultValueback to summary
private Object setDefaultValue(AbstractNestablePropertyAccessor.PropertyTokenHolder tokens)
setPropertyValueback to summary
public void setPropertyValue(String propertyName, Object value) throws BeansException

Implements abstract org.springframework.beans.AbstractPropertyAccessor.setPropertyValue.

Implements org.springframework.beans.PropertyAccessor.setPropertyValue.

Doc from org.springframework.beans.AbstractPropertyAccessor.setPropertyValue.

Actually set a property value.

Parameters
propertyName:String

name of the property to set value of

value:Object

the new value

Annotations
@Override
setPropertyValueback to summary
public void setPropertyValue(PropertyValue pv) throws BeansException

Overrides org.springframework.beans.AbstractPropertyAccessor.setPropertyValue.

Implements org.springframework.beans.PropertyAccessor.setPropertyValue.

Doc from org.springframework.beans.PropertyAccessor.setPropertyValue.

Set the specified value as current property value.

Parameters
pv:PropertyValue

an object containing the new property value

Annotations
@Override
setPropertyValueback to summary
protected void setPropertyValue(AbstractNestablePropertyAccessor.PropertyTokenHolder tokens, PropertyValue pv) throws BeansException
setWrappedInstanceback to summary
public 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.

Parameters
object:Object

the new target object

setWrappedInstanceback to summary
public 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.

Parameters
object:Object

the new target object

nestedPath:String

the nested path of the object

rootObject:Object

the root object at the top of the path

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.springframework.beans back to summary

protected abstract Class AbstractNestablePropertyAccessor.PropertyHandler

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.AbstractNestablePropertyAccessor.PropertyHandler
Known Direct Subclasses
org.springframework.beans.BeanWrapperImpl.BeanPropertyHandler, org.springframework.beans.DirectFieldAccessor.FieldPropertyHandler

A handler for a specific property.

Field Summary

Modifier and TypeField and Description
private final Class<?>
private final boolean
private final boolean

Constructor Summary

AccessConstructor and Description
public
PropertyHandler(Class<?> propertyType, boolean readable, boolean writable)

Method Summary

Modifier and TypeMethod and Description
public TypeDescriptor
getCollectionType(int nestingLevel)

public TypeDescriptor
getMapKeyType(int nestingLevel)

public TypeDescriptor
getMapValueType(int nestingLevel)

public Class<?>
public abstract ResolvableType
public abstract Object
public boolean
public boolean
public abstract TypeDescriptor
nested(int level)

public abstract void
public boolean
public abstract TypeDescriptor
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

propertyTypeback to summary
private final Class<?> propertyType
Annotations
@Nullable
readableback to summary
private final boolean readable
writableback to summary
private final boolean writable

Constructor Detail

PropertyHandlerback to summary
public PropertyHandler(Class<?> propertyType, boolean readable, boolean writable)

Method Detail

getCollectionTypeback to summary
public TypeDescriptor getCollectionType(int nestingLevel)
getMapKeyTypeback to summary
public TypeDescriptor getMapKeyType(int nestingLevel)
getMapValueTypeback to summary
public TypeDescriptor getMapValueType(int nestingLevel)
getPropertyTypeback to summary
public Class<?> getPropertyType()
Annotations
@Nullable
getResolvableTypeback to summary
public abstract ResolvableType getResolvableType()
getValueback to summary
public abstract Object getValue() throws Exception
Annotations
@Nullable
isReadableback to summary
public boolean isReadable()
isWritableback to summary
public boolean isWritable()
nestedback to summary
public abstract TypeDescriptor nested(int level)
Annotations
@Nullable
setValueback to summary
public abstract void setValue(Object value) throws Exception
setValueFallbackIfPossibleback to summary
public boolean setValueFallbackIfPossible(Object value)
toTypeDescriptorback to summary
public abstract TypeDescriptor toTypeDescriptor()
org.springframework.beans back to summary

protected Class AbstractNestablePropertyAccessor.PropertyTokenHolder

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.AbstractNestablePropertyAccessor.PropertyTokenHolder

Holder class used to store property tokens.

Field Summary

Modifier and TypeField and Description
public String
public String
public String[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actualNameback to summary
public String actualName
canonicalNameback to summary
public String canonicalName
keysback to summary
public String[] keys
Annotations
@Nullable

Constructor Detail

PropertyTokenHolderback to summary
public PropertyTokenHolder(String name)