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)BeanWrapperPropertyEditorRegistrySupport
-
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
ConstructorsConstructorDescriptionCreate 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 NotWritablePropertyExceptioncreateNotWritablePropertyException(String propertyName) Create aNotWritablePropertyExceptionfor the specified property.protected org.springframework.beans.BeanWrapperImpl.BeanPropertyHandlergetLocalPropertyHandler(String propertyName) Return aAbstractNestablePropertyAccessor.PropertyHandlerfor 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 BeanWrapperImplnewNestedPropertyAccessor(Object object, String nestedPath) Create a new nested property accessor instance.voidsetBeanInstance(Object object) Set a bean instance to hold, without any unwrapping ofOptional.protected voidsetIntrospectionClass(Class<?> clazz) Set the class to introspect.voidsetWrappedInstance(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, toStringMethods inherited from class org.springframework.beans.AbstractPropertyAccessor
isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setExtractOldValueForEditor, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValuesMethods inherited from class org.springframework.beans.TypeConverterSupport
convertIfNecessary, convertIfNecessary, convertIfNecessary, convertIfNecessaryMethods inherited from class org.springframework.beans.PropertyEditorRegistrySupport
copyCustomEditorsTo, copyDefaultEditorsTo, findCustomEditor, getConversionService, getDefaultEditor, guessPropertyTypeFromEditors, hasCustomEditorForElement, overrideDefaultEditor, registerCustomEditor, registerCustomEditor, registerDefaultEditors, setConversionService, useConfigValueEditorsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.beans.BeanWrapper
getAutoGrowCollectionLimit, getWrappedClass, getWrappedInstance, setAutoGrowCollectionLimitMethods inherited from interface org.springframework.beans.ConfigurablePropertyAccessor
getConversionService, isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setConversionService, setExtractOldValueForEditorMethods inherited from interface org.springframework.beans.PropertyAccessor
getPropertyType, getPropertyTypeDescriptor, getPropertyValue, isReadableProperty, isWritableProperty, setPropertyValue, setPropertyValue, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValuesMethods inherited from interface org.springframework.beans.PropertyEditorRegistry
findCustomEditor, registerCustomEditor, registerCustomEditorMethods 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:AbstractNestablePropertyAccessorSwitch 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:
setWrappedInstancein 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
convertIfNecessarymethods 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:AbstractNestablePropertyAccessorReturn aAbstractNestablePropertyAccessor.PropertyHandlerfor the specified localpropertyName. Only used to reach a property available in the current context.- Specified by:
getLocalPropertyHandlerin classAbstractNestablePropertyAccessor- Parameters:
propertyName- the name of a local property- Returns:
- the handler for that property, or
nullif it has not been found
-
newNestedPropertyAccessor
Description copied from class:AbstractNestablePropertyAccessorCreate a new nested property accessor instance. Can be overridden in subclasses to create a PropertyAccessor subclass.- Specified by:
newNestedPropertyAccessorin 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:AbstractNestablePropertyAccessorCreate aNotWritablePropertyExceptionfor the specified property.- Specified by:
createNotWritablePropertyExceptionin classAbstractNestablePropertyAccessor
-
getPropertyDescriptors
Description copied from interface:BeanWrapperObtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).- Specified by:
getPropertyDescriptorsin interfaceBeanWrapper- Returns:
- the PropertyDescriptors for the wrapped object
-
getPropertyDescriptor
public PropertyDescriptor getPropertyDescriptor(String propertyName) throws InvalidPropertyException Description copied from interface:BeanWrapperObtain the property descriptor for a specific property of the wrapped object.- Specified by:
getPropertyDescriptorin interfaceBeanWrapper- Parameters:
propertyName- the property to obtain the descriptor for (may be a nested path, but not an indexed/mapped property)- Returns:
- the property descriptor for the specified property
- Throws:
InvalidPropertyException- if there is no such property
-