Top Description Inners Fields Constructors Methods
org.springframework.beans

public Class BeanWrapperImpl

extends AbstractNestablePropertyAccessor
implements BeanWrapper
Class Inheritance
All Implemented Interfaces
org.springframework.beans.BeanWrapper, org.springframework.beans.ConfigurablePropertyAccessor, org.springframework.beans.TypeConverter, org.springframework.beans.PropertyEditorRegistry, org.springframework.beans.PropertyAccessor
Imports
java.beans.PropertyDescriptor, java.lang.reflect.Method, org.apache.commons.logging.LogFactory, org.springframework.core.ResolvableType, org.springframework.core.convert.TypeDescriptor, org.springframework.lang.Nullable, org.springframework.util.Assert, .ReflectionUtils

Default BeanWrapper implementation that should be sufficient for all typical use cases. Caches introspection results for efficiency.

Note

Auto-registers default property editors from the org.springframework.beans.propertyeditors package, which apply in addition to the JDK's standard PropertyEditors. Applications can call the registerCustomEditor(Class, java.beans.PropertyEditor) method to register an editor for a particular instance (i.e. they are not shared across the application). See the base class PropertyEditorRegistrySupport for details.

NOTE: As of Spring 2.5, this is - for almost all purposes - an internal class. It is just public in order to allow for access from other framework packages. For standard application access purposes, use the PropertyAccessorFactory#forBeanPropertyAccess factory method instead.

Authors
Rod Johnson, Juergen Hoeller, Rob Harrop, Stephane Nicoll
Since
15 April 2001
See Also
registerCustomEditor, setPropertyValues, setPropertyValue, getPropertyValue, getPropertyType, BeanWrapper, PropertyEditorRegistrySupport

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private CachedIntrospectionResults
cachedIntrospectionResults

Cached introspections results for this object, to prevent encountering the cost of JavaBeans introspection every time.

Inherited from org.springframework.beans.AbstractNestablePropertyAccessor:
rootObjectwrappedObject

Constructor Summary

AccessConstructor and Description
public
BeanWrapperImpl()

Create a new empty BeanWrapperImpl.

public
BeanWrapperImpl(boolean
whether to register default editors (can be suppressed if the BeanWrapper won't need any type conversion)
registerDefaultEditors
)

Create a new empty BeanWrapperImpl.

public
BeanWrapperImpl(Object
the object wrapped by this BeanWrapper
object
)

Create a new BeanWrapperImpl for the given object.

public
BeanWrapperImpl(Class<?>
class to instantiate and wrap
clazz
)

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

public
BeanWrapperImpl(Object
the object wrapped by this BeanWrapper
object
,
String
the nested path of the object
nestedPath
,
Object
the root object at the top of the path
rootObject
)

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

private
BeanWrapperImpl(Object
the object wrapped by this BeanWrapper
object
,
String
the nested path of the object
nestedPath
,
BeanWrapperImpl
the containing BeanWrapper (must not be null)
parent
)

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

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the new value, possibly the result of type conversion
convertForProperty
(Object
the value to convert
value
,
String
the target property (note that nested or indexed properties are not supported here)
propertyName
)

Convert the given value for the specified property to the latter's type.

protected NotWritablePropertyException
private CachedIntrospectionResults
getCachedIntrospectionResults()

Obtain a lazily initialized CachedIntrospectionResults instance for the wrapped object.

protected BeanWrapperImpl.BeanPropertyHandler
getLocalPropertyHandler(String
the name of a local property
propertyName
)

Implements abstract org.springframework.beans.AbstractNestablePropertyAccessor.getLocalPropertyHandler.

Return a PropertyHandler for the specified local propertyName.

public PropertyDescriptor
getPropertyDescriptor(String
the property to obtain the descriptor for (may be a nested path, but not an indexed/mapped property)
propertyName
)

Implements org.springframework.beans.BeanWrapper.getPropertyDescriptor.

Obtain the property descriptor for a specific property of the wrapped object.

public PropertyDescriptor[]
getPropertyDescriptors()

Implements org.springframework.beans.BeanWrapper.getPropertyDescriptors.

Obtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).

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

Implements abstract org.springframework.beans.AbstractNestablePropertyAccessor.newNestedPropertyAccessor.

Create a new nested property accessor instance.

public void
setBeanInstance(Object
the actual target object
object
)

Set a bean instance to hold, without any unwrapping of java.util.Optional.

protected void
setIntrospectionClass(Class<?>
the class to introspect
clazz
)

Set the class to introspect.

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
)

Overrides org.springframework.beans.AbstractNestablePropertyAccessor.setWrappedInstance.

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.

Inherited from org.springframework.beans.AbstractNestablePropertyAccessor:
convertForPropertygetAutoGrowCollectionLimitgetFinalPathgetNestedPathgetPropertyAccessorForPropertyPathgetPropertyHandlergetPropertyTypegetPropertyTypeDescriptorgetPropertyValuegetPropertyValuegetRootClassgetRootInstancegetWrappedClassgetWrappedInstanceisReadablePropertyisWritablePropertysetAutoGrowCollectionLimitsetPropertyValuesetPropertyValuesetPropertyValuesetWrappedInstancetoString

Field Detail

cachedIntrospectionResultsback to summary
private CachedIntrospectionResults cachedIntrospectionResults

Cached introspections results for this object, to prevent encountering the cost of JavaBeans introspection every time.

Annotations
@Nullable

Constructor Detail

BeanWrapperImplback to summary
public BeanWrapperImpl()

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

See Also
setWrappedInstance
BeanWrapperImplback to summary
public BeanWrapperImpl(boolean registerDefaultEditors)

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

Parameters
registerDefaultEditors:boolean

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

See Also
setWrappedInstance
BeanWrapperImplback to summary
public BeanWrapperImpl(Object object)

Create a new BeanWrapperImpl for the given object.

Parameters
object:Object

the object wrapped by this BeanWrapper

BeanWrapperImplback to summary
public BeanWrapperImpl(Class<?> clazz)

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

Parameters
clazz:Class<?>

class to instantiate and wrap

BeanWrapperImplback to summary
public BeanWrapperImpl(Object object, String nestedPath, Object rootObject)

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

Parameters
object:Object

the object wrapped by this BeanWrapper

nestedPath:String

the nested path of the object

rootObject:Object

the root object at the top of the path

BeanWrapperImplback to summary
private BeanWrapperImpl(Object object, String nestedPath, BeanWrapperImpl parent)

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

Parameters
object:Object

the object wrapped by this BeanWrapper

nestedPath:String

the nested path of the object

parent:BeanWrapperImpl

the containing BeanWrapper (must not be null)

Method Detail

convertForPropertyback to summary
public Object convertForProperty(Object value, String propertyName) throws TypeMismatchException

Convert the given value for the specified property to the latter's type.

This method is only intended for optimizations in a BeanFactory. Use the convertIfNecessary methods for programmatic conversion.

Parameters
value:Object

the value to convert

propertyName:String

the target property (note that nested or indexed properties are not supported here)

Returns:Object

the new value, possibly the result of type conversion

Annotations
@Nullable
Exceptions
TypeMismatchException:
if type conversion failed
createNotWritablePropertyExceptionback to summary
protected NotWritablePropertyException createNotWritablePropertyException(String propertyName)

Implements abstract org.springframework.beans.AbstractNestablePropertyAccessor.createNotWritablePropertyException.

Doc from org.springframework.beans.AbstractNestablePropertyAccessor.createNotWritablePropertyException.

Create a NotWritablePropertyException for the specified property.

Annotations
@Override
getCachedIntrospectionResultsback to summary
private CachedIntrospectionResults getCachedIntrospectionResults()

Obtain a lazily initialized CachedIntrospectionResults instance for the wrapped object.

getLocalPropertyHandlerback to summary
protected BeanWrapperImpl.BeanPropertyHandler getLocalPropertyHandler(String propertyName)

Implements abstract org.springframework.beans.AbstractNestablePropertyAccessor.getLocalPropertyHandler.

Doc from org.springframework.beans.AbstractNestablePropertyAccessor.getLocalPropertyHandler.

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:BeanWrapperImpl.BeanPropertyHandler

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

Annotations
@Override
@Nullable
getPropertyDescriptorback to summary
public PropertyDescriptor getPropertyDescriptor(String propertyName) throws InvalidPropertyException

Implements org.springframework.beans.BeanWrapper.getPropertyDescriptor.

Doc from org.springframework.beans.BeanWrapper.getPropertyDescriptor.

Obtain the property descriptor for a specific property of the wrapped object.

Parameters
propertyName:String

the property to obtain the descriptor for (may be a nested path, but not an indexed/mapped property)

Returns:PropertyDescriptor

the property descriptor for the specified property

Annotations
@Override
Exceptions
InvalidPropertyException:
if there is no such property
getPropertyDescriptorsback to summary
public PropertyDescriptor[] getPropertyDescriptors()

Implements org.springframework.beans.BeanWrapper.getPropertyDescriptors.

Doc from org.springframework.beans.BeanWrapper.getPropertyDescriptors.

Obtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).

Returns:PropertyDescriptor[]

the PropertyDescriptors for the wrapped object

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

Implements abstract org.springframework.beans.AbstractNestablePropertyAccessor.newNestedPropertyAccessor.

Doc from org.springframework.beans.AbstractNestablePropertyAccessor.newNestedPropertyAccessor.

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:BeanWrapperImpl

the nested PropertyAccessor instance

Annotations
@Override
setBeanInstanceback to summary
public void setBeanInstance(Object object)

Set a bean instance to hold, without any unwrapping of java.util.Optional.

Parameters
object:Object

the actual target object

Since
4.3
See Also
setWrappedInstance(Object)
setIntrospectionClassback to summary
protected void setIntrospectionClass(Class<?> clazz)

Set the class to introspect. Needs to be called when the target object changes.

Parameters
clazz:Class<?>

the class to introspect

setWrappedInstanceback to summary
public void setWrappedInstance(Object object, String nestedPath, Object rootObject)

Overrides org.springframework.beans.AbstractNestablePropertyAccessor.setWrappedInstance.

Doc from org.springframework.beans.AbstractNestablePropertyAccessor.setWrappedInstance.

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

Annotations
@Override
org.springframework.beans back to summary

private Class BeanWrapperImpl.BeanPropertyHandler

extends PropertyHandler
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final GenericTypeAwarePropertyDescriptor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public TypeDescriptor
public TypeDescriptor
public ResolvableType
public Object
public TypeDescriptor
public void
public boolean
public TypeDescriptor
Inherited from org.springframework.beans.AbstractNestablePropertyAccessor.PropertyHandler:
getMapKeyTypegetPropertyTypeisReadableisWritable

Field Detail

pdback to summary
private final GenericTypeAwarePropertyDescriptor pd

Constructor Detail

BeanPropertyHandlerback to summary
public BeanPropertyHandler(GenericTypeAwarePropertyDescriptor pd)

Method Detail

getCollectionTypeback to summary
public TypeDescriptor getCollectionType(int nestingLevel)

Overrides org.springframework.beans.AbstractNestablePropertyAccessor.PropertyHandler.getCollectionType.

Annotations
@Override
getMapValueTypeback to summary
public TypeDescriptor getMapValueType(int nestingLevel)

Overrides org.springframework.beans.AbstractNestablePropertyAccessor.PropertyHandler.getMapValueType.

Annotations
@Override
getResolvableTypeback to summary
public ResolvableType getResolvableType()

Implements abstract org.springframework.beans.AbstractNestablePropertyAccessor.PropertyHandler.getResolvableType.

Annotations
@Override
getValueback to summary
public Object getValue() throws Exception

Implements abstract org.springframework.beans.AbstractNestablePropertyAccessor.PropertyHandler.getValue.

Annotations
@Override
@Nullable
nestedback to summary
public TypeDescriptor nested(int level)

Implements abstract org.springframework.beans.AbstractNestablePropertyAccessor.PropertyHandler.nested.

Annotations
@Override
@Nullable
setValueback to summary
public void setValue(Object value) throws Exception

Implements abstract org.springframework.beans.AbstractNestablePropertyAccessor.PropertyHandler.setValue.

Annotations
@Override
setValueFallbackIfPossibleback to summary
public boolean setValueFallbackIfPossible(Object value)

Overrides org.springframework.beans.AbstractNestablePropertyAccessor.PropertyHandler.setValueFallbackIfPossible.

Annotations
@Override
toTypeDescriptorback to summary
public TypeDescriptor toTypeDescriptor()

Implements abstract org.springframework.beans.AbstractNestablePropertyAccessor.PropertyHandler.toTypeDescriptor.

Annotations
@Override