|
The Spring Framework | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.beans.PropertyEditorRegistrySupport
org.springframework.beans.AbstractPropertyAccessor
org.springframework.beans.BeanWrapperImpl
public class BeanWrapperImpl
Default BeanWrapper implementation that should be sufficient
for all typical use cases. Caches introspection results for efficiency.
Note: This class never tries to load a class by name, as this can pose class loading problems in J2EE applications with multiple deployment modules. The caller is responsible for loading a target class.
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.
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(Class clazz)
Create new BeanWrapperImpl, wrapping a new instance of the specified class. |
|
BeanWrapperImpl(Object object)
Create new BeanWrapperImpl for the given object. |
|
BeanWrapperImpl(Object object,
String nestedPath,
Object rootObject)
Create new BeanWrapperImpl for the given object, registering a nested path that the object is in. |
|
| Method Summary | |
|---|---|
Object |
convertIfNecessary(Object value,
Class requiredType)
Convert the value to the required type (if necessary from a String). |
Object |
convertIfNecessary(Object value,
Class requiredType,
MethodParameter methodParam)
Convert the value to the required type (if necessary from a String). |
Object |
doTypeConversionIfNecessary(Object value,
Class requiredType)
Deprecated. in favor of convertIfNecessary |
protected BeanWrapperImpl |
getBeanWrapperForPropertyPath(String propertyPath)
Recursively navigate to return a BeanWrapper for the nested property path. |
String |
getNestedPath()
Return the nested path of the object wrapped by this BeanWrapper. |
PropertyDescriptor |
getPropertyDescriptor(String propertyName)
Get the property descriptor for a particular property. |
protected PropertyDescriptor |
getPropertyDescriptorInternal(String propertyName)
Internal version of getPropertyDescriptor: Returns null if not found rather than throwing an exception. |
PropertyDescriptor[] |
getPropertyDescriptors()
Get the PropertyDescriptors identified on this object (standard JavaBeans introspection). |
Class |
getPropertyType(String propertyName)
Determine the property type for the given property path. |
Object |
getPropertyValue(String propertyName)
Actually get the value of a property. |
Class |
getRootClass()
Return the class of the root object at the top of the path of this BeanWrapper. |
Object |
getRootInstance()
Return the root object at the top of the path of this BeanWrapper. |
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. |
protected BeanWrapperImpl |
newNestedBeanWrapper(Object object,
String nestedPath)
Create a new nested BeanWrapper instance. |
protected void |
setIntrospectionClass(Class clazz)
Set the class to introspect. |
void |
setPropertyValue(String propertyName,
Object value)
Actually set a property value. |
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()
|
| Methods inherited from class org.springframework.beans.AbstractPropertyAccessor |
|---|
isExtractOldValueForEditor, setExtractOldValueForEditor, setPropertyValue, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues |
| Methods inherited from class org.springframework.beans.PropertyEditorRegistrySupport |
|---|
copyCustomEditorsTo, copyDefaultEditorsTo, findCustomEditor, getDefaultEditor, guessPropertyTypeFromEditors, registerCustomEditor, registerCustomEditor, registerDefaultEditors |
| 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 |
|---|
isExtractOldValueForEditor, setExtractOldValueForEditor |
| Methods inherited from interface org.springframework.beans.PropertyAccessor |
|---|
setPropertyValue, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues |
| Methods inherited from interface org.springframework.beans.PropertyEditorRegistry |
|---|
findCustomEditor, registerCustomEditor, registerCustomEditor |
| Constructor Detail |
|---|
public BeanWrapperImpl()
setWrappedInstance(java.lang.Object)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)public BeanWrapperImpl(Object object)
object - object wrapped by this BeanWrapperpublic BeanWrapperImpl(Class clazz)
clazz - class to instantiate and wrap
public BeanWrapperImpl(Object object,
String nestedPath,
Object rootObject)
object - object wrapped by this BeanWrappernestedPath - the nested path of the objectrootObject - the root object at the top of the path| Method Detail |
|---|
public void setWrappedInstance(Object object)
setWrappedInstance in interface BeanWrapperobject - new target
public void setWrappedInstance(Object object,
String nestedPath,
Object rootObject)
object - new targetnestedPath - the nested path of the objectrootObject - the root object at the top of the pathpublic Object getWrappedInstance()
BeanWrappernull).
getWrappedInstance in interface BeanWrapperpublic Class getWrappedClass()
BeanWrapper
getWrappedClass in interface BeanWrapperpublic String getNestedPath()
public Object getRootInstance()
getNestedPath()public Class getRootClass()
getNestedPath()protected void setIntrospectionClass(Class clazz)
clazz - the class to introspectpublic PropertyDescriptor[] getPropertyDescriptors()
BeanWrapper
getPropertyDescriptors in interface BeanWrapper
public PropertyDescriptor getPropertyDescriptor(String propertyName)
throws BeansException
BeanWrapper
getPropertyDescriptor in interface BeanWrapperpropertyName - property to check status for
InvalidPropertyException - if there is no such property
BeansException
protected PropertyDescriptor getPropertyDescriptorInternal(String propertyName)
throws BeansException
null if not found rather than throwing an exception.
BeansExceptionpublic boolean isReadableProperty(String propertyName)
PropertyAccessor
isReadableProperty in interface PropertyAccessorpropertyName - property to check status for
public boolean isWritableProperty(String propertyName)
PropertyAccessor
isWritableProperty in interface PropertyAccessorpropertyName - property to check status for
public Class getPropertyType(String propertyName)
throws BeansException
PropertyEditorRegistrySupportfindCustomEditor if no required type has been specified,
to be able to find a type-specific editor even if just given a property path.
Default implementation always returns null.
BeanWrapperImpl overrides this with the standard getPropertyType
method as defined by the BeanWrapper interface.
getPropertyType in interface PropertyAccessorgetPropertyType in class AbstractPropertyAccessorpropertyName - the property path to determine the type for
null if not determinable
BeansExceptionPropertyAccessor.getPropertyType(String)
public Object doTypeConversionIfNecessary(Object value,
Class requiredType)
throws TypeMismatchException
convertIfNecessary
TypeMismatchExceptionconvertIfNecessary(Object, Class)
public Object convertIfNecessary(Object value,
Class requiredType)
throws TypeMismatchException
TypeConverterConversions 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.
convertIfNecessary in interface TypeConvertervalue - the value to convertrequiredType - the type we must convert to
(or null if not known, for example in case of a collection element)
TypeMismatchException - if type conversion failedPropertyEditor.setAsText(String),
PropertyEditor.getValue()
public Object convertIfNecessary(Object value,
Class requiredType,
MethodParameter methodParam)
throws TypeMismatchException
TypeConverterConversions 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.
convertIfNecessary in interface TypeConvertervalue - the value to convertrequiredType - 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)
TypeMismatchException - if type conversion failedPropertyEditor.setAsText(String),
PropertyEditor.getValue()
protected BeanWrapperImpl getBeanWrapperForPropertyPath(String propertyPath)
throws BeansException
propertyPath - property property path, which may be nested
BeansException
protected BeanWrapperImpl newNestedBeanWrapper(Object object,
String nestedPath)
Default implementation creates a BeanWrapperImpl instance. Can be overridden in subclasses to create a BeanWrapperImpl subclass.
object - object wrapped by this BeanWrappernestedPath - the nested path of the object
public Object getPropertyValue(String propertyName)
throws BeansException
AbstractPropertyAccessor
getPropertyValue in interface PropertyAccessorgetPropertyValue in class AbstractPropertyAccessorpropertyName - name of the property to get the value of
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
public void setPropertyValue(String propertyName,
Object value)
throws BeansException
AbstractPropertyAccessor
setPropertyValue in interface PropertyAccessorsetPropertyValue in class AbstractPropertyAccessorpropertyName - name of the property to set value ofvalue - the new value
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
BeansExceptionpublic String toString()
toString in class Object
|
The Spring Framework | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||