Class BeanWrapperImpl
- All Implemented Interfaces:
BeanWrapper
,ConfigurablePropertyAccessor
,PropertyAccessor
,PropertyEditorRegistry
,TypeConverter
public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements BeanWrapper
DefaultBeanWrapper
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 thePropertyEditorRegistrySupport.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 classPropertyEditorRegistrySupport
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
Constructors Constructor Description BeanWrapperImpl()
Create 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
convertForProperty(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
.PropertyDescriptor
getPropertyDescriptor(String propertyName)
Obtain the property descriptor for a specific property of the wrapped object.PropertyDescriptor[]
getPropertyDescriptors()
Obtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).AccessControlContext
getSecurityContext()
Return the security context used during the invocation of the wrapped instance methods.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
setSecurityContext(AccessControlContext acc)
Set the security context used during the invocation of the wrapped instance methods.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
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
Constructor Detail
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:
setWrappedInstance(java.lang.Object, java.lang.String, java.lang.Object)
BeanWrapperImpl
public BeanWrapperImpl(Object object)
Create a new BeanWrapperImpl for the given object.- Parameters:
object
- the object wrapped by this BeanWrapper
BeanWrapperImpl
public BeanWrapperImpl(Class<?> clazz)
Create a new BeanWrapperImpl, wrapping a new instance of the specified class.- Parameters:
clazz
- class to instantiate and wrap
BeanWrapperImpl
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
- the object wrapped by this BeanWrappernestedPath
- the nested path of the objectrootObject
- the root object at the top of the path
Method Detail
setBeanInstance
public void setBeanInstance(Object object)
Set a bean instance to hold, without any unwrapping ofOptional
.- Parameters:
object
- the actual target object- Since:
- 4.3
- See Also:
AbstractNestablePropertyAccessor.setWrappedInstance(Object)
setWrappedInstance
public void setWrappedInstance(Object object, String nestedPath, 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
protected void setIntrospectionClass(Class<?> clazz)
Set the class to introspect. Needs to be called when the target object changes.- Parameters:
clazz
- the class to introspect
setSecurityContext
public void setSecurityContext(AccessControlContext acc)
Set the security context used during the invocation of the wrapped instance methods. Can be null.
getSecurityContext
public AccessControlContext getSecurityContext()
Return the security context used during the invocation of the wrapped instance methods. Can be null.
convertForProperty
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
- 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
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
protected BeanWrapperImpl newNestedPropertyAccessor(Object object, String nestedPath)
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
- object wrapped by this PropertyAccessornestedPath
- the nested path of the object- Returns:
- the nested PropertyAccessor instance
createNotWritablePropertyException
protected NotWritablePropertyException createNotWritablePropertyException(String propertyName)
Description copied from class:AbstractNestablePropertyAccessor
Create aNotWritablePropertyException
for the specified property.- Specified by:
createNotWritablePropertyException
in classAbstractNestablePropertyAccessor
getPropertyDescriptors
public PropertyDescriptor[] 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