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
Modifier and Type | Class and Description |
---|---|
private class |
BeanWrapperImpl.BeanPropertyHandler |
AbstractNestablePropertyAccessor.PropertyHandler, AbstractNestablePropertyAccessor.PropertyTokenHolder
Modifier and Type | Field and Description |
---|---|
private java.security.AccessControlContext |
acc
The security context used for invoking the property methods
|
private CachedIntrospectionResults |
cachedIntrospectionResults
Cached introspections results for this object, to prevent encountering
the cost of JavaBeans introspection every time.
|
rootObject, wrappedObject
typeConverterDelegate
NESTED_PROPERTY_SEPARATOR, NESTED_PROPERTY_SEPARATOR_CHAR, PROPERTY_KEY_PREFIX, PROPERTY_KEY_PREFIX_CHAR, PROPERTY_KEY_SUFFIX, PROPERTY_KEY_SUFFIX_CHAR
Modifier | Constructor and Description |
---|---|
|
BeanWrapperImpl()
Create a new empty BeanWrapperImpl.
|
|
BeanWrapperImpl(boolean registerDefaultEditors)
Create a new empty BeanWrapperImpl.
|
|
BeanWrapperImpl(java.lang.Class<?> clazz)
Create a new BeanWrapperImpl, wrapping a new instance of the specified class.
|
|
BeanWrapperImpl(java.lang.Object object)
Create a new BeanWrapperImpl for the given object.
|
private |
BeanWrapperImpl(java.lang.Object object,
java.lang.String nestedPath,
BeanWrapperImpl parent)
Create a new BeanWrapperImpl for the given object,
registering a nested path that the object is in.
|
|
BeanWrapperImpl(java.lang.Object object,
java.lang.String nestedPath,
java.lang.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 |
---|---|
java.lang.Object |
convertForProperty(java.lang.Object value,
java.lang.String propertyName)
Convert the given value for the specified property to the latter's type.
|
protected NotWritablePropertyException |
createNotWritablePropertyException(java.lang.String propertyName)
Create a
NotWritablePropertyException for the specified property. |
private CachedIntrospectionResults |
getCachedIntrospectionResults()
Obtain a lazily initializted CachedIntrospectionResults instance
for the wrapped object.
|
protected BeanWrapperImpl.BeanPropertyHandler |
getLocalPropertyHandler(java.lang.String propertyName)
Return a
AbstractNestablePropertyAccessor.PropertyHandler for the specified local propertyName . |
java.beans.PropertyDescriptor |
getPropertyDescriptor(java.lang.String propertyName)
Obtain the property descriptor for a specific property
of the wrapped object.
|
java.beans.PropertyDescriptor[] |
getPropertyDescriptors()
Obtain the PropertyDescriptors for the wrapped object
(as determined by standard JavaBeans introspection).
|
java.security.AccessControlContext |
getSecurityContext()
Return the security context used during the invocation of the wrapped instance methods.
|
protected BeanWrapperImpl |
newNestedPropertyAccessor(java.lang.Object object,
java.lang.String nestedPath)
Create a new nested property accessor instance.
|
private Property |
property(java.beans.PropertyDescriptor pd) |
void |
setBeanInstance(java.lang.Object object)
Set a bean instance to hold, without any unwrapping of
Optional . |
protected void |
setIntrospectionClass(java.lang.Class<?> clazz)
Set the class to introspect.
|
void |
setSecurityContext(java.security.AccessControlContext acc)
Set the security context used during the invocation of the wrapped instance methods.
|
void |
setWrappedInstance(java.lang.Object object,
java.lang.String nestedPath,
java.lang.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
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
private CachedIntrospectionResults cachedIntrospectionResults
private java.security.AccessControlContext acc
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(java.lang.Object object)
object
- object wrapped by this BeanWrapperpublic BeanWrapperImpl(java.lang.Class<?> clazz)
clazz
- class to instantiate and wrappublic BeanWrapperImpl(java.lang.Object object, java.lang.String nestedPath, java.lang.Object rootObject)
object
- object wrapped by this BeanWrappernestedPath
- the nested path of the objectrootObject
- the root object at the top of the pathprivate BeanWrapperImpl(java.lang.Object object, java.lang.String nestedPath, BeanWrapperImpl parent)
object
- object wrapped by this BeanWrappernestedPath
- the nested path of the objectparent
- the containing BeanWrapper (must not be null
)public void setBeanInstance(java.lang.Object object)
Optional
.object
- the actual target objectAbstractNestablePropertyAccessor.setWrappedInstance(Object)
public void setWrappedInstance(java.lang.Object object, @Nullable java.lang.String nestedPath, @Nullable java.lang.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(java.lang.Class<?> clazz)
clazz
- the class to introspectprivate CachedIntrospectionResults getCachedIntrospectionResults()
public void setSecurityContext(java.security.AccessControlContext acc)
public java.security.AccessControlContext getSecurityContext()
@Nullable public java.lang.Object convertForProperty(java.lang.Object value, java.lang.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 failedprivate Property property(java.beans.PropertyDescriptor pd)
protected BeanWrapperImpl.BeanPropertyHandler getLocalPropertyHandler(java.lang.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(java.lang.Object object, java.lang.String nestedPath)
AbstractNestablePropertyAccessor
newNestedPropertyAccessor
in class AbstractNestablePropertyAccessor
object
- object wrapped by this PropertyAccessornestedPath
- the nested path of the objectprotected NotWritablePropertyException createNotWritablePropertyException(java.lang.String propertyName)
AbstractNestablePropertyAccessor
NotWritablePropertyException
for the specified property.createNotWritablePropertyException
in class AbstractNestablePropertyAccessor
public java.beans.PropertyDescriptor[] getPropertyDescriptors()
BeanWrapper
getPropertyDescriptors
in interface BeanWrapper
public java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.String propertyName) throws InvalidPropertyException
BeanWrapper
getPropertyDescriptor
in interface BeanWrapper
propertyName
- the property to obtain the descriptor for
(may be a nested path, but no indexed/mapped property)InvalidPropertyException
- if there is no such property