org.springframework.beans
Class TypeConverterDelegate

java.lang.Object
  extended by org.springframework.beans.TypeConverterDelegate

 class TypeConverterDelegate
extends java.lang.Object

Internal helper class for converting property values to target types.

Works on a given PropertyEditorRegistrySupport instance. Used as a delegate by BeanWrapperImpl and SimpleTypeConverter.

Since:
2.0
Author:
Juergen Hoeller, Rob Harrop
See Also:
BeanWrapperImpl, SimpleTypeConverter

Field Summary
private static Log logger
           
private  PropertyEditorRegistrySupport propertyEditorRegistry
           
private  java.lang.Object targetObject
           
 
Constructor Summary
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.
 
Method Summary
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, 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.
protected  java.lang.Object convertToTypedArray(java.lang.Object input, java.lang.String propertyName, java.lang.Class<?> componentType)
           
protected  java.util.Collection convertToTypedCollection(java.util.Collection original, java.lang.String propertyName, java.lang.Class requiredType, TypeDescriptor typeDescriptor)
           
protected  java.util.Map convertToTypedMap(java.util.Map original, java.lang.String propertyName, java.lang.Class requiredType, TypeDescriptor typeDescriptor)
           
protected  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.
protected  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.
protected  java.beans.PropertyEditor findDefaultEditor(java.lang.Class requiredType, TypeDescriptor typeDescriptor)
          Find a default editor for the given type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final Log logger

propertyEditorRegistry

private final PropertyEditorRegistrySupport propertyEditorRegistry

targetObject

private final java.lang.Object targetObject
Constructor Detail

TypeConverterDelegate

public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry)
Create a new TypeConverterDelegate for the given editor registry.

Parameters:
propertyEditorRegistry - the editor registry to use

TypeConverterDelegate

public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry,
                             java.lang.Object targetObject)
Create a new TypeConverterDelegate for the given editor registry and bean instance.

Parameters:
propertyEditorRegistry - the editor registry to use
targetObject - the target object to work on (as context that can be passed to editors)
Method Detail

convertIfNecessary

public <T> T convertIfNecessary(java.lang.Object newValue,
                                java.lang.Class<T> requiredType,
                                MethodParameter methodParam)
                     throws java.lang.IllegalArgumentException
Convert the value to the specified required type.

Parameters:
newValue - the proposed new value
requiredType - 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)
Returns:
the new value, possibly the result of type conversion
Throws:
java.lang.IllegalArgumentException - if type conversion failed

convertIfNecessary

public <T> T convertIfNecessary(java.lang.String propertyName,
                                java.lang.Object oldValue,
                                java.lang.Object newValue,
                                java.lang.Class<T> requiredType)
                     throws java.lang.IllegalArgumentException
Convert the value to the required type for the specified property.

Parameters:
propertyName - name of the property
oldValue - the previous value, if available (may be null)
newValue - the proposed new value
requiredType - the type we must convert to (or null if not known, for example in case of a collection element)
Returns:
the new value, possibly the result of type conversion
Throws:
java.lang.IllegalArgumentException - if type conversion failed

convertIfNecessary

public <T> T convertIfNecessary(java.lang.String propertyName,
                                java.lang.Object oldValue,
                                java.lang.Object newValue,
                                java.lang.Class<T> requiredType,
                                TypeDescriptor typeDescriptor)
                     throws java.lang.IllegalArgumentException
Convert the value to the required type (if necessary from a String), for the specified property.

Parameters:
propertyName - name of the property
oldValue - the previous value, if available (may be null)
newValue - the proposed new value
requiredType - 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 field
Returns:
the new value, possibly the result of type conversion
Throws:
java.lang.IllegalArgumentException - if type conversion failed

attemptToConvertStringToEnum

private java.lang.Object attemptToConvertStringToEnum(java.lang.Class<?> requiredType,
                                                      java.lang.String trimmedValue,
                                                      java.lang.Object currentConvertedValue)

findDefaultEditor

protected java.beans.PropertyEditor findDefaultEditor(java.lang.Class requiredType,
                                                      TypeDescriptor typeDescriptor)
Find a default editor for the given type.

Parameters:
requiredType - the type to find an editor for
descriptor - the JavaBeans descriptor for the property
Returns:
the corresponding editor, or null if none

doConvertValue

protected 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.

Parameters:
oldValue - the previous value, if available (may be null)
newValue - the proposed new value
requiredType - the type we must convert to (or null if not known, for example in case of a collection element)
editor - the PropertyEditor to use
Returns:
the new value, possibly the result of type conversion
Throws:
java.lang.IllegalArgumentException - if type conversion failed

doConvertTextValue

protected 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.

Parameters:
oldValue - the previous value, if available (may be null)
newTextValue - the proposed text value
editor - the PropertyEditor to use
Returns:
the converted value

convertToTypedArray

protected java.lang.Object convertToTypedArray(java.lang.Object input,
                                               java.lang.String propertyName,
                                               java.lang.Class<?> componentType)

convertToTypedCollection

protected java.util.Collection convertToTypedCollection(java.util.Collection original,
                                                        java.lang.String propertyName,
                                                        java.lang.Class requiredType,
                                                        TypeDescriptor typeDescriptor)

convertToTypedMap

protected java.util.Map convertToTypedMap(java.util.Map original,
                                          java.lang.String propertyName,
                                          java.lang.Class requiredType,
                                          TypeDescriptor typeDescriptor)

buildIndexedPropertyName

private java.lang.String buildIndexedPropertyName(java.lang.String propertyName,
                                                  int index)

buildKeyedPropertyName

private java.lang.String buildKeyedPropertyName(java.lang.String propertyName,
                                                java.lang.Object key)

canCreateCopy

private boolean canCreateCopy(java.lang.Class requiredType)