public class DirectFieldAccessor extends AbstractPropertyAccessor
PropertyAccessor
implementation that directly accesses instance fields.
Allows for direct binding to fields instead of going through JavaBean setters.
As of Spring 4.1, this implementation supports nested field traversal.
A DirectFieldAccessor's default for the "extractOldValueForEditor" setting is "true", since a field can always be read without side effects.
AbstractPropertyAccessor.setExtractOldValueForEditor(boolean)
,
BeanWrapper
,
DirectFieldBindingResult
,
DataBinder.initDirectFieldAccess()
Modifier and Type | Class and Description |
---|---|
private class |
DirectFieldAccessor.FieldAccessor
Provide an easy access to a potentially hierarchical value.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,DirectFieldAccessor.FieldAccessor> |
fieldMap |
private java.lang.Object |
rootObject |
typeConverterDelegate
NESTED_PROPERTY_SEPARATOR, NESTED_PROPERTY_SEPARATOR_CHAR, PROPERTY_KEY_PREFIX, PROPERTY_KEY_PREFIX_CHAR, PROPERTY_KEY_SUFFIX, PROPERTY_KEY_SUFFIX_CHAR
Constructor and Description |
---|
DirectFieldAccessor(java.lang.Object rootObject)
Create a new DirectFieldAccessor for the given root object.
|
Modifier and Type | Method and Description |
---|---|
private DirectFieldAccessor.FieldAccessor |
doGetFieldAccessor(java.lang.String propertyPath,
java.lang.Class<?> targetClass) |
private DirectFieldAccessor.FieldAccessor |
getFieldAccessor(java.lang.String propertyPath) |
java.lang.Class<?> |
getPropertyType(java.lang.String propertyPath)
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 instance.
|
java.lang.Object |
getRootInstance()
Return the root object at the top of the path of this instance.
|
private boolean |
hasProperty(java.lang.String propertyPath) |
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.
|
private DirectFieldAccessor.FieldAccessor |
root(java.lang.String canonicalName,
java.lang.String actualName,
java.lang.reflect.Field field)
Create a root
DirectFieldAccessor.FieldAccessor . |
void |
setPropertyValue(java.lang.String propertyName,
java.lang.Object newValue)
Actually set a property value.
|
isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setExtractOldValueForEditor, setPropertyValue, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues
convertIfNecessary, convertIfNecessary, convertIfNecessary
copyCustomEditorsTo, copyDefaultEditorsTo, findCustomEditor, getConversionService, getDefaultEditor, guessPropertyTypeFromEditors, hasCustomEditorForElement, overrideDefaultEditor, registerCustomEditor, registerCustomEditor, registerDefaultEditors, setConversionService, useConfigValueEditors
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getConversionService, setConversionService
findCustomEditor, registerCustomEditor, registerCustomEditor
convertIfNecessary, convertIfNecessary, convertIfNecessary
private final java.lang.Object rootObject
private final java.util.Map<java.lang.String,DirectFieldAccessor.FieldAccessor> fieldMap
public DirectFieldAccessor(java.lang.Object rootObject)
rootObject
- the root object to accesspublic final java.lang.Object getRootInstance()
public final java.lang.Class<?> getRootClass()
public boolean isReadableProperty(java.lang.String propertyName) throws BeansException
PropertyAccessor
Returns false
if the property doesn't exist.
propertyName
- the property to check
(may be a nested path and/or an indexed/mapped property)BeansException
public boolean isWritableProperty(java.lang.String propertyName) throws BeansException
PropertyAccessor
Returns false
if the property doesn't exist.
propertyName
- the property to check
(may be a nested path and/or an indexed/mapped property)BeansException
public java.lang.Class<?> getPropertyType(java.lang.String propertyPath) throws BeansException
PropertyEditorRegistrySupport
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.
getPropertyType
in interface PropertyAccessor
getPropertyType
in class AbstractPropertyAccessor
propertyPath
- the property path to determine the type fornull
if not determinableInvalidPropertyException
- if there is no such property or
if the property isn't readablePropertyAccessException
- if the property was valid but the
accessor method failedBeansException
PropertyAccessor.getPropertyType(String)
public TypeDescriptor getPropertyTypeDescriptor(java.lang.String propertyName) throws BeansException
PropertyAccessor
propertyName
- the property to check
(may be a nested path and/or an indexed/mapped property)null
if not determinableInvalidPropertyException
- if there is no such property or
if the property isn't readableBeansException
public java.lang.Object getPropertyValue(java.lang.String propertyName) throws BeansException
AbstractPropertyAccessor
getPropertyValue
in interface PropertyAccessor
getPropertyValue
in class AbstractPropertyAccessor
propertyName
- name of the property to get the value ofInvalidPropertyException
- if there is no such property or
if the property isn't readablePropertyAccessException
- if the property was valid but the
accessor method failedBeansException
public void setPropertyValue(java.lang.String propertyName, java.lang.Object newValue) throws BeansException
AbstractPropertyAccessor
setPropertyValue
in interface PropertyAccessor
setPropertyValue
in class AbstractPropertyAccessor
propertyName
- name of the property to set value ofnewValue
- the new valueInvalidPropertyException
- if there is no such property or
if the property isn't writablePropertyAccessException
- if the property was valid but the
accessor method failed or a type mismatch occuredBeansException
private boolean hasProperty(java.lang.String propertyPath)
private DirectFieldAccessor.FieldAccessor getFieldAccessor(java.lang.String propertyPath)
private DirectFieldAccessor.FieldAccessor doGetFieldAccessor(java.lang.String propertyPath, java.lang.Class<?> targetClass)
private DirectFieldAccessor.FieldAccessor root(java.lang.String canonicalName, java.lang.String actualName, java.lang.reflect.Field field)
DirectFieldAccessor.FieldAccessor
.canonicalName
- the full expression for the field to accessactualName
- the name of the local (root) propertyfield
- the field accessing the property