class TypeConverterDelegate
extends java.lang.Object
Works on a given PropertyEditorRegistrySupport
instance.
Used as a delegate by BeanWrapperImpl
and SimpleTypeConverter
.
BeanWrapperImpl
,
SimpleTypeConverter
Modifier and Type | Field and Description |
---|---|
private static Log |
logger |
private PropertyEditorRegistrySupport |
propertyEditorRegistry |
private java.lang.Object |
targetObject |
Constructor and Description |
---|
TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry)
Create a new TypeConverterDelegate for the given editor registry.
|
TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry,
java.lang.Object targetObject)
Create a new TypeConverterDelegate for the given editor registry and bean instance.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.Object |
attemptToConvertStringToEnum(java.lang.Class<?> requiredType,
java.lang.String trimmedValue,
java.lang.Object currentConvertedValue) |
private java.lang.String |
buildIndexedPropertyName(java.lang.String propertyName,
int index) |
private java.lang.String |
buildKeyedPropertyName(java.lang.String propertyName,
java.lang.Object key) |
private boolean |
canCreateCopy(java.lang.Class<?> requiredType) |
<T> T |
convertIfNecessary(java.lang.Object newValue,
java.lang.Class<T> requiredType,
java.lang.reflect.Field field)
Convert the value to the specified required type.
|
<T> T |
convertIfNecessary(java.lang.Object newValue,
java.lang.Class<T> requiredType,
MethodParameter methodParam)
Convert the value to the specified required type.
|
<T> T |
convertIfNecessary(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue,
java.lang.Class<T> requiredType)
Convert the value to the required type for the specified property.
|
<T> T |
convertIfNecessary(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue,
java.lang.Class<T> requiredType,
TypeDescriptor typeDescriptor)
Convert the value to the required type (if necessary from a String),
for the specified property.
|
private java.lang.Object |
convertToTypedArray(java.lang.Object input,
java.lang.String propertyName,
java.lang.Class<?> componentType) |
private java.util.Collection<?> |
convertToTypedCollection(java.util.Collection<?> original,
java.lang.String propertyName,
java.lang.Class<?> requiredType,
TypeDescriptor typeDescriptor) |
private java.util.Map<?,?> |
convertToTypedMap(java.util.Map<?,?> original,
java.lang.String propertyName,
java.lang.Class<?> requiredType,
TypeDescriptor typeDescriptor) |
private java.lang.Object |
doConvertTextValue(java.lang.Object oldValue,
java.lang.String newTextValue,
java.beans.PropertyEditor editor)
Convert the given text value using the given property editor.
|
private java.lang.Object |
doConvertValue(java.lang.Object oldValue,
java.lang.Object newValue,
java.lang.Class<?> requiredType,
java.beans.PropertyEditor editor)
Convert the value to the required type (if necessary from a String),
using the given property editor.
|
private java.beans.PropertyEditor |
findDefaultEditor(java.lang.Class<?> requiredType)
Find a default editor for the given type.
|
private static final Log logger
private final PropertyEditorRegistrySupport propertyEditorRegistry
@Nullable private final java.lang.Object targetObject
public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry)
propertyEditorRegistry
- the editor registry to usepublic TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry, @Nullable java.lang.Object targetObject)
propertyEditorRegistry
- the editor registry to usetargetObject
- the target object to work on (as context that can be passed to editors)@Nullable public <T> T convertIfNecessary(@Nullable java.lang.Object newValue, @Nullable java.lang.Class<T> requiredType, @Nullable MethodParameter methodParam) throws java.lang.IllegalArgumentException
newValue
- the proposed new valuerequiredType
- 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
(may be null
)java.lang.IllegalArgumentException
- if type conversion failed@Nullable public <T> T convertIfNecessary(@Nullable java.lang.Object newValue, @Nullable java.lang.Class<T> requiredType, @Nullable java.lang.reflect.Field field) throws java.lang.IllegalArgumentException
newValue
- the proposed new valuerequiredType
- the type we must convert to
(or null
if not known, for example in case of a collection element)field
- the reflective field that is the target of the conversion
(may be null
)java.lang.IllegalArgumentException
- if type conversion failed@Nullable public <T> T convertIfNecessary(@Nullable java.lang.String propertyName, @Nullable java.lang.Object oldValue, java.lang.Object newValue, @Nullable java.lang.Class<T> requiredType) throws java.lang.IllegalArgumentException
propertyName
- name of the propertyoldValue
- the previous value, if available (may be null
)newValue
- the proposed new valuerequiredType
- the type we must convert to
(or null
if not known, for example in case of a collection element)java.lang.IllegalArgumentException
- if type conversion failed@Nullable public <T> T convertIfNecessary(@Nullable java.lang.String propertyName, @Nullable java.lang.Object oldValue, @Nullable java.lang.Object newValue, @Nullable java.lang.Class<T> requiredType, @Nullable TypeDescriptor typeDescriptor) throws java.lang.IllegalArgumentException
propertyName
- name of the propertyoldValue
- the previous value, if available (may be null
)newValue
- the proposed new valuerequiredType
- the type we must convert to
(or null
if not known, for example in case of a collection element)typeDescriptor
- the descriptor for the target property or fieldjava.lang.IllegalArgumentException
- if type conversion failedprivate java.lang.Object attemptToConvertStringToEnum(java.lang.Class<?> requiredType, java.lang.String trimmedValue, java.lang.Object currentConvertedValue)
@Nullable private java.beans.PropertyEditor findDefaultEditor(@Nullable java.lang.Class<?> requiredType)
requiredType
- the type to find an editor fornull
if none@Nullable private java.lang.Object doConvertValue(@Nullable java.lang.Object oldValue, @Nullable java.lang.Object newValue, @Nullable java.lang.Class<?> requiredType, @Nullable java.beans.PropertyEditor editor)
oldValue
- the previous value, if available (may be null
)newValue
- the proposed new valuerequiredType
- the type we must convert to
(or null
if not known, for example in case of a collection element)editor
- the PropertyEditor to usejava.lang.IllegalArgumentException
- if type conversion failedprivate java.lang.Object doConvertTextValue(@Nullable java.lang.Object oldValue, java.lang.String newTextValue, java.beans.PropertyEditor editor)
oldValue
- the previous value, if available (may be null
)newTextValue
- the proposed text valueeditor
- the PropertyEditor to useprivate java.lang.Object convertToTypedArray(java.lang.Object input, @Nullable java.lang.String propertyName, java.lang.Class<?> componentType)
private java.util.Collection<?> convertToTypedCollection(java.util.Collection<?> original, @Nullable java.lang.String propertyName, java.lang.Class<?> requiredType, @Nullable TypeDescriptor typeDescriptor)
private java.util.Map<?,?> convertToTypedMap(java.util.Map<?,?> original, @Nullable java.lang.String propertyName, java.lang.Class<?> requiredType, @Nullable TypeDescriptor typeDescriptor)
@Nullable private java.lang.String buildIndexedPropertyName(@Nullable java.lang.String propertyName, int index)
@Nullable private java.lang.String buildKeyedPropertyName(@Nullable java.lang.String propertyName, java.lang.Object key)
private boolean canCreateCopy(java.lang.Class<?> requiredType)