BindingPoint to ConversionPoint, javadoc

This commit is contained in:
Keith Donald
2009-05-15 20:32:23 +00:00
parent 2ede4d2731
commit 46c9a003eb
40 changed files with 229 additions and 197 deletions

View File

@@ -27,17 +27,19 @@ import org.springframework.util.Assert;
// TODO doesn't support more than depth of one (eg. Map<String,List<Foo>> or List<String>[])
/**
* Type metadata about a bindable target value.
* A point where conversion needs to be performed. Provides additional context about the point such
* as field or method parameter information.
*
* @author Keith Donald
* @author Andy Clement
*/
public class BindingPoint<T> {
public class ConversionPoint<T> {
/**
* Constant value typeDescriptor for the type of a null value
*/
public final static BindingPoint NULL_TYPE_DESCRIPTOR = new BindingPoint((Class<?>) null);
@SuppressWarnings("unchecked")
public final static ConversionPoint NULL = new ConversionPoint((Class<?>) null);
private MethodParameter methodParameter;
@@ -52,7 +54,7 @@ public class BindingPoint<T> {
* a Map or collection, where no additional binding metadata is available.
* @param type the actual type
*/
public BindingPoint(Class<?> type) {
public ConversionPoint(Class<?> type) {
this.type = type;
}
@@ -61,7 +63,7 @@ public class BindingPoint<T> {
* from a method parameter, such as a setter method argument.
* @param methodParameter the MethodParameter to wrap
*/
public BindingPoint(MethodParameter methodParameter) {
public ConversionPoint(MethodParameter methodParameter) {
Assert.notNull(methodParameter, "MethodParameter must not be null");
this.methodParameter = methodParameter;
}
@@ -70,7 +72,7 @@ public class BindingPoint<T> {
* Create a new descriptor for a field. Use this constructor when a bound value originates from a field.
* @param field the field to wrap
*/
public BindingPoint(Field field) {
public ConversionPoint(Field field) {
Assert.notNull(field, "Field must not be null");
this.field = field;
}
@@ -153,7 +155,6 @@ public class BindingPoint<T> {
/**
* Determine the generic key type of the wrapped Map parameter/field, if any.
*
* @return the generic type, or <code>null</code> if none
*/
public Class<?> getMapKeyType() {
@@ -168,7 +169,6 @@ public class BindingPoint<T> {
/**
* Determine the generic value type of the wrapped Map parameter/field, if any.
*
* @return the generic type, or <code>null</code> if none
*/
public Class<?> getMapValueType() {
@@ -201,7 +201,6 @@ public class BindingPoint<T> {
* Return the wrapped MethodParameter, if any.
* <p>
* Note: Either MethodParameter or Field is available.
*
* @return the MethodParameter, or <code>null</code> if none
*/
public MethodParameter getMethodParameter() {
@@ -212,7 +211,6 @@ public class BindingPoint<T> {
* Return the wrapped Field, if any.
* <p>
* Note: Either MethodParameter or Field is available.
*
* @return the Field, or <code>null</code> if none
*/
public Field getField() {
@@ -248,7 +246,8 @@ public class BindingPoint<T> {
* @param targetType the target type
* @return true if this type is assignable to the target
*/
public boolean isAssignableTo(BindingPoint targetType) {
@SuppressWarnings("unchecked")
public boolean isAssignableTo(ConversionPoint targetType) {
return targetType.getType().isAssignableFrom(getType());
}
@@ -257,9 +256,9 @@ public class BindingPoint<T> {
* @param type the class
* @return the type descriptor
*/
public static <T> BindingPoint<T> valueOf(Class<T> type) {
public static <T> ConversionPoint<T> valueOf(Class<T> type) {
// TODO needs a cache for common type descriptors
return new BindingPoint<T>(type);
return new ConversionPoint<T>(type);
}
/**
@@ -267,9 +266,10 @@ public class BindingPoint<T> {
* @param object the object
* @return the type descriptor
*/
public static BindingPoint forObject(Object object) {
@SuppressWarnings("unchecked")
public static ConversionPoint forObject(Object object) {
if (object == null) {
return NULL_TYPE_DESCRIPTOR;
return NULL;
} else {
return valueOf(object.getClass());
}

View File

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

View File

@@ -19,10 +19,10 @@ import org.springframework.core.convert.ConvertException;
import org.springframework.core.convert.TypeConverter;
/**
* A converter converts a source object of type S to a target of type T and back.
* A converter converts a source object of type S to a target of type T.
* <p>
* Implementations of this interface are thread-safe and can be shared. Converters are typically registered with and
* accessed through a {@link TypeConverter}.
* invoked behind a {@link TypeConverter}. They typically should not be called directly.
* </p>
* @author Keith Donald
*/

View File

@@ -15,6 +15,20 @@
*/
package org.springframework.core.convert.converter;
/**
* A factory for a "ranged" converters that can convert objects from S to subtypes of R.
* @author kdonald
* @param <S> The source type converters created by this factory can convert from
* @param <R> The target range (or base) type converters created by this factory can convert to;
* for example {@link Number} for a set of number subtypes.
*/
public interface ConverterFactory<S, R> {
/**
* Get the converter to convert from S to target type T, where T is also an instance of R.
* @param <T> the target type
* @param targetType the target type to convert to
* @return A converter from S to T
*/
<T extends R> Converter<S, T> getConverter(Class<T> targetType);
}

View File

@@ -1,12 +1,29 @@
package org.springframework.core.convert.converter;
/**
* A interface for registering converters with a type conversion system.
* @author Keith Donald
*/
public interface ConverterRegistry {
/**
* Add a converter to this registry.
*/
void addConverter(Converter<?, ?> converter);
/**
* Add a converter factory to this registry.
*/
void addConverterFactory(ConverterFactory<?, ?> converter);
/**
* Remove a converter from this registry.
*/
void removeConverter(Converter<?, ?> converter);
/**
* Remove a converter factory from this registry.
*/
void removeConverterFactory(Converter<?, ?> converter);
}

View File

@@ -16,7 +16,7 @@
package org.springframework.core.convert.support;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.BindingPoint;
import org.springframework.core.convert.ConversionPoint;
/**
* 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 BindingPoint sourceCollectionType;
private ConversionPoint sourceCollectionType;
private BindingPoint targetCollectionType;
private ConversionPoint targetCollectionType;
public AbstractCollectionConverter(BindingPoint sourceCollectionType, BindingPoint targetCollectionType, GenericTypeConverter conversionService) {
public AbstractCollectionConverter(ConversionPoint sourceCollectionType, ConversionPoint targetCollectionType, GenericTypeConverter conversionService) {
this.conversionService = conversionService;
this.sourceCollectionType = sourceCollectionType;
this.targetCollectionType = targetCollectionType;
Class<?> sourceElementType = sourceCollectionType.getElementType();
Class<?> targetElementType = targetCollectionType.getElementType();
if (sourceElementType != null && targetElementType != null) {
elementConverter = conversionService.getConversionExecutor(sourceElementType, BindingPoint.valueOf(targetElementType));
elementConverter = conversionService.getConversionExecutor(sourceElementType, ConversionPoint.valueOf(targetElementType));
} else {
elementConverter = NoOpConversionExecutor.INSTANCE;
}

View File

@@ -18,7 +18,7 @@ package org.springframework.core.convert.support;
import java.lang.reflect.Array;
import org.springframework.core.convert.TypeConverter;
import org.springframework.core.convert.BindingPoint;
import org.springframework.core.convert.ConversionPoint;
/**
* 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.BindingPoint;
*/
class ArrayToArray extends AbstractCollectionConverter {
public ArrayToArray(BindingPoint sourceArrayType, BindingPoint targetArrayType, GenericTypeConverter conversionService) {
public ArrayToArray(ConversionPoint sourceArrayType, ConversionPoint targetArrayType, GenericTypeConverter conversionService) {
super(sourceArrayType, targetArrayType, conversionService);
}

View File

@@ -18,7 +18,7 @@ package org.springframework.core.convert.support;
import java.lang.reflect.Array;
import java.util.Collection;
import org.springframework.core.convert.BindingPoint;
import org.springframework.core.convert.ConversionPoint;
/**
* 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.BindingPoint;
*/
class ArrayToCollection extends AbstractCollectionConverter {
public ArrayToCollection(BindingPoint sourceArrayType, BindingPoint targetCollectionType,
public ArrayToCollection(ConversionPoint sourceArrayType, ConversionPoint targetCollectionType,
GenericTypeConverter conversionService) {
super(sourceArrayType, targetCollectionType, conversionService);
}

View File

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

View File

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

View File

@@ -28,7 +28,7 @@ import java.util.Map;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeConverter;
import org.springframework.core.convert.BindingPoint;
import org.springframework.core.convert.ConversionPoint;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.core.convert.converter.ConverterInfo;
@@ -98,10 +98,10 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
return canConvert(sourceType, BindingPoint.valueOf(targetType));
return canConvert(sourceType, ConversionPoint.valueOf(targetType));
}
public boolean canConvert(Class<?> sourceType, BindingPoint<?> targetType) {
public boolean canConvert(Class<?> sourceType, ConversionPoint<?> targetType) {
ConversionExecutor executor = getConversionExecutor(sourceType, targetType);
if (executor != null) {
return true;
@@ -115,10 +115,10 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
}
public <S, T> T convert(S source, Class<T> targetType) {
return convert(source, BindingPoint.valueOf(targetType));
return convert(source, ConversionPoint.valueOf(targetType));
}
public <S, T> T convert(S source, BindingPoint<T> targetType) {
public <S, T> T convert(S source, ConversionPoint<T> targetType) {
if (source == null) {
return null;
}
@@ -139,11 +139,11 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
}
}
ConversionExecutor getConversionExecutor(Class sourceClass, BindingPoint targetType)
ConversionExecutor getConversionExecutor(Class sourceClass, ConversionPoint targetType)
throws ConverterNotFoundException {
Assert.notNull(sourceClass, "The sourceType to convert from is required");
Assert.notNull(targetType, "The targetType to convert to is required");
BindingPoint sourceType = BindingPoint.valueOf(sourceClass);
ConversionPoint sourceType = ConversionPoint.valueOf(sourceClass);
if (sourceType.isArray()) {
if (targetType.isArray()) {
return new ArrayToArray(sourceType, targetType, this);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -28,7 +28,7 @@ import java.util.Map;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.core.convert.BindingPoint;
import org.springframework.core.convert.ConversionPoint;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.converter.Converter;
@@ -156,7 +156,7 @@ public class GenericTypeConverterTests {
@Test
public void convertArrayToListGenericTypeConversion() throws Exception {
converter.addConverter(new StringToInteger());
List<Integer> result = converter.convert(new String[] { "1", "2", "3" }, new BindingPoint<List<Integer>>(getClass().getDeclaredField("genericList")));
List<Integer> result = converter.convert(new String[] { "1", "2", "3" }, new ConversionPoint<List<Integer>>(getClass().getDeclaredField("genericList")));
assertEquals(new Integer("1"), result.get(0));
assertEquals(new Integer("2"), result.get(1));
assertEquals(new Integer("3"), result.get(2));
@@ -214,7 +214,7 @@ public class GenericTypeConverterTests {
foo.put("2", "BAZ");
converter.addConverter(new StringToInteger());
converter.addConverter(new StringToEnumFactory().getConverter(FooEnum.class));
Map<String, FooEnum> map = converter.convert(foo, new BindingPoint<Map<String, FooEnum>>(getClass().getField("genericMap")));
Map<String, FooEnum> map = converter.convert(foo, new ConversionPoint<Map<String, FooEnum>>(getClass().getField("genericMap")));
assertEquals(map.get(1), FooEnum.BAR);
assertEquals(map.get(2), FooEnum.BAZ);
}

View File

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