|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.beans.PropertyEditorRegistrySupport 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: 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)
,
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 |
doTypeConversionIfNecessary(Object newValue,
Class requiredType)
Convert the value to the required type (if necessary from a String). |
protected Object |
doTypeConversionIfNecessary(String propertyName,
String fullPropertyName,
Object oldValue,
Object newValue,
Class requiredType)
Convert the value to the required type (if necessary from a String), for the specified property. |
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)
Obtain the property descriptor for a specific property of the wrapped object. |
protected PropertyDescriptor |
getPropertyDescriptorInternal(String propertyName)
Internal version of getPropertyDescriptor(java.lang.String) :
Returns null if not found rather than throwing an exception. |
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. |
Object |
getPropertyValue(String propertyName)
Get the current value of the specified 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()
Return the type of the wrapped JavaBean object. |
Object |
getWrappedInstance()
Return the bean instance wrapped by this object, if any. |
boolean |
isExtractOldValueForEditor()
Return whether to extract the old property value when applying a property editor to a new value for a property. |
boolean |
isReadableProperty(String propertyName)
Determine whether the specified property is readable. |
boolean |
isWritableProperty(String propertyName)
Determine whether the specified property is writable. |
protected BeanWrapperImpl |
newNestedBeanWrapper(Object object,
String nestedPath)
Create a new nested BeanWrapper instance. |
void |
setExtractOldValueForEditor(boolean extractOldValueForEditor)
Set whether to extract the old property value when applying a property editor to a new value for a property. |
protected void |
setIntrospectionClass(Class clazz)
Set the class to introspect. |
void |
setPropertyValue(PropertyValue pv)
Set the specified value as current property value. |
void |
setPropertyValue(String propertyName,
Object value)
Set the specified value as current property value. |
void |
setPropertyValues(Map map)
Bulk update from a Map. |
void |
setPropertyValues(PropertyValues pvs)
The preferred way to perform a batch update. |
void |
setPropertyValues(PropertyValues propertyValues,
boolean ignoreUnknown)
Perform a batch update with full control over behavior. |
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.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.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 wrappublic 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 pathMethod Detail |
---|
public void setWrappedInstance(Object object)
setWrappedInstance
in interface BeanWrapper
object
- the new target objectpublic void setWrappedInstance(Object object, String nestedPath, Object rootObject)
object
- the new target objectnestedPath
- the nested path of the objectrootObject
- the root object at the top of the pathpublic Object getWrappedInstance()
BeanWrapper
getWrappedInstance
in interface BeanWrapper
null
if none setpublic Class getWrappedClass()
BeanWrapper
getWrappedClass
in interface BeanWrapper
null
if no wrapped object has been setpublic String getNestedPath()
public Object getRootInstance()
getNestedPath()
public Class getRootClass()
getNestedPath()
protected void setIntrospectionClass(Class clazz)
clazz
- the class to introspectpublic void setExtractOldValueForEditor(boolean extractOldValueForEditor)
BeanWrapper
Default is "false", avoiding side effects caused by getters. Turn this to "true" to expose previous property values to custom editors.
setExtractOldValueForEditor
in interface BeanWrapper
public boolean isExtractOldValueForEditor()
BeanWrapper
isExtractOldValueForEditor
in interface BeanWrapper
public PropertyDescriptor[] getPropertyDescriptors()
BeanWrapper
getPropertyDescriptors
in interface BeanWrapper
public PropertyDescriptor getPropertyDescriptor(String propertyName) throws BeansException
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
BeansException
protected PropertyDescriptor getPropertyDescriptorInternal(String propertyName) throws BeansException
getPropertyDescriptor(java.lang.String)
:
Returns null
if not found rather than throwing an exception.
propertyName
- the property to obtain the descriptor for
null
if not found
BeansException
- in case of introspection failurepublic Class getPropertyType(String propertyName) throws BeansException
PropertyEditorRegistrySupport
findCustomEditor
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 BeanWrapper
getPropertyType
in class PropertyEditorRegistrySupport
propertyName
- the property path to determine the type for
null
if not determinable
InvalidPropertyException
- if there is no such property or
if the property isn't readable
BeansException
BeanWrapper.getPropertyType(String)
public boolean isReadableProperty(String propertyName)
BeanWrapper
Returns false
if the property doesn't exist.
isReadableProperty
in interface BeanWrapper
propertyName
- property to check status for
(may be a nested path and/or an indexed/mapped property)
public boolean isWritableProperty(String propertyName)
BeanWrapper
Returns false
if the property doesn't exist.
isWritableProperty
in interface BeanWrapper
propertyName
- property to check status for
(may be a nested path and/or an indexed/mapped property)
protected BeanWrapperImpl getBeanWrapperForPropertyPath(String propertyPath)
propertyPath
- property property path, which may be nested
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
PropertyAccessor
getPropertyValue
in interface PropertyAccessor
propertyName
- the name of the property to get the value of
(may be a nested path and/or an indexed/mapped property)
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
PropertyAccessor
setPropertyValue
in interface PropertyAccessor
propertyName
- the name of the property to set the value of
(may be a nested path and/or an indexed/mapped property)value
- 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
BeansException
public void setPropertyValue(PropertyValue pv) throws BeansException
PropertyAccessor
setPropertyValue
in interface PropertyAccessor
pv
- an object containing the new property 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
BeansException
public void setPropertyValues(Map map) throws BeansException
setPropertyValues
in interface PropertyAccessor
map
- map containing properties to set, as name-value pairs.
The map may include nested properties.
BeansException
- if there's a fatal, low-level exceptionpublic void setPropertyValues(PropertyValues pvs) throws BeansException
PropertyAccessor
Note that performing a batch update differs from performing a single update,
in that an implementation of this class will continue to update properties
if a recoverable error (such as a type mismatch, but not an
invalid field name or the like) is encountered, throwing a
PropertyAccessExceptionsException
containing all the individual errors.
This exception can be examined later to see all binding errors.
Properties that were successfully updated remain changed.
Does not allow unknown fields or invalid fields.
setPropertyValues
in interface PropertyAccessor
pvs
- PropertyValues to set on the target object
InvalidPropertyException
- if there is no such property or
if the property isn't writable
PropertyAccessExceptionsException
- if one or more PropertyAccessExceptions
occured for specific properties during the batch update. This exception bundles
all individual PropertyAccessExceptions. All other properties will have been
successfully updated.
BeansException
PropertyAccessor.setPropertyValues(PropertyValues, boolean)
public void setPropertyValues(PropertyValues propertyValues, boolean ignoreUnknown) throws BeansException
PropertyAccessor
Note that performing a batch update differs from performing a single update,
in that an implementation of this class will continue to update properties
if a recoverable error (such as a type mismatch, but not an
invalid field name or the like) is encountered, throwing a
PropertyAccessExceptionsException
containing all the individual errors.
This exception can be examined later to see all binding errors.
Properties that were successfully updated remain changed.
setPropertyValues
in interface PropertyAccessor
propertyValues
- PropertyValues to set on the target objectignoreUnknown
- should we ignore unknown properties (not found in the bean)
InvalidPropertyException
- if there is no such property or
if the property isn't writable
PropertyAccessExceptionsException
- if one or more PropertyAccessExceptions
occured for specific properties during the batch update. This exception bundles
all individual PropertyAccessExceptions. All other properties will have been
successfully updated.
BeansException
public Object doTypeConversionIfNecessary(Object newValue, Class requiredType) throws TypeMismatchException
Conversions from String to any type 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 by BeanWrapperImpl.
newValue
- proposed change valuerequiredType
- the type we must convert to
TypeMismatchException
- if type conversion failedPropertyEditor.setAsText(String)
,
PropertyEditor.getValue()
protected Object doTypeConversionIfNecessary(String propertyName, String fullPropertyName, Object oldValue, Object newValue, Class requiredType) throws TypeMismatchException
propertyName
- name of the propertyoldValue
- previous value, if available (may be null
)newValue
- proposed change valuerequiredType
- the type we must convert to
(or null
if not known, for example in case of a collection element)
TypeMismatchException
- if type conversion failedpublic String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |