diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeConverter.java index eedefe2d04e..386a2e39e76 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeConverter.java @@ -19,8 +19,7 @@ package org.springframework.core.convert; * A service interface for type conversion. This is the entry point into the convert system. *

* Call {@link #convert(Object, Class)} to perform a thread-safe type conversion using this system.
- * Call {@link #convert(Object, ConversionContext)} to perform a conversion with additional context about the point - * where conversion needs to occur. + * Call {@link #convert(Object, TypeDescriptor)} to perform a conversion with additional context about the targetType to convert to. * * @author Keith Donald */ @@ -37,10 +36,10 @@ public interface TypeConverter { /** * Returns true if objects of sourceType can be converted to the type of the conversion point. * @param source the source to convert from (may be null) - * @param context context about the point where conversion would occur + * @param targetType context about the target type to convert to * @return true if a conversion can be performed, false if not */ - boolean canConvert(Class sourceType, ConversionContext context); + boolean canConvert(Class sourceType, TypeDescriptor targetType); /** * Convert the source to targetType. @@ -54,10 +53,10 @@ public interface TypeConverter { /** * Convert the source to type T needed by the conversion point. * @param source the source to convert from (may be null) - * @param context context about the point where conversion will occur - * @return the converted object, an instance of {@link ConversionContext#getType()}, or null if a null source was provided + * @param targetType context about the target type to convert to + * @return the converted object, an instance of {@link TypeDescriptor#getType()}, or null if a null source was provided * @throws ConvertException if an exception occurred */ - T convert(S source, ConversionContext context); + T convert(S source, TypeDescriptor targetType); } \ No newline at end of file diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionContext.java b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java similarity index 88% rename from org.springframework.core/src/main/java/org/springframework/core/convert/ConversionContext.java rename to org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index 5fc74fa346c..5dcdb99e7d8 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionContext.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -27,19 +27,17 @@ import org.springframework.util.Assert; // TODO doesn't support more than depth of one (eg. Map> or List[]) /** - * Context about a point where conversion needs to be performed. Provides context about the point such - * as field or method parameter information. - * + * Context about a type to convert to. * @author Keith Donald * @author Andy Clement */ -public class ConversionContext { +public class TypeDescriptor { /** * Constant value for the null object */ @SuppressWarnings("unchecked") - public final static ConversionContext NULL = new ConversionContext((Class) null); + public final static TypeDescriptor NULL = new TypeDescriptor((Class) null); private MethodParameter methodParameter; @@ -50,29 +48,30 @@ public class ConversionContext { private Class type; /** - * Creates a new context for the given type. Use this constructor when a conversion point comes from a source such as - * a Map or collection, where no additional binding metadata is available. + * Creates a new descriptor for the given type. + * Use this constructor when a conversion point comes from a source such as a Map or collection, where no additional context is available. * @param type the actual type */ - public ConversionContext(Class type) { + public TypeDescriptor(Class type) { this.type = type; } /** - * Create a new context for a method or constructor parameter. Use this constructor when a conversion point originates - * from a method parameter, such as a setter method argument. + * Create a new type descriptor from a method or constructor parameter. + * Use this constructor when a target conversion point originates from a method parameter, such as a setter method argument. * @param methodParameter the MethodParameter to wrap */ - public ConversionContext(MethodParameter methodParameter) { + public TypeDescriptor(MethodParameter methodParameter) { Assert.notNull(methodParameter, "MethodParameter must not be null"); this.methodParameter = methodParameter; } /** - * Create a new context for a field. Use this constructor when a conversion point originates from a field. + * Create a new type descriptor for a field. + * Use this constructor when a target conversion point originates from a field. * @param field the field to wrap */ - public ConversionContext(Field field) { + public TypeDescriptor(Field field) { Assert.notNull(field, "Field must not be null"); this.field = field; } @@ -246,7 +245,7 @@ public class ConversionContext { * @return true if this type is assignable to the target */ @SuppressWarnings("unchecked") - public boolean isAssignableTo(ConversionContext targetType) { + public boolean isAssignableTo(TypeDescriptor targetType) { return targetType.getType().isAssignableFrom(getType()); } @@ -255,9 +254,9 @@ public class ConversionContext { * @param type the class * @return the type descriptor */ - public static ConversionContext valueOf(Class type) { + public static TypeDescriptor valueOf(Class type) { // TODO needs a cache for common type descriptors - return new ConversionContext(type); + return new TypeDescriptor(type); } /** @@ -266,7 +265,7 @@ public class ConversionContext { * @return the type descriptor */ @SuppressWarnings("unchecked") - public static ConversionContext forObject(Object object) { + public static TypeDescriptor forObject(Object object) { if (object == null) { return NULL; } else { diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/AbstractCollectionConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/AbstractCollectionConverter.java index 16e0d144fa3..a72dc586d19 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/AbstractCollectionConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/AbstractCollectionConverter.java @@ -16,7 +16,7 @@ package org.springframework.core.convert.support; import org.springframework.core.convert.ConversionFailedException; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; /** * Base class for converters that convert to and from collection types (arrays and java.util.Collection types) @@ -28,18 +28,18 @@ abstract class AbstractCollectionConverter implements ConversionExecutor { private ConversionExecutor elementConverter; - private ConversionContext sourceCollectionType; + private TypeDescriptor sourceCollectionType; - private ConversionContext targetCollectionType; + private TypeDescriptor targetCollectionType; - public AbstractCollectionConverter(ConversionContext sourceCollectionType, ConversionContext targetCollectionType, GenericTypeConverter conversionService) { + public AbstractCollectionConverter(TypeDescriptor sourceCollectionType, TypeDescriptor targetCollectionType, GenericTypeConverter conversionService) { this.conversionService = conversionService; this.sourceCollectionType = sourceCollectionType; this.targetCollectionType = targetCollectionType; Class sourceElementType = sourceCollectionType.getElementType(); Class targetElementType = targetCollectionType.getElementType(); if (sourceElementType != null && targetElementType != null) { - elementConverter = conversionService.getConversionExecutor(sourceElementType, ConversionContext.valueOf(targetElementType)); + elementConverter = conversionService.getConversionExecutor(sourceElementType, TypeDescriptor.valueOf(targetElementType)); } else { elementConverter = NoOpConversionExecutor.INSTANCE; } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArray.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArray.java index c95943d54a6..bea0cbf9182 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArray.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArray.java @@ -18,7 +18,7 @@ package org.springframework.core.convert.support; import java.lang.reflect.Array; import org.springframework.core.convert.TypeConverter; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; /** * Special one-way converter that converts from a source array to a target array. Supports type conversion of the @@ -29,7 +29,7 @@ import org.springframework.core.convert.ConversionContext; */ class ArrayToArray extends AbstractCollectionConverter { - public ArrayToArray(ConversionContext sourceArrayType, ConversionContext targetArrayType, GenericTypeConverter conversionService) { + public ArrayToArray(TypeDescriptor sourceArrayType, TypeDescriptor targetArrayType, GenericTypeConverter conversionService) { super(sourceArrayType, targetArrayType, conversionService); } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollection.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollection.java index 937b98331f2..d9510d184f5 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollection.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollection.java @@ -18,7 +18,7 @@ package org.springframework.core.convert.support; import java.lang.reflect.Array; import java.util.Collection; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; /** * Special converter that converts from a source array to a target collection. Supports the selection of an @@ -29,7 +29,7 @@ import org.springframework.core.convert.ConversionContext; */ class ArrayToCollection extends AbstractCollectionConverter { - public ArrayToCollection(ConversionContext sourceArrayType, ConversionContext targetCollectionType, + public ArrayToCollection(TypeDescriptor sourceArrayType, TypeDescriptor targetCollectionType, GenericTypeConverter conversionService) { super(sourceArrayType, targetCollectionType, conversionService); } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArray.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArray.java index eab82496cd9..ae2ef8aa152 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArray.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArray.java @@ -19,7 +19,7 @@ import java.lang.reflect.Array; import java.util.Collection; import java.util.Iterator; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; /** * Special converter that converts from target collection to a source array. @@ -28,7 +28,7 @@ import org.springframework.core.convert.ConversionContext; */ class CollectionToArray extends AbstractCollectionConverter { - public CollectionToArray(ConversionContext sourceArrayType, ConversionContext targetCollectionType, + public CollectionToArray(TypeDescriptor sourceArrayType, TypeDescriptor targetCollectionType, GenericTypeConverter conversionService) { super(sourceArrayType, targetCollectionType, conversionService); } @@ -52,7 +52,7 @@ class CollectionToArray extends AbstractCollectionConverter { while (it.hasNext()) { Object value = it.next(); if (value != null) { - elementConverter = getConversionService().getConversionExecutor(value.getClass(), ConversionContext.valueOf(getTargetElementType())); + elementConverter = getConversionService().getConversionExecutor(value.getClass(), TypeDescriptor.valueOf(getTargetElementType())); break; } } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollection.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollection.java index ba8e252a8b4..c70318979c4 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollection.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollection.java @@ -18,7 +18,7 @@ package org.springframework.core.convert.support; import java.util.Collection; import java.util.Iterator; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; /** * A converter that can convert from one collection type to another. @@ -27,7 +27,7 @@ import org.springframework.core.convert.ConversionContext; */ class CollectionToCollection extends AbstractCollectionConverter { - public CollectionToCollection(ConversionContext sourceCollectionType, ConversionContext targetCollectionType, + public CollectionToCollection(TypeDescriptor sourceCollectionType, TypeDescriptor targetCollectionType, GenericTypeConverter conversionService) { super(sourceCollectionType, targetCollectionType, conversionService); } @@ -53,7 +53,7 @@ class CollectionToCollection extends AbstractCollectionConverter { while (it.hasNext()) { Object value = it.next(); if (value != null) { - elementConverter = getConversionService().getConversionExecutor(value.getClass(), ConversionContext.valueOf(getTargetElementType())); + elementConverter = getConversionService().getConversionExecutor(value.getClass(), TypeDescriptor.valueOf(getTargetElementType())); break; } } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java index d8b7c29cd7d..7a0d2f25885 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java @@ -26,7 +26,7 @@ import java.util.List; import java.util.Map; import org.springframework.core.GenericTypeResolver; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.TypeConverter; import org.springframework.core.convert.converter.Converter; @@ -52,9 +52,6 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry { */ private final Map sourceTypeConverters = new HashMap(); - /** - * An optional parent conversion service. - */ private TypeConverter parent; /** @@ -108,16 +105,16 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry { // implementing TypeConverter public boolean canConvert(Class sourceType, Class targetType) { - return canConvert(sourceType, ConversionContext.valueOf(targetType)); + return canConvert(sourceType, TypeDescriptor.valueOf(targetType)); } - public boolean canConvert(Class sourceType, ConversionContext context) { - ConversionExecutor executor = getConversionExecutor(sourceType, context); + public boolean canConvert(Class sourceType, TypeDescriptor targetType) { + ConversionExecutor executor = getConversionExecutor(sourceType, targetType); if (executor != null) { return true; } else { if (parent != null) { - return parent.canConvert(sourceType, context); + return parent.canConvert(sourceType, targetType); } else { return false; } @@ -125,28 +122,28 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry { } public T convert(S source, Class targetType) { - return convert(source, ConversionContext.valueOf(targetType)); + return convert(source, TypeDescriptor.valueOf(targetType)); } - public T convert(S source, ConversionContext context) { + public T convert(S source, TypeDescriptor targetType) { if (source == null) { return null; } - ConversionExecutor executor = getConversionExecutor(source.getClass(), context); + ConversionExecutor executor = getConversionExecutor(source.getClass(), targetType); if (executor != null) { return (T) executor.execute(source); } else { if (parent != null) { - return parent.convert(source, context); + return parent.convert(source, targetType); } else { - throw new ConverterNotFoundException(source.getClass(), context.getType(), + throw new ConverterNotFoundException(source.getClass(), targetType.getType(), "No converter found that can convert from sourceType [" + source.getClass().getName() - + "] to targetType [" + context.getName() + "]"); + + "] to targetType [" + targetType.getName() + "]"); } } } - ConversionExecutor getConversionExecutor(Class sourceClass, ConversionContext targetType) + ConversionExecutor getConversionExecutor(Class sourceClass, TypeDescriptor targetType) throws ConverterNotFoundException { Assert.notNull(sourceClass, "The sourceType to convert from is required"); Assert.notNull(targetType, "The targetType to convert to is required"); @@ -154,7 +151,7 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry { // TODO for Andy - is this correct way to handle the Null TypedValue? return NoOpConversionExecutor.INSTANCE; } - ConversionContext sourceType = ConversionContext.valueOf(sourceClass); + TypeDescriptor sourceType = TypeDescriptor.valueOf(sourceClass); if (sourceType.isArray()) { if (targetType.isArray()) { return new ArrayToArray(sourceType, targetType, this); diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMap.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMap.java index 7ceb409843a..bf59ebc34fd 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMap.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMap.java @@ -22,7 +22,7 @@ import java.util.SortedMap; import java.util.TreeMap; import org.springframework.core.convert.ConversionFailedException; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; /** * Converts from one map to another map, with support for converting individual map elements based on generic type information. @@ -31,9 +31,9 @@ import org.springframework.core.convert.ConversionContext; @SuppressWarnings("unchecked") class MapToMap implements ConversionExecutor { - private ConversionContext sourceType; + private TypeDescriptor sourceType; - private ConversionContext targetType; + private TypeDescriptor targetType; private GenericTypeConverter conversionService; @@ -45,7 +45,7 @@ class MapToMap implements ConversionExecutor { * @param targetType the target map type * @param conversionService the conversion service */ - public MapToMap(ConversionContext sourceType, ConversionContext targetType, GenericTypeConverter conversionService) { + public MapToMap(TypeDescriptor sourceType, TypeDescriptor targetType, GenericTypeConverter conversionService) { this.sourceType = sourceType; this.targetType = targetType; this.conversionService = conversionService; @@ -55,9 +55,9 @@ class MapToMap implements ConversionExecutor { private EntryConverter createEntryConverter() { if (sourceType.isMapEntryTypeKnown() && targetType.isMapEntryTypeKnown()) { ConversionExecutor keyConverter = conversionService.getConversionExecutor(sourceType.getMapKeyType(), - ConversionContext.valueOf(targetType.getMapKeyType())); + TypeDescriptor.valueOf(targetType.getMapKeyType())); ConversionExecutor valueConverter = conversionService.getConversionExecutor(sourceType.getMapValueType(), - ConversionContext.valueOf(targetType.getMapValueType())); + TypeDescriptor.valueOf(targetType.getMapValueType())); return new EntryConverter(keyConverter, valueConverter); } else { return EntryConverter.NO_OP_INSTANCE; @@ -94,11 +94,11 @@ class MapToMap implements ConversionExecutor { Object key = entry.getKey(); Object value = entry.getValue(); if (keyConverter == null && key != null) { - keyConverter = conversionService.getConversionExecutor(key.getClass(), ConversionContext + keyConverter = conversionService.getConversionExecutor(key.getClass(), TypeDescriptor .valueOf(targetKeyType)); } if (valueConverter == null && value != null) { - valueConverter = conversionService.getConversionExecutor(value.getClass(), ConversionContext + valueConverter = conversionService.getConversionExecutor(value.getClass(), TypeDescriptor .valueOf(targetValueType)); } if (keyConverter != null && valueConverter != null) { diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StaticConversionExecutor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StaticConversionExecutor.java index ae6862fa2cd..fa3cd6c7b62 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StaticConversionExecutor.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StaticConversionExecutor.java @@ -16,7 +16,7 @@ package org.springframework.core.convert.support; import org.springframework.core.convert.ConversionFailedException; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.Converter; import org.springframework.core.style.ToStringCreator; @@ -27,13 +27,13 @@ import org.springframework.core.style.ToStringCreator; @SuppressWarnings("unchecked") class StaticConversionExecutor implements ConversionExecutor { - private final ConversionContext sourceType; + private final TypeDescriptor sourceType; - private final ConversionContext targetType; + private final TypeDescriptor targetType; private final Converter converter; - public StaticConversionExecutor(ConversionContext sourceType, ConversionContext targetType, Converter converter) { + public StaticConversionExecutor(TypeDescriptor sourceType, TypeDescriptor targetType, Converter converter) { this.sourceType = sourceType; this.targetType = targetType; this.converter = converter; diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/ConversionContextTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java similarity index 77% rename from org.springframework.core/src/test/java/org/springframework/core/convert/ConversionContextTests.java rename to org.springframework.core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java index 80439cbc15a..a4447fedc3a 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/ConversionContextTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java @@ -26,7 +26,7 @@ import org.junit.Test; /** * @author Andy Clement */ -public class ConversionContextTests { +public class TypeDescriptorTests { List listOfString; int[] intArray; @@ -34,13 +34,13 @@ public class ConversionContextTests { @Test public void testWrapperType() { - ConversionContext desc = ConversionContext.valueOf(int.class); + TypeDescriptor desc = TypeDescriptor.valueOf(int.class); assertEquals(Integer.class, desc.getType()); } @Test public void listDescriptors() throws Exception { - ConversionContext typeDescriptor = new ConversionContext(ConversionContextTests.class.getDeclaredField("listOfString")); + TypeDescriptor typeDescriptor = new TypeDescriptor(TypeDescriptorTests.class.getDeclaredField("listOfString")); assertFalse(typeDescriptor.isArray()); assertEquals(List.class,typeDescriptor.getType()); assertEquals(String.class,typeDescriptor.getElementType()); @@ -50,7 +50,7 @@ public class ConversionContextTests { @Test public void arrayTypeDescriptors() throws Exception { - ConversionContext typeDescriptor = new ConversionContext(ConversionContextTests.class.getDeclaredField("intArray")); + TypeDescriptor typeDescriptor = new TypeDescriptor(TypeDescriptorTests.class.getDeclaredField("intArray")); assertTrue(typeDescriptor.isArray()); assertEquals(Integer.TYPE,typeDescriptor.getElementType()); assertEquals("int[]",typeDescriptor.asString()); @@ -58,14 +58,14 @@ public class ConversionContextTests { @Test public void buildingArrayTypeDescriptors() throws Exception { - ConversionContext typeDescriptor = new ConversionContext(new int[0].getClass()); + TypeDescriptor typeDescriptor = new TypeDescriptor(new int[0].getClass()); assertTrue(typeDescriptor.isArray()); assertEquals(Integer.TYPE,typeDescriptor.getElementType()); } @Test public void complexTypeDescriptors() throws Exception { - ConversionContext typeDescriptor = new ConversionContext(ConversionContextTests.class.getDeclaredField("arrayOfListOfString")); + TypeDescriptor typeDescriptor = new TypeDescriptor(TypeDescriptorTests.class.getDeclaredField("arrayOfListOfString")); assertTrue(typeDescriptor.isArray()); assertEquals(List.class,typeDescriptor.getElementType()); // TODO asc notice that the type of the list elements is lost: typeDescriptor.getElementType() should return a TypeDescriptor diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToArrayTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToArrayTests.java index a453b097384..fca7405f16f 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToArrayTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToArrayTests.java @@ -3,7 +3,7 @@ package org.springframework.core.convert.support; import static org.junit.Assert.assertEquals; import org.junit.Test; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.ArrayToArray; import org.springframework.core.convert.support.DefaultTypeConverter; @@ -12,7 +12,7 @@ public class ArrayToArrayTests { @Test public void testArrayToArrayConversion() { DefaultTypeConverter service = new DefaultTypeConverter(); - ArrayToArray c = new ArrayToArray(ConversionContext.valueOf(String[].class), ConversionContext.valueOf(Integer[].class), service); + ArrayToArray c = new ArrayToArray(TypeDescriptor.valueOf(String[].class), TypeDescriptor.valueOf(Integer[].class), service); Integer[] result = (Integer[]) c.execute(new String[] { "1", "2", "3" }); assertEquals(new Integer(1), result[0]); assertEquals(new Integer(2), result[1]); diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToCollectionTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToCollectionTests.java index 1d07366ca12..7eb49534a04 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToCollectionTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToCollectionTests.java @@ -9,7 +9,7 @@ import java.util.Set; import java.util.SortedSet; import org.junit.Test; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.ArrayToCollection; import org.springframework.core.convert.support.DefaultTypeConverter; @@ -18,7 +18,7 @@ public class ArrayToCollectionTests { @Test public void testArrayToCollectionConversion() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - ArrayToCollection c = new ArrayToCollection(ConversionContext.valueOf(String[].class), new ConversionContext(getClass().getField("bindTarget")), service); + ArrayToCollection c = new ArrayToCollection(TypeDescriptor.valueOf(String[].class), new TypeDescriptor(getClass().getField("bindTarget")), service); List result = (List) c.execute(new String[] { "1", "2", "3" }); assertEquals(new Integer(1), result.get(0)); assertEquals(new Integer(2), result.get(1)); @@ -28,7 +28,7 @@ public class ArrayToCollectionTests { @Test public void testArrayToSetConversion() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - ArrayToCollection c = new ArrayToCollection(ConversionContext.valueOf(String[].class), new ConversionContext(getClass().getField("setTarget")), service); + ArrayToCollection c = new ArrayToCollection(TypeDescriptor.valueOf(String[].class), new TypeDescriptor(getClass().getField("setTarget")), service); Set result = (Set) c.execute(new String[] { "1" }); assertEquals("1", result.iterator().next()); } @@ -36,7 +36,7 @@ public class ArrayToCollectionTests { @Test public void testArrayToSortedSetConversion() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - ArrayToCollection c = new ArrayToCollection(ConversionContext.valueOf(String[].class), new ConversionContext(getClass().getField("sortedSetTarget")), service); + ArrayToCollection c = new ArrayToCollection(TypeDescriptor.valueOf(String[].class), new TypeDescriptor(getClass().getField("sortedSetTarget")), service); SortedSet result = (SortedSet) c.execute(new String[] { "1" }); assertEquals(new Integer(1), result.iterator().next()); } @@ -44,7 +44,7 @@ public class ArrayToCollectionTests { @Test public void testArrayToCollectionImplConversion() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - ArrayToCollection c = new ArrayToCollection(ConversionContext.valueOf(String[].class), new ConversionContext(getClass().getField("implTarget")), service); + ArrayToCollection c = new ArrayToCollection(TypeDescriptor.valueOf(String[].class), new TypeDescriptor(getClass().getField("implTarget")), service); LinkedList result = (LinkedList) c.execute(new String[] { "1" }); assertEquals("1", result.iterator().next()); } @@ -52,7 +52,7 @@ public class ArrayToCollectionTests { @Test public void testArrayToNonGenericCollectionConversionNullElement() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - ArrayToCollection c = new ArrayToCollection(ConversionContext.valueOf(String[].class), new ConversionContext(getClass().getField("listTarget")), service); + ArrayToCollection c = new ArrayToCollection(TypeDescriptor.valueOf(String[].class), new TypeDescriptor(getClass().getField("listTarget")), service); List result = (List) c.execute(new Integer[] { null, new Integer(1) }); assertEquals(null, result.get(0)); assertEquals(new Integer(1), result.get(1)); diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToArrayTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToArrayTests.java index 4f1ffc024ab..b4aaa4fcb92 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToArrayTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToArrayTests.java @@ -6,7 +6,7 @@ import java.util.ArrayList; import java.util.Collection; import org.junit.Test; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.CollectionToArray; import org.springframework.core.convert.support.DefaultTypeConverter; @@ -15,8 +15,8 @@ public class CollectionToArrayTests { @Test public void testCollectionToArrayConversion() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - CollectionToArray c = new CollectionToArray(new ConversionContext(getClass().getField("bindTarget")), - ConversionContext.valueOf(Integer[].class), service); + CollectionToArray c = new CollectionToArray(new TypeDescriptor(getClass().getField("bindTarget")), + TypeDescriptor.valueOf(Integer[].class), service); bindTarget.add("1"); bindTarget.add("2"); bindTarget.add("3"); @@ -29,7 +29,7 @@ public class CollectionToArrayTests { @Test public void testCollectionToArrayConversionNoGenericInfo() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - CollectionToArray c = new CollectionToArray(ConversionContext.valueOf(Collection.class), ConversionContext + CollectionToArray c = new CollectionToArray(TypeDescriptor.valueOf(Collection.class), TypeDescriptor .valueOf(Integer[].class), service); bindTarget.add("1"); bindTarget.add("2"); @@ -43,7 +43,7 @@ public class CollectionToArrayTests { @Test public void testCollectionToArrayConversionNoGenericInfoNullElement() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - CollectionToArray c = new CollectionToArray(ConversionContext.valueOf(Collection.class), ConversionContext + CollectionToArray c = new CollectionToArray(TypeDescriptor.valueOf(Collection.class), TypeDescriptor .valueOf(Integer[].class), service); bindTarget.add(null); bindTarget.add("1"); diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionTests.java index 2866df2c2ff..e3945a996db 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionTests.java @@ -8,7 +8,7 @@ import java.util.Collection; import java.util.List; import org.junit.Test; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.CollectionToCollection; import org.springframework.core.convert.support.DefaultTypeConverter; @@ -17,8 +17,8 @@ public class CollectionToCollectionTests { @Test public void testCollectionToCollectionConversion() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - CollectionToCollection c = new CollectionToCollection(new ConversionContext(getClass().getField("bindTarget")), - new ConversionContext(getClass().getField("integerTarget")), service); + CollectionToCollection c = new CollectionToCollection(new TypeDescriptor(getClass().getField("bindTarget")), + new TypeDescriptor(getClass().getField("integerTarget")), service); bindTarget.add("1"); bindTarget.add("2"); bindTarget.add("3"); @@ -31,8 +31,8 @@ public class CollectionToCollectionTests { @Test public void testCollectionToCollectionConversionNoGenericInfo() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - CollectionToCollection c = new CollectionToCollection(ConversionContext.valueOf(Collection.class), - ConversionContext.valueOf(List.class), service); + CollectionToCollection c = new CollectionToCollection(TypeDescriptor.valueOf(Collection.class), + TypeDescriptor.valueOf(List.class), service); bindTarget.add("1"); bindTarget.add("2"); bindTarget.add("3"); @@ -45,8 +45,8 @@ public class CollectionToCollectionTests { @Test public void testCollectionToCollectionConversionNoGenericInfoSource() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - CollectionToCollection c = new CollectionToCollection(ConversionContext.valueOf(Collection.class), - new ConversionContext(getClass().getField("integerTarget")), service); + CollectionToCollection c = new CollectionToCollection(TypeDescriptor.valueOf(Collection.class), + new TypeDescriptor(getClass().getField("integerTarget")), service); bindTarget.add("1"); bindTarget.add("2"); bindTarget.add("3"); @@ -59,8 +59,8 @@ public class CollectionToCollectionTests { @Test public void testCollectionToCollectionConversionNoGenericInfoSourceNullValues() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - CollectionToCollection c = new CollectionToCollection(ConversionContext.valueOf(Collection.class), - new ConversionContext(getClass().getField("integerTarget")), service); + CollectionToCollection c = new CollectionToCollection(TypeDescriptor.valueOf(Collection.class), + new TypeDescriptor(getClass().getField("integerTarget")), service); bindTarget.add(null); bindTarget.add("1"); bindTarget.add("2"); @@ -77,8 +77,8 @@ public class CollectionToCollectionTests { @Test public void testCollectionToCollectionConversionNoGenericInfoSourceEmpty() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - CollectionToCollection c = new CollectionToCollection(ConversionContext.valueOf(Collection.class), - new ConversionContext(getClass().getField("integerTarget")), service); + CollectionToCollection c = new CollectionToCollection(TypeDescriptor.valueOf(Collection.class), + new TypeDescriptor(getClass().getField("integerTarget")), service); List result = (List) c.execute(bindTarget); assertTrue(result.isEmpty()); } diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericTypeConverterTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericTypeConverterTests.java index 2f0cfd835eb..3876b68c18d 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericTypeConverterTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericTypeConverterTests.java @@ -29,7 +29,7 @@ import java.util.Map; import org.junit.Ignore; import org.junit.Test; import org.springframework.core.convert.ConversionFailedException; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.converter.Converter; @@ -88,7 +88,7 @@ public class GenericTypeConverterTests { @Test public void convertNullConversionPointType() { - assertEquals("3", converter.convert("3", ConversionContext.NULL)); + assertEquals("3", converter.convert("3", TypeDescriptor.NULL)); } @@ -168,7 +168,7 @@ public class GenericTypeConverterTests { @Test public void convertArrayToListGenericTypeConversion() throws Exception { converter.add(new StringToInteger()); - List result = converter.convert(new String[] { "1", "2", "3" }, new ConversionContext>(getClass().getDeclaredField("genericList"))); + List result = converter.convert(new String[] { "1", "2", "3" }, new TypeDescriptor>(getClass().getDeclaredField("genericList"))); assertEquals(new Integer("1"), result.get(0)); assertEquals(new Integer("2"), result.get(1)); assertEquals(new Integer("3"), result.get(2)); @@ -226,7 +226,7 @@ public class GenericTypeConverterTests { foo.put("2", "BAZ"); converter.add(new StringToInteger()); converter.add(new StringToEnumFactory().getConverter(FooEnum.class)); - Map map = converter.convert(foo, new ConversionContext>(getClass().getField("genericMap"))); + Map map = converter.convert(foo, new TypeDescriptor>(getClass().getField("genericMap"))); assertEquals(map.get(1), FooEnum.BAR); assertEquals(map.get(2), FooEnum.BAZ); } diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/MapToMapTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/MapToMapTests.java index 43f5cf5bfd3..c2c338737ff 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/MapToMapTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/MapToMapTests.java @@ -6,7 +6,7 @@ import java.util.HashMap; import java.util.Map; import org.junit.Test; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.DefaultTypeConverter; import org.springframework.core.convert.support.MapToMap; @@ -15,8 +15,8 @@ public class MapToMapTests { @Test public void testMapToMapConversion() throws Exception { DefaultTypeConverter converter = new DefaultTypeConverter(); - MapToMap c = new MapToMap(new ConversionContext>(getClass().getField("source")), - new ConversionContext>(getClass().getField("bindTarget")), converter); + MapToMap c = new MapToMap(new TypeDescriptor>(getClass().getField("source")), + new TypeDescriptor>(getClass().getField("bindTarget")), converter); source.put("1", "BAR"); source.put("2", "BAZ"); Map result = (Map) c.execute(source); @@ -27,8 +27,8 @@ public class MapToMapTests { @Test public void testMapToMapConversionNoGenericInfoOnSource() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - MapToMap c = new MapToMap(ConversionContext.valueOf(Map.class), - new ConversionContext(getClass().getField("bindTarget")), service); + MapToMap c = new MapToMap(TypeDescriptor.valueOf(Map.class), + new TypeDescriptor(getClass().getField("bindTarget")), service); source.put("1", "BAR"); source.put("2", "BAZ"); Map result = (Map) c.execute(source); @@ -39,8 +39,8 @@ public class MapToMapTests { @Test public void testMapToMapConversionNoGenericInfo() throws Exception { DefaultTypeConverter service = new DefaultTypeConverter(); - MapToMap c = new MapToMap(ConversionContext.valueOf(Map.class), - ConversionContext.valueOf(Map.class), service); + MapToMap c = new MapToMap(TypeDescriptor.valueOf(Map.class), + TypeDescriptor.valueOf(Map.class), service); source.put("1", "BAR"); source.put("2", "BAZ"); Map result = (Map) c.execute(source); diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/TypeConverter.java b/org.springframework.expression/src/main/java/org/springframework/expression/TypeConverter.java index 78ae2cfa60f..e4422dd29db 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/TypeConverter.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/TypeConverter.java @@ -16,7 +16,7 @@ package org.springframework.expression; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; /** * A type converter can convert values between different types encountered @@ -48,7 +48,7 @@ public interface TypeConverter { * @return the converted value * @throws EvaluationException if conversion is not possible */ - Object convertValue(Object value, ConversionContext typeDescriptor) throws EvaluationException; + Object convertValue(Object value, TypeDescriptor typeDescriptor) throws EvaluationException; /** * Return true if the type converter can convert the specified type to the desired target type. @@ -64,6 +64,6 @@ public interface TypeConverter { * @param typeDescriptor a type descriptor that supplies extra information about the requested result type * @return true if that conversion can be performed */ - boolean canConvert(Class sourceType, ConversionContext typeDescriptor); + boolean canConvert(Class sourceType, TypeDescriptor typeDescriptor); } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/TypedValue.java b/org.springframework.expression/src/main/java/org/springframework/expression/TypedValue.java index 1ed0bcdd501..e98e6ef7d9f 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/TypedValue.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/TypedValue.java @@ -15,7 +15,7 @@ */ package org.springframework.expression; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; /** * Encapsulates an object and a type descriptor that describes it. @@ -28,9 +28,9 @@ import org.springframework.core.convert.ConversionContext; public class TypedValue { private Object value; - private ConversionContext typeDescriptor; + private TypeDescriptor typeDescriptor; - public static final TypedValue NULL_TYPED_VALUE = new TypedValue(null, ConversionContext.NULL); + public static final TypedValue NULL_TYPED_VALUE = new TypedValue(null, TypeDescriptor.NULL); /** * Create a TypedValue for a simple object. The type descriptor is inferred @@ -39,7 +39,7 @@ public class TypedValue { */ public TypedValue(Object value) { this.value = value; - this.typeDescriptor = ConversionContext.forObject(value); + this.typeDescriptor = TypeDescriptor.forObject(value); } /** @@ -47,7 +47,7 @@ public class TypedValue { * @param value the object value * @param typeDescriptor a type descriptor describing the type of the value */ - public TypedValue(Object value, ConversionContext typeDescriptor) { + public TypedValue(Object value, TypeDescriptor typeDescriptor) { this.value = value; this.typeDescriptor = typeDescriptor; } @@ -56,7 +56,7 @@ public class TypedValue { return this.value; } - public ConversionContext getTypeDescriptor() { + public TypeDescriptor getTypeDescriptor() { return this.typeDescriptor; } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java index d820b85d427..515b0c00561 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Map; import java.util.Stack; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; import org.springframework.expression.Operation; @@ -99,7 +99,7 @@ public class ExpressionState { if (value==null) { return TypedValue.NULL_TYPED_VALUE; } else { - return new TypedValue(value,ConversionContext.forObject(value)); + return new TypedValue(value,TypeDescriptor.forObject(value)); } } @@ -111,11 +111,11 @@ public class ExpressionState { return this.relatedContext.getTypeLocator().findType(type); } - public Object convertValue(Object value, ConversionContext targetTypeDescriptor) throws EvaluationException { + public Object convertValue(Object value, TypeDescriptor targetTypeDescriptor) throws EvaluationException { return this.relatedContext.getTypeConverter().convertValue(value, targetTypeDescriptor); } - public Object convertValue(TypedValue value, ConversionContext targetTypeDescriptor) throws EvaluationException { + public Object convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor) throws EvaluationException { return this.relatedContext.getTypeConverter().convertValue(value.getValue(), targetTypeDescriptor); } @@ -153,7 +153,7 @@ public class ExpressionState { OperatorOverloader overloader = this.relatedContext.getOperatorOverloader(); if (overloader.overridesOperation(op, left, right)) { Object returnValue = overloader.operate(op, left, right); - return new TypedValue(returnValue,ConversionContext.forObject(returnValue)); + return new TypedValue(returnValue,TypeDescriptor.forObject(returnValue)); } else { String leftType = (left==null?"null":left.getClass().getName()); diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/CommonTypeDescriptors.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/CommonTypeDescriptors.java index 9cfe891b606..4505025473b 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/CommonTypeDescriptors.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/CommonTypeDescriptors.java @@ -15,7 +15,7 @@ */ package org.springframework.expression.spel.ast; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; /** * @author Andy Clement @@ -23,16 +23,16 @@ import org.springframework.core.convert.ConversionContext; */ public interface CommonTypeDescriptors { // TODO push into TypeDescriptor? - static ConversionContext BOOLEAN_TYPE_DESCRIPTOR = ConversionContext.valueOf(Boolean.class); - static ConversionContext INTEGER_TYPE_DESCRIPTOR = ConversionContext.valueOf(Integer.class); - static ConversionContext CHARACTER_TYPE_DESCRIPTOR = ConversionContext.valueOf(Character.class); - static ConversionContext LONG_TYPE_DESCRIPTOR = ConversionContext.valueOf(Long.class); - static ConversionContext SHORT_TYPE_DESCRIPTOR = ConversionContext.valueOf(Short.class); - static ConversionContext BYTE_TYPE_DESCRIPTOR = ConversionContext.valueOf(Byte.class); - static ConversionContext FLOAT_TYPE_DESCRIPTOR = ConversionContext.valueOf(Float.class); - static ConversionContext DOUBLE_TYPE_DESCRIPTOR = ConversionContext.valueOf(Double.class); - static ConversionContext STRING_TYPE_DESCRIPTOR = ConversionContext.valueOf(String.class); - static ConversionContext CLASS_TYPE_DESCRIPTOR = ConversionContext.valueOf(Class.class); - static ConversionContext OBJECT_TYPE_DESCRIPTOR = ConversionContext.valueOf(Object.class); + static TypeDescriptor BOOLEAN_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Boolean.class); + static TypeDescriptor INTEGER_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Integer.class); + static TypeDescriptor CHARACTER_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Character.class); + static TypeDescriptor LONG_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Long.class); + static TypeDescriptor SHORT_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Short.class); + static TypeDescriptor BYTE_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Byte.class); + static TypeDescriptor FLOAT_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Float.class); + static TypeDescriptor DOUBLE_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Double.class); + static TypeDescriptor STRING_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(String.class); + static TypeDescriptor CLASS_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Class.class); + static TypeDescriptor OBJECT_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Object.class); } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java index 8cb83698b00..9721153c8db 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java @@ -22,7 +22,7 @@ import java.lang.reflect.Modifier; import org.antlr.runtime.Token; import org.springframework.core.MethodParameter; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypeConverter; import org.springframework.expression.TypedValue; @@ -104,7 +104,7 @@ public class FunctionReference extends SpelNodeImpl { try { ReflectionUtils.makeAccessible(m); Object result = m.invoke(m.getClass(), functionArgs); - return new TypedValue(result, new ConversionContext(new MethodParameter(m,-1))); + return new TypedValue(result, new TypeDescriptor(new MethodParameter(m,-1))); } catch (IllegalArgumentException e) { throw new SpelException(getCharPositionInLine(), e, SpelMessages.EXCEPTION_DURING_FUNCTION_CALL, name, e .getMessage()); diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java index 846d70adc9d..76e329555c2 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.Map; import org.antlr.runtime.Token; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypedValue; import org.springframework.expression.spel.ExpressionState; @@ -47,15 +47,15 @@ public class Indexer extends SpelNodeImpl { public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue context = state.getActiveContextObject(); Object targetObject = context.getValue(); - ConversionContext targetObjectTypeDescriptor = context.getTypeDescriptor(); + TypeDescriptor targetObjectTypeDescriptor = context.getTypeDescriptor(); TypedValue indexValue = getChild(0).getValueInternal(state); Object index = indexValue.getValue(); // Indexing into a Map if (targetObject instanceof Map) { - Object possiblyConvertedKey = state.convertValue(indexValue,ConversionContext.valueOf(targetObjectTypeDescriptor.getMapKeyType())); + Object possiblyConvertedKey = state.convertValue(indexValue,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getMapKeyType())); Object o = ((Map) targetObject).get(possiblyConvertedKey); - return new TypedValue(o,ConversionContext.valueOf(targetObjectTypeDescriptor.getMapValueType())); + return new TypedValue(o,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getMapValueType())); } int idx = (Integer)state.convertValue(index, INTEGER_TYPE_DESCRIPTOR); @@ -65,7 +65,7 @@ public class Indexer extends SpelNodeImpl { } if (targetObject.getClass().isArray()) { - return new TypedValue(accessArrayElement(targetObject, idx),ConversionContext.valueOf(targetObjectTypeDescriptor.getElementType())); + return new TypedValue(accessArrayElement(targetObject, idx),TypeDescriptor.valueOf(targetObjectTypeDescriptor.getElementType())); } else if (targetObject instanceof Collection) { Collection c = (Collection) targetObject; if (idx >= c.size()) { @@ -74,7 +74,7 @@ public class Indexer extends SpelNodeImpl { int pos = 0; for (Object o : c) { if (pos == idx) { - return new TypedValue(o,ConversionContext.valueOf(targetObjectTypeDescriptor.getElementType())); + return new TypedValue(o,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getElementType())); } pos++; } @@ -99,7 +99,7 @@ public class Indexer extends SpelNodeImpl { public void setValue(ExpressionState state, Object newValue) throws EvaluationException { TypedValue contextObject = state.getActiveContextObject(); Object targetObject = contextObject.getValue(); - ConversionContext targetObjectTypeDescriptor = contextObject.getTypeDescriptor(); + TypeDescriptor targetObjectTypeDescriptor = contextObject.getTypeDescriptor(); TypedValue index = getChild(0).getValueInternal(state); if (targetObject == null) { @@ -108,8 +108,8 @@ public class Indexer extends SpelNodeImpl { // Indexing into a Map if (targetObjectTypeDescriptor.isMap()) { Map map = (Map)targetObject; - Object possiblyConvertedKey = state.convertValue(index.getValue(),ConversionContext.valueOf(targetObjectTypeDescriptor.getMapKeyType())); - Object possiblyConvertedValue = state.convertValue(newValue,ConversionContext.valueOf(targetObjectTypeDescriptor.getMapValueType())); + Object possiblyConvertedKey = state.convertValue(index.getValue(),TypeDescriptor.valueOf(targetObjectTypeDescriptor.getMapKeyType())); + Object possiblyConvertedValue = state.convertValue(newValue,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getMapValueType())); map.put(possiblyConvertedKey,possiblyConvertedValue); return; } @@ -125,7 +125,7 @@ public class Indexer extends SpelNodeImpl { } if (targetObject instanceof List) { List list = (List)targetObject; - Object possiblyConvertedValue = state.convertValue(newValue,ConversionContext.valueOf(targetObjectTypeDescriptor.getElementType())); + Object possiblyConvertedValue = state.convertValue(newValue,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getElementType())); list.set(idx,possiblyConvertedValue); } else { throw new SpelException(SpelMessages.INDEXING_NOT_SUPPORTED_FOR_TYPE, contextObject.getClass().getName()); @@ -185,7 +185,7 @@ public class Indexer extends SpelNodeImpl { } else { Object[] array = (Object[]) ctx; checkAccess(array.length, idx); - array[idx] = state.convertValue(newValue, ConversionContext.valueOf(clazz)); + array[idx] = state.convertValue(newValue, TypeDescriptor.valueOf(clazz)); } } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorDivide.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorDivide.java index dc51a8949cb..4521d331d9c 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorDivide.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorDivide.java @@ -17,7 +17,7 @@ package org.springframework.expression.spel.ast; import org.antlr.runtime.Token; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationException; import org.springframework.expression.Operation; import org.springframework.expression.TypedValue; @@ -56,7 +56,7 @@ public class OperatorDivide extends Operator { } } Object result = state.operate(Operation.DIVIDE, operandOne, operandTwo); - return new TypedValue(result,ConversionContext.forObject(result)); + return new TypedValue(result,TypeDescriptor.forObject(result)); } } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Projection.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Projection.java index 57230c234da..1e22430aa5d 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Projection.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Projection.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.Map; import org.antlr.runtime.Token; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypedValue; import org.springframework.expression.spel.ExpressionState; @@ -60,13 +60,13 @@ public class Projection extends SpelNodeImpl { List result = new ArrayList(); for (Map.Entry entry : mapdata.entrySet()) { try { - state.pushActiveContextObject(new TypedValue(entry,ConversionContext.valueOf(Map.Entry.class))); + state.pushActiveContextObject(new TypedValue(entry,TypeDescriptor.valueOf(Map.Entry.class))); result.add(getChild(0).getValueInternal(state).getValue()); } finally { state.popActiveContextObject(); } } - return new TypedValue(result,ConversionContext.valueOf(List.class)); // TODO unable to build correct type descriptor + return new TypedValue(result,TypeDescriptor.valueOf(List.class)); // TODO unable to build correct type descriptor } else if (operand instanceof List) { List data = new ArrayList(); data.addAll((Collection) operand); @@ -74,7 +74,7 @@ public class Projection extends SpelNodeImpl { int idx = 0; for (Object element : data) { try { - state.pushActiveContextObject(new TypedValue(element,ConversionContext.valueOf(op.getTypeDescriptor().getType()))); + state.pushActiveContextObject(new TypedValue(element,TypeDescriptor.valueOf(op.getTypeDescriptor().getType()))); state.enterScope("index", idx); result.add(getChild(0).getValueInternal(state).getValue()); } finally { diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Selection.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Selection.java index 8039c061fab..8efaffefb56 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Selection.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Selection.java @@ -23,7 +23,7 @@ import java.util.List; import java.util.Map; import org.antlr.runtime.Token; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypedValue; import org.springframework.expression.spel.ExpressionState; @@ -66,7 +66,7 @@ public class Selection extends SpelNodeImpl { for (Map.Entry entry : mapdata.entrySet()) { try { lastKey = entry.getKey(); - TypedValue kvpair = new TypedValue(entry,ConversionContext.valueOf(Map.Entry.class)); + TypedValue kvpair = new TypedValue(entry,TypeDescriptor.valueOf(Map.Entry.class)); state.pushActiveContextObject(kvpair); Object o = selectionCriteria.getValueInternal(state).getValue(); if (o instanceof Boolean) { @@ -86,13 +86,13 @@ public class Selection extends SpelNodeImpl { } } if ((variant == FIRST || variant == LAST) && result.size() == 0) { - return new TypedValue(null,ConversionContext.NULL); + return new TypedValue(null,TypeDescriptor.NULL); } if (variant == LAST) { Map resultMap = new HashMap(); Object lastValue = result.get(lastKey); resultMap.put(lastKey,lastValue); - return new TypedValue(resultMap,ConversionContext.valueOf(Map.class)); + return new TypedValue(resultMap,TypeDescriptor.valueOf(Map.class)); } return new TypedValue(result,op.getTypeDescriptor()); } else if (operand instanceof Collection) { @@ -102,13 +102,13 @@ public class Selection extends SpelNodeImpl { int idx = 0; for (Object element : data) { try { - state.pushActiveContextObject(new TypedValue(element,ConversionContext.valueOf(op.getTypeDescriptor().getElementType()))); + state.pushActiveContextObject(new TypedValue(element,TypeDescriptor.valueOf(op.getTypeDescriptor().getElementType()))); state.enterScope("index", idx); Object o = selectionCriteria.getValueInternal(state).getValue(); if (o instanceof Boolean) { if (((Boolean) o).booleanValue() == true) { if (variant == FIRST) { - return new TypedValue(element,ConversionContext.valueOf(op.getTypeDescriptor().getElementType())); + return new TypedValue(element,TypeDescriptor.valueOf(op.getTypeDescriptor().getElementType())); } result.add(element); } @@ -126,7 +126,7 @@ public class Selection extends SpelNodeImpl { return TypedValue.NULL_TYPED_VALUE; } if (variant == LAST) { - return new TypedValue(result.get(result.size() - 1),ConversionContext.valueOf(op.getTypeDescriptor().getElementType())); + return new TypedValue(result.get(result.size() - 1),TypeDescriptor.valueOf(op.getTypeDescriptor().getElementType())); } return new TypedValue(result,op.getTypeDescriptor()); } else { diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorExecutor.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorExecutor.java index c0dd5c391bd..fa2a4478d23 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorExecutor.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorExecutor.java @@ -18,7 +18,7 @@ package org.springframework.expression.spel.support; import java.lang.reflect.Constructor; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.AccessException; import org.springframework.expression.ConstructorExecutor; import org.springframework.expression.EvaluationContext; @@ -56,7 +56,7 @@ class ReflectiveConstructorExecutor implements ConstructorExecutor { if (!c.isAccessible()) { c.setAccessible(true); } - return new TypedValue(c.newInstance(arguments),ConversionContext.valueOf(c.getClass())); + return new TypedValue(c.newInstance(arguments),TypeDescriptor.valueOf(c.getClass())); } catch (Exception ex) { throw new AccessException("Problem invoking constructor: " + c, ex); } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java index bf2676a43bc..4cdf47346aa 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java @@ -19,7 +19,7 @@ package org.springframework.expression.spel.support; import java.lang.reflect.Method; import org.springframework.core.MethodParameter; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; import org.springframework.expression.MethodExecutor; @@ -55,7 +55,7 @@ class ReflectiveMethodExecutor implements MethodExecutor { arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.method.getParameterTypes(), arguments); } ReflectionUtils.makeAccessible(this.method); - return new TypedValue(this.method.invoke(target, arguments), new ConversionContext(new MethodParameter(method,-1))); + return new TypedValue(this.method.invoke(target, arguments), new TypeDescriptor(new MethodParameter(method,-1))); } catch (Exception ex) { throw new AccessException("Problem invoking method: " + this.method, ex); } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyResolver.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyResolver.java index d317d6bad3f..b318d3fc34f 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyResolver.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyResolver.java @@ -25,7 +25,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.springframework.core.MethodParameter; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; @@ -48,7 +48,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor { protected final Map writerCache = new ConcurrentHashMap(); - protected final Map typeDescriptorCache = new ConcurrentHashMap(); + protected final Map typeDescriptorCache = new ConcurrentHashMap(); /** * @return null which means this is a general purpose accessor @@ -72,14 +72,14 @@ public class ReflectivePropertyResolver implements PropertyAccessor { Method method = findGetterForProperty(name, type, target instanceof Class); if (method != null) { this.readerCache.put(cacheKey, method); - this.typeDescriptorCache.put(cacheKey, new ConversionContext(new MethodParameter(method,-1))); + this.typeDescriptorCache.put(cacheKey, new TypeDescriptor(new MethodParameter(method,-1))); return true; } else { Field field = findField(name, type, target instanceof Class); if (field != null) { this.readerCache.put(cacheKey, field); - this.typeDescriptorCache.put(cacheKey, new ConversionContext(field)); + this.typeDescriptorCache.put(cacheKey, new TypeDescriptor(field)); return true; } } @@ -96,7 +96,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor { if (target instanceof Class) { throw new AccessException("Cannot access length on array class itself"); } - return new TypedValue(Array.getLength(target),ConversionContext.valueOf(Integer.TYPE)); + return new TypedValue(Array.getLength(target),TypeDescriptor.valueOf(Integer.TYPE)); } CacheKey cacheKey = new CacheKey(type, name); @@ -114,7 +114,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor { if (method != null) { try { ReflectionUtils.makeAccessible(method); - ConversionContext resultTypeDescriptor = new ConversionContext(new MethodParameter(method,-1)); + TypeDescriptor resultTypeDescriptor = new TypeDescriptor(new MethodParameter(method,-1)); return new TypedValue(method.invoke(target),resultTypeDescriptor); } catch (Exception ex) { @@ -135,7 +135,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor { if (field != null) { try { ReflectionUtils.makeAccessible(field); - return new TypedValue(field.get(target),new ConversionContext(field)); + return new TypedValue(field.get(target),new TypeDescriptor(field)); } catch (Exception ex) { throw new AccessException("Unable to access field: " + name, ex); @@ -158,14 +158,14 @@ public class ReflectivePropertyResolver implements PropertyAccessor { Method method = findSetterForProperty(name, type, target instanceof Class); if (method != null) { this.writerCache.put(cacheKey, method); - this.typeDescriptorCache.put(cacheKey, new ConversionContext(new MethodParameter(method,0))); + this.typeDescriptorCache.put(cacheKey, new TypeDescriptor(new MethodParameter(method,0))); return true; } else { Field field = findField(name, type, target instanceof Class); if (field != null) { this.writerCache.put(cacheKey, field); - this.typeDescriptorCache.put(cacheKey, new ConversionContext(field)); + this.typeDescriptorCache.put(cacheKey, new TypeDescriptor(field)); return true; } } @@ -179,7 +179,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor { Class type = (target instanceof Class ? (Class) target : target.getClass()); Object possiblyConvertedNewValue = newValue; - ConversionContext typeDescriptor = getTypeDescriptor(context, target, name); + TypeDescriptor typeDescriptor = getTypeDescriptor(context, target, name); if (typeDescriptor != null) { try { possiblyConvertedNewValue = context.getTypeConverter().convertValue(newValue, typeDescriptor); @@ -236,17 +236,17 @@ public class ReflectivePropertyResolver implements PropertyAccessor { throw new AccessException("Neither setter nor field found for property '" + name + "'"); } - private ConversionContext getTypeDescriptor(EvaluationContext context, Object target, String name) { + private TypeDescriptor getTypeDescriptor(EvaluationContext context, Object target, String name) { if (target == null) { return null; } Class type = (target instanceof Class ? (Class) target : target.getClass()); if (type.isArray() && name.equals("length")) { - return ConversionContext.valueOf(Integer.TYPE); + return TypeDescriptor.valueOf(Integer.TYPE); } CacheKey cacheKey = new CacheKey(type, name); - ConversionContext typeDescriptor = this.typeDescriptorCache.get(cacheKey); + TypeDescriptor typeDescriptor = this.typeDescriptorCache.get(cacheKey); if (typeDescriptor == null) { // attempt to populate the cache entry try { diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java index 369e1763985..b02029cbf04 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java @@ -22,7 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.ConstructorResolver; import org.springframework.expression.EvaluationContext; import org.springframework.expression.MethodResolver; @@ -75,10 +75,10 @@ public class StandardEvaluationContext implements EvaluationContext { } public void setRootObject(Object rootObject) { - this.rootObject = new TypedValue(rootObject,ConversionContext.forObject(rootObject)); + this.rootObject = new TypedValue(rootObject,TypeDescriptor.forObject(rootObject)); } - public void setRootObject(Object rootObject, ConversionContext typeDescriptor) { + public void setRootObject(Object rootObject, TypeDescriptor typeDescriptor) { this.rootObject = new TypedValue(rootObject,typeDescriptor); } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java index 36f130c7535..23c7b9af27e 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java @@ -18,7 +18,7 @@ package org.springframework.expression.spel.support; import org.springframework.core.convert.ConvertException; import org.springframework.core.convert.ConverterNotFoundException; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.DefaultTypeConverter; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypeConverter; @@ -46,11 +46,11 @@ public class StandardTypeConverter implements TypeConverter { @SuppressWarnings("unchecked") public T convertValue(Object value, Class targetType) throws EvaluationException { - return (T) convertValue(value, ConversionContext.valueOf(targetType)); + return (T) convertValue(value, TypeDescriptor.valueOf(targetType)); } @SuppressWarnings("unchecked") - public Object convertValue(Object value, ConversionContext typeDescriptor) throws EvaluationException { + public Object convertValue(Object value, TypeDescriptor typeDescriptor) throws EvaluationException { try { return this.typeConverter.convert(value, typeDescriptor); } @@ -63,10 +63,10 @@ public class StandardTypeConverter implements TypeConverter { } public boolean canConvert(Class sourceType, Class targetType) { - return canConvert(sourceType, ConversionContext.valueOf(targetType)); + return canConvert(sourceType, TypeDescriptor.valueOf(targetType)); } - public boolean canConvert(Class sourceType, ConversionContext targetType) { + public boolean canConvert(Class sourceType, TypeDescriptor targetType) { return this.typeConverter.canConvert(sourceType, targetType); } diff --git a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionLanguageScenarioTests.java b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionLanguageScenarioTests.java index 89a313e38e2..ab6ce9f4815 100644 --- a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionLanguageScenarioTests.java +++ b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionLanguageScenarioTests.java @@ -23,7 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; @@ -236,7 +236,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase { private static class FruitColourAccessor implements PropertyAccessor { private static Map propertyMap = new HashMap(); - private static ConversionContext mapElementTypeDescriptor = ConversionContext.valueOf(Color.class); + private static TypeDescriptor mapElementTypeDescriptor = TypeDescriptor.valueOf(Color.class); static { propertyMap.put("banana",Color.yellow); @@ -295,7 +295,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase { } public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException { - return new TypedValue(propertyMap.get(name),ConversionContext.valueOf(Color.class)); + return new TypedValue(propertyMap.get(name),TypeDescriptor.valueOf(Color.class)); } public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException { diff --git a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionStateTests.java b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionStateTests.java index c4d18e18ed0..d8e198f2b20 100644 --- a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionStateTests.java +++ b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionStateTests.java @@ -18,7 +18,7 @@ package org.springframework.expression.spel; import java.util.HashMap; import java.util.Map; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; import org.springframework.expression.Operation; @@ -117,7 +117,7 @@ public class ExpressionStateTests extends ExpressionTestCase { assertEquals(TypedValue.NULL_TYPED_VALUE,state.getRootContextObject()); - ((StandardEvaluationContext)state.getEvaluationContext()).setRootObject(null,ConversionContext.NULL); + ((StandardEvaluationContext)state.getEvaluationContext()).setRootObject(null,TypeDescriptor.NULL); assertEquals(null,state.getRootContextObject().getValue()); } @@ -222,10 +222,10 @@ public class ExpressionStateTests extends ExpressionTestCase { public void testTypeConversion() throws EvaluationException { ExpressionState state = getState(); - String s = (String)state.convertValue(34,ConversionContext.valueOf(String.class)); + String s = (String)state.convertValue(34,TypeDescriptor.valueOf(String.class)); assertEquals("34",s); - s = (String)state.convertValue(new TypedValue(34),ConversionContext.valueOf(String.class)); + s = (String)state.convertValue(new TypedValue(34),TypeDescriptor.valueOf(String.class)); assertEquals("34",s); } diff --git a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java index 25872c2fd2d..76fa7ef3505 100644 --- a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java +++ b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java @@ -19,7 +19,7 @@ package org.springframework.expression.spel; import java.util.ArrayList; import java.util.List; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.DefaultTypeConverter; import org.springframework.core.convert.support.GenericTypeConverter; import org.springframework.expression.EvaluationException; @@ -35,9 +35,9 @@ import org.springframework.expression.spel.support.StandardEvaluationContext; public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCase { private static List listOfString = new ArrayList(); - private static ConversionContext typeDescriptorForListOfString = null; + private static TypeDescriptor typeDescriptorForListOfString = null; private static List listOfInteger = new ArrayList(); - private static ConversionContext typeDescriptorForListOfInteger = null; + private static TypeDescriptor typeDescriptorForListOfInteger = null; static { listOfString.add("1"); @@ -50,8 +50,8 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas public void setUp() throws Exception { super.setUp(); - typeDescriptorForListOfString = new ConversionContext(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfString")); - typeDescriptorForListOfInteger = new ConversionContext(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfInteger")); + typeDescriptorForListOfString = new TypeDescriptor(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfString")); + typeDescriptorForListOfInteger = new TypeDescriptor(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfInteger")); } @@ -96,20 +96,20 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas private final DefaultTypeConverter service = new DefaultTypeConverter(); public boolean canConvert(Class sourceType, Class targetType) { - return this.service.canConvert(sourceType, ConversionContext.valueOf(targetType)); + return this.service.canConvert(sourceType, TypeDescriptor.valueOf(targetType)); } - public boolean canConvert(Class sourceType, ConversionContext typeDescriptor) { + public boolean canConvert(Class sourceType, TypeDescriptor typeDescriptor) { return this.service.canConvert(sourceType, typeDescriptor); } @SuppressWarnings("unchecked") public T convertValue(Object value, Class targetType) throws EvaluationException { - return (T) this.service.convert(value,ConversionContext.valueOf(targetType)); + return (T) this.service.convert(value,TypeDescriptor.valueOf(targetType)); } @SuppressWarnings("unchecked") - public Object convertValue(Object value, ConversionContext typeDescriptor) throws EvaluationException { + public Object convertValue(Object value, TypeDescriptor typeDescriptor) throws EvaluationException { return this.service.convert(value, typeDescriptor); } } diff --git a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ScenariosForSpringSecurity.java b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ScenariosForSpringSecurity.java index 10497815488..f6ef4865f1a 100644 --- a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ScenariosForSpringSecurity.java +++ b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ScenariosForSpringSecurity.java @@ -19,7 +19,7 @@ package org.springframework.expression.spel; import java.lang.reflect.Method; import org.springframework.core.MethodParameter; -import org.springframework.core.convert.ConversionContext; +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; @@ -214,7 +214,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase { } public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException { - return new TypedValue(new Principal(),ConversionContext.valueOf(Principal.class)); + return new TypedValue(new Principal(),TypeDescriptor.valueOf(Principal.class)); } public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException { @@ -244,7 +244,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase { } public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException { - return new TypedValue(activePerson,ConversionContext.valueOf(Person.class)); + return new TypedValue(activePerson,TypeDescriptor.valueOf(Person.class)); } public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException { @@ -283,7 +283,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase { if (m.isVarArgs()) { args = ReflectionHelper.setupArgumentsForVarargsInvocation(m.getParameterTypes(), args); } - return new TypedValue(m.invoke(null, args), new ConversionContext(new MethodParameter(m,-1))); + return new TypedValue(m.invoke(null, args), new TypeDescriptor(new MethodParameter(m,-1))); } catch (Exception ex) { throw new AccessException("Problem invoking hasRole", ex);