|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.beans.BeanWrapperImpl
Default implementation of the BeanWrapper interface that should be sufficient for all normal uses. 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 all default property editors (not the custom ones) in the org.springframework.beans.propertyeditors package. Applications can either use a standard PropertyEditorManager to register a custom editor before using a BeanWrapperImpl instance, or call the instance's registerCustomEditor method to register an editor for the particular instance.
BeanWrapperImpl will convert List and array values to the corresponding target arrays, if necessary. Custom property editors that deal with Lists or arrays can be written against a comma delimited String as String arrays are converted in such a format if the array itself is not assignable.
registerCustomEditor(java.lang.Class, java.beans.PropertyEditor)
,
PropertyEditorManager
,
ClassEditor
,
FileEditor
,
LocaleEditor
,
PropertiesEditor
,
StringArrayPropertyEditor
,
URLEditor
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(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)
Create new BeanWrapperImpl for the given object, registering a nested path that the object is in. |
Method Summary | |
java.lang.Object |
doTypeConversionIfNecessary(java.lang.Object newValue,
java.lang.Class requiredType)
Convert the value to the required type (if necessary from a String). |
protected java.lang.Object |
doTypeConversionIfNecessary(java.lang.String propertyName,
java.lang.String fullPropertyName,
java.lang.Object oldValue,
java.lang.Object newValue,
java.lang.Class requiredType)
Convert the value to the required type (if necessary from a String), for the specified property. |
java.beans.PropertyEditor |
findCustomEditor(java.lang.Class requiredType,
java.lang.String propertyPath)
Find a custom property editor for the given type and property. |
protected BeanWrapperImpl |
getBeanWrapperForPropertyPath(java.lang.String propertyPath)
Recursively navigate to return a BeanWrapper for the nested property path. |
java.beans.PropertyDescriptor |
getPropertyDescriptor(java.lang.String propertyName)
Get the property descriptor for a particular property. |
protected java.beans.PropertyDescriptor |
getPropertyDescriptorInternal(java.lang.String propertyName)
Internal version of getPropertyDescriptor: Returns null if not found rather than throwing an exception. |
java.beans.PropertyDescriptor[] |
getPropertyDescriptors()
Get the PropertyDescriptors identified on this object (standard JavaBeans introspection). |
java.lang.Class |
getPropertyType(java.lang.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. |
java.lang.Object |
getPropertyValue(java.lang.String propertyName)
Get the value of a property. |
protected java.lang.Object |
getPropertyValue(java.lang.String propertyName,
java.lang.String actualName,
java.lang.String key)
|
java.lang.Class |
getWrappedClass()
Convenience method to return the class of the wrapped object. |
java.lang.Object |
getWrappedInstance()
Return the bean wrapped by this object (cannot be null). |
boolean |
isReadableProperty(java.lang.String propertyName)
Return whether this property is readable. |
boolean |
isWritableProperty(java.lang.String propertyName)
Return whether this property is writable. |
void |
registerCustomEditor(java.lang.Class requiredType,
java.beans.PropertyEditor propertyEditor)
Register the given custom property editor for all properties of the given type. |
void |
registerCustomEditor(java.lang.Class requiredType,
java.lang.String propertyPath,
java.beans.PropertyEditor propertyEditor)
Register the given custom property editor for the given type and property, or for all properties of the given type. |
protected void |
setIntrospectionClass(java.lang.Class clazz)
Set the class to introspect. |
void |
setPropertyValue(PropertyValue pv)
Update a property value. |
void |
setPropertyValue(java.lang.String propertyName,
java.lang.Object value)
Set a property value. |
protected void |
setPropertyValue(java.lang.String propertyName,
java.lang.String actualName,
java.lang.String key,
java.lang.Object value)
|
void |
setPropertyValues(java.util.Map map)
Bulk update from a Map. |
void |
setPropertyValues(PropertyValues pvs)
The preferred way to perform a bulk update. |
void |
setPropertyValues(PropertyValues propertyValues,
boolean ignoreUnknown)
Perform a bulk update with full control over behavior. |
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)
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()
This method is expensive! |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public BeanWrapperImpl()
setWrappedInstance(java.lang.Object)
public BeanWrapperImpl(java.lang.Object object)
object
- object wrapped by this BeanWrapperpublic BeanWrapperImpl(java.lang.Class clazz)
clazz
- class to instantiate and wrappublic BeanWrapperImpl(java.lang.Object object, java.lang.String nestedPath)
object
- object wrapped by this BeanWrapper.nestedPath
- the nested path of the objectMethod Detail |
public void setWrappedInstance(java.lang.Object object)
setWrappedInstance
in interface BeanWrapper
object
- new targetpublic void setWrappedInstance(java.lang.Object object, java.lang.String nestedPath)
object
- new targetnestedPath
- the nested path of the objectpublic java.lang.Object getWrappedInstance()
BeanWrapper
getWrappedInstance
in interface BeanWrapper
public java.lang.Class getWrappedClass()
BeanWrapper
getWrappedClass
in interface BeanWrapper
protected void setIntrospectionClass(java.lang.Class clazz)
clazz
- the class to introspectpublic void registerCustomEditor(java.lang.Class requiredType, java.beans.PropertyEditor propertyEditor)
BeanWrapper
registerCustomEditor
in interface BeanWrapper
requiredType
- type of the propertypropertyEditor
- editor to registerpublic void registerCustomEditor(java.lang.Class requiredType, java.lang.String propertyPath, java.beans.PropertyEditor propertyEditor)
BeanWrapper
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.
registerCustomEditor
in interface BeanWrapper
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 typepropertyEditor
- editor to registerpublic java.beans.PropertyEditor findCustomEditor(java.lang.Class requiredType, java.lang.String propertyPath)
BeanWrapper
findCustomEditor
in interface BeanWrapper
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
protected BeanWrapperImpl getBeanWrapperForPropertyPath(java.lang.String propertyPath) throws BeansException
propertyPath
- property property path, which may be nested
BeansException
public java.lang.Object getPropertyValue(java.lang.String propertyName) throws BeansException
PropertyAccessor
getPropertyValue
in interface PropertyAccessor
propertyName
- name of the property to get the value of
BeansException
protected java.lang.Object getPropertyValue(java.lang.String propertyName, java.lang.String actualName, java.lang.String key) throws BeansException
BeansException
public void setPropertyValue(java.lang.String propertyName, java.lang.Object value) throws BeansException
PropertyAccessor
setPropertyValue
in interface PropertyAccessor
propertyName
- name of the property to set value ofvalue
- the new value
BeansException
protected void setPropertyValue(java.lang.String propertyName, java.lang.String actualName, java.lang.String key, java.lang.Object value) throws BeansException
BeansException
public void setPropertyValue(PropertyValue pv) throws BeansException
PropertyAccessor
setPropertyValue
in interface PropertyAccessor
pv
- object containing new property value
BeansException
public void setPropertyValues(java.util.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 bulk 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 stay changed.
Does not allow unknown fields. Equivalent to setPropertyValues(pvs, false).
setPropertyValues
in interface PropertyAccessor
pvs
- PropertyValues to set on the target object
BeansException
PropertyAccessor.setPropertyValues(PropertyValues, boolean)
public void setPropertyValues(PropertyValues propertyValues, boolean ignoreUnknown) throws BeansException
PropertyAccessor
Note that performing a bulk 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 stay changed.
Does not allow unknown fields.
setPropertyValues
in interface PropertyAccessor
propertyValues
- PropertyValues to set on the target objectignoreUnknown
- should we ignore unknown values (not found in the bean)
BeansException
public java.lang.Object doTypeConversionIfNecessary(java.lang.Object newValue, java.lang.Class requiredType) throws BeansException
newValue
- proposed change value.requiredType
- type we must convert to
BeansException
- if there is an internal errorprotected java.lang.Object doTypeConversionIfNecessary(java.lang.String propertyName, java.lang.String fullPropertyName, java.lang.Object oldValue, java.lang.Object newValue, java.lang.Class requiredType) throws BeansException
propertyName
- name of the propertyoldValue
- previous value, if available (may be null)newValue
- proposed change value.requiredType
- type we must convert to
BeansException
- if there is an internal errorpublic java.beans.PropertyDescriptor[] getPropertyDescriptors()
BeanWrapper
getPropertyDescriptors
in interface BeanWrapper
public java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.String propertyName) throws BeansException
BeanWrapper
getPropertyDescriptor
in interface BeanWrapper
propertyName
- property to check status for
BeansException
protected java.beans.PropertyDescriptor getPropertyDescriptorInternal(java.lang.String propertyName) throws BeansException
BeansException
public java.lang.Class getPropertyType(java.lang.String propertyName) throws BeansException
BeanWrapper
getPropertyType
in interface BeanWrapper
propertyName
- property to check status for
BeansException
public boolean isReadableProperty(java.lang.String propertyName)
BeanWrapper
isReadableProperty
in interface BeanWrapper
propertyName
- property to check status for
public boolean isWritableProperty(java.lang.String propertyName)
BeanWrapper
isWritableProperty
in interface BeanWrapper
propertyName
- property to check status for
public java.lang.String toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |