public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements BeanWrapper
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.
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
AbstractNestablePropertyAccessor.PropertyHandler, AbstractNestablePropertyAccessor.PropertyTokenHolder
NESTED_PROPERTY_SEPARATOR, NESTED_PROPERTY_SEPARATOR_CHAR, PROPERTY_KEY_PREFIX, PROPERTY_KEY_PREFIX_CHAR, PROPERTY_KEY_SUFFIX, PROPERTY_KEY_SUFFIX_CHAR
Constructor and 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.
|
Modifier and Type | Method and 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 a
NotWritablePropertyException for the specified property. |
protected org.springframework.beans.BeanWrapperImpl.BeanPropertyHandler |
getLocalPropertyHandler(String propertyName)
Return a
AbstractNestablePropertyAccessor.PropertyHandler for the specified local propertyName . |
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 of
Optional . |
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.
|
convertForProperty, getAutoGrowCollectionLimit, getFinalPath, getNestedPath, getPropertyAccessorForPropertyPath, getPropertyHandler, getPropertyType, getPropertyTypeDescriptor, getPropertyValue, getPropertyValue, getRootClass, getRootInstance, getWrappedClass, getWrappedInstance, isReadableProperty, isWritableProperty, setAutoGrowCollectionLimit, setPropertyValue, setPropertyValue, setPropertyValue, setWrappedInstance, toString
isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setExtractOldValueForEditor, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues
convertIfNecessary, convertIfNecessary, convertIfNecessary, convertIfNecessary
copyCustomEditorsTo, copyDefaultEditorsTo, findCustomEditor, getConversionService, getDefaultEditor, guessPropertyTypeFromEditors, hasCustomEditorForElement, overrideDefaultEditor, registerCustomEditor, registerCustomEditor, registerDefaultEditors, setConversionService, useConfigValueEditors
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getAutoGrowCollectionLimit, getWrappedClass, getWrappedInstance, setAutoGrowCollectionLimit
getConversionService, isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setConversionService, setExtractOldValueForEditor
getPropertyType, getPropertyTypeDescriptor, getPropertyValue, isReadableProperty, isWritableProperty, setPropertyValue, setPropertyValue, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues
findCustomEditor, registerCustomEditor, registerCustomEditor
convertIfNecessary, convertIfNecessary, convertIfNecessary, convertIfNecessary
public BeanWrapperImpl()
public BeanWrapperImpl(boolean registerDefaultEditors)
registerDefaultEditors
- whether to register default editors
(can be suppressed if the BeanWrapper won't need any type conversion)setWrappedInstance(java.lang.Object, java.lang.String, java.lang.Object)
public BeanWrapperImpl(Object object)
object
- the object wrapped by this BeanWrapperpublic BeanWrapperImpl(Class<?> clazz)
clazz
- class to instantiate and wrappublic BeanWrapperImpl(Object object, String nestedPath, Object rootObject)
object
- the object wrapped by this BeanWrappernestedPath
- the nested path of the objectrootObject
- the root object at the top of the pathpublic void setBeanInstance(Object object)
Optional
.object
- the actual target objectAbstractNestablePropertyAccessor.setWrappedInstance(Object)
public void setWrappedInstance(Object object, @Nullable String nestedPath, @Nullable Object rootObject)
AbstractNestablePropertyAccessor
setWrappedInstance
in class AbstractNestablePropertyAccessor
object
- the new target objectnestedPath
- the nested path of the objectrootObject
- the root object at the top of the pathprotected void setIntrospectionClass(Class<?> clazz)
clazz
- the class to introspectpublic void setSecurityContext(@Nullable AccessControlContext acc)
@Nullable public AccessControlContext getSecurityContext()
@Nullable public Object convertForProperty(@Nullable Object value, String propertyName) throws TypeMismatchException
This method is only intended for optimizations in a BeanFactory.
Use the convertIfNecessary
methods for programmatic conversion.
value
- the value to convertpropertyName
- the target property
(note that nested or indexed properties are not supported here)TypeMismatchException
- if type conversion failed@Nullable protected org.springframework.beans.BeanWrapperImpl.BeanPropertyHandler getLocalPropertyHandler(String propertyName)
AbstractNestablePropertyAccessor
AbstractNestablePropertyAccessor.PropertyHandler
for the specified local propertyName
.
Only used to reach a property available in the current context.getLocalPropertyHandler
in class AbstractNestablePropertyAccessor
propertyName
- the name of a local propertynull
if it has not been foundprotected BeanWrapperImpl newNestedPropertyAccessor(Object object, String nestedPath)
AbstractNestablePropertyAccessor
newNestedPropertyAccessor
in class AbstractNestablePropertyAccessor
object
- the object wrapped by this PropertyAccessornestedPath
- the nested path of the objectprotected NotWritablePropertyException createNotWritablePropertyException(String propertyName)
AbstractNestablePropertyAccessor
NotWritablePropertyException
for the specified property.createNotWritablePropertyException
in class AbstractNestablePropertyAccessor
public PropertyDescriptor[] getPropertyDescriptors()
BeanWrapper
getPropertyDescriptors
in interface BeanWrapper
public PropertyDescriptor getPropertyDescriptor(String propertyName) throws InvalidPropertyException
BeanWrapper
getPropertyDescriptor
in interface BeanWrapper
propertyName
- the property to obtain the descriptor for
(may be a nested path, but not an indexed/mapped property)InvalidPropertyException
- if there is no such property