org.springframework.beans
Interface BeanWrapper

All Superinterfaces:
PropertyAccessor
All Known Implementing Classes:
BeanWrapperImpl

public interface BeanWrapper
extends PropertyAccessor

The central interface of Spring's low-level JavaBeans infrastructure; the default implementation is BeanWrapperImpl. Typically not directly used by application code but rather implicitly via a BeanFactory or a DataBinder.

To be implemented by classes that can manipulate Java beans. Implementing classes have the ability to get and set property values (individually or in bulk), get property descriptors and query the readability and writability of properties.

This interface supports nested properties enabling the setting of properties on subproperties to an unlimited depth.

If a property update causes an exception, a PropertyVetoException will be thrown. Bulk updates continue after exceptions are encountered, throwing an exception wrapping all exceptions encountered during the update.

BeanWrapper implementations can be used repeatedly, with their "target" or wrapped object changed.

Since:
13 April 2001
Author:
Rod Johnson
See Also:
BeanWrapperImpl, BeanFactory, DataBinder

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
 
Method Summary
 PropertyEditor findCustomEditor(Class requiredType, String propertyPath)
          Find a custom property editor for the given type and property.
 PropertyDescriptor getPropertyDescriptor(String propertyName)
          Get the property descriptor for a particular property.
 PropertyDescriptor[] getPropertyDescriptors()
          Get the PropertyDescriptors identified on this object (standard JavaBeans introspection).
 Class getPropertyType(String propertyName)
          Determine the property type for a particular property, either checking the property descriptor or checking the value in case of an indexed or mapped element.
 Class getWrappedClass()
          Convenience method to return the class of the wrapped object.
 Object getWrappedInstance()
          Return the bean wrapped by this object (cannot be null).
 boolean isReadableProperty(String propertyName)
          Return whether this property is readable.
 boolean isWritableProperty(String propertyName)
          Return whether this property is writable.
 void registerCustomEditor(Class requiredType, PropertyEditor propertyEditor)
          Register the given custom property editor for all properties of the given type.
 void registerCustomEditor(Class requiredType, String propertyPath, PropertyEditor propertyEditor)
          Register the given custom property editor for the given type and property, or for all properties of the given type.
 void setWrappedInstance(Object obj)
          Change the wrapped object.
 
Methods inherited from interface org.springframework.beans.PropertyAccessor
getPropertyValue, setPropertyValue, setPropertyValue, setPropertyValues, setPropertyValues, setPropertyValues
 

Method Detail

setWrappedInstance

void setWrappedInstance(Object obj)
Change the wrapped object. Implementations are required to allow the type of the wrapped object to change.

Parameters:
obj - wrapped object that we are manipulating

getWrappedInstance

Object getWrappedInstance()
Return the bean wrapped by this object (cannot be null).

Returns:
the bean wrapped by this object

getWrappedClass

Class getWrappedClass()
Convenience method to return the class of the wrapped object.

Returns:
the class of the wrapped object

registerCustomEditor

void registerCustomEditor(Class requiredType,
                          PropertyEditor propertyEditor)
Register the given custom property editor for all properties of the given type.

Parameters:
requiredType - type of the property
propertyEditor - editor to register

registerCustomEditor

void registerCustomEditor(Class requiredType,
                          String propertyPath,
                          PropertyEditor propertyEditor)
Register the given custom property editor for the given type and property, or for all properties of the given type.

If the property path denotes an array or Collection property, the editor will get applied either to the array/Collection itself (the PropertyEditor has to create an array or Collection value) or to each element (the PropertyEditor has to create the element type), depending on the specified required type.

Note: Only one single registered custom editor per property path is supported. In case of a Collection/array, do not register an editor for both the Collection/array and each element on the same property.

Parameters:
requiredType - type of the property (can be null if a property is given but should be specified in any case for consistency checking)
propertyPath - path of the property (name or nested path), or null if registering an editor for all properties of the given type
propertyEditor - editor to register

findCustomEditor

PropertyEditor findCustomEditor(Class requiredType,
                                String propertyPath)
Find a custom property editor for the given type and property.

Parameters:
requiredType - type of the property (can be null if a property is given but should be specified in any case for consistency checking)
propertyPath - path of the property (name or nested path), or null if looking for an editor for all properties of the given type
Returns:
the registered editor, or null if none

getPropertyDescriptors

PropertyDescriptor[] getPropertyDescriptors()
                                            throws BeansException
Get the PropertyDescriptors identified on this object (standard JavaBeans introspection).

Returns:
the PropertyDescriptors identified on this object
Throws:
BeansException

getPropertyDescriptor

PropertyDescriptor getPropertyDescriptor(String propertyName)
                                         throws BeansException
Get the property descriptor for a particular property.

Parameters:
propertyName - property to check status for
Returns:
the property descriptor for the particular property
Throws:
InvalidPropertyException - if there is no such property
BeansException

getPropertyType

Class getPropertyType(String propertyName)
                      throws BeansException
Determine the property type for a particular property, either checking the property descriptor or checking the value in case of an indexed or mapped element.

Parameters:
propertyName - property to check status for
Returns:
the property type for the particular property, or null if not determinable (can only happen with an indexed or mapped element)
Throws:
InvalidPropertyException - if there is no such property
BeansException

isReadableProperty

boolean isReadableProperty(String propertyName)
                           throws BeansException
Return whether this property is readable. Returns false if the property doesn't exist.

Parameters:
propertyName - property to check status for
Returns:
whether this property is readable
Throws:
BeansException

isWritableProperty

boolean isWritableProperty(String propertyName)
                           throws BeansException
Return whether this property is writable. Returns false if the property doesn't exist.

Parameters:
propertyName - property to check status for
Returns:
whether this property is writable
Throws:
BeansException


Copyright (c) 2002-2005 The Spring Framework Project.