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 SummaryNested classes/interfaces inherited from class org.springframework.beans.AbstractNestablePropertyAccessorAbstractNestablePropertyAccessor.PropertyHandler, AbstractNestablePropertyAccessor.PropertyTokenHolder
- 
Field SummaryFields inherited from interface org.springframework.beans.PropertyAccessorNESTED_PROPERTY_SEPARATOR, NESTED_PROPERTY_SEPARATOR_CHAR, PROPERTY_KEY_PREFIX, PROPERTY_KEY_PREFIX_CHAR, PROPERTY_KEY_SUFFIX, PROPERTY_KEY_SUFFIX_CHAR
- 
Constructor SummaryConstructorsConstructorDescriptionCreate 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 SummaryModifier 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.AbstractNestablePropertyAccessorconvertForProperty, 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.AbstractPropertyAccessorisAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setExtractOldValueForEditor, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValuesMethods inherited from class org.springframework.beans.TypeConverterSupportconvertIfNecessary, convertIfNecessary, convertIfNecessary, convertIfNecessaryMethods inherited from class org.springframework.beans.PropertyEditorRegistrySupportcopyCustomEditorsTo, copyDefaultEditorsTo, findCustomEditor, getConversionService, getDefaultEditor, guessPropertyTypeFromEditors, hasCustomEditorForElement, overrideDefaultEditor, registerCustomEditor, registerCustomEditor, registerDefaultEditors, setConversionService, setDefaultEditorRegistrar, useConfigValueEditorsMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.beans.BeanWrappergetAutoGrowCollectionLimit, getWrappedClass, getWrappedInstance, setAutoGrowCollectionLimitMethods inherited from interface org.springframework.beans.ConfigurablePropertyAccessorgetConversionService, isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setConversionService, setExtractOldValueForEditorMethods inherited from interface org.springframework.beans.PropertyAccessorgetPropertyType, getPropertyTypeDescriptor, getPropertyValue, isReadableProperty, isWritableProperty, setPropertyValue, setPropertyValue, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValuesMethods inherited from interface org.springframework.beans.PropertyEditorRegistryfindCustomEditor, registerCustomEditor, registerCustomEditorMethods inherited from interface org.springframework.beans.TypeConverterconvertIfNecessary, convertIfNecessary, convertIfNecessary, convertIfNecessary
- 
Constructor Details- 
BeanWrapperImplpublic BeanWrapperImpl()Create a new empty BeanWrapperImpl. Wrapped instance needs to be set afterwards. Registers default editors.
- 
BeanWrapperImplpublic 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:
 
- 
BeanWrapperImplCreate a new BeanWrapperImpl for the given object.- Parameters:
- object- the object wrapped by this BeanWrapper
 
- 
BeanWrapperImplCreate a new BeanWrapperImpl, wrapping a new instance of the specified class.- Parameters:
- clazz- class to instantiate and wrap
 
- 
BeanWrapperImplCreate a new BeanWrapperImpl for the given object, registering a nested path that the object is in.- Parameters:
- object- the object wrapped by this BeanWrapper
- nestedPath- the nested path of the object
- rootObject- the root object at the top of the path
 
 
- 
- 
Method Details- 
setBeanInstanceSet a bean instance to hold, without any unwrapping ofOptional.- Parameters:
- object- the actual target object
- Since:
- 4.3
- See Also:
 
- 
setWrappedInstancepublic 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 class- AbstractNestablePropertyAccessor
- Parameters:
- object- the new target object
- nestedPath- the nested path of the object
- rootObject- the root object at the top of the path
 
- 
setIntrospectionClassSet 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 convert
- propertyName- 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 class- AbstractNestablePropertyAccessor
- Parameters:
- propertyName- the name of a local property
- Returns:
- the handler for that property, or nullif it has not been found
 
- 
newNestedPropertyAccessorDescription copied from class:AbstractNestablePropertyAccessorCreate a new nested property accessor instance. Can be overridden in subclasses to create a PropertyAccessor subclass.- Specified by:
- newNestedPropertyAccessorin class- AbstractNestablePropertyAccessor
- Parameters:
- object- the object wrapped by this PropertyAccessor
- nestedPath- the nested path of the object
- Returns:
- the nested PropertyAccessor instance
 
- 
createNotWritablePropertyExceptionDescription copied from class:AbstractNestablePropertyAccessorCreate aNotWritablePropertyExceptionfor the specified property.- Specified by:
- createNotWritablePropertyExceptionin class- AbstractNestablePropertyAccessor
 
- 
getPropertyDescriptorsDescription copied from interface:BeanWrapperObtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).- Specified by:
- getPropertyDescriptorsin interface- BeanWrapper
- Returns:
- the PropertyDescriptors for the wrapped object
 
- 
getPropertyDescriptorpublic 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 interface- BeanWrapper
- 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
 
 
-