removed ConversionService/TypeConverter convenience methods in order to restore 3.0's SPI (for backwards compatibility with implementers)

This commit is contained in:
Juergen Hoeller
2011-02-10 01:24:08 +00:00
parent b7d7fa7b7e
commit cd584afe93
13 changed files with 97 additions and 87 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ public interface TypeConverter {
/**
* Convert (may coerce) a value from one type to another, for example from a boolean to a string.
* The typeDescriptor parameter enables support for typed collections - if the caller really wishes they
* can have a List<Integer> for example, rather than simply a List.
* can have a List&lt;Integer&gt; for example, rather than simply a List.
* @param value the value to be converted
* @param sourceType a type descriptor that supplies extra information about the source object
* @param targetType a type descriptor that supplies extra information about the requested result type
@@ -50,8 +50,4 @@ public interface TypeConverter {
*/
Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType);
// 3.1 additions for encapsulation of TypeDescriptor.forObject(value);
Object convertValue(Object value, TypeDescriptor targetType);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -141,7 +141,8 @@ public class ExpressionState {
}
public Object convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor) throws EvaluationException {
return this.relatedContext.getTypeConverter().convertValue(value.getValue(), targetTypeDescriptor);
Object val = value.getValue();
return this.relatedContext.getTypeConverter().convertValue(val, TypeDescriptor.forObject(val), targetTypeDescriptor);
}
/*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,8 +35,9 @@ import org.springframework.expression.spel.SpelMessage;
import org.springframework.expression.spel.SpelNode;
/**
* Represents the invocation of a constructor. Either a constructor on a regular type or construction of an array. When
* an array is constructed, an initializer can be specified.
* Represents the invocation of a constructor. Either a constructor on a regular type or
* construction of an array. When an array is constructed, an initializer can be specified.
*
* <p>
* Examples:<br>
* new String('hello world')<br>
@@ -322,7 +323,7 @@ public class ConstructorReference extends SpelNodeImpl {
for (int i = 0; i < newObjectArray.length; i++) {
SpelNode elementNode = initializer.getChild(i);
Object arrayEntry = elementNode.getValue(state);
newObjectArray[i] = typeConverter.convertValue(arrayEntry, toTypeDescriptor);
newObjectArray[i] = typeConverter.convertValue(arrayEntry, TypeDescriptor.forObject(arrayEntry), toTypeDescriptor);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -241,7 +241,8 @@ public class ReflectionHelper {
else {
targetType = new TypeDescriptor(MethodParameter.forMethodOrConstructor(methodOrCtor, argPosition));
}
arguments[argPosition] = converter.convertValue(arguments[argPosition], targetType);
Object argument = arguments[argPosition];
arguments[argPosition] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
}
}
@@ -278,7 +279,7 @@ public class ReflectionHelper {
if (converter == null) {
throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, argument.getClass().getName(), targetType);
}
arguments[argPosition] = converter.convertValue(argument, targetType);
arguments[argPosition] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
}
}
catch (EvaluationException ex) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -218,7 +218,8 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
TypeDescriptor typeDescriptor = getTypeDescriptor(context, target, name);
if (typeDescriptor != null) {
try {
possiblyConvertedNewValue = context.getTypeConverter().convertValue(newValue, typeDescriptor);
possiblyConvertedNewValue = context.getTypeConverter().convertValue(
newValue, TypeDescriptor.forObject(newValue), typeDescriptor);
}
catch (EvaluationException evaluationException) {
throw new AccessException("Type conversion failure",evaluationException);

View File

@@ -75,8 +75,4 @@ public class StandardTypeConverter implements TypeConverter {
}
}
public Object convertValue(Object value, TypeDescriptor targetType) {
return convertValue(value, TypeDescriptor.forObject(value), targetType);
}
}