costin code review comments

This commit is contained in:
Keith Donald 2009-05-18 13:13:34 +00:00
parent 0cc3542aed
commit 8cbab5acb6
39 changed files with 242 additions and 255 deletions

View File

@ -17,7 +17,7 @@
package org.springframework.context.expression; package org.springframework.context.expression;
import org.springframework.beans.factory.config.BeanExpressionContext; import org.springframework.beans.factory.config.BeanExpressionContext;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.AccessException; import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.PropertyAccessor; import org.springframework.expression.PropertyAccessor;

View File

@ -17,7 +17,7 @@
package org.springframework.context.expression; package org.springframework.context.expression;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.AccessException; import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.PropertyAccessor; import org.springframework.expression.PropertyAccessor;

View File

@ -27,19 +27,19 @@ import org.springframework.util.Assert;
// TODO doesn't support more than depth of one (eg. Map<String,List<Foo>> or List<String>[]) // TODO doesn't support more than depth of one (eg. Map<String,List<Foo>> or List<String>[])
/** /**
* A point where conversion needs to be performed. Provides additional context about the point such * Context about a point where conversion needs to be performed. Provides context about the point such
* as field or method parameter information. * as field or method parameter information.
* *
* @author Keith Donald * @author Keith Donald
* @author Andy Clement * @author Andy Clement
*/ */
public class ConversionPoint<T> { public class ConversionContext<T> {
/** /**
* Constant value typeDescriptor for the type of a null value * Constant value for the null object
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public final static ConversionPoint NULL = new ConversionPoint((Class<?>) null); public final static ConversionContext NULL = new ConversionContext((Class<?>) null);
private MethodParameter methodParameter; private MethodParameter methodParameter;
@ -50,36 +50,35 @@ public class ConversionPoint<T> {
private Class<?> type; private Class<?> type;
/** /**
* Creates a new descriptor for the given type. Use this constructor when a bound value comes from a source such as * 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. * a Map or collection, where no additional binding metadata is available.
* @param type the actual type * @param type the actual type
*/ */
public ConversionPoint(Class<?> type) { public ConversionContext(Class<?> type) {
this.type = type; this.type = type;
} }
/** /**
* Create a new descriptor for a method or constructor parameter. Use this constructor when a bound value originates * 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. * from a method parameter, such as a setter method argument.
* @param methodParameter the MethodParameter to wrap * @param methodParameter the MethodParameter to wrap
*/ */
public ConversionPoint(MethodParameter methodParameter) { public ConversionContext(MethodParameter methodParameter) {
Assert.notNull(methodParameter, "MethodParameter must not be null"); Assert.notNull(methodParameter, "MethodParameter must not be null");
this.methodParameter = methodParameter; this.methodParameter = methodParameter;
} }
/** /**
* Create a new descriptor for a field. Use this constructor when a bound value originates from a field. * Create a new context for a field. Use this constructor when a conversion point originates from a field.
* @param field the field to wrap * @param field the field to wrap
*/ */
public ConversionPoint(Field field) { public ConversionContext(Field field) {
Assert.notNull(field, "Field must not be null"); Assert.notNull(field, "Field must not be null");
this.field = field; this.field = field;
} }
/** /**
* Determine the declared (non-generic) type of the wrapped parameter/field. * Determine the declared (non-generic) type of the wrapped parameter/field.
*
* @return the declared type (never <code>null</code>) * @return the declared type (never <code>null</code>)
*/ */
public Class<?> getType() { public Class<?> getType() {
@ -247,7 +246,7 @@ public class ConversionPoint<T> {
* @return true if this type is assignable to the target * @return true if this type is assignable to the target
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public boolean isAssignableTo(ConversionPoint targetType) { public boolean isAssignableTo(ConversionContext targetType) {
return targetType.getType().isAssignableFrom(getType()); return targetType.getType().isAssignableFrom(getType());
} }
@ -256,9 +255,9 @@ public class ConversionPoint<T> {
* @param type the class * @param type the class
* @return the type descriptor * @return the type descriptor
*/ */
public static <T> ConversionPoint<T> valueOf(Class<T> type) { public static <T> ConversionContext<T> valueOf(Class<T> type) {
// TODO needs a cache for common type descriptors // TODO needs a cache for common type descriptors
return new ConversionPoint<T>(type); return new ConversionContext<T>(type);
} }
/** /**
@ -267,7 +266,7 @@ public class ConversionPoint<T> {
* @return the type descriptor * @return the type descriptor
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static ConversionPoint forObject(Object object) { public static ConversionContext forObject(Object object) {
if (object == null) { if (object == null) {
return NULL; return NULL;
} else { } else {

View File

@ -19,7 +19,7 @@ package org.springframework.core.convert;
* A service interface for type conversion. This is the entry point into the convert system. * A service interface for type conversion. This is the entry point into the convert system.
* <p> * <p>
* Call {@link #convert(Object, Class)} to perform a thread-safe type conversion using this system.<br> * Call {@link #convert(Object, Class)} to perform a thread-safe type conversion using this system.<br>
* Call {@link #convert(Object, ConversionPoint)} to perform a conversion with additional context about the point * Call {@link #convert(Object, ConversionContext)} to perform a conversion with additional context about the point
* where conversion needs to occur. * where conversion needs to occur.
* *
* @author Keith Donald * @author Keith Donald
@ -37,10 +37,10 @@ public interface TypeConverter {
/** /**
* Returns true if objects of sourceType can be converted to the type of the conversion point. * 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 source the source to convert from (may be null)
* @param point context about the point where conversion would occur * @param context context about the point where conversion would occur
* @return true if a conversion can be performed, false if not * @return true if a conversion can be performed, false if not
*/ */
boolean canConvert(Class<?> sourceType, ConversionPoint<?> point); boolean canConvert(Class<?> sourceType, ConversionContext<?> context);
/** /**
* Convert the source to targetType. * Convert the source to targetType.
@ -54,10 +54,10 @@ public interface TypeConverter {
/** /**
* Convert the source to type T needed by the conversion point. * Convert the source to type T needed by the conversion point.
* @param source the source to convert from (may be null) * @param source the source to convert from (may be null)
* @param point context about the point where conversion will occur * @param context context about the point where conversion will occur
* @return the converted object, an instance of {@link ConversionPoint#getType()}</code>, or <code>null</code> if a null source was provided * @return the converted object, an instance of {@link ConversionContext#getType()}</code>, or <code>null</code> if a null source was provided
* @throws ConvertException if an exception occurred * @throws ConvertException if an exception occurred
*/ */
<S, T> T convert(S source, ConversionPoint<T> point); <S, T> T convert(S source, ConversionContext<T> context);
} }

View File

@ -24,21 +24,17 @@ public interface ConverterRegistry {
/** /**
* Add a converter to this registry. * Add a converter to this registry.
*/ */
void addConverter(Converter<?, ?> converter); void add(Converter<?, ?> converter);
/** /**
* Add a converter factory to this registry. * Add a converter factory to this registry.
*/ */
void addConverterFactory(ConverterFactory<?, ?> converterFactory); void add(ConverterFactory<?, ?> converterFactory);
/** /**
* Remove a converter from this registry. * Remove the conversion logic from the sourceType to the targetType.
* @param sourceType the source type
* @param targetType the target type
*/ */
void removeConverter(Converter<?, ?> converter); void removeConverter(Class<?> sourceType, Class<?> targetType);
/**
* Remove a converter factory from this registry.
*/
void removeConverterFactory(ConverterFactory<?, ?> converterFactory);
} }

View File

@ -16,7 +16,7 @@
package org.springframework.core.convert.support; package org.springframework.core.convert.support;
import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
/** /**
* Base class for converters that convert to and from collection types (arrays and java.util.Collection types) * 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 ConversionExecutor elementConverter;
private ConversionPoint sourceCollectionType; private ConversionContext sourceCollectionType;
private ConversionPoint targetCollectionType; private ConversionContext targetCollectionType;
public AbstractCollectionConverter(ConversionPoint sourceCollectionType, ConversionPoint targetCollectionType, GenericTypeConverter conversionService) { public AbstractCollectionConverter(ConversionContext sourceCollectionType, ConversionContext targetCollectionType, GenericTypeConverter conversionService) {
this.conversionService = conversionService; this.conversionService = conversionService;
this.sourceCollectionType = sourceCollectionType; this.sourceCollectionType = sourceCollectionType;
this.targetCollectionType = targetCollectionType; this.targetCollectionType = targetCollectionType;
Class<?> sourceElementType = sourceCollectionType.getElementType(); Class<?> sourceElementType = sourceCollectionType.getElementType();
Class<?> targetElementType = targetCollectionType.getElementType(); Class<?> targetElementType = targetCollectionType.getElementType();
if (sourceElementType != null && targetElementType != null) { if (sourceElementType != null && targetElementType != null) {
elementConverter = conversionService.getConversionExecutor(sourceElementType, ConversionPoint.valueOf(targetElementType)); elementConverter = conversionService.getConversionExecutor(sourceElementType, ConversionContext.valueOf(targetElementType));
} else { } else {
elementConverter = NoOpConversionExecutor.INSTANCE; elementConverter = NoOpConversionExecutor.INSTANCE;
} }

View File

@ -18,7 +18,7 @@ package org.springframework.core.convert.support;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import org.springframework.core.convert.TypeConverter; import org.springframework.core.convert.TypeConverter;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
/** /**
* Special one-way converter that converts from a source array to a target array. Supports type conversion of the * 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.ConversionPoint;
*/ */
class ArrayToArray extends AbstractCollectionConverter { class ArrayToArray extends AbstractCollectionConverter {
public ArrayToArray(ConversionPoint sourceArrayType, ConversionPoint targetArrayType, GenericTypeConverter conversionService) { public ArrayToArray(ConversionContext sourceArrayType, ConversionContext targetArrayType, GenericTypeConverter conversionService) {
super(sourceArrayType, targetArrayType, conversionService); super(sourceArrayType, targetArrayType, conversionService);
} }

View File

@ -18,7 +18,7 @@ package org.springframework.core.convert.support;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.Collection; import java.util.Collection;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
/** /**
* Special converter that converts from a source array to a target collection. Supports the selection of an * 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.ConversionPoint;
*/ */
class ArrayToCollection extends AbstractCollectionConverter { class ArrayToCollection extends AbstractCollectionConverter {
public ArrayToCollection(ConversionPoint sourceArrayType, ConversionPoint targetCollectionType, public ArrayToCollection(ConversionContext sourceArrayType, ConversionContext targetCollectionType,
GenericTypeConverter conversionService) { GenericTypeConverter conversionService) {
super(sourceArrayType, targetCollectionType, conversionService); super(sourceArrayType, targetCollectionType, conversionService);
} }

View File

@ -19,7 +19,7 @@ import java.lang.reflect.Array;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
/** /**
* Special converter that converts from target collection to a source array. * Special converter that converts from target collection to a source array.
@ -28,7 +28,7 @@ import org.springframework.core.convert.ConversionPoint;
*/ */
class CollectionToArray extends AbstractCollectionConverter { class CollectionToArray extends AbstractCollectionConverter {
public CollectionToArray(ConversionPoint sourceArrayType, ConversionPoint targetCollectionType, public CollectionToArray(ConversionContext sourceArrayType, ConversionContext targetCollectionType,
GenericTypeConverter conversionService) { GenericTypeConverter conversionService) {
super(sourceArrayType, targetCollectionType, conversionService); super(sourceArrayType, targetCollectionType, conversionService);
} }
@ -52,7 +52,7 @@ class CollectionToArray extends AbstractCollectionConverter {
while (it.hasNext()) { while (it.hasNext()) {
Object value = it.next(); Object value = it.next();
if (value != null) { if (value != null) {
elementConverter = getConversionService().getConversionExecutor(value.getClass(), ConversionPoint.valueOf(getTargetElementType())); elementConverter = getConversionService().getConversionExecutor(value.getClass(), ConversionContext.valueOf(getTargetElementType()));
break; break;
} }
} }

View File

@ -18,7 +18,7 @@ package org.springframework.core.convert.support;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
/** /**
* A converter that can convert from one collection type to another. * A converter that can convert from one collection type to another.
@ -27,7 +27,7 @@ import org.springframework.core.convert.ConversionPoint;
*/ */
class CollectionToCollection extends AbstractCollectionConverter { class CollectionToCollection extends AbstractCollectionConverter {
public CollectionToCollection(ConversionPoint sourceCollectionType, ConversionPoint targetCollectionType, public CollectionToCollection(ConversionContext sourceCollectionType, ConversionContext targetCollectionType,
GenericTypeConverter conversionService) { GenericTypeConverter conversionService) {
super(sourceCollectionType, targetCollectionType, conversionService); super(sourceCollectionType, targetCollectionType, conversionService);
} }
@ -53,7 +53,7 @@ class CollectionToCollection extends AbstractCollectionConverter {
while (it.hasNext()) { while (it.hasNext()) {
Object value = it.next(); Object value = it.next();
if (value != null) { if (value != null) {
elementConverter = getConversionService().getConversionExecutor(value.getClass(), ConversionPoint.valueOf(getTargetElementType())); elementConverter = getConversionService().getConversionExecutor(value.getClass(), ConversionContext.valueOf(getTargetElementType()));
break; break;
} }
} }

View File

@ -35,22 +35,22 @@ public class DefaultTypeConverter extends GenericTypeConverter {
* Add all default converters to the conversion service. * Add all default converters to the conversion service.
*/ */
protected void addDefaultConverters() { protected void addDefaultConverters() {
addConverter(new StringToByte()); add(new StringToByte());
addConverter(new StringToBoolean()); add(new StringToBoolean());
addConverter(new StringToCharacter()); add(new StringToCharacter());
addConverter(new StringToShort()); add(new StringToShort());
addConverter(new StringToInteger()); add(new StringToInteger());
addConverter(new StringToLong()); add(new StringToLong());
addConverter(new StringToFloat()); add(new StringToFloat());
addConverter(new StringToDouble()); add(new StringToDouble());
addConverter(new StringToBigInteger()); add(new StringToBigInteger());
addConverter(new StringToBigDecimal()); add(new StringToBigDecimal());
addConverter(new StringToLocale()); add(new StringToLocale());
addConverter(new NumberToCharacter()); add(new NumberToCharacter());
addConverter(new ObjectToString()); add(new ObjectToString());
addConverterFactory(new StringToEnumFactory()); add(new StringToEnumFactory());
addConverterFactory(new NumberToNumberFactory()); add(new NumberToNumberFactory());
addConverterFactory(new CharacterToNumberFactory()); add(new CharacterToNumberFactory());
} }
} }

View File

@ -26,7 +26,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.core.GenericTypeResolver; import org.springframework.core.GenericTypeResolver;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeConverter; import org.springframework.core.convert.TypeConverter;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
@ -71,11 +71,9 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
this.parent = parent; this.parent = parent;
} }
/** // implementing ConverterRegistry
* Register the Converter with this conversion service.
* @param converter the converter to register public void add(Converter converter) {
*/
public void addConverter(Converter converter) {
List typeInfo = getRequiredTypeInfo(converter); List typeInfo = getRequiredTypeInfo(converter);
Class sourceType = (Class) typeInfo.get(0); Class sourceType = (Class) typeInfo.get(0);
Class targetType = (Class) typeInfo.get(1); Class targetType = (Class) typeInfo.get(1);
@ -83,7 +81,7 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
sourceMap.put(targetType, converter); sourceMap.put(targetType, converter);
} }
public void addConverterFactory(ConverterFactory<?, ?> converterFactory) { public void add(ConverterFactory<?, ?> converterFactory) {
List typeInfo = getRequiredTypeInfo(converterFactory); List typeInfo = getRequiredTypeInfo(converterFactory);
Class sourceType = (Class) typeInfo.get(0); Class sourceType = (Class) typeInfo.get(0);
Class targetType = (Class) typeInfo.get(1); Class targetType = (Class) typeInfo.get(1);
@ -91,15 +89,9 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
sourceMap.put(targetType, converterFactory); sourceMap.put(targetType, converterFactory);
} }
public void removeConverter(Converter<?, ?> converter) { public void removeConverter(Class<?> sourceType, Class<?> targetType) {
List typeInfo = getRequiredTypeInfo(converter);
Class sourceType = (Class) typeInfo.get(0);
Class targetType = (Class) typeInfo.get(1);
Map sourceMap = getSourceMap(sourceType); Map sourceMap = getSourceMap(sourceType);
Converter existing = (Converter) sourceMap.get(targetType); sourceMap.remove(targetType);
if (converter == existing) {
sourceMap.remove(targetType);
}
} }
public void removeConverterFactory(ConverterFactory<?, ?> converter) { public void removeConverterFactory(ConverterFactory<?, ?> converter) {
@ -113,19 +105,19 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
} }
} }
// implementing ConversionService // implementing TypeConverter
public boolean canConvert(Class<?> sourceType, Class<?> targetType) { public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
return canConvert(sourceType, ConversionPoint.valueOf(targetType)); return canConvert(sourceType, ConversionContext.valueOf(targetType));
} }
public boolean canConvert(Class<?> sourceType, ConversionPoint<?> targetType) { public boolean canConvert(Class<?> sourceType, ConversionContext<?> context) {
ConversionExecutor executor = getConversionExecutor(sourceType, targetType); ConversionExecutor executor = getConversionExecutor(sourceType, context);
if (executor != null) { if (executor != null) {
return true; return true;
} else { } else {
if (parent != null) { if (parent != null) {
return parent.canConvert(sourceType, targetType); return parent.canConvert(sourceType, context);
} else { } else {
return false; return false;
} }
@ -133,28 +125,28 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
} }
public <S, T> T convert(S source, Class<T> targetType) { public <S, T> T convert(S source, Class<T> targetType) {
return convert(source, ConversionPoint.valueOf(targetType)); return convert(source, ConversionContext.valueOf(targetType));
} }
public <S, T> T convert(S source, ConversionPoint<T> targetType) { public <S, T> T convert(S source, ConversionContext<T> context) {
if (source == null) { if (source == null) {
return null; return null;
} }
ConversionExecutor executor = getConversionExecutor(source.getClass(), targetType); ConversionExecutor executor = getConversionExecutor(source.getClass(), context);
if (executor != null) { if (executor != null) {
return (T) executor.execute(source); return (T) executor.execute(source);
} else { } else {
if (parent != null) { if (parent != null) {
return parent.convert(source, targetType); return parent.convert(source, context);
} else { } else {
throw new ConverterNotFoundException(source.getClass(), targetType.getType(), throw new ConverterNotFoundException(source.getClass(), context.getType(),
"No converter found that can convert from sourceType [" + source.getClass().getName() "No converter found that can convert from sourceType [" + source.getClass().getName()
+ "] to targetType [" + targetType.getName() + "]"); + "] to targetType [" + context.getName() + "]");
} }
} }
} }
ConversionExecutor getConversionExecutor(Class sourceClass, ConversionPoint targetType) ConversionExecutor getConversionExecutor(Class sourceClass, ConversionContext targetType)
throws ConverterNotFoundException { throws ConverterNotFoundException {
Assert.notNull(sourceClass, "The sourceType to convert from is required"); Assert.notNull(sourceClass, "The sourceType to convert from is required");
Assert.notNull(targetType, "The targetType to convert to is required"); Assert.notNull(targetType, "The targetType to convert to is required");
@ -162,7 +154,7 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
// TODO for Andy - is this correct way to handle the Null TypedValue? // TODO for Andy - is this correct way to handle the Null TypedValue?
return NoOpConversionExecutor.INSTANCE; return NoOpConversionExecutor.INSTANCE;
} }
ConversionPoint sourceType = ConversionPoint.valueOf(sourceClass); ConversionContext sourceType = ConversionContext.valueOf(sourceClass);
if (sourceType.isArray()) { if (sourceType.isArray()) {
if (targetType.isArray()) { if (targetType.isArray()) {
return new ArrayToArray(sourceType, targetType, this); return new ArrayToArray(sourceType, targetType, this);

View File

@ -22,7 +22,7 @@ import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
/** /**
* Converts from one map to another map, with support for converting individual map elements based on generic type information. * 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.ConversionPoint;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
class MapToMap implements ConversionExecutor { class MapToMap implements ConversionExecutor {
private ConversionPoint sourceType; private ConversionContext sourceType;
private ConversionPoint targetType; private ConversionContext targetType;
private GenericTypeConverter conversionService; private GenericTypeConverter conversionService;
@ -45,7 +45,7 @@ class MapToMap implements ConversionExecutor {
* @param targetType the target map type * @param targetType the target map type
* @param conversionService the conversion service * @param conversionService the conversion service
*/ */
public MapToMap(ConversionPoint sourceType, ConversionPoint targetType, GenericTypeConverter conversionService) { public MapToMap(ConversionContext sourceType, ConversionContext targetType, GenericTypeConverter conversionService) {
this.sourceType = sourceType; this.sourceType = sourceType;
this.targetType = targetType; this.targetType = targetType;
this.conversionService = conversionService; this.conversionService = conversionService;
@ -55,9 +55,9 @@ class MapToMap implements ConversionExecutor {
private EntryConverter createEntryConverter() { private EntryConverter createEntryConverter() {
if (sourceType.isMapEntryTypeKnown() && targetType.isMapEntryTypeKnown()) { if (sourceType.isMapEntryTypeKnown() && targetType.isMapEntryTypeKnown()) {
ConversionExecutor keyConverter = conversionService.getConversionExecutor(sourceType.getMapKeyType(), ConversionExecutor keyConverter = conversionService.getConversionExecutor(sourceType.getMapKeyType(),
ConversionPoint.valueOf(targetType.getMapKeyType())); ConversionContext.valueOf(targetType.getMapKeyType()));
ConversionExecutor valueConverter = conversionService.getConversionExecutor(sourceType.getMapValueType(), ConversionExecutor valueConverter = conversionService.getConversionExecutor(sourceType.getMapValueType(),
ConversionPoint.valueOf(targetType.getMapValueType())); ConversionContext.valueOf(targetType.getMapValueType()));
return new EntryConverter(keyConverter, valueConverter); return new EntryConverter(keyConverter, valueConverter);
} else { } else {
return EntryConverter.NO_OP_INSTANCE; return EntryConverter.NO_OP_INSTANCE;
@ -94,11 +94,11 @@ class MapToMap implements ConversionExecutor {
Object key = entry.getKey(); Object key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
if (keyConverter == null && key != null) { if (keyConverter == null && key != null) {
keyConverter = conversionService.getConversionExecutor(key.getClass(), ConversionPoint keyConverter = conversionService.getConversionExecutor(key.getClass(), ConversionContext
.valueOf(targetKeyType)); .valueOf(targetKeyType));
} }
if (valueConverter == null && value != null) { if (valueConverter == null && value != null) {
valueConverter = conversionService.getConversionExecutor(value.getClass(), ConversionPoint valueConverter = conversionService.getConversionExecutor(value.getClass(), ConversionContext
.valueOf(targetValueType)); .valueOf(targetValueType));
} }
if (keyConverter != null && valueConverter != null) { if (keyConverter != null && valueConverter != null) {

View File

@ -16,7 +16,7 @@
package org.springframework.core.convert.support; package org.springframework.core.convert.support;
import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
import org.springframework.core.style.ToStringCreator; import org.springframework.core.style.ToStringCreator;
@ -27,13 +27,13 @@ import org.springframework.core.style.ToStringCreator;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
class StaticConversionExecutor implements ConversionExecutor { class StaticConversionExecutor implements ConversionExecutor {
private final ConversionPoint sourceType; private final ConversionContext sourceType;
private final ConversionPoint targetType; private final ConversionContext targetType;
private final Converter converter; private final Converter converter;
public StaticConversionExecutor(ConversionPoint sourceType, ConversionPoint targetType, Converter converter) { public StaticConversionExecutor(ConversionContext sourceType, ConversionContext targetType, Converter converter) {
this.sourceType = sourceType; this.sourceType = sourceType;
this.targetType = targetType; this.targetType = targetType;
this.converter = converter; this.converter = converter;

View File

@ -26,7 +26,7 @@ import org.junit.Test;
/** /**
* @author Andy Clement * @author Andy Clement
*/ */
public class ConversionPointTests { public class ConversionContextTests {
List<String> listOfString; List<String> listOfString;
int[] intArray; int[] intArray;
@ -34,13 +34,13 @@ public class ConversionPointTests {
@Test @Test
public void testWrapperType() { public void testWrapperType() {
ConversionPoint desc = ConversionPoint.valueOf(int.class); ConversionContext desc = ConversionContext.valueOf(int.class);
assertEquals(Integer.class, desc.getType()); assertEquals(Integer.class, desc.getType());
} }
@Test @Test
public void listDescriptors() throws Exception { public void listDescriptors() throws Exception {
ConversionPoint typeDescriptor = new ConversionPoint(ConversionPointTests.class.getDeclaredField("listOfString")); ConversionContext typeDescriptor = new ConversionContext(ConversionContextTests.class.getDeclaredField("listOfString"));
assertFalse(typeDescriptor.isArray()); assertFalse(typeDescriptor.isArray());
assertEquals(List.class,typeDescriptor.getType()); assertEquals(List.class,typeDescriptor.getType());
assertEquals(String.class,typeDescriptor.getElementType()); assertEquals(String.class,typeDescriptor.getElementType());
@ -50,7 +50,7 @@ public class ConversionPointTests {
@Test @Test
public void arrayTypeDescriptors() throws Exception { public void arrayTypeDescriptors() throws Exception {
ConversionPoint typeDescriptor = new ConversionPoint(ConversionPointTests.class.getDeclaredField("intArray")); ConversionContext typeDescriptor = new ConversionContext(ConversionContextTests.class.getDeclaredField("intArray"));
assertTrue(typeDescriptor.isArray()); assertTrue(typeDescriptor.isArray());
assertEquals(Integer.TYPE,typeDescriptor.getElementType()); assertEquals(Integer.TYPE,typeDescriptor.getElementType());
assertEquals("int[]",typeDescriptor.asString()); assertEquals("int[]",typeDescriptor.asString());
@ -58,14 +58,14 @@ public class ConversionPointTests {
@Test @Test
public void buildingArrayTypeDescriptors() throws Exception { public void buildingArrayTypeDescriptors() throws Exception {
ConversionPoint typeDescriptor = new ConversionPoint(new int[0].getClass()); ConversionContext typeDescriptor = new ConversionContext(new int[0].getClass());
assertTrue(typeDescriptor.isArray()); assertTrue(typeDescriptor.isArray());
assertEquals(Integer.TYPE,typeDescriptor.getElementType()); assertEquals(Integer.TYPE,typeDescriptor.getElementType());
} }
@Test @Test
public void complexTypeDescriptors() throws Exception { public void complexTypeDescriptors() throws Exception {
ConversionPoint typeDescriptor = new ConversionPoint(ConversionPointTests.class.getDeclaredField("arrayOfListOfString")); ConversionContext typeDescriptor = new ConversionContext(ConversionContextTests.class.getDeclaredField("arrayOfListOfString"));
assertTrue(typeDescriptor.isArray()); assertTrue(typeDescriptor.isArray());
assertEquals(List.class,typeDescriptor.getElementType()); assertEquals(List.class,typeDescriptor.getElementType());
// TODO asc notice that the type of the list elements is lost: typeDescriptor.getElementType() should return a TypeDescriptor // TODO asc notice that the type of the list elements is lost: typeDescriptor.getElementType() should return a TypeDescriptor

View File

@ -3,7 +3,7 @@ package org.springframework.core.convert.support;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.core.convert.support.ArrayToArray; import org.springframework.core.convert.support.ArrayToArray;
import org.springframework.core.convert.support.DefaultTypeConverter; import org.springframework.core.convert.support.DefaultTypeConverter;
@ -12,7 +12,7 @@ public class ArrayToArrayTests {
@Test @Test
public void testArrayToArrayConversion() { public void testArrayToArrayConversion() {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
ArrayToArray c = new ArrayToArray(ConversionPoint.valueOf(String[].class), ConversionPoint.valueOf(Integer[].class), service); ArrayToArray c = new ArrayToArray(ConversionContext.valueOf(String[].class), ConversionContext.valueOf(Integer[].class), service);
Integer[] result = (Integer[]) c.execute(new String[] { "1", "2", "3" }); Integer[] result = (Integer[]) c.execute(new String[] { "1", "2", "3" });
assertEquals(new Integer(1), result[0]); assertEquals(new Integer(1), result[0]);
assertEquals(new Integer(2), result[1]); assertEquals(new Integer(2), result[1]);

View File

@ -9,7 +9,7 @@ import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.core.convert.support.ArrayToCollection; import org.springframework.core.convert.support.ArrayToCollection;
import org.springframework.core.convert.support.DefaultTypeConverter; import org.springframework.core.convert.support.DefaultTypeConverter;
@ -18,7 +18,7 @@ public class ArrayToCollectionTests {
@Test @Test
public void testArrayToCollectionConversion() throws Exception { public void testArrayToCollectionConversion() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
ArrayToCollection c = new ArrayToCollection(ConversionPoint.valueOf(String[].class), new ConversionPoint(getClass().getField("bindTarget")), service); ArrayToCollection c = new ArrayToCollection(ConversionContext.valueOf(String[].class), new ConversionContext(getClass().getField("bindTarget")), service);
List result = (List) c.execute(new String[] { "1", "2", "3" }); List result = (List) c.execute(new String[] { "1", "2", "3" });
assertEquals(new Integer(1), result.get(0)); assertEquals(new Integer(1), result.get(0));
assertEquals(new Integer(2), result.get(1)); assertEquals(new Integer(2), result.get(1));
@ -28,7 +28,7 @@ public class ArrayToCollectionTests {
@Test @Test
public void testArrayToSetConversion() throws Exception { public void testArrayToSetConversion() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
ArrayToCollection c = new ArrayToCollection(ConversionPoint.valueOf(String[].class), new ConversionPoint(getClass().getField("setTarget")), service); ArrayToCollection c = new ArrayToCollection(ConversionContext.valueOf(String[].class), new ConversionContext(getClass().getField("setTarget")), service);
Set result = (Set) c.execute(new String[] { "1" }); Set result = (Set) c.execute(new String[] { "1" });
assertEquals("1", result.iterator().next()); assertEquals("1", result.iterator().next());
} }
@ -36,7 +36,7 @@ public class ArrayToCollectionTests {
@Test @Test
public void testArrayToSortedSetConversion() throws Exception { public void testArrayToSortedSetConversion() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
ArrayToCollection c = new ArrayToCollection(ConversionPoint.valueOf(String[].class), new ConversionPoint(getClass().getField("sortedSetTarget")), service); ArrayToCollection c = new ArrayToCollection(ConversionContext.valueOf(String[].class), new ConversionContext(getClass().getField("sortedSetTarget")), service);
SortedSet result = (SortedSet) c.execute(new String[] { "1" }); SortedSet result = (SortedSet) c.execute(new String[] { "1" });
assertEquals(new Integer(1), result.iterator().next()); assertEquals(new Integer(1), result.iterator().next());
} }
@ -44,7 +44,7 @@ public class ArrayToCollectionTests {
@Test @Test
public void testArrayToCollectionImplConversion() throws Exception { public void testArrayToCollectionImplConversion() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
ArrayToCollection c = new ArrayToCollection(ConversionPoint.valueOf(String[].class), new ConversionPoint(getClass().getField("implTarget")), service); ArrayToCollection c = new ArrayToCollection(ConversionContext.valueOf(String[].class), new ConversionContext(getClass().getField("implTarget")), service);
LinkedList result = (LinkedList) c.execute(new String[] { "1" }); LinkedList result = (LinkedList) c.execute(new String[] { "1" });
assertEquals("1", result.iterator().next()); assertEquals("1", result.iterator().next());
} }
@ -52,7 +52,7 @@ public class ArrayToCollectionTests {
@Test @Test
public void testArrayToNonGenericCollectionConversionNullElement() throws Exception { public void testArrayToNonGenericCollectionConversionNullElement() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
ArrayToCollection c = new ArrayToCollection(ConversionPoint.valueOf(String[].class), new ConversionPoint(getClass().getField("listTarget")), service); ArrayToCollection c = new ArrayToCollection(ConversionContext.valueOf(String[].class), new ConversionContext(getClass().getField("listTarget")), service);
List result = (List) c.execute(new Integer[] { null, new Integer(1) }); List result = (List) c.execute(new Integer[] { null, new Integer(1) });
assertEquals(null, result.get(0)); assertEquals(null, result.get(0));
assertEquals(new Integer(1), result.get(1)); assertEquals(new Integer(1), result.get(1));

View File

@ -6,7 +6,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.core.convert.support.CollectionToArray; import org.springframework.core.convert.support.CollectionToArray;
import org.springframework.core.convert.support.DefaultTypeConverter; import org.springframework.core.convert.support.DefaultTypeConverter;
@ -15,8 +15,8 @@ public class CollectionToArrayTests {
@Test @Test
public void testCollectionToArrayConversion() throws Exception { public void testCollectionToArrayConversion() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
CollectionToArray c = new CollectionToArray(new ConversionPoint(getClass().getField("bindTarget")), CollectionToArray c = new CollectionToArray(new ConversionContext(getClass().getField("bindTarget")),
ConversionPoint.valueOf(Integer[].class), service); ConversionContext.valueOf(Integer[].class), service);
bindTarget.add("1"); bindTarget.add("1");
bindTarget.add("2"); bindTarget.add("2");
bindTarget.add("3"); bindTarget.add("3");
@ -29,7 +29,7 @@ public class CollectionToArrayTests {
@Test @Test
public void testCollectionToArrayConversionNoGenericInfo() throws Exception { public void testCollectionToArrayConversionNoGenericInfo() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
CollectionToArray c = new CollectionToArray(ConversionPoint.valueOf(Collection.class), ConversionPoint CollectionToArray c = new CollectionToArray(ConversionContext.valueOf(Collection.class), ConversionContext
.valueOf(Integer[].class), service); .valueOf(Integer[].class), service);
bindTarget.add("1"); bindTarget.add("1");
bindTarget.add("2"); bindTarget.add("2");
@ -43,7 +43,7 @@ public class CollectionToArrayTests {
@Test @Test
public void testCollectionToArrayConversionNoGenericInfoNullElement() throws Exception { public void testCollectionToArrayConversionNoGenericInfoNullElement() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
CollectionToArray c = new CollectionToArray(ConversionPoint.valueOf(Collection.class), ConversionPoint CollectionToArray c = new CollectionToArray(ConversionContext.valueOf(Collection.class), ConversionContext
.valueOf(Integer[].class), service); .valueOf(Integer[].class), service);
bindTarget.add(null); bindTarget.add(null);
bindTarget.add("1"); bindTarget.add("1");

View File

@ -8,7 +8,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.core.convert.support.CollectionToCollection; import org.springframework.core.convert.support.CollectionToCollection;
import org.springframework.core.convert.support.DefaultTypeConverter; import org.springframework.core.convert.support.DefaultTypeConverter;
@ -17,8 +17,8 @@ public class CollectionToCollectionTests {
@Test @Test
public void testCollectionToCollectionConversion() throws Exception { public void testCollectionToCollectionConversion() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
CollectionToCollection c = new CollectionToCollection(new ConversionPoint(getClass().getField("bindTarget")), CollectionToCollection c = new CollectionToCollection(new ConversionContext(getClass().getField("bindTarget")),
new ConversionPoint(getClass().getField("integerTarget")), service); new ConversionContext(getClass().getField("integerTarget")), service);
bindTarget.add("1"); bindTarget.add("1");
bindTarget.add("2"); bindTarget.add("2");
bindTarget.add("3"); bindTarget.add("3");
@ -31,8 +31,8 @@ public class CollectionToCollectionTests {
@Test @Test
public void testCollectionToCollectionConversionNoGenericInfo() throws Exception { public void testCollectionToCollectionConversionNoGenericInfo() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
CollectionToCollection c = new CollectionToCollection(ConversionPoint.valueOf(Collection.class), CollectionToCollection c = new CollectionToCollection(ConversionContext.valueOf(Collection.class),
ConversionPoint.valueOf(List.class), service); ConversionContext.valueOf(List.class), service);
bindTarget.add("1"); bindTarget.add("1");
bindTarget.add("2"); bindTarget.add("2");
bindTarget.add("3"); bindTarget.add("3");
@ -45,8 +45,8 @@ public class CollectionToCollectionTests {
@Test @Test
public void testCollectionToCollectionConversionNoGenericInfoSource() throws Exception { public void testCollectionToCollectionConversionNoGenericInfoSource() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
CollectionToCollection c = new CollectionToCollection(ConversionPoint.valueOf(Collection.class), CollectionToCollection c = new CollectionToCollection(ConversionContext.valueOf(Collection.class),
new ConversionPoint(getClass().getField("integerTarget")), service); new ConversionContext(getClass().getField("integerTarget")), service);
bindTarget.add("1"); bindTarget.add("1");
bindTarget.add("2"); bindTarget.add("2");
bindTarget.add("3"); bindTarget.add("3");
@ -59,8 +59,8 @@ public class CollectionToCollectionTests {
@Test @Test
public void testCollectionToCollectionConversionNoGenericInfoSourceNullValues() throws Exception { public void testCollectionToCollectionConversionNoGenericInfoSourceNullValues() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
CollectionToCollection c = new CollectionToCollection(ConversionPoint.valueOf(Collection.class), CollectionToCollection c = new CollectionToCollection(ConversionContext.valueOf(Collection.class),
new ConversionPoint(getClass().getField("integerTarget")), service); new ConversionContext(getClass().getField("integerTarget")), service);
bindTarget.add(null); bindTarget.add(null);
bindTarget.add("1"); bindTarget.add("1");
bindTarget.add("2"); bindTarget.add("2");
@ -77,8 +77,8 @@ public class CollectionToCollectionTests {
@Test @Test
public void testCollectionToCollectionConversionNoGenericInfoSourceEmpty() throws Exception { public void testCollectionToCollectionConversionNoGenericInfoSourceEmpty() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
CollectionToCollection c = new CollectionToCollection(ConversionPoint.valueOf(Collection.class), CollectionToCollection c = new CollectionToCollection(ConversionContext.valueOf(Collection.class),
new ConversionPoint(getClass().getField("integerTarget")), service); new ConversionContext(getClass().getField("integerTarget")), service);
List result = (List) c.execute(bindTarget); List result = (List) c.execute(bindTarget);
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());
} }

View File

@ -29,7 +29,7 @@ import java.util.Map;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
@ -39,7 +39,7 @@ public class GenericTypeConverterTests {
@Test @Test
public void executeConversion() { public void executeConversion() {
converter.addConverter(new StringToInteger()); converter.add(new StringToInteger());
assertEquals(new Integer(3), converter.convert("3", Integer.class)); assertEquals(new Integer(3), converter.convert("3", Integer.class));
} }
@ -65,7 +65,7 @@ public class GenericTypeConverterTests {
@Test @Test
public void addConverterNoSourceTargetClassInfoAvailable() { public void addConverterNoSourceTargetClassInfoAvailable() {
try { try {
converter.addConverter(new Converter() { converter.add(new Converter() {
public Object convert(Object source) throws Exception { public Object convert(Object source) throws Exception {
return source; return source;
} }
@ -88,13 +88,13 @@ public class GenericTypeConverterTests {
@Test @Test
public void convertNullConversionPointType() { public void convertNullConversionPointType() {
assertEquals("3", converter.convert("3", ConversionPoint.NULL)); assertEquals("3", converter.convert("3", ConversionContext.NULL));
} }
@Test @Test
public void convertWrongTypeArgument() { public void convertWrongTypeArgument() {
converter.addConverter(new StringToInteger()); converter.add(new StringToInteger());
try { try {
converter.convert("BOGUS", Integer.class); converter.convert("BOGUS", Integer.class);
fail("Should have failed"); fail("Should have failed");
@ -105,7 +105,7 @@ public class GenericTypeConverterTests {
@Test @Test
public void convertSuperSourceType() { public void convertSuperSourceType() {
converter.addConverter(new Converter<CharSequence, Integer>() { converter.add(new Converter<CharSequence, Integer>() {
public Integer convert(CharSequence source) throws Exception { public Integer convert(CharSequence source) throws Exception {
return Integer.valueOf(source.toString()); return Integer.valueOf(source.toString());
} }
@ -117,7 +117,7 @@ public class GenericTypeConverterTests {
@Test @Test
@Ignore @Ignore
public void convertNoSuperTargetType() { public void convertNoSuperTargetType() {
converter.addConverter(new Converter<CharSequence, Number>() { converter.add(new Converter<CharSequence, Number>() {
public Integer convert(CharSequence source) throws Exception { public Integer convert(CharSequence source) throws Exception {
return Integer.valueOf(source.toString()); return Integer.valueOf(source.toString());
} }
@ -132,14 +132,14 @@ public class GenericTypeConverterTests {
@Test @Test
public void convertObjectToPrimitive() { public void convertObjectToPrimitive() {
converter.addConverter(new StringToInteger()); converter.add(new StringToInteger());
Integer three = converter.convert("3", int.class); Integer three = converter.convert("3", int.class);
assertEquals(3, three.intValue()); assertEquals(3, three.intValue());
} }
@Test @Test
public void convertArrayToArray() { public void convertArrayToArray() {
converter.addConverter(new StringToInteger()); converter.add(new StringToInteger());
Integer[] result = converter.convert(new String[] { "1", "2", "3" }, Integer[].class); Integer[] result = converter.convert(new String[] { "1", "2", "3" }, Integer[].class);
assertEquals(new Integer(1), result[0]); assertEquals(new Integer(1), result[0]);
assertEquals(new Integer(2), result[1]); assertEquals(new Integer(2), result[1]);
@ -148,7 +148,7 @@ public class GenericTypeConverterTests {
@Test @Test
public void convertArrayToPrimitiveArray() { public void convertArrayToPrimitiveArray() {
converter.addConverter(new StringToInteger()); converter.add(new StringToInteger());
int[] result = (int[]) converter.convert(new String[] { "1", "2", "3" }, int[].class); int[] result = (int[]) converter.convert(new String[] { "1", "2", "3" }, int[].class);
assertEquals(1, result[0]); assertEquals(1, result[0]);
assertEquals(2, result[1]); assertEquals(2, result[1]);
@ -167,8 +167,8 @@ public class GenericTypeConverterTests {
@Test @Test
public void convertArrayToListGenericTypeConversion() throws Exception { public void convertArrayToListGenericTypeConversion() throws Exception {
converter.addConverter(new StringToInteger()); converter.add(new StringToInteger());
List<Integer> result = converter.convert(new String[] { "1", "2", "3" }, new ConversionPoint<List<Integer>>(getClass().getDeclaredField("genericList"))); List<Integer> result = converter.convert(new String[] { "1", "2", "3" }, new ConversionContext<List<Integer>>(getClass().getDeclaredField("genericList")));
assertEquals(new Integer("1"), result.get(0)); assertEquals(new Integer("1"), result.get(0));
assertEquals(new Integer("2"), result.get(1)); assertEquals(new Integer("2"), result.get(1));
assertEquals(new Integer("3"), result.get(2)); assertEquals(new Integer("3"), result.get(2));
@ -205,7 +205,7 @@ public class GenericTypeConverterTests {
@Test @Test
public void convertListToArrayWithComponentConversion() { public void convertListToArrayWithComponentConversion() {
converter.addConverter(new StringToInteger()); converter.add(new StringToInteger());
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
list.add("1"); list.add("1");
list.add("2"); list.add("2");
@ -224,9 +224,9 @@ public class GenericTypeConverterTests {
Map<String, String> foo = new HashMap<String, String>(); Map<String, String> foo = new HashMap<String, String>();
foo.put("1", "BAR"); foo.put("1", "BAR");
foo.put("2", "BAZ"); foo.put("2", "BAZ");
converter.addConverter(new StringToInteger()); converter.add(new StringToInteger());
converter.addConverter(new StringToEnumFactory().getConverter(FooEnum.class)); converter.add(new StringToEnumFactory().getConverter(FooEnum.class));
Map<String, FooEnum> map = converter.convert(foo, new ConversionPoint<Map<String, FooEnum>>(getClass().getField("genericMap"))); Map<String, FooEnum> map = converter.convert(foo, new ConversionContext<Map<String, FooEnum>>(getClass().getField("genericMap")));
assertEquals(map.get(1), FooEnum.BAR); assertEquals(map.get(1), FooEnum.BAR);
assertEquals(map.get(2), FooEnum.BAZ); assertEquals(map.get(2), FooEnum.BAZ);
} }
@ -242,7 +242,7 @@ public class GenericTypeConverterTests {
@Ignore @Ignore
@Test @Test
public void convertObjectToArrayWithElementConversion() { public void convertObjectToArrayWithElementConversion() {
converter.addConverter(new StringToInteger()); converter.add(new StringToInteger());
Integer[] result = converter.convert("123", Integer[].class); Integer[] result = converter.convert("123", Integer[].class);
assertEquals(1, result.length); assertEquals(1, result.length);
assertEquals(new Integer(123), result[0]); assertEquals(new Integer(123), result[0]);

View File

@ -6,7 +6,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.core.convert.support.DefaultTypeConverter; import org.springframework.core.convert.support.DefaultTypeConverter;
import org.springframework.core.convert.support.MapToMap; import org.springframework.core.convert.support.MapToMap;
@ -15,8 +15,8 @@ public class MapToMapTests {
@Test @Test
public void testMapToMapConversion() throws Exception { public void testMapToMapConversion() throws Exception {
DefaultTypeConverter converter = new DefaultTypeConverter(); DefaultTypeConverter converter = new DefaultTypeConverter();
MapToMap c = new MapToMap(new ConversionPoint<Map<String, String>>(getClass().getField("source")), MapToMap c = new MapToMap(new ConversionContext<Map<String, String>>(getClass().getField("source")),
new ConversionPoint<Map<String, FooEnum>>(getClass().getField("bindTarget")), converter); new ConversionContext<Map<String, FooEnum>>(getClass().getField("bindTarget")), converter);
source.put("1", "BAR"); source.put("1", "BAR");
source.put("2", "BAZ"); source.put("2", "BAZ");
Map<String, FooEnum> result = (Map<String, FooEnum>) c.execute(source); Map<String, FooEnum> result = (Map<String, FooEnum>) c.execute(source);
@ -27,8 +27,8 @@ public class MapToMapTests {
@Test @Test
public void testMapToMapConversionNoGenericInfoOnSource() throws Exception { public void testMapToMapConversionNoGenericInfoOnSource() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
MapToMap c = new MapToMap(ConversionPoint.valueOf(Map.class), MapToMap c = new MapToMap(ConversionContext.valueOf(Map.class),
new ConversionPoint(getClass().getField("bindTarget")), service); new ConversionContext(getClass().getField("bindTarget")), service);
source.put("1", "BAR"); source.put("1", "BAR");
source.put("2", "BAZ"); source.put("2", "BAZ");
Map result = (Map) c.execute(source); Map result = (Map) c.execute(source);
@ -39,8 +39,8 @@ public class MapToMapTests {
@Test @Test
public void testMapToMapConversionNoGenericInfo() throws Exception { public void testMapToMapConversionNoGenericInfo() throws Exception {
DefaultTypeConverter service = new DefaultTypeConverter(); DefaultTypeConverter service = new DefaultTypeConverter();
MapToMap c = new MapToMap(ConversionPoint.valueOf(Map.class), MapToMap c = new MapToMap(ConversionContext.valueOf(Map.class),
ConversionPoint.valueOf(Map.class), service); ConversionContext.valueOf(Map.class), service);
source.put("1", "BAR"); source.put("1", "BAR");
source.put("2", "BAZ"); source.put("2", "BAZ");
Map result = (Map) c.execute(source); Map result = (Map) c.execute(source);

View File

@ -16,7 +16,7 @@
package org.springframework.expression; package org.springframework.expression;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
/** /**
* A type converter can convert values between different types encountered * A type converter can convert values between different types encountered
@ -48,7 +48,7 @@ public interface TypeConverter {
* @return the converted value * @return the converted value
* @throws EvaluationException if conversion is not possible * @throws EvaluationException if conversion is not possible
*/ */
Object convertValue(Object value, ConversionPoint typeDescriptor) throws EvaluationException; Object convertValue(Object value, ConversionContext typeDescriptor) throws EvaluationException;
/** /**
* Return true if the type converter can convert the specified type to the desired target type. * 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 * @param typeDescriptor a type descriptor that supplies extra information about the requested result type
* @return true if that conversion can be performed * @return true if that conversion can be performed
*/ */
boolean canConvert(Class<?> sourceType, ConversionPoint typeDescriptor); boolean canConvert(Class<?> sourceType, ConversionContext typeDescriptor);
} }

View File

@ -15,7 +15,7 @@
*/ */
package org.springframework.expression; package org.springframework.expression;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
/** /**
* Encapsulates an object and a type descriptor that describes it. * Encapsulates an object and a type descriptor that describes it.
@ -28,9 +28,9 @@ import org.springframework.core.convert.ConversionPoint;
public class TypedValue { public class TypedValue {
private Object value; private Object value;
private ConversionPoint typeDescriptor; private ConversionContext typeDescriptor;
public static final TypedValue NULL_TYPED_VALUE = new TypedValue(null, ConversionPoint.NULL); public static final TypedValue NULL_TYPED_VALUE = new TypedValue(null, ConversionContext.NULL);
/** /**
* Create a TypedValue for a simple object. The type descriptor is inferred * Create a TypedValue for a simple object. The type descriptor is inferred
@ -39,7 +39,7 @@ public class TypedValue {
*/ */
public TypedValue(Object value) { public TypedValue(Object value) {
this.value = value; this.value = value;
this.typeDescriptor = ConversionPoint.forObject(value); this.typeDescriptor = ConversionContext.forObject(value);
} }
/** /**
@ -47,7 +47,7 @@ public class TypedValue {
* @param value the object value * @param value the object value
* @param typeDescriptor a type descriptor describing the type of the value * @param typeDescriptor a type descriptor describing the type of the value
*/ */
public TypedValue(Object value, ConversionPoint typeDescriptor) { public TypedValue(Object value, ConversionContext typeDescriptor) {
this.value = value; this.value = value;
this.typeDescriptor = typeDescriptor; this.typeDescriptor = typeDescriptor;
} }
@ -56,7 +56,7 @@ public class TypedValue {
return this.value; return this.value;
} }
public ConversionPoint getTypeDescriptor() { public ConversionContext getTypeDescriptor() {
return this.typeDescriptor; return this.typeDescriptor;
} }

View File

@ -20,7 +20,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Stack; import java.util.Stack;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation; import org.springframework.expression.Operation;
@ -99,7 +99,7 @@ public class ExpressionState {
if (value==null) { if (value==null) {
return TypedValue.NULL_TYPED_VALUE; return TypedValue.NULL_TYPED_VALUE;
} else { } else {
return new TypedValue(value,ConversionPoint.forObject(value)); return new TypedValue(value,ConversionContext.forObject(value));
} }
} }
@ -111,11 +111,11 @@ public class ExpressionState {
return this.relatedContext.getTypeLocator().findType(type); return this.relatedContext.getTypeLocator().findType(type);
} }
public Object convertValue(Object value, ConversionPoint targetTypeDescriptor) throws EvaluationException { public Object convertValue(Object value, ConversionContext targetTypeDescriptor) throws EvaluationException {
return this.relatedContext.getTypeConverter().convertValue(value, targetTypeDescriptor); return this.relatedContext.getTypeConverter().convertValue(value, targetTypeDescriptor);
} }
public Object convertValue(TypedValue value, ConversionPoint targetTypeDescriptor) throws EvaluationException { public Object convertValue(TypedValue value, ConversionContext targetTypeDescriptor) throws EvaluationException {
return this.relatedContext.getTypeConverter().convertValue(value.getValue(), targetTypeDescriptor); return this.relatedContext.getTypeConverter().convertValue(value.getValue(), targetTypeDescriptor);
} }
@ -153,7 +153,7 @@ public class ExpressionState {
OperatorOverloader overloader = this.relatedContext.getOperatorOverloader(); OperatorOverloader overloader = this.relatedContext.getOperatorOverloader();
if (overloader.overridesOperation(op, left, right)) { if (overloader.overridesOperation(op, left, right)) {
Object returnValue = overloader.operate(op, left, right); Object returnValue = overloader.operate(op, left, right);
return new TypedValue(returnValue,ConversionPoint.forObject(returnValue)); return new TypedValue(returnValue,ConversionContext.forObject(returnValue));
} }
else { else {
String leftType = (left==null?"null":left.getClass().getName()); String leftType = (left==null?"null":left.getClass().getName());

View File

@ -15,7 +15,7 @@
*/ */
package org.springframework.expression.spel.ast; package org.springframework.expression.spel.ast;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
/** /**
* @author Andy Clement * @author Andy Clement
@ -23,16 +23,16 @@ import org.springframework.core.convert.ConversionPoint;
*/ */
public interface CommonTypeDescriptors { public interface CommonTypeDescriptors {
// TODO push into TypeDescriptor? // TODO push into TypeDescriptor?
static ConversionPoint BOOLEAN_TYPE_DESCRIPTOR = ConversionPoint.valueOf(Boolean.class); static ConversionContext BOOLEAN_TYPE_DESCRIPTOR = ConversionContext.valueOf(Boolean.class);
static ConversionPoint INTEGER_TYPE_DESCRIPTOR = ConversionPoint.valueOf(Integer.class); static ConversionContext INTEGER_TYPE_DESCRIPTOR = ConversionContext.valueOf(Integer.class);
static ConversionPoint CHARACTER_TYPE_DESCRIPTOR = ConversionPoint.valueOf(Character.class); static ConversionContext CHARACTER_TYPE_DESCRIPTOR = ConversionContext.valueOf(Character.class);
static ConversionPoint LONG_TYPE_DESCRIPTOR = ConversionPoint.valueOf(Long.class); static ConversionContext LONG_TYPE_DESCRIPTOR = ConversionContext.valueOf(Long.class);
static ConversionPoint SHORT_TYPE_DESCRIPTOR = ConversionPoint.valueOf(Short.class); static ConversionContext SHORT_TYPE_DESCRIPTOR = ConversionContext.valueOf(Short.class);
static ConversionPoint BYTE_TYPE_DESCRIPTOR = ConversionPoint.valueOf(Byte.class); static ConversionContext BYTE_TYPE_DESCRIPTOR = ConversionContext.valueOf(Byte.class);
static ConversionPoint FLOAT_TYPE_DESCRIPTOR = ConversionPoint.valueOf(Float.class); static ConversionContext FLOAT_TYPE_DESCRIPTOR = ConversionContext.valueOf(Float.class);
static ConversionPoint DOUBLE_TYPE_DESCRIPTOR = ConversionPoint.valueOf(Double.class); static ConversionContext DOUBLE_TYPE_DESCRIPTOR = ConversionContext.valueOf(Double.class);
static ConversionPoint STRING_TYPE_DESCRIPTOR = ConversionPoint.valueOf(String.class); static ConversionContext STRING_TYPE_DESCRIPTOR = ConversionContext.valueOf(String.class);
static ConversionPoint CLASS_TYPE_DESCRIPTOR = ConversionPoint.valueOf(Class.class); static ConversionContext CLASS_TYPE_DESCRIPTOR = ConversionContext.valueOf(Class.class);
static ConversionPoint OBJECT_TYPE_DESCRIPTOR = ConversionPoint.valueOf(Object.class); static ConversionContext OBJECT_TYPE_DESCRIPTOR = ConversionContext.valueOf(Object.class);
} }

View File

@ -22,7 +22,7 @@ import java.lang.reflect.Modifier;
import org.antlr.runtime.Token; import org.antlr.runtime.Token;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
import org.springframework.expression.TypeConverter; import org.springframework.expression.TypeConverter;
import org.springframework.expression.TypedValue; import org.springframework.expression.TypedValue;
@ -104,7 +104,7 @@ public class FunctionReference extends SpelNodeImpl {
try { try {
ReflectionUtils.makeAccessible(m); ReflectionUtils.makeAccessible(m);
Object result = m.invoke(m.getClass(), functionArgs); Object result = m.invoke(m.getClass(), functionArgs);
return new TypedValue(result, new ConversionPoint(new MethodParameter(m,-1))); return new TypedValue(result, new ConversionContext(new MethodParameter(m,-1)));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new SpelException(getCharPositionInLine(), e, SpelMessages.EXCEPTION_DURING_FUNCTION_CALL, name, e throw new SpelException(getCharPositionInLine(), e, SpelMessages.EXCEPTION_DURING_FUNCTION_CALL, name, e
.getMessage()); .getMessage());

View File

@ -21,7 +21,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.antlr.runtime.Token; import org.antlr.runtime.Token;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
import org.springframework.expression.TypedValue; import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.ExpressionState;
@ -47,15 +47,15 @@ public class Indexer extends SpelNodeImpl {
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
TypedValue context = state.getActiveContextObject(); TypedValue context = state.getActiveContextObject();
Object targetObject = context.getValue(); Object targetObject = context.getValue();
ConversionPoint targetObjectTypeDescriptor = context.getTypeDescriptor(); ConversionContext targetObjectTypeDescriptor = context.getTypeDescriptor();
TypedValue indexValue = getChild(0).getValueInternal(state); TypedValue indexValue = getChild(0).getValueInternal(state);
Object index = indexValue.getValue(); Object index = indexValue.getValue();
// Indexing into a Map // Indexing into a Map
if (targetObject instanceof Map) { if (targetObject instanceof Map) {
Object possiblyConvertedKey = state.convertValue(indexValue,ConversionPoint.valueOf(targetObjectTypeDescriptor.getMapKeyType())); Object possiblyConvertedKey = state.convertValue(indexValue,ConversionContext.valueOf(targetObjectTypeDescriptor.getMapKeyType()));
Object o = ((Map<?, ?>) targetObject).get(possiblyConvertedKey); Object o = ((Map<?, ?>) targetObject).get(possiblyConvertedKey);
return new TypedValue(o,ConversionPoint.valueOf(targetObjectTypeDescriptor.getMapValueType())); return new TypedValue(o,ConversionContext.valueOf(targetObjectTypeDescriptor.getMapValueType()));
} }
int idx = (Integer)state.convertValue(index, INTEGER_TYPE_DESCRIPTOR); int idx = (Integer)state.convertValue(index, INTEGER_TYPE_DESCRIPTOR);
@ -65,7 +65,7 @@ public class Indexer extends SpelNodeImpl {
} }
if (targetObject.getClass().isArray()) { if (targetObject.getClass().isArray()) {
return new TypedValue(accessArrayElement(targetObject, idx),ConversionPoint.valueOf(targetObjectTypeDescriptor.getElementType())); return new TypedValue(accessArrayElement(targetObject, idx),ConversionContext.valueOf(targetObjectTypeDescriptor.getElementType()));
} else if (targetObject instanceof Collection) { } else if (targetObject instanceof Collection) {
Collection<?> c = (Collection<?>) targetObject; Collection<?> c = (Collection<?>) targetObject;
if (idx >= c.size()) { if (idx >= c.size()) {
@ -74,7 +74,7 @@ public class Indexer extends SpelNodeImpl {
int pos = 0; int pos = 0;
for (Object o : c) { for (Object o : c) {
if (pos == idx) { if (pos == idx) {
return new TypedValue(o,ConversionPoint.valueOf(targetObjectTypeDescriptor.getElementType())); return new TypedValue(o,ConversionContext.valueOf(targetObjectTypeDescriptor.getElementType()));
} }
pos++; pos++;
} }
@ -99,7 +99,7 @@ public class Indexer extends SpelNodeImpl {
public void setValue(ExpressionState state, Object newValue) throws EvaluationException { public void setValue(ExpressionState state, Object newValue) throws EvaluationException {
TypedValue contextObject = state.getActiveContextObject(); TypedValue contextObject = state.getActiveContextObject();
Object targetObject = contextObject.getValue(); Object targetObject = contextObject.getValue();
ConversionPoint targetObjectTypeDescriptor = contextObject.getTypeDescriptor(); ConversionContext targetObjectTypeDescriptor = contextObject.getTypeDescriptor();
TypedValue index = getChild(0).getValueInternal(state); TypedValue index = getChild(0).getValueInternal(state);
if (targetObject == null) { if (targetObject == null) {
@ -108,8 +108,8 @@ public class Indexer extends SpelNodeImpl {
// Indexing into a Map // Indexing into a Map
if (targetObjectTypeDescriptor.isMap()) { if (targetObjectTypeDescriptor.isMap()) {
Map map = (Map)targetObject; Map map = (Map)targetObject;
Object possiblyConvertedKey = state.convertValue(index.getValue(),ConversionPoint.valueOf(targetObjectTypeDescriptor.getMapKeyType())); Object possiblyConvertedKey = state.convertValue(index.getValue(),ConversionContext.valueOf(targetObjectTypeDescriptor.getMapKeyType()));
Object possiblyConvertedValue = state.convertValue(newValue,ConversionPoint.valueOf(targetObjectTypeDescriptor.getMapValueType())); Object possiblyConvertedValue = state.convertValue(newValue,ConversionContext.valueOf(targetObjectTypeDescriptor.getMapValueType()));
map.put(possiblyConvertedKey,possiblyConvertedValue); map.put(possiblyConvertedKey,possiblyConvertedValue);
return; return;
} }
@ -125,7 +125,7 @@ public class Indexer extends SpelNodeImpl {
} }
if (targetObject instanceof List) { if (targetObject instanceof List) {
List list = (List)targetObject; List list = (List)targetObject;
Object possiblyConvertedValue = state.convertValue(newValue,ConversionPoint.valueOf(targetObjectTypeDescriptor.getElementType())); Object possiblyConvertedValue = state.convertValue(newValue,ConversionContext.valueOf(targetObjectTypeDescriptor.getElementType()));
list.set(idx,possiblyConvertedValue); list.set(idx,possiblyConvertedValue);
} else { } else {
throw new SpelException(SpelMessages.INDEXING_NOT_SUPPORTED_FOR_TYPE, contextObject.getClass().getName()); throw new SpelException(SpelMessages.INDEXING_NOT_SUPPORTED_FOR_TYPE, contextObject.getClass().getName());
@ -185,7 +185,7 @@ public class Indexer extends SpelNodeImpl {
} else { } else {
Object[] array = (Object[]) ctx; Object[] array = (Object[]) ctx;
checkAccess(array.length, idx); checkAccess(array.length, idx);
array[idx] = state.convertValue(newValue, ConversionPoint.valueOf(clazz)); array[idx] = state.convertValue(newValue, ConversionContext.valueOf(clazz));
} }
} }

View File

@ -17,7 +17,7 @@
package org.springframework.expression.spel.ast; package org.springframework.expression.spel.ast;
import org.antlr.runtime.Token; import org.antlr.runtime.Token;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation; import org.springframework.expression.Operation;
import org.springframework.expression.TypedValue; import org.springframework.expression.TypedValue;
@ -56,7 +56,7 @@ public class OperatorDivide extends Operator {
} }
} }
Object result = state.operate(Operation.DIVIDE, operandOne, operandTwo); Object result = state.operate(Operation.DIVIDE, operandOne, operandTwo);
return new TypedValue(result,ConversionPoint.forObject(result)); return new TypedValue(result,ConversionContext.forObject(result));
} }
} }

View File

@ -22,7 +22,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.antlr.runtime.Token; import org.antlr.runtime.Token;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
import org.springframework.expression.TypedValue; import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.ExpressionState;
@ -60,13 +60,13 @@ public class Projection extends SpelNodeImpl {
List<Object> result = new ArrayList<Object>(); List<Object> result = new ArrayList<Object>();
for (Map.Entry entry : mapdata.entrySet()) { for (Map.Entry entry : mapdata.entrySet()) {
try { try {
state.pushActiveContextObject(new TypedValue(entry,ConversionPoint.valueOf(Map.Entry.class))); state.pushActiveContextObject(new TypedValue(entry,ConversionContext.valueOf(Map.Entry.class)));
result.add(getChild(0).getValueInternal(state).getValue()); result.add(getChild(0).getValueInternal(state).getValue());
} finally { } finally {
state.popActiveContextObject(); state.popActiveContextObject();
} }
} }
return new TypedValue(result,ConversionPoint.valueOf(List.class)); // TODO unable to build correct type descriptor return new TypedValue(result,ConversionContext.valueOf(List.class)); // TODO unable to build correct type descriptor
} else if (operand instanceof List) { } else if (operand instanceof List) {
List<Object> data = new ArrayList<Object>(); List<Object> data = new ArrayList<Object>();
data.addAll((Collection<?>) operand); data.addAll((Collection<?>) operand);
@ -74,7 +74,7 @@ public class Projection extends SpelNodeImpl {
int idx = 0; int idx = 0;
for (Object element : data) { for (Object element : data) {
try { try {
state.pushActiveContextObject(new TypedValue(element,ConversionPoint.valueOf(op.getTypeDescriptor().getType()))); state.pushActiveContextObject(new TypedValue(element,ConversionContext.valueOf(op.getTypeDescriptor().getType())));
state.enterScope("index", idx); state.enterScope("index", idx);
result.add(getChild(0).getValueInternal(state).getValue()); result.add(getChild(0).getValueInternal(state).getValue());
} finally { } finally {

View File

@ -23,7 +23,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.antlr.runtime.Token; import org.antlr.runtime.Token;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
import org.springframework.expression.TypedValue; import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.ExpressionState;
@ -66,7 +66,7 @@ public class Selection extends SpelNodeImpl {
for (Map.Entry entry : mapdata.entrySet()) { for (Map.Entry entry : mapdata.entrySet()) {
try { try {
lastKey = entry.getKey(); lastKey = entry.getKey();
TypedValue kvpair = new TypedValue(entry,ConversionPoint.valueOf(Map.Entry.class)); TypedValue kvpair = new TypedValue(entry,ConversionContext.valueOf(Map.Entry.class));
state.pushActiveContextObject(kvpair); state.pushActiveContextObject(kvpair);
Object o = selectionCriteria.getValueInternal(state).getValue(); Object o = selectionCriteria.getValueInternal(state).getValue();
if (o instanceof Boolean) { if (o instanceof Boolean) {
@ -86,13 +86,13 @@ public class Selection extends SpelNodeImpl {
} }
} }
if ((variant == FIRST || variant == LAST) && result.size() == 0) { if ((variant == FIRST || variant == LAST) && result.size() == 0) {
return new TypedValue(null,ConversionPoint.NULL); return new TypedValue(null,ConversionContext.NULL);
} }
if (variant == LAST) { if (variant == LAST) {
Map resultMap = new HashMap(); Map resultMap = new HashMap();
Object lastValue = result.get(lastKey); Object lastValue = result.get(lastKey);
resultMap.put(lastKey,lastValue); resultMap.put(lastKey,lastValue);
return new TypedValue(resultMap,ConversionPoint.valueOf(Map.class)); return new TypedValue(resultMap,ConversionContext.valueOf(Map.class));
} }
return new TypedValue(result,op.getTypeDescriptor()); return new TypedValue(result,op.getTypeDescriptor());
} else if (operand instanceof Collection) { } else if (operand instanceof Collection) {
@ -102,13 +102,13 @@ public class Selection extends SpelNodeImpl {
int idx = 0; int idx = 0;
for (Object element : data) { for (Object element : data) {
try { try {
state.pushActiveContextObject(new TypedValue(element,ConversionPoint.valueOf(op.getTypeDescriptor().getElementType()))); state.pushActiveContextObject(new TypedValue(element,ConversionContext.valueOf(op.getTypeDescriptor().getElementType())));
state.enterScope("index", idx); state.enterScope("index", idx);
Object o = selectionCriteria.getValueInternal(state).getValue(); Object o = selectionCriteria.getValueInternal(state).getValue();
if (o instanceof Boolean) { if (o instanceof Boolean) {
if (((Boolean) o).booleanValue() == true) { if (((Boolean) o).booleanValue() == true) {
if (variant == FIRST) { if (variant == FIRST) {
return new TypedValue(element,ConversionPoint.valueOf(op.getTypeDescriptor().getElementType())); return new TypedValue(element,ConversionContext.valueOf(op.getTypeDescriptor().getElementType()));
} }
result.add(element); result.add(element);
} }
@ -126,7 +126,7 @@ public class Selection extends SpelNodeImpl {
return TypedValue.NULL_TYPED_VALUE; return TypedValue.NULL_TYPED_VALUE;
} }
if (variant == LAST) { if (variant == LAST) {
return new TypedValue(result.get(result.size() - 1),ConversionPoint.valueOf(op.getTypeDescriptor().getElementType())); return new TypedValue(result.get(result.size() - 1),ConversionContext.valueOf(op.getTypeDescriptor().getElementType()));
} }
return new TypedValue(result,op.getTypeDescriptor()); return new TypedValue(result,op.getTypeDescriptor());
} else { } else {

View File

@ -18,7 +18,7 @@ package org.springframework.expression.spel.support;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.AccessException; import org.springframework.expression.AccessException;
import org.springframework.expression.ConstructorExecutor; import org.springframework.expression.ConstructorExecutor;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
@ -56,7 +56,7 @@ class ReflectiveConstructorExecutor implements ConstructorExecutor {
if (!c.isAccessible()) { if (!c.isAccessible()) {
c.setAccessible(true); c.setAccessible(true);
} }
return new TypedValue(c.newInstance(arguments),ConversionPoint.valueOf(c.getClass())); return new TypedValue(c.newInstance(arguments),ConversionContext.valueOf(c.getClass()));
} catch (Exception ex) { } catch (Exception ex) {
throw new AccessException("Problem invoking constructor: " + c, ex); throw new AccessException("Problem invoking constructor: " + c, ex);
} }

View File

@ -19,7 +19,7 @@ package org.springframework.expression.spel.support;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.AccessException; import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.MethodExecutor; import org.springframework.expression.MethodExecutor;
@ -55,7 +55,7 @@ class ReflectiveMethodExecutor implements MethodExecutor {
arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.method.getParameterTypes(), arguments); arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.method.getParameterTypes(), arguments);
} }
ReflectionUtils.makeAccessible(this.method); ReflectionUtils.makeAccessible(this.method);
return new TypedValue(this.method.invoke(target, arguments), new ConversionPoint(new MethodParameter(method,-1))); return new TypedValue(this.method.invoke(target, arguments), new ConversionContext(new MethodParameter(method,-1)));
} catch (Exception ex) { } catch (Exception ex) {
throw new AccessException("Problem invoking method: " + this.method, ex); throw new AccessException("Problem invoking method: " + this.method, ex);
} }

View File

@ -25,7 +25,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.AccessException; import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
@ -48,7 +48,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
protected final Map<CacheKey, Member> writerCache = new ConcurrentHashMap<CacheKey, Member>(); protected final Map<CacheKey, Member> writerCache = new ConcurrentHashMap<CacheKey, Member>();
protected final Map<CacheKey, ConversionPoint> typeDescriptorCache = new ConcurrentHashMap<CacheKey,ConversionPoint>(); protected final Map<CacheKey, ConversionContext> typeDescriptorCache = new ConcurrentHashMap<CacheKey,ConversionContext>();
/** /**
* @return null which means this is a general purpose accessor * @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); Method method = findGetterForProperty(name, type, target instanceof Class);
if (method != null) { if (method != null) {
this.readerCache.put(cacheKey, method); this.readerCache.put(cacheKey, method);
this.typeDescriptorCache.put(cacheKey, new ConversionPoint(new MethodParameter(method,-1))); this.typeDescriptorCache.put(cacheKey, new ConversionContext(new MethodParameter(method,-1)));
return true; return true;
} }
else { else {
Field field = findField(name, type, target instanceof Class); Field field = findField(name, type, target instanceof Class);
if (field != null) { if (field != null) {
this.readerCache.put(cacheKey, field); this.readerCache.put(cacheKey, field);
this.typeDescriptorCache.put(cacheKey, new ConversionPoint(field)); this.typeDescriptorCache.put(cacheKey, new ConversionContext(field));
return true; return true;
} }
} }
@ -96,7 +96,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
if (target instanceof Class) { if (target instanceof Class) {
throw new AccessException("Cannot access length on array class itself"); throw new AccessException("Cannot access length on array class itself");
} }
return new TypedValue(Array.getLength(target),ConversionPoint.valueOf(Integer.TYPE)); return new TypedValue(Array.getLength(target),ConversionContext.valueOf(Integer.TYPE));
} }
CacheKey cacheKey = new CacheKey(type, name); CacheKey cacheKey = new CacheKey(type, name);
@ -114,7 +114,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
if (method != null) { if (method != null) {
try { try {
ReflectionUtils.makeAccessible(method); ReflectionUtils.makeAccessible(method);
ConversionPoint resultTypeDescriptor = new ConversionPoint(new MethodParameter(method,-1)); ConversionContext resultTypeDescriptor = new ConversionContext(new MethodParameter(method,-1));
return new TypedValue(method.invoke(target),resultTypeDescriptor); return new TypedValue(method.invoke(target),resultTypeDescriptor);
} }
catch (Exception ex) { catch (Exception ex) {
@ -135,7 +135,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
if (field != null) { if (field != null) {
try { try {
ReflectionUtils.makeAccessible(field); ReflectionUtils.makeAccessible(field);
return new TypedValue(field.get(target),new ConversionPoint(field)); return new TypedValue(field.get(target),new ConversionContext(field));
} }
catch (Exception ex) { catch (Exception ex) {
throw new AccessException("Unable to access field: " + name, 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); Method method = findSetterForProperty(name, type, target instanceof Class);
if (method != null) { if (method != null) {
this.writerCache.put(cacheKey, method); this.writerCache.put(cacheKey, method);
this.typeDescriptorCache.put(cacheKey, new ConversionPoint(new MethodParameter(method,0))); this.typeDescriptorCache.put(cacheKey, new ConversionContext(new MethodParameter(method,0)));
return true; return true;
} }
else { else {
Field field = findField(name, type, target instanceof Class); Field field = findField(name, type, target instanceof Class);
if (field != null) { if (field != null) {
this.writerCache.put(cacheKey, field); this.writerCache.put(cacheKey, field);
this.typeDescriptorCache.put(cacheKey, new ConversionPoint(field)); this.typeDescriptorCache.put(cacheKey, new ConversionContext(field));
return true; return true;
} }
} }
@ -179,7 +179,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass()); Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass());
Object possiblyConvertedNewValue = newValue; Object possiblyConvertedNewValue = newValue;
ConversionPoint typeDescriptor = getTypeDescriptor(context, target, name); ConversionContext typeDescriptor = getTypeDescriptor(context, target, name);
if (typeDescriptor != null) { if (typeDescriptor != null) {
try { try {
possiblyConvertedNewValue = context.getTypeConverter().convertValue(newValue, typeDescriptor); 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 + "'"); throw new AccessException("Neither setter nor field found for property '" + name + "'");
} }
private ConversionPoint getTypeDescriptor(EvaluationContext context, Object target, String name) { private ConversionContext getTypeDescriptor(EvaluationContext context, Object target, String name) {
if (target == null) { if (target == null) {
return null; return null;
} }
Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass()); Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass());
if (type.isArray() && name.equals("length")) { if (type.isArray() && name.equals("length")) {
return ConversionPoint.valueOf(Integer.TYPE); return ConversionContext.valueOf(Integer.TYPE);
} }
CacheKey cacheKey = new CacheKey(type, name); CacheKey cacheKey = new CacheKey(type, name);
ConversionPoint typeDescriptor = this.typeDescriptorCache.get(cacheKey); ConversionContext typeDescriptor = this.typeDescriptorCache.get(cacheKey);
if (typeDescriptor == null) { if (typeDescriptor == null) {
// attempt to populate the cache entry // attempt to populate the cache entry
try { try {

View File

@ -22,7 +22,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.ConstructorResolver; import org.springframework.expression.ConstructorResolver;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.MethodResolver; import org.springframework.expression.MethodResolver;
@ -75,10 +75,10 @@ public class StandardEvaluationContext implements EvaluationContext {
} }
public void setRootObject(Object rootObject) { public void setRootObject(Object rootObject) {
this.rootObject = new TypedValue(rootObject,ConversionPoint.forObject(rootObject)); this.rootObject = new TypedValue(rootObject,ConversionContext.forObject(rootObject));
} }
public void setRootObject(Object rootObject, ConversionPoint typeDescriptor) { public void setRootObject(Object rootObject, ConversionContext typeDescriptor) {
this.rootObject = new TypedValue(rootObject,typeDescriptor); this.rootObject = new TypedValue(rootObject,typeDescriptor);
} }

View File

@ -18,7 +18,7 @@ package org.springframework.expression.spel.support;
import org.springframework.core.convert.ConvertException; import org.springframework.core.convert.ConvertException;
import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.core.convert.support.DefaultTypeConverter; import org.springframework.core.convert.support.DefaultTypeConverter;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
import org.springframework.expression.TypeConverter; import org.springframework.expression.TypeConverter;
@ -46,11 +46,11 @@ public class StandardTypeConverter implements TypeConverter {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T convertValue(Object value, Class<T> targetType) throws EvaluationException { public <T> T convertValue(Object value, Class<T> targetType) throws EvaluationException {
return (T) convertValue(value, ConversionPoint.valueOf(targetType)); return (T) convertValue(value, ConversionContext.valueOf(targetType));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object convertValue(Object value, ConversionPoint typeDescriptor) throws EvaluationException { public Object convertValue(Object value, ConversionContext typeDescriptor) throws EvaluationException {
try { try {
return this.typeConverter.convert(value, typeDescriptor); return this.typeConverter.convert(value, typeDescriptor);
} }
@ -63,10 +63,10 @@ public class StandardTypeConverter implements TypeConverter {
} }
public boolean canConvert(Class<?> sourceType, Class<?> targetType) { public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
return canConvert(sourceType, ConversionPoint.valueOf(targetType)); return canConvert(sourceType, ConversionContext.valueOf(targetType));
} }
public boolean canConvert(Class<?> sourceType, ConversionPoint targetType) { public boolean canConvert(Class<?> sourceType, ConversionContext targetType) {
return this.typeConverter.canConvert(sourceType, targetType); return this.typeConverter.canConvert(sourceType, targetType);
} }

View File

@ -23,7 +23,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.AccessException; import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
@ -236,7 +236,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
private static class FruitColourAccessor implements PropertyAccessor { private static class FruitColourAccessor implements PropertyAccessor {
private static Map<String,Color> propertyMap = new HashMap<String,Color>(); private static Map<String,Color> propertyMap = new HashMap<String,Color>();
private static ConversionPoint mapElementTypeDescriptor = ConversionPoint.valueOf(Color.class); private static ConversionContext mapElementTypeDescriptor = ConversionContext.valueOf(Color.class);
static { static {
propertyMap.put("banana",Color.yellow); 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 { public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
return new TypedValue(propertyMap.get(name),ConversionPoint.valueOf(Color.class)); return new TypedValue(propertyMap.get(name),ConversionContext.valueOf(Color.class));
} }
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException { public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {

View File

@ -18,7 +18,7 @@ package org.springframework.expression.spel;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation; import org.springframework.expression.Operation;
@ -117,7 +117,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
assertEquals(TypedValue.NULL_TYPED_VALUE,state.getRootContextObject()); assertEquals(TypedValue.NULL_TYPED_VALUE,state.getRootContextObject());
((StandardEvaluationContext)state.getEvaluationContext()).setRootObject(null,ConversionPoint.NULL); ((StandardEvaluationContext)state.getEvaluationContext()).setRootObject(null,ConversionContext.NULL);
assertEquals(null,state.getRootContextObject().getValue()); assertEquals(null,state.getRootContextObject().getValue());
} }
@ -222,10 +222,10 @@ public class ExpressionStateTests extends ExpressionTestCase {
public void testTypeConversion() throws EvaluationException { public void testTypeConversion() throws EvaluationException {
ExpressionState state = getState(); ExpressionState state = getState();
String s = (String)state.convertValue(34,ConversionPoint.valueOf(String.class)); String s = (String)state.convertValue(34,ConversionContext.valueOf(String.class));
assertEquals("34",s); assertEquals("34",s);
s = (String)state.convertValue(new TypedValue(34),ConversionPoint.valueOf(String.class)); s = (String)state.convertValue(new TypedValue(34),ConversionContext.valueOf(String.class));
assertEquals("34",s); assertEquals("34",s);
} }

View File

@ -19,7 +19,7 @@ package org.springframework.expression.spel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.core.convert.support.DefaultTypeConverter; import org.springframework.core.convert.support.DefaultTypeConverter;
import org.springframework.core.convert.support.GenericTypeConverter; import org.springframework.core.convert.support.GenericTypeConverter;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
@ -35,9 +35,9 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCase { public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCase {
private static List<String> listOfString = new ArrayList<String>(); private static List<String> listOfString = new ArrayList<String>();
private static ConversionPoint typeDescriptorForListOfString = null; private static ConversionContext typeDescriptorForListOfString = null;
private static List<Integer> listOfInteger = new ArrayList<Integer>(); private static List<Integer> listOfInteger = new ArrayList<Integer>();
private static ConversionPoint typeDescriptorForListOfInteger = null; private static ConversionContext typeDescriptorForListOfInteger = null;
static { static {
listOfString.add("1"); listOfString.add("1");
@ -50,8 +50,8 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
typeDescriptorForListOfString = new ConversionPoint(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfString")); typeDescriptorForListOfString = new ConversionContext(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfString"));
typeDescriptorForListOfInteger = new ConversionPoint(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfInteger")); typeDescriptorForListOfInteger = new ConversionContext(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfInteger"));
} }
@ -96,20 +96,20 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
private final DefaultTypeConverter service = new DefaultTypeConverter(); private final DefaultTypeConverter service = new DefaultTypeConverter();
public boolean canConvert(Class<?> sourceType, Class<?> targetType) { public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
return this.service.canConvert(sourceType, ConversionPoint.valueOf(targetType)); return this.service.canConvert(sourceType, ConversionContext.valueOf(targetType));
} }
public boolean canConvert(Class<?> sourceType, ConversionPoint typeDescriptor) { public boolean canConvert(Class<?> sourceType, ConversionContext typeDescriptor) {
return this.service.canConvert(sourceType, typeDescriptor); return this.service.canConvert(sourceType, typeDescriptor);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T convertValue(Object value, Class<T> targetType) throws EvaluationException { public <T> T convertValue(Object value, Class<T> targetType) throws EvaluationException {
return (T) this.service.convert(value,ConversionPoint.valueOf(targetType)); return (T) this.service.convert(value,ConversionContext.valueOf(targetType));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object convertValue(Object value, ConversionPoint typeDescriptor) throws EvaluationException { public Object convertValue(Object value, ConversionContext typeDescriptor) throws EvaluationException {
return this.service.convert(value, typeDescriptor); return this.service.convert(value, typeDescriptor);
} }
} }

View File

@ -19,7 +19,7 @@ package org.springframework.expression.spel;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionPoint; import org.springframework.core.convert.ConversionContext;
import org.springframework.expression.AccessException; import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException; 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 { public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
return new TypedValue(new Principal(),ConversionPoint.valueOf(Principal.class)); return new TypedValue(new Principal(),ConversionContext.valueOf(Principal.class));
} }
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException { 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 { public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
return new TypedValue(activePerson,ConversionPoint.valueOf(Person.class)); return new TypedValue(activePerson,ConversionContext.valueOf(Person.class));
} }
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException { public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
@ -283,7 +283,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
if (m.isVarArgs()) { if (m.isVarArgs()) {
args = ReflectionHelper.setupArgumentsForVarargsInvocation(m.getParameterTypes(), args); args = ReflectionHelper.setupArgumentsForVarargsInvocation(m.getParameterTypes(), args);
} }
return new TypedValue(m.invoke(null, args), new ConversionPoint(new MethodParameter(m,-1))); return new TypedValue(m.invoke(null, args), new ConversionContext(new MethodParameter(m,-1)));
} }
catch (Exception ex) { catch (Exception ex) {
throw new AccessException("Problem invoking hasRole", ex); throw new AccessException("Problem invoking hasRole", ex);