Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.beans
Class BeanWrapperImpl

    java.lang.Object
      org.springframework.beans.PropertyEditorRegistrySupport
          org.springframework.beans.AbstractPropertyAccessor
              org.springframework.beans.BeanWrapperImpl

All Implemented Interfaces:
  BeanWrapper, ConfigurablePropertyAccessor, PropertyAccessor, PropertyEditorRegistry, TypeConverter

    public class BeanWrapperImpl

extends AbstractPropertyAccessor
implements BeanWrapper

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

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

Since:
  15 April 2001
Author:
  Rod Johnson, Juergen Hoeller, Rob Harrop
See Also:
  `PropertyEditorRegistrySupport.registerCustomEditor(java.lang.Class, java.beans.PropertyEditor)`, `AbstractPropertyAccessor.setPropertyValues(java.util.Map)`, `setPropertyValue(java.lang.String, java.lang.Object)`, `getPropertyValue(java.lang.String)`, `getPropertyType(java.lang.String)`, `BeanWrapper`, `PropertyEditorRegistrySupport`

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
`BeanWrapperImpl()` Create new empty BeanWrapperImpl.
`BeanWrapperImpl(boolean registerDefaultEditors)` Create new empty BeanWrapperImpl.
`BeanWrapperImpl(java.lang.Class<?> clazz)` Create new BeanWrapperImpl, wrapping a new instance of the specified class.
`BeanWrapperImpl(java.lang.Object object)` Create new BeanWrapperImpl for the given object.
`BeanWrapperImpl(java.lang.Object object, java.lang.String nestedPath, java.lang.Object rootObject)` Create new BeanWrapperImpl for the given object, registering a nested path that the object is in.

Method Summary
`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.
`
`<T> T`
` | `convertIfNecessary(java.lang.Object value, java.lang.Class<T> requiredType, MethodParameter methodParam)` Convert the value to the required type (if necessary from a String).
`int` | `getAutoGrowCollectionLimit()` Return the limit for array and collection auto-growing.
`protected BeanWrapperImpl` | `getBeanWrapperForPropertyPath(java.lang.String propertyPath)` Recursively navigate to return a BeanWrapper for the nested property path.
`java.lang.String` | `getNestedPath()` Return the nested path of the object wrapped by this BeanWrapper.
`java.beans.PropertyDescriptor` | `getPropertyDescriptor(java.lang.String propertyName)` Obtain the property descriptor for a specific property of the wrapped object.
`protected java.beans.PropertyDescriptor` | `getPropertyDescriptorInternal(java.lang.String propertyName)` Internal version of `getPropertyDescriptor(java.lang.String)`: Returns `null` if not found rather than throwing an exception.
`java.beans.PropertyDescriptor[]` | `getPropertyDescriptors()` Obtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).
`java.lang.Class` | `getPropertyType(java.lang.String propertyName)` Determine the property type for the given property path.
`TypeDescriptor` | `getPropertyTypeDescriptor(java.lang.String propertyName)` Return a type descriptor for the specified property: preferably from the read method, falling back to the write method.
`java.lang.Object` | `getPropertyValue(java.lang.String propertyName)` Actually get the value of a property.
`java.lang.Class` | `getRootClass()` Return the class of the root object at the top of the path of this BeanWrapper.
`java.lang.Object` | `getRootInstance()` Return the root object at the top of the path of this BeanWrapper.
`java.security.AccessControlContext` | `getSecurityContext()` Return the security context used during the invocation of the wrapped instance methods.
`java.lang.Class` | `getWrappedClass()` Return the type of the wrapped JavaBean object.
`java.lang.Object` | `getWrappedInstance()` Return the bean instance wrapped by this object, if any.
`boolean` | `isAutoGrowNestedPaths()` Return whether "auto-growing" of nested paths has been activated.
`boolean` | `isReadableProperty(java.lang.String propertyName)` Determine whether the specified property is readable.
`boolean` | `isWritableProperty(java.lang.String propertyName)` Determine whether the specified property is writable.
`protected BeanWrapperImpl` | `newNestedBeanWrapper(java.lang.Object object, java.lang.String nestedPath)` Create a new nested BeanWrapper instance.
`void` | `setAutoGrowCollectionLimit(int autoGrowCollectionLimit)` Specify a limit for array and collection auto-growing.
`void` | `setAutoGrowNestedPaths(boolean autoGrowNestedPaths)` Set whether this BeanWrapper should attempt to "auto-grow" a nested path that contains a null value.
`protected void` | `setIntrospectionClass(java.lang.Class clazz)` Set the class to introspect.
`void` | `setPropertyValue(PropertyValue pv)` Set the specified value as current property value.
`void` | `setPropertyValue(java.lang.String propertyName, java.lang.Object value)` Actually set a property value.
`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)` 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(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.
`java.lang.String` | `toString()`

Methods inherited from class org.springframework.beans.AbstractPropertyAccessor
`convertIfNecessary, isExtractOldValueForEditor, setExtractOldValueForEditor, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues`

Methods inherited from class org.springframework.beans.PropertyEditorRegistrySupport
`copyCustomEditorsTo, copyDefaultEditorsTo, findCustomEditor, getConversionService, getDefaultEditor, guessPropertyTypeFromEditors, hasCustomEditorForElement, isSharedEditor, overrideDefaultEditor, registerCustomEditor, registerCustomEditor, registerDefaultEditors, registerSharedEditor, setConversionService, useConfigValueEditors`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.springframework.beans.ConfigurablePropertyAccessor
`getConversionService, isExtractOldValueForEditor, setConversionService, setExtractOldValueForEditor`

Methods inherited from interface org.springframework.beans.PropertyAccessor
`setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues`

Methods inherited from interface org.springframework.beans.PropertyEditorRegistry
`findCustomEditor, registerCustomEditor, registerCustomEditor`

Methods inherited from interface org.springframework.beans.TypeConverter
`convertIfNecessary`

Constructor Detail

### BeanWrapperImpl

    public BeanWrapperImpl()

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

  See Also:
    `setWrappedInstance(java.lang.Object)`

### BeanWrapperImpl

    public BeanWrapperImpl(boolean registerDefaultEditors)

  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)
  See Also:
    `setWrappedInstance(java.lang.Object)`

### BeanWrapperImpl

    public BeanWrapperImpl(java.lang.Object object)

  Create new BeanWrapperImpl for the given object.

  Parameters:
    `object` - object wrapped by this BeanWrapper

### BeanWrapperImpl

    public BeanWrapperImpl(java.lang.Class<?> clazz)

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

  Parameters:
    `clazz` - class to instantiate and wrap

### BeanWrapperImpl

    public BeanWrapperImpl(java.lang.Object object,
                           java.lang.String nestedPath,
                           java.lang.Object rootObject)

  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

Method Detail

### setWrappedInstance

    public void setWrappedInstance(java.lang.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.

  Parameters:
    `object` - the new target object

### setWrappedInstance

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

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

### getWrappedInstance

    public final java.lang.Object getWrappedInstance()

  Description copied from interface: `BeanWrapper`
  Return the bean instance wrapped by this object, if any.

  Specified by:
    `getWrappedInstance` in interface `BeanWrapper`
  Returns:
    the bean instance, or `null` if none set

### getWrappedClass

    public final java.lang.Class getWrappedClass()

  Description copied from interface: `BeanWrapper`
  Return the type of the wrapped JavaBean object.

  Specified by:
    `getWrappedClass` in interface `BeanWrapper`
  Returns:
    the type of the wrapped bean instance, or `null` if no wrapped object has been set

### getNestedPath

    public final java.lang.String getNestedPath()

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

### getRootInstance

    public final java.lang.Object getRootInstance()

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

  See Also:
    `getNestedPath()`

### getRootClass

    public final java.lang.Class getRootClass()

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

  See Also:
    `getNestedPath()`

### setAutoGrowNestedPaths

    public void setAutoGrowNestedPaths(boolean autoGrowNestedPaths)

  Set whether this BeanWrapper should attempt to "auto-grow" a nested path that contains a null value.

  If "true", a null path location will be populated with a default object value and traversed instead of resulting in a `NullValueInNestedPathException`. Turning this flag on also enables auto-growth of collection elements when accessing an out-of-bounds index.

  Default is "false" on a plain BeanWrapper.

  Specified by:
    `setAutoGrowNestedPaths` in interface `BeanWrapper`

### isAutoGrowNestedPaths

    public boolean isAutoGrowNestedPaths()

  Return whether "auto-growing" of nested paths has been activated.

  Specified by:
    `isAutoGrowNestedPaths` in interface `BeanWrapper`

### setAutoGrowCollectionLimit

    public void setAutoGrowCollectionLimit(int autoGrowCollectionLimit)

  Specify a limit for array and collection auto-growing.

  Default is unlimited on a plain BeanWrapper.

  Specified by:
    `setAutoGrowCollectionLimit` in interface `BeanWrapper`

### getAutoGrowCollectionLimit

    public int getAutoGrowCollectionLimit()

  Return the limit for array and collection auto-growing.

  Specified by:
    `getAutoGrowCollectionLimit` in interface `BeanWrapper`

### setSecurityContext

    public void setSecurityContext(java.security.AccessControlContext acc)

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

### getSecurityContext

    public java.security.AccessControlContext getSecurityContext()

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

### setIntrospectionClass

    protected void setIntrospectionClass(java.lang.Class clazz)

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

  Parameters:
    `clazz` - the class to introspect

### getPropertyDescriptors

    public java.beans.PropertyDescriptor[] getPropertyDescriptors()

  Description copied from interface: `BeanWrapper`
  Obtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).

  Specified by:
    `getPropertyDescriptors` in interface `BeanWrapper`
  Returns:
    the PropertyDescriptors for the wrapped object

### getPropertyDescriptor

    public java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.String propertyName)
                                                        throws BeansException

  Description copied from interface: `BeanWrapper`
  Obtain the property descriptor for a specific property of the wrapped object.

  Specified by:
    `getPropertyDescriptor` in interface `BeanWrapper`
  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
  Throws:
    `InvalidPropertyException` - if there is no such property
    `BeansException`

### getPropertyDescriptorInternal

    protected java.beans.PropertyDescriptor getPropertyDescriptorInternal(java.lang.String propertyName)
                                                                   throws BeansException

  Internal version of `getPropertyDescriptor(java.lang.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

### getPropertyType

    public java.lang.Class getPropertyType(java.lang.String propertyName)
                                    throws BeansException

  Description copied from class: `PropertyEditorRegistrySupport`
  Determine the property type for the given property path.

  Called by `PropertyEditorRegistrySupport.findCustomEditor(java.lang.Class, java.lang.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.

  Specified by:
    `getPropertyType` in interface `PropertyAccessor`
  Overrides:
    `getPropertyType` in class `AbstractPropertyAccessor`
  Parameters:
    `propertyName` - the property path to determine the type for
  Returns:
    the type of the property, or `null` if not determinable
  Throws:
    `InvalidPropertyException` - if there is no such property or if the property isn't readable
    `PropertyAccessException` - if the property was valid but the accessor method failed
    `BeansException`
  See Also:
    `PropertyAccessor.getPropertyType(String)`

### getPropertyTypeDescriptor

    public TypeDescriptor getPropertyTypeDescriptor(java.lang.String propertyName)
                                             throws BeansException

  Description copied from interface: `PropertyAccessor`
  Return a type descriptor for the specified property: preferably from the read method, falling back to the write method.

  Specified by:
    `getPropertyTypeDescriptor` in interface `PropertyAccessor`
  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
  Throws:
    `InvalidPropertyException` - if there is no such property or if the property isn't readable
    `BeansException`

### isReadableProperty

    public boolean isReadableProperty(java.lang.String propertyName)

  Description copied from interface: `PropertyAccessor`
  Determine whether the specified property is readable.

  Returns `false` if the property doesn't exist.

  Specified by:
    `isReadableProperty` in interface `PropertyAccessor`
  Parameters:
    `propertyName` - the property to check (may be a nested path and/or an indexed/mapped property)
  Returns:
    whether the property is readable

### isWritableProperty

    public boolean isWritableProperty(java.lang.String propertyName)

  Description copied from interface: `PropertyAccessor`
  Determine whether the specified property is writable.

  Returns `false` if the property doesn't exist.

  Specified by:
    `isWritableProperty` in interface `PropertyAccessor`
  Parameters:
    `propertyName` - the property to check (may be a nested path and/or an indexed/mapped property)
  Returns:
    whether the property is writable

### convertIfNecessary

    public <T> T convertIfNecessary(java.lang.Object value,
                                    java.lang.Class<T> requiredType,
                                    MethodParameter methodParam)
                         throws TypeMismatchException

  Description copied from interface: `TypeConverter`
  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.

  Specified by:
    `convertIfNecessary` in interface `TypeConverter`
  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
  Throws:
    `TypeMismatchException` - if type conversion failed
  See Also:
    `PropertyEditor.setAsText(String)`, `PropertyEditor.getValue()`

### convertForProperty

    public java.lang.Object convertForProperty(java.lang.Object value,
                                               java.lang.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 `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

### getBeanWrapperForPropertyPath

    protected BeanWrapperImpl getBeanWrapperForPropertyPath(java.lang.String propertyPath)

  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

### newNestedBeanWrapper

    protected BeanWrapperImpl newNestedBeanWrapper(java.lang.Object object,
                                                   java.lang.String nestedPath)

  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

### getPropertyValue

    public java.lang.Object getPropertyValue(java.lang.String propertyName)
                                      throws BeansException

  Description copied from class: `AbstractPropertyAccessor`
  Actually get the value of a property.

  Specified by:
    `getPropertyValue` in interface `PropertyAccessor`
  Specified by:
    `getPropertyValue` in class `AbstractPropertyAccessor`
  Parameters:
    `propertyName` - name of the property to get the value of
  Returns:
    the value of the property
  Throws:
    `InvalidPropertyException` - if there is no such property or if the property isn't readable
    `PropertyAccessException` - if the property was valid but the accessor method failed
    `BeansException`

### setPropertyValue

    public void setPropertyValue(java.lang.String propertyName,
                                 java.lang.Object value)
                          throws BeansException

  Description copied from class: `AbstractPropertyAccessor`
  Actually set a property value.

  Specified by:
    `setPropertyValue` in interface `PropertyAccessor`
  Specified by:
    `setPropertyValue` in class `AbstractPropertyAccessor`
  Parameters:
    `propertyName` - name of the property to set value of
    `value` - the new value
  Throws:
    `InvalidPropertyException` - if there is no such property or if the property isn't writable
    `PropertyAccessException` - if the property was valid but the accessor method failed or a type mismatch occured
    `BeansException`

### setPropertyValue

    public void setPropertyValue(PropertyValue pv)
                          throws BeansException

  Description copied from interface: `PropertyAccessor`
  Set the specified value as current property value.

  Specified by:
    `setPropertyValue` in interface `PropertyAccessor`
  Overrides:
    `setPropertyValue` in class `AbstractPropertyAccessor`
  Parameters:
    `pv` - an object containing the new property value
  Throws:
    `InvalidPropertyException` - if there is no such property or if the property isn't writable
    `PropertyAccessException` - if the property was valid but the accessor method failed or a type mismatch occured
    `BeansException`

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD