|
|
|
@ -81,7 +81,7 @@ class TypeConverterDelegate { |
|
|
|
* @return the new value, possibly the result of type conversion |
|
|
|
* @return the new value, possibly the result of type conversion |
|
|
|
* @throws IllegalArgumentException if type conversion failed |
|
|
|
* @throws IllegalArgumentException if type conversion failed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Object convertIfNecessary(Object newValue, Class requiredType) throws IllegalArgumentException { |
|
|
|
public <T> T convertIfNecessary(Object newValue, Class<T> requiredType) throws IllegalArgumentException { |
|
|
|
return convertIfNecessary(null, null, newValue, requiredType, null, null); |
|
|
|
return convertIfNecessary(null, null, newValue, requiredType, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -95,7 +95,7 @@ class TypeConverterDelegate { |
|
|
|
* @return the new value, possibly the result of type conversion |
|
|
|
* @return the new value, possibly the result of type conversion |
|
|
|
* @throws IllegalArgumentException if type conversion failed |
|
|
|
* @throws IllegalArgumentException if type conversion failed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Object convertIfNecessary(Object newValue, Class requiredType, MethodParameter methodParam) |
|
|
|
public <T> T convertIfNecessary(Object newValue, Class<T> requiredType, MethodParameter methodParam) |
|
|
|
throws IllegalArgumentException { |
|
|
|
throws IllegalArgumentException { |
|
|
|
|
|
|
|
|
|
|
|
return convertIfNecessary(null, null, newValue, requiredType, null, methodParam); |
|
|
|
return convertIfNecessary(null, null, newValue, requiredType, null, methodParam); |
|
|
|
@ -111,8 +111,8 @@ class TypeConverterDelegate { |
|
|
|
* @return the new value, possibly the result of type conversion |
|
|
|
* @return the new value, possibly the result of type conversion |
|
|
|
* @throws IllegalArgumentException if type conversion failed |
|
|
|
* @throws IllegalArgumentException if type conversion failed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Object convertIfNecessary( |
|
|
|
public <T> T convertIfNecessary( |
|
|
|
String propertyName, Object oldValue, Object newValue, Class requiredType) |
|
|
|
String propertyName, Object oldValue, Object newValue, Class<T> requiredType) |
|
|
|
throws IllegalArgumentException { |
|
|
|
throws IllegalArgumentException { |
|
|
|
|
|
|
|
|
|
|
|
return convertIfNecessary(propertyName, oldValue, newValue, requiredType, null, null); |
|
|
|
return convertIfNecessary(propertyName, oldValue, newValue, requiredType, null, null); |
|
|
|
@ -149,8 +149,9 @@ class TypeConverterDelegate { |
|
|
|
* @return the new value, possibly the result of type conversion |
|
|
|
* @return the new value, possibly the result of type conversion |
|
|
|
* @throws IllegalArgumentException if type conversion failed |
|
|
|
* @throws IllegalArgumentException if type conversion failed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected Object convertIfNecessary( |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
String propertyName, Object oldValue, Object newValue, Class requiredType, |
|
|
|
protected <T> T convertIfNecessary( |
|
|
|
|
|
|
|
String propertyName, Object oldValue, Object newValue, Class<T> requiredType, |
|
|
|
PropertyDescriptor descriptor, MethodParameter methodParam) |
|
|
|
PropertyDescriptor descriptor, MethodParameter methodParam) |
|
|
|
throws IllegalArgumentException { |
|
|
|
throws IllegalArgumentException { |
|
|
|
|
|
|
|
|
|
|
|
@ -173,11 +174,11 @@ class TypeConverterDelegate { |
|
|
|
if (convertedValue != null) { |
|
|
|
if (convertedValue != null) { |
|
|
|
if (String.class.equals(requiredType) && ClassUtils.isPrimitiveOrWrapper(convertedValue.getClass())) { |
|
|
|
if (String.class.equals(requiredType) && ClassUtils.isPrimitiveOrWrapper(convertedValue.getClass())) { |
|
|
|
// We can stringify any primitive value...
|
|
|
|
// We can stringify any primitive value...
|
|
|
|
return convertedValue.toString(); |
|
|
|
return (T) convertedValue.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (requiredType.isArray()) { |
|
|
|
else if (requiredType.isArray()) { |
|
|
|
// Array required -> apply appropriate conversion of elements.
|
|
|
|
// Array required -> apply appropriate conversion of elements.
|
|
|
|
return convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType()); |
|
|
|
return (T) convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (convertedValue instanceof Collection && CollectionFactory.isApproximableCollectionType(requiredType)) { |
|
|
|
else if (convertedValue instanceof Collection && CollectionFactory.isApproximableCollectionType(requiredType)) { |
|
|
|
// Convert elements to target type, if determined.
|
|
|
|
// Convert elements to target type, if determined.
|
|
|
|
@ -228,7 +229,7 @@ class TypeConverterDelegate { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return convertedValue; |
|
|
|
return (T) convertedValue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -278,7 +279,7 @@ class TypeConverterDelegate { |
|
|
|
// we just want to allow special PropertyEditors to override setValue
|
|
|
|
// we just want to allow special PropertyEditors to override setValue
|
|
|
|
// for type conversion from non-String values to the required type.
|
|
|
|
// for type conversion from non-String values to the required type.
|
|
|
|
try { |
|
|
|
try { |
|
|
|
Object newConvertedValue = null; |
|
|
|
Object newConvertedValue; |
|
|
|
if (sharedEditor) { |
|
|
|
if (sharedEditor) { |
|
|
|
// Synchronized access to shared editor instance.
|
|
|
|
// Synchronized access to shared editor instance.
|
|
|
|
synchronized (editor) { |
|
|
|
synchronized (editor) { |
|
|
|
@ -358,7 +359,7 @@ class TypeConverterDelegate { |
|
|
|
return editor.getValue(); |
|
|
|
return editor.getValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Object convertToTypedArray(Object input, String propertyName, Class componentType) { |
|
|
|
protected Object convertToTypedArray(Object input, String propertyName, Class<?> componentType) { |
|
|
|
if (input instanceof Collection) { |
|
|
|
if (input instanceof Collection) { |
|
|
|
// Convert Collection elements to array elements.
|
|
|
|
// Convert Collection elements to array elements.
|
|
|
|
Collection coll = (Collection) input; |
|
|
|
Collection coll = (Collection) input; |
|
|
|
@ -409,8 +410,8 @@ class TypeConverterDelegate { |
|
|
|
return original; |
|
|
|
return original; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Collection convertedCopy = null; |
|
|
|
Collection convertedCopy; |
|
|
|
Iterator it = null; |
|
|
|
Iterator it; |
|
|
|
try { |
|
|
|
try { |
|
|
|
it = original.iterator(); |
|
|
|
it = original.iterator(); |
|
|
|
if (it == null) { |
|
|
|
if (it == null) { |
|
|
|
@ -461,8 +462,8 @@ class TypeConverterDelegate { |
|
|
|
return original; |
|
|
|
return original; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Map convertedCopy = null; |
|
|
|
Map convertedCopy; |
|
|
|
Iterator it = null; |
|
|
|
Iterator it; |
|
|
|
try { |
|
|
|
try { |
|
|
|
it = original.entrySet().iterator(); |
|
|
|
it = original.entrySet().iterator(); |
|
|
|
if (it == null) { |
|
|
|
if (it == null) { |
|
|
|
|