Class BeanWrapperImpl
- All Implemented Interfaces:
BeanWrapper
,ConfigurablePropertyAccessor
,PropertyAccessor
,PropertyEditorRegistry
,TypeConverter
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 PropertyEditorRegistrySupport.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(java.lang.Object)
factory method instead.
- Since:
- 15 April 2001
- Author:
- Rod Johnson, Juergen Hoeller, Rob Harrop, Stephane Nicoll
- See Also:
-
PropertyEditorRegistrySupport.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)
AbstractPropertyAccessor.setPropertyValues(java.util.Map<?, ?>)
AbstractNestablePropertyAccessor.setPropertyValue(java.lang.String, java.lang.Object)
AbstractNestablePropertyAccessor.getPropertyValue(java.lang.String)
AbstractNestablePropertyAccessor.getPropertyType(java.lang.String)
BeanWrapper
PropertyEditorRegistrySupport
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.beans.AbstractNestablePropertyAccessor
AbstractNestablePropertyAccessor.PropertyHandler, AbstractNestablePropertyAccessor.PropertyTokenHolder
-
Field Summary
Fields inherited from interface org.springframework.beans.PropertyAccessor
NESTED_PROPERTY_SEPARATOR, NESTED_PROPERTY_SEPARATOR_CHAR, PROPERTY_KEY_PREFIX, PROPERTY_KEY_PREFIX_CHAR, PROPERTY_KEY_SUFFIX, PROPERTY_KEY_SUFFIX_CHAR
-
Constructor Summary
ConstructorDescriptionCreate a new empty BeanWrapperImpl.BeanWrapperImpl
(boolean registerDefaultEditors) Create a new empty BeanWrapperImpl.BeanWrapperImpl
(Class<?> clazz) Create a new BeanWrapperImpl, wrapping a new instance of the specified class.BeanWrapperImpl
(Object object) Create a new BeanWrapperImpl for the given object.BeanWrapperImpl
(Object object, String nestedPath, Object rootObject) Create a new BeanWrapperImpl for the given object, registering a nested path that the object is in. -
Method Summary
Modifier and TypeMethodDescriptionconvertForProperty
(Object value, String propertyName) Convert the given value for the specified property to the latter's type.protected NotWritablePropertyException
createNotWritablePropertyException
(String propertyName) Create aNotWritablePropertyException
for the specified property.protected org.springframework.beans.BeanWrapperImpl.BeanPropertyHandler
getLocalPropertyHandler
(String propertyName) Return aAbstractNestablePropertyAccessor.PropertyHandler
for the specified localpropertyName
.getPropertyDescriptor
(String propertyName) Obtain the property descriptor for a specific property of the wrapped object.Obtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).protected BeanWrapperImpl
newNestedPropertyAccessor
(Object object, String nestedPath) Create a new nested property accessor instance.void
setBeanInstance
(Object object) Set a bean instance to hold, without any unwrapping ofOptional
.protected void
setIntrospectionClass
(Class<?> clazz) Set the class to introspect.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.Methods inherited from class org.springframework.beans.AbstractNestablePropertyAccessor
convertForProperty, getAutoGrowCollectionLimit, getFinalPath, getNestedPath, getPropertyAccessorForPropertyPath, getPropertyHandler, getPropertyType, getPropertyTypeDescriptor, getPropertyValue, getPropertyValue, getRootClass, getRootInstance, getWrappedClass, getWrappedInstance, isReadableProperty, isWritableProperty, setAutoGrowCollectionLimit, setPropertyValue, setPropertyValue, setPropertyValue, setWrappedInstance, toString
Methods inherited from class org.springframework.beans.AbstractPropertyAccessor
isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setExtractOldValueForEditor, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues
Methods inherited from class org.springframework.beans.TypeConverterSupport
convertIfNecessary, convertIfNecessary, convertIfNecessary, convertIfNecessary
Methods inherited from class org.springframework.beans.PropertyEditorRegistrySupport
copyCustomEditorsTo, copyDefaultEditorsTo, findCustomEditor, getConversionService, getDefaultEditor, guessPropertyTypeFromEditors, hasCustomEditorForElement, overrideDefaultEditor, registerCustomEditor, registerCustomEditor, registerDefaultEditors, setConversionService, useConfigValueEditors
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.beans.BeanWrapper
getAutoGrowCollectionLimit, getWrappedClass, getWrappedInstance, setAutoGrowCollectionLimit
Methods inherited from interface org.springframework.beans.ConfigurablePropertyAccessor
getConversionService, isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setConversionService, setExtractOldValueForEditor
Methods inherited from interface org.springframework.beans.PropertyAccessor
getPropertyType, getPropertyTypeDescriptor, getPropertyValue, isReadableProperty, isWritableProperty, setPropertyValue, setPropertyValue, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues
Methods inherited from interface org.springframework.beans.PropertyEditorRegistry
findCustomEditor, registerCustomEditor, registerCustomEditor
Methods inherited from interface org.springframework.beans.TypeConverter
convertIfNecessary, convertIfNecessary, convertIfNecessary, convertIfNecessary
-
Constructor Details
-
BeanWrapperImpl
public BeanWrapperImpl()Create a new empty BeanWrapperImpl. Wrapped instance needs to be set afterwards. Registers default editors. -
BeanWrapperImpl
public BeanWrapperImpl(boolean registerDefaultEditors) Create a new empty BeanWrapperImpl. Wrapped instance needs to be set afterwards.- Parameters:
registerDefaultEditors
- whether to register default editors (can be suppressed if the BeanWrapper won't need any type conversion)- See Also:
-
BeanWrapperImpl
Create a new BeanWrapperImpl for the given object.- Parameters:
object
- the object wrapped by this BeanWrapper
-
BeanWrapperImpl
Create a new BeanWrapperImpl, wrapping a new instance of the specified class.- Parameters:
clazz
- class to instantiate and wrap
-
BeanWrapperImpl
Create a new BeanWrapperImpl for the given object, registering a nested path that the object is in.- Parameters:
object
- the object wrapped by this BeanWrappernestedPath
- the nested path of the objectrootObject
- the root object at the top of the path
-
-
Method Details
-
setBeanInstance
Set a bean instance to hold, without any unwrapping ofOptional
.- Parameters:
object
- the actual target object- Since:
- 4.3
- See Also:
-
setWrappedInstance
public void setWrappedInstance(Object object, @Nullable String nestedPath, @Nullable Object rootObject) Description copied from class:AbstractNestablePropertyAccessor
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.- Overrides:
setWrappedInstance
in classAbstractNestablePropertyAccessor
- Parameters:
object
- the new target objectnestedPath
- the nested path of the objectrootObject
- the root object at the top of the path
-
setIntrospectionClass
Set the class to introspect. Needs to be called when the target object changes.- Parameters:
clazz
- the class to introspect
-
convertForProperty
@Nullable public Object convertForProperty(@Nullable 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
- the value to convertpropertyName
- the target property (note that nested or indexed properties are not supported here)- Returns:
- the new value, possibly the result of type conversion
- Throws:
TypeMismatchException
- if type conversion failed
-
getLocalPropertyHandler
@Nullable protected org.springframework.beans.BeanWrapperImpl.BeanPropertyHandler getLocalPropertyHandler(String propertyName) Description copied from class:AbstractNestablePropertyAccessor
Return aAbstractNestablePropertyAccessor.PropertyHandler
for the specified localpropertyName
. Only used to reach a property available in the current context.- Specified by:
getLocalPropertyHandler
in classAbstractNestablePropertyAccessor
- Parameters:
propertyName
- the name of a local property- Returns:
- the handler for that property, or
null
if it has not been found
-
newNestedPropertyAccessor
Description copied from class:AbstractNestablePropertyAccessor
Create a new nested property accessor instance. Can be overridden in subclasses to create a PropertyAccessor subclass.- Specified by:
newNestedPropertyAccessor
in classAbstractNestablePropertyAccessor
- Parameters:
object
- the object wrapped by this PropertyAccessornestedPath
- the nested path of the object- Returns:
- the nested PropertyAccessor instance
-
createNotWritablePropertyException
Description copied from class:AbstractNestablePropertyAccessor
Create aNotWritablePropertyException
for the specified property.- Specified by:
createNotWritablePropertyException
in classAbstractNestablePropertyAccessor
-
getPropertyDescriptors
Description copied from interface:BeanWrapper
Obtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).- Specified by:
getPropertyDescriptors
in interfaceBeanWrapper
- Returns:
- the PropertyDescriptors for the wrapped object
-
getPropertyDescriptor
public PropertyDescriptor getPropertyDescriptor(String propertyName) throws InvalidPropertyException Description copied from interface:BeanWrapper
Obtain the property descriptor for a specific property of the wrapped object.- Specified by:
getPropertyDescriptor
in interfaceBeanWrapper
- Parameters:
propertyName
- the property to obtain the descriptor for (may be a nested path, but no indexed/mapped property)- Returns:
- the property descriptor for the specified property
- Throws:
InvalidPropertyException
- if there is no such property
-