public class PropertyEditorRegistrySupport extends java.lang.Object implements PropertyEditorRegistry
PropertyEditorRegistry
interface.
Provides management of default editors and custom editors.
Mainly serves as base class for BeanWrapperImpl
.PropertyEditorSupport.setAsText(java.lang.String)
,
PropertyEditorSupport.setValue(java.lang.Object)
Modifier and Type | Class and Description |
---|---|
private static class |
PropertyEditorRegistrySupport.CustomEditorHolder
Holder for a registered custom editor with property name.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
configValueEditorsActive |
private ConversionService |
conversionService |
private java.util.Map<java.lang.Class<?>,java.beans.PropertyEditor> |
customEditorCache |
private java.util.Map<java.lang.Class<?>,java.beans.PropertyEditor> |
customEditors |
private java.util.Map<java.lang.String,PropertyEditorRegistrySupport.CustomEditorHolder> |
customEditorsForPath |
private java.util.Map<java.lang.Class<?>,java.beans.PropertyEditor> |
defaultEditors |
private boolean |
defaultEditorsActive |
private java.util.Map<java.lang.Class<?>,java.beans.PropertyEditor> |
overriddenDefaultEditors |
private java.util.Set<java.beans.PropertyEditor> |
sharedEditors |
Constructor and Description |
---|
PropertyEditorRegistrySupport() |
Modifier and Type | Method and Description |
---|---|
private void |
addStrippedPropertyPaths(java.util.List<java.lang.String> strippedPaths,
java.lang.String nestedPath,
java.lang.String propertyPath)
Add property paths with all variations of stripped keys and/or indexes.
|
protected void |
copyCustomEditorsTo(PropertyEditorRegistry target,
java.lang.String nestedProperty)
Copy the custom editors registered in this instance to the given target registry.
|
protected void |
copyDefaultEditorsTo(PropertyEditorRegistrySupport target)
Copy the default editors registered in this instance to the given target registry.
|
private void |
createDefaultEditors()
Actually register the default editors for this registry instance.
|
java.beans.PropertyEditor |
findCustomEditor(java.lang.Class<?> requiredType,
java.lang.String propertyPath)
Find a custom property editor for the given type and property.
|
ConversionService |
getConversionService()
Return the associated ConversionService, if any.
|
private java.beans.PropertyEditor |
getCustomEditor(java.lang.Class<?> requiredType)
Get custom editor for the given type.
|
private java.beans.PropertyEditor |
getCustomEditor(java.lang.String propertyName,
java.lang.Class<?> requiredType)
Get custom editor that has been registered for the given property.
|
java.beans.PropertyEditor |
getDefaultEditor(java.lang.Class<?> requiredType)
Retrieve the default editor for the given property type, if any.
|
protected java.lang.Class<?> |
getPropertyType(java.lang.String propertyPath)
Determine the property type for the given property path.
|
protected java.lang.Class<?> |
guessPropertyTypeFromEditors(java.lang.String propertyName)
Guess the property type of the specified property from the registered
custom editors (provided that they were registered for a specific type).
|
boolean |
hasCustomEditorForElement(java.lang.Class<?> elementType,
java.lang.String propertyPath)
Determine whether this registry contains a custom editor
for the specified array/collection element.
|
boolean |
isSharedEditor(java.beans.PropertyEditor propertyEditor)
Check whether the given editor instance is a shared editor, that is,
whether the given editor instance might be used concurrently.
|
void |
overrideDefaultEditor(java.lang.Class<?> requiredType,
java.beans.PropertyEditor propertyEditor)
Override the default editor for the specified type with the given property editor.
|
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 |
registerDefaultEditors()
Activate the default editors for this registry instance,
allowing for lazily registering default editors when needed.
|
void |
registerSharedEditor(java.lang.Class<?> requiredType,
java.beans.PropertyEditor propertyEditor)
Deprecated.
as of Spring 3.0, in favor of PropertyEditorRegistrars or ConversionService usage
|
void |
setConversionService(ConversionService conversionService)
Specify a Spring 3.0 ConversionService to use for converting
property values, as an alternative to JavaBeans PropertyEditors.
|
void |
useConfigValueEditors()
Activate config value editors which are only intended for configuration purposes,
such as
StringArrayPropertyEditor . |
private ConversionService conversionService
private boolean defaultEditorsActive
private boolean configValueEditorsActive
private java.util.Map<java.lang.Class<?>,java.beans.PropertyEditor> defaultEditors
private java.util.Map<java.lang.Class<?>,java.beans.PropertyEditor> overriddenDefaultEditors
private java.util.Map<java.lang.Class<?>,java.beans.PropertyEditor> customEditors
private java.util.Map<java.lang.String,PropertyEditorRegistrySupport.CustomEditorHolder> customEditorsForPath
private java.util.Set<java.beans.PropertyEditor> sharedEditors
private java.util.Map<java.lang.Class<?>,java.beans.PropertyEditor> customEditorCache
public void setConversionService(ConversionService conversionService)
public ConversionService getConversionService()
protected void registerDefaultEditors()
public void useConfigValueEditors()
StringArrayPropertyEditor
.
Those editors are not registered by default simply because they are in
general inappropriate for data binding purposes. Of course, you may register
them individually in any case, through registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)
.
public void overrideDefaultEditor(java.lang.Class<?> requiredType, java.beans.PropertyEditor propertyEditor)
Note that this is different from registering a custom editor in that the editor semantically still is a default editor. A ConversionService will override such a default editor, whereas custom editors usually override the ConversionService.
requiredType
- the type of the propertypropertyEditor
- the editor to registerregisterCustomEditor(Class, PropertyEditor)
public java.beans.PropertyEditor getDefaultEditor(java.lang.Class<?> requiredType)
Lazily registers the default editors, if they are active.
requiredType
- type of the propertynull
if none foundregisterDefaultEditors()
private void createDefaultEditors()
protected void copyDefaultEditorsTo(PropertyEditorRegistrySupport target)
target
- the target registry to copy topublic void registerCustomEditor(java.lang.Class<?> requiredType, java.beans.PropertyEditor propertyEditor)
PropertyEditorRegistry
registerCustomEditor
in interface PropertyEditorRegistry
requiredType
- the type of the propertypropertyEditor
- the editor to registerpublic void registerCustomEditor(java.lang.Class<?> requiredType, java.lang.String propertyPath, java.beans.PropertyEditor propertyEditor)
PropertyEditorRegistry
If the property path denotes an array or Collection property,
the editor will get applied either to the array/Collection itself
(the <code>PropertyEditor</code> 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 the case of a Collection/array, do not register an editor for both the Collection/array and each element on the same property.
For example, if you wanted to register an editor for "items[n].quantity" (for all values n), you would use "items.quantity" as the value of the 'propertyPath' argument to this method.
registerCustomEditor
in interface PropertyEditorRegistry
requiredType
- the type of the property. This may be null
if a property is given but should be specified in any case, in particular in
case of a Collection - making clear whether the editor is supposed to apply
to the entire Collection itself or to each of its entries. So as a general rule:
Do not specify null
here in case of a Collection/array!propertyPath
- the path of the property (name or nested path), or
null
if registering an editor for all properties of the given typepropertyEditor
- editor to register@Deprecated public void registerSharedEditor(java.lang.Class<?> requiredType, java.beans.PropertyEditor propertyEditor)
requiredType
- the type of the propertypropertyEditor
- the shared editor to registerpublic boolean isSharedEditor(java.beans.PropertyEditor propertyEditor)
propertyEditor
- the editor instance to checkpublic java.beans.PropertyEditor findCustomEditor(java.lang.Class<?> requiredType, java.lang.String propertyPath)
PropertyEditorRegistry
findCustomEditor
in interface PropertyEditorRegistry
requiredType
- the type of the property (can be null
if a property
is given but should be specified in any case for consistency checking)propertyPath
- the path of the property (name or nested path), or
null
if looking for an editor for all properties of the given typenull
if nonepublic boolean hasCustomEditorForElement(java.lang.Class<?> elementType, java.lang.String propertyPath)
elementType
- the target type of the element
(can be null
if not known)propertyPath
- the property path (typically of the array/collection;
can be null
if not known)protected java.lang.Class<?> getPropertyType(java.lang.String propertyPath)
Called by 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.
propertyPath
- the property path to determine the type fornull
if not determinablePropertyAccessor.getPropertyType(String)
private java.beans.PropertyEditor getCustomEditor(java.lang.String propertyName, java.lang.Class<?> requiredType)
propertyName
- the property path to look forrequiredType
- the type to look fornull
if none specific for this propertyprivate java.beans.PropertyEditor getCustomEditor(java.lang.Class<?> requiredType)
getAsText
).requiredType
- the type to look fornull
if none found for this typePropertyEditor.getAsText()
protected java.lang.Class<?> guessPropertyTypeFromEditors(java.lang.String propertyName)
propertyName
- the name of the propertynull
if not determinableprotected void copyCustomEditorsTo(PropertyEditorRegistry target, java.lang.String nestedProperty)
target
- the target registry to copy tonestedProperty
- the nested property path of the target registry, if any.
If this is non-null, only editors registered for a path below this nested property
will be copied. If this is null, all editors will be copied.private void addStrippedPropertyPaths(java.util.List<java.lang.String> strippedPaths, java.lang.String nestedPath, java.lang.String propertyPath)
strippedPaths
- the result list to add tonestedPath
- the current nested pathpropertyPath
- the property path to check for keys/indexes to strip