public class

BeanWrapperImpl

extends AbstractPropertyAccessor
implements BeanWrapper
java.lang.Object
   ↳ org.springframework.beans.PropertyEditorRegistrySupport
     ↳ org.springframework.beans.AbstractPropertyAccessor
       ↳ org.springframework.beans.BeanWrapperImpl

Class Overview

Default 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 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.

BeanWrapperImpl will convert collection and array values to the corresponding target collections or arrays, if necessary. Custom property editors that deal with collections or arrays can either be written via PropertyEditor's setValue, or against a comma-delimited String via setAsText, as String arrays are converted in such a format if the array itself is not assignable.

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 forBeanPropertyAccess(Object) factory method instead.

Summary

[Expand]
Inherited Constants
From interface org.springframework.beans.PropertyAccessor
Public Constructors
BeanWrapperImpl()
Create new empty BeanWrapperImpl.
BeanWrapperImpl(boolean registerDefaultEditors)
Create new empty BeanWrapperImpl.
BeanWrapperImpl(Object object)
Create new BeanWrapperImpl for the given object.
BeanWrapperImpl(Class<?> clazz)
Create new BeanWrapperImpl, wrapping a new instance of the specified class.
BeanWrapperImpl(Object object, String nestedPath, Object rootObject)
Create new BeanWrapperImpl for the given object, registering a nested path that the object is in.
Public Methods
Object convertForProperty(Object value, String propertyName)
Convert the given value for the specified property to the latter's type.
<T> T convertIfNecessary(Object value, Class<T> requiredType, MethodParameter methodParam)
Convert the value to the required type (if necessary from a String).
final String getNestedPath()
Return the nested path of the object wrapped by this BeanWrapper.
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).
Class getPropertyType(String propertyName)
Determine the property type for the given property path.
TypeDescriptor getPropertyTypeDescriptor(String propertyName)
Return a type descriptor for the specified property: preferably from the read method, falling back to the write method.
Object getPropertyValue(String propertyName)
Actually get the value of a property.
final Class getRootClass()
Return the class of the root object at the top of the path of this BeanWrapper.
final Object getRootInstance()
Return the root object at the top of the path of this BeanWrapper.
AccessControlContext getSecurityContext()
Return the security context used during the invocation of the wrapped instance methods.
final Class getWrappedClass()
Return the type of the wrapped JavaBean object.
final Object getWrappedInstance()
Return the bean instance wrapped by this object, if any.
boolean isAutoGrowNestedPaths()
If this BeanWrapper should "auto grow" nested paths.
boolean isReadableProperty(String propertyName)
Determine whether the specified property is readable.
boolean isWritableProperty(String propertyName)
Determine whether the specified property is writable.
void setAutoGrowNestedPaths(boolean autoGrowNestedPaths)
If this BeanWrapper should "auto grow" nested paths.
void setPropertyValue(String propertyName, Object value)
Actually set a property value.
void setPropertyValue(PropertyValue pv)
Set the specified value as current property value.
void setSecurityContext(AccessControlContext acc)
Set the security context used during the invocation of the wrapped instance methods.
void setWrappedInstance(Object object)
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.
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.
String toString()
Protected Methods
BeanWrapperImpl getBeanWrapperForPropertyPath(String propertyPath)
Recursively navigate to return a BeanWrapper for the nested property path.
PropertyDescriptor getPropertyDescriptorInternal(String propertyName)
Internal version of getPropertyDescriptor(String): Returns null if not found rather than throwing an exception.
BeanWrapperImpl newNestedBeanWrapper(Object object, String nestedPath)
Create a new nested BeanWrapper instance.
void setIntrospectionClass(Class clazz)
Set the class to introspect.
[Expand]
Inherited Methods
From class org.springframework.beans.AbstractPropertyAccessor
From class org.springframework.beans.PropertyEditorRegistrySupport
From class java.lang.Object
From interface org.springframework.beans.BeanWrapper
From interface org.springframework.beans.ConfigurablePropertyAccessor
From interface org.springframework.beans.PropertyAccessor
From interface org.springframework.beans.PropertyEditorRegistry
From interface org.springframework.beans.TypeConverter

Public Constructors

public BeanWrapperImpl ()

Also: SpringBeans

Create new empty BeanWrapperImpl. Wrapped instance needs to be set afterwards. Registers default editors.

public BeanWrapperImpl (boolean registerDefaultEditors)

Also: SpringBeans

Create 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)

public BeanWrapperImpl (Object object)

Also: SpringBeans

Create new BeanWrapperImpl for the given object.

Parameters
object object wrapped by this BeanWrapper

public BeanWrapperImpl (Class<?> clazz)

Also: SpringBeans

Create new BeanWrapperImpl, wrapping a new instance of the specified class.

Parameters
clazz class to instantiate and wrap

public BeanWrapperImpl (Object object, String nestedPath, Object rootObject)

Also: SpringBeans

Create new BeanWrapperImpl for the given object, registering a nested path that the object is in.

Parameters
object object wrapped by this BeanWrapper
nestedPath the nested path of the object
rootObject the root object at the top of the path

Public Methods

public Object convertForProperty (Object value, String propertyName)

Also: SpringBeans

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 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

public T convertIfNecessary (Object value, Class<T> requiredType, MethodParameter methodParam)

Convert the value to the required type (if necessary from a String).

Conversions from String to any type will typically use the setAsText method of the PropertyEditor class. Note that a PropertyEditor must be registered for the given class for this to work; this is a standard JavaBeans API. A number of PropertyEditors are automatically registered.

Parameters
value the value to convert
requiredType the type we must convert to (or null if not known, for example in case of a collection element)
methodParam the method parameter that is the target of the conversion (for analysis of generic types; may be null)
Returns
  • the new value, possibly the result of type conversion

public final String getNestedPath ()

Also: SpringBeans

Return the nested path of the object wrapped by this BeanWrapper.

public PropertyDescriptor getPropertyDescriptor (String propertyName)

Also: SpringBeans

Obtain the property descriptor for a specific property of the wrapped object.

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

public PropertyDescriptor[] getPropertyDescriptors ()

Also: SpringBeans

Obtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).

Returns
  • the PropertyDescriptors for the wrapped object

public Class getPropertyType (String propertyName)

Also: SpringBeans

Determine the property type for the given property path.

Called by findCustomEditor(Class, String) if no required type has been specified, to be able to find a type-specific editor even if just given a property path.

The default implementation always returns null. BeanWrapperImpl overrides this with the standard getPropertyType method as defined by the BeanWrapper interface.

Parameters
propertyName the property path to determine the type for
Returns
  • the type of the property, or null if not determinable

public TypeDescriptor getPropertyTypeDescriptor (String propertyName)

Also: SpringBeans

Return a type descriptor for the specified property: preferably from the read method, falling back to the write method.

Parameters
propertyName the property to check (may be a nested path and/or an indexed/mapped property)
Returns
  • the property type for the particular property, or null if not determinable

public Object getPropertyValue (String propertyName)

Also: SpringBeans

Actually get the value of a property.

Parameters
propertyName name of the property to get the value of
Returns
  • the value of the property

public final Class getRootClass ()

Also: SpringBeans

Return the class of the root object at the top of the path of this BeanWrapper.

See Also

public final Object getRootInstance ()

Also: SpringBeans

Return the root object at the top of the path of this BeanWrapper.

See Also

public AccessControlContext getSecurityContext ()

Also: SpringBeans

Return the security context used during the invocation of the wrapped instance methods. Can be null.

public final Class getWrappedClass ()

Also: SpringBeans

Return the type of the wrapped JavaBean object.

Returns
  • the type of the wrapped bean instance, or null if no wrapped object has been set

public final Object getWrappedInstance ()

Also: SpringBeans

Return the bean instance wrapped by this object, if any.

Returns
  • the bean instance, or null if none set

public boolean isAutoGrowNestedPaths ()

Also: SpringBeans

If this BeanWrapper should "auto grow" nested paths.

public boolean isReadableProperty (String propertyName)

Also: SpringBeans

Determine whether the specified property is readable.

Returns false if the property doesn't exist.

Parameters
propertyName the property to check (may be a nested path and/or an indexed/mapped property)
Returns
  • whether the property is readable

public boolean isWritableProperty (String propertyName)

Also: SpringBeans

Determine whether the specified property is writable.

Returns false if the property doesn't exist.

Parameters
propertyName the property to check (may be a nested path and/or an indexed/mapped property)
Returns
  • whether the property is writable

public void setAutoGrowNestedPaths (boolean autoGrowNestedPaths)

Also: SpringBeans

If this BeanWrapper should "auto grow" nested paths. When true, auto growth is triggered on nested paths when null values are encountered. When true, auto growth is triggered on collection properties when out of bounds indexes are accessed. Default is false.

public void setPropertyValue (String propertyName, Object value)

Also: SpringBeans

Actually set a property value.

Parameters
propertyName name of the property to set value of
value the new value

public void setPropertyValue (PropertyValue pv)

Also: SpringBeans

Set the specified value as current property value.

Parameters
pv an object containing the new property value

public void setSecurityContext (AccessControlContext acc)

Also: SpringBeans

Set the security context used during the invocation of the wrapped instance methods. Can be null.

public void setWrappedInstance (Object object)

Also: SpringBeans

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.

Parameters
object the new target object

public void setWrappedInstance (Object object, String nestedPath, Object rootObject)

Also: SpringBeans

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.

Parameters
object the new target object
nestedPath the nested path of the object
rootObject the root object at the top of the path

public String toString ()

Protected Methods

protected BeanWrapperImpl getBeanWrapperForPropertyPath (String propertyPath)

Also: SpringBeans

Recursively navigate to return a BeanWrapper for the nested property path.

Parameters
propertyPath property property path, which may be nested
Returns
  • a BeanWrapper for the target bean

protected PropertyDescriptor getPropertyDescriptorInternal (String propertyName)

Also: SpringBeans

Internal version of getPropertyDescriptor(String): Returns null if not found rather than throwing an exception.

Parameters
propertyName the property to obtain the descriptor for
Returns
  • the property descriptor for the specified property, or null if not found
Throws
BeansException in case of introspection failure

protected BeanWrapperImpl newNestedBeanWrapper (Object object, String nestedPath)

Also: SpringBeans

Create a new nested BeanWrapper instance.

Default implementation creates a BeanWrapperImpl instance. Can be overridden in subclasses to create a BeanWrapperImpl subclass.

Parameters
object object wrapped by this BeanWrapper
nestedPath the nested path of the object
Returns
  • the nested BeanWrapper instance

protected void setIntrospectionClass (Class clazz)

Also: SpringBeans

Set the class to introspect. Needs to be called when the target object changes.

Parameters
clazz the class to introspect