sourceClass) throws Exception;
-
-}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/TwoWayConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/converter/TwoWayConverter.java
deleted file mode 100644
index f31ba5e1d2c..00000000000
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/TwoWayConverter.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.springframework.core.convert.converter;
-
-import org.springframework.core.convert.ConversionService;
-import org.springframework.core.convert.ConvertException;
-
-/**
- * A converter that can also convert a target object of type T to a source of class S.
- *
- * Implementations of this interface are thread-safe and can be shared. Converters are typically registered with and
- * accessed through a {@link ConversionService}.
- *
- * @author Keith Donald
- */
-public interface TwoWayConverter extends Converter {
-
- /**
- * Convert the target of type T back to source type S.
- * @param target the target object to convert, which must be an instance of T
- * @return the converted object, which must be an instance of S
- * @throws Exception an exception occurred performing the conversion; may be any checked exception, the conversion
- * system will handle wrapping the failure in a {@link ConvertException} that provides a consistent type
- * conversion error context
- */
- public S convertBack(T target) throws Exception;
-}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/package.html b/org.springframework.core/src/main/java/org/springframework/core/convert/converter/package.html
index 59e9fba652b..b177a079bc2 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/package.html
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/converter/package.html
@@ -1,7 +1,7 @@
-User Converter API and default Converter implementations.
+SPI to implement Converters.
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/package.html b/org.springframework.core/src/main/java/org/springframework/core/convert/package.html
index c2fb2e8425b..31a8c0d2932 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/package.html
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/package.html
@@ -1,7 +1,7 @@
-Type conversion system SPI.
+Type conversion system API.
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/ReverseSuperConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/service/ReverseSuperConverter.java
deleted file mode 100644
index 1ec9686cf62..00000000000
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/ReverseSuperConverter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2004-2009 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.core.convert.service;
-
-import org.springframework.core.convert.converter.SuperConverter;
-import org.springframework.core.convert.converter.SuperTwoWayConverter;
-
-/**
- * A super converter that reverses another super converter.
- * @author Keith Donald
- */
-@SuppressWarnings("unchecked")
-class ReverseSuperConverter implements SuperConverter {
-
- private SuperTwoWayConverter converter;
-
- public ReverseSuperConverter(SuperTwoWayConverter converter) {
- this.converter = converter;
- }
-
- public Object convert(Object source, Class targetClass) throws Exception {
- return converter.convertBack(source, targetClass);
- }
-
-}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/StaticSuperConversionExecutor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/service/StaticSuperConversionExecutor.java
deleted file mode 100644
index e1f1303391c..00000000000
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/StaticSuperConversionExecutor.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2004-2009 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.core.convert.service;
-
-import org.springframework.core.convert.ConversionExecutionException;
-import org.springframework.core.convert.TypeDescriptor;
-import org.springframework.core.convert.converter.SuperConverter;
-import org.springframework.core.style.ToStringCreator;
-
-/**
- * Default conversion executor implementation for super converters.
- * @author Keith Donald
- */
-@SuppressWarnings("unchecked")
-class StaticSuperConversionExecutor implements ConversionExecutor {
-
- private final TypeDescriptor sourceType;
-
- private final TypeDescriptor targetType;
-
- private final SuperConverter converter;
-
- public StaticSuperConversionExecutor(TypeDescriptor sourceType, TypeDescriptor targetType, SuperConverter converter) {
- this.sourceType = sourceType;
- this.targetType = targetType;
- this.converter = converter;
- }
-
- public Object execute(Object source) throws ConversionExecutionException {
- if (source == null) {
- return null;
- }
- if (!sourceType.isInstance(source)) {
- throw new ConversionExecutionException(source, sourceType.getType(), targetType, "Source object "
- + source + " to convert is expected to be an instance of [" + sourceType.getName() + "]");
- }
- try {
- return converter.convert(source, targetType.getType());
- } catch (Exception e) {
- throw new ConversionExecutionException(source, sourceType.getType(), targetType, e);
- }
- }
-
- public boolean equals(Object o) {
- if (!(o instanceof StaticSuperConversionExecutor)) {
- return false;
- }
- StaticSuperConversionExecutor other = (StaticSuperConversionExecutor) o;
- return sourceType.equals(other.sourceType) && targetType.equals(other.targetType);
- }
-
- public int hashCode() {
- return sourceType.hashCode() + targetType.hashCode();
- }
-
- public String toString() {
- return new ToStringCreator(this).append("sourceClass", sourceType).append("targetClass", targetType)
- .toString();
- }
-}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/SuperTwoWayConverterConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/service/SuperTwoWayConverterConverter.java
deleted file mode 100644
index 479d065e261..00000000000
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/SuperTwoWayConverterConverter.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2004-2009 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.core.convert.service;
-
-import org.springframework.core.convert.converter.Converter;
-import org.springframework.core.convert.converter.ConverterInfo;
-import org.springframework.core.convert.converter.SuperConverter;
-import org.springframework.core.convert.converter.SuperTwoWayConverter;
-
-/**
- * Adapts a {@link SuperTwoWayConverter} to the {@link Converter} interface in a type safe way. This adapter is useful
- * for applying more general {@link SuperConverter} logic to a specific source/target class pair.
- */
-@SuppressWarnings("unchecked")
-class SuperTwoWayConverterConverter implements Converter, ConverterInfo {
-
- private SuperTwoWayConverter superConverter;
-
- private Class sourceType;
-
- private Class targetType;
-
- public SuperTwoWayConverterConverter(SuperTwoWayConverter superConverter, Class sourceType, Class targetType) {
- this.superConverter = superConverter;
- this.sourceType = sourceType;
- this.targetType = targetType;
- }
-
- public Class getSourceType() {
- return sourceType;
- }
-
- public Class getTargetType() {
- return targetType;
- }
-
- public Object convert(Object source) throws Exception {
- return superConverter.convert(source, targetType);
- }
-
- public Object convertBack(Object target) throws Exception {
- return superConverter.convertBack(target, sourceType);
- }
-
-}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/package.html b/org.springframework.core/src/main/java/org/springframework/core/convert/service/package.html
deleted file mode 100644
index e62832fd8b1..00000000000
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/package.html
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-ConversionService implementation.
-
-
-
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/AbstractCollectionConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/AbstractCollectionConverter.java
similarity index 89%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/AbstractCollectionConverter.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/AbstractCollectionConverter.java
index a5ef6262e97..3c546d1a0da 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/AbstractCollectionConverter.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/AbstractCollectionConverter.java
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
-import org.springframework.core.convert.ConversionExecutionException;
-import org.springframework.core.convert.ConversionService;
+import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.TypeDescriptor;
/**
@@ -72,11 +71,11 @@ abstract class AbstractCollectionConverter implements ConversionExecutor {
return elementConverter;
}
- public Object execute(Object source) throws ConversionExecutionException {
+ public Object execute(Object source) {
try {
return doExecute(source);
} catch (Exception e) {
- throw new ConversionExecutionException(source, sourceCollectionType.getType(), targetCollectionType, e);
+ throw new ConversionException(source, sourceCollectionType.getType(), targetCollectionType.getType(), e);
}
}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/ArrayToArray.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArray.java
similarity index 87%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/ArrayToArray.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArray.java
index 2ffa0253244..4ec9b2e77e5 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/ArrayToArray.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArray.java
@@ -13,17 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import java.lang.reflect.Array;
-import org.springframework.core.convert.ConversionService;
+import org.springframework.core.convert.TypeConverter;
import org.springframework.core.convert.TypeDescriptor;
/**
* Special one-way converter that converts from a source array to a target array. Supports type conversion of the
* individual array elements; for example, the ability to convert a String[] to an Integer[]. Mainly used internally by
- * {@link ConversionService} implementations.
+ * {@link TypeConverter} implementations.
*
* @author Keith Donald
*/
@@ -34,7 +34,7 @@ class ArrayToArray extends AbstractCollectionConverter {
}
@Override
- public Object doExecute(Object sourceArray) throws Exception {
+ public Object doExecute(Object sourceArray) {
int length = Array.getLength(sourceArray);
Object targetArray = Array.newInstance(getTargetElementType(), length);
for (int i = 0; i < length; i++) {
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/ArrayToCollection.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollection.java
similarity index 97%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/ArrayToCollection.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollection.java
index e21315f5617..b01566c15ec 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/ArrayToCollection.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollection.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import java.lang.reflect.Array;
import java.util.Collection;
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/NumberToCharacter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CharacterToNumberFactory.java
similarity index 58%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/NumberToCharacter.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/CharacterToNumberFactory.java
index 636f450b68f..54d48de9850 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/NumberToCharacter.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CharacterToNumberFactory.java
@@ -13,12 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.util.NumberUtils;
/**
- * Converts from any JDK-standard Number implementation to a Character and back.
+ * Converts from a Character to any JDK-standard Number implementation.
*
* Support Number classes including Byte, Short, Integer, Float, Double, Long, BigInteger, BigDecimal. This class
* delegates to {@link NumberUtils#convertNumberToTargetClass(Number, Class)} to perform the conversion.
@@ -35,15 +37,23 @@ import org.springframework.util.NumberUtils;
*
* @author Keith Donald
*/
-public class NumberToCharacter implements SuperTwoWayConverter {
+public class CharacterToNumberFactory implements ConverterFactory {
- @SuppressWarnings("unchecked")
- public RT convert(Number source, Class targetClass) {
- return (RT) Character.valueOf((char) source.shortValue());
+ public Converter getConverter(Class targetType) {
+ return new CharacterToNumber(targetType);
}
- public RS convertBack(Character target, Class sourceClass) {
- return NumberUtils.convertNumberToTargetClass((short) target.charValue(), sourceClass);
- }
+ private static class CharacterToNumber implements Converter {
+
+ private Class targetType;
+
+ public CharacterToNumber(Class targetType) {
+ this.targetType = targetType;
+ }
+ public T convert(Character source) throws Exception {
+ return NumberUtils.convertNumberToTargetClass((short) source.charValue(), targetType);
+ }
+
+ }
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionConversionUtils.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionConversionUtils.java
similarity index 97%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionConversionUtils.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionConversionUtils.java
index f899af5f2b4..950c395c906 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionConversionUtils.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionConversionUtils.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import java.util.ArrayList;
import java.util.Collection;
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionToArray.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArray.java
similarity index 93%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionToArray.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArray.java
index d70bdae5159..61aae61ef6c 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionToArray.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArray.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import java.lang.reflect.Array;
import java.util.Collection;
@@ -57,7 +57,7 @@ class CollectionToArray extends AbstractCollectionConverter {
}
}
}
- return elementConverter;
+ return elementConverter != null ? elementConverter : NoOpConversionExecutor.INSTANCE;
}
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionToCollection.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollection.java
similarity index 97%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionToCollection.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollection.java
index b189b547035..3e715cb1227 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionToCollection.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollection.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import java.util.Collection;
import java.util.Iterator;
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/ConversionExecutor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ConversionExecutor.java
similarity index 83%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/ConversionExecutor.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/ConversionExecutor.java
index a84bbe5019c..283f1ef858b 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/ConversionExecutor.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ConversionExecutor.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
-import org.springframework.core.convert.ConversionExecutionException;
+import org.springframework.core.convert.ConversionException;
/**
* A command parameterized with the information necessary to perform a conversion of a source input to a
@@ -29,7 +29,7 @@ public interface ConversionExecutor {
/**
* Convert the source.
* @param source the source to convert
- * @throws ConversionExecutionException if an exception occurs during type conversion
+ * @throws ConversionException if an exception occurs during type conversion
*/
public Object execute(Object source);
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/DefaultConversionService.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java
similarity index 57%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/DefaultConversionService.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java
index 73e28ea151a..18bbf942c26 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/DefaultConversionService.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java
@@ -13,28 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Date;
-import java.util.Locale;
-
-import org.springframework.core.convert.converter.NumberToCharacter;
-import org.springframework.core.convert.converter.NumberToNumber;
-import org.springframework.core.convert.converter.ObjectToString;
-import org.springframework.core.convert.converter.StringToBigDecimal;
-import org.springframework.core.convert.converter.StringToBigInteger;
-import org.springframework.core.convert.converter.StringToBoolean;
-import org.springframework.core.convert.converter.StringToByte;
-import org.springframework.core.convert.converter.StringToCharacter;
-import org.springframework.core.convert.converter.StringToDouble;
-import org.springframework.core.convert.converter.StringToEnum;
-import org.springframework.core.convert.converter.StringToFloat;
-import org.springframework.core.convert.converter.StringToInteger;
-import org.springframework.core.convert.converter.StringToLocale;
-import org.springframework.core.convert.converter.StringToLong;
-import org.springframework.core.convert.converter.StringToShort;
+import org.springframework.core.convert.support.StringToEnumFactory.StringToEnum;
/**
* Default implementation of a conversion service. Will automatically register from string converters for
@@ -66,8 +47,6 @@ public class DefaultConversionService extends GenericConversionService {
addConverter(new StringToBigInteger());
addConverter(new StringToBigDecimal());
addConverter(new StringToLocale());
- addConverter(new StringToEnum());
- addConverter(new NumberToNumber());
addConverter(new NumberToCharacter());
addConverter(new ObjectToString());
}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/GenericConversionService.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
similarity index 59%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/GenericConversionService.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
index d9f35da6d3b..0e4d29f31a5 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/GenericConversionService.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@@ -26,14 +26,11 @@ import java.util.List;
import java.util.Map;
import org.springframework.core.GenericTypeResolver;
-import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.ConverterNotFoundException;
+import org.springframework.core.convert.TypeConverter;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterInfo;
-import org.springframework.core.convert.converter.SuperConverter;
-import org.springframework.core.convert.converter.SuperTwoWayConverter;
-import org.springframework.core.convert.converter.TwoWayConverter;
import org.springframework.util.Assert;
/**
@@ -46,7 +43,7 @@ import org.springframework.util.Assert;
* @author Keith Donald
*/
@SuppressWarnings("unchecked")
-public class GenericConversionService implements ConversionService {
+public class GenericConversionService implements TypeConverter {
/**
* An indexed map of Converters. Each Map.Entry key is a source class (S) that can be converted from. Each Map.Entry
@@ -54,28 +51,22 @@ public class GenericConversionService implements ConversionService {
*/
private final Map sourceTypeConverters = new HashMap();
- /**
- * An indexed map of SuperConverters. Each Map.Entry key is a source class (S) that can be converted from. Each
- * Map.Entry value is a Map that defines the targetType-to-SuperConverter mappings for that source.
- */
- private final Map sourceTypeSuperConverters = new HashMap();
-
/**
* An optional parent conversion service.
*/
- private ConversionService parent;
+ private TypeConverter parent;
/**
* Returns the parent of this conversion service. Could be null.
*/
- public ConversionService getParent() {
+ public TypeConverter getParent() {
return parent;
}
/**
* Set the parent of this conversion service. This is optional.
*/
- public void setParent(ConversionService parent) {
+ public void setParent(TypeConverter parent) {
this.parent = parent;
}
@@ -90,47 +81,11 @@ public class GenericConversionService implements ConversionService {
// index forward
Map sourceMap = getSourceMap(sourceType);
sourceMap.put(targetType, converter);
- if (converter instanceof TwoWayConverter) {
- // index reverse
- sourceMap = getSourceMap(targetType);
- sourceMap.put(sourceType, new ReverseConverter((TwoWayConverter) converter));
- }
- }
-
- /**
- * Register the SuperConverter with this conversion service.
- * @param converter the super converter to register
- */
- public void addConverter(SuperConverter converter) {
- List typeInfo = getRequiredTypeInfo(converter);
- Class sourceType = (Class) typeInfo.get(0);
- Class targetType = (Class) typeInfo.get(1);
- // index forward
- Map sourceMap = getSourceSuperConverterMap(sourceType);
- sourceMap.put(targetType, converter);
- if (converter instanceof SuperTwoWayConverter) {
- // index reverse
- sourceMap = getSourceSuperConverterMap(targetType);
- sourceMap.put(sourceType, new ReverseSuperConverter((SuperTwoWayConverter) converter));
- }
- }
-
- /**
- * Adapts a {@link SuperTwoWayConverter} that converts between BS and BT class hierarchies to a {@link Converter}
- * that converts between the specific BS/BT sub types S and T.
- * @param sourceType the source class S to convert from, which must be equal or extend BS
- * @param targetType the target type T to convert to, which must equal or extend BT
- * @param converter the super two way converter
- * @return a converter that converts from S to T by delegating to the super converter
- */
- public static Converter converterFor(Class sourceType, Class targetType,
- SuperTwoWayConverter converter) {
- return new SuperTwoWayConverterConverter(converter, sourceType, targetType);
}
// implementing ConversionService
- public boolean canConvert(Class> sourceType, TypeDescriptor targetType) {
+ public boolean canConvert(Class> sourceType, TypeDescriptor> targetType) {
ConversionExecutor executor = getConversionExecutor(sourceType, targetType);
if (executor != null) {
return true;
@@ -147,6 +102,9 @@ public class GenericConversionService implements ConversionService {
if (source == null) {
return null;
}
+ if (source.getClass().isAssignableFrom(targetType.getType())) {
+ return source;
+ }
ConversionExecutor executor = getConversionExecutor(source.getClass(), targetType);
if (executor != null) {
return executor.execute(source);
@@ -154,7 +112,7 @@ public class GenericConversionService implements ConversionService {
if (parent != null) {
return parent.convert(source, targetType);
} else {
- throw new ConverterNotFoundException(source.getClass(), targetType,
+ throw new ConverterNotFoundException(source.getClass(), targetType.getType(),
"No converter found that can convert from sourceType [" + source.getClass().getName()
+ "] to targetType [" + targetType.getName() + "]");
}
@@ -203,15 +161,7 @@ public class GenericConversionService implements ConversionService {
if (converter != null) {
return new StaticConversionExecutor(sourceType, targetType, converter);
} else {
- SuperConverter superConverter = findRegisteredSuperConverter(sourceClass, targetType.getType());
- if (superConverter != null) {
- return new StaticSuperConversionExecutor(sourceType, targetType, superConverter);
- } else {
- if (sourceType.isAssignableTo(targetType)) {
- return new StaticConversionExecutor(sourceType, targetType, NoOpConverter.INSTANCE);
- }
- return null;
- }
+ return null;
}
}
@@ -231,8 +181,7 @@ public class GenericConversionService implements ConversionService {
for (Type genericInterface : genericInterfaces) {
if (genericInterface instanceof ParameterizedType) {
ParameterizedType pInterface = (ParameterizedType) genericInterface;
- if (Converter.class.isAssignableFrom((Class) pInterface.getRawType())
- || SuperConverter.class.isAssignableFrom((Class) pInterface.getRawType())) {
+ if (Converter.class.isAssignableFrom((Class) pInterface.getRawType())) {
Class s = getParameterClass(pInterface.getActualTypeArguments()[0], converter.getClass());
Class t = getParameterClass(pInterface.getActualTypeArguments()[1], converter.getClass());
typeInfo.add(getParameterClass(s, converter.getClass()));
@@ -270,15 +219,6 @@ public class GenericConversionService implements ConversionService {
return sourceMap;
}
- private Map getSourceSuperConverterMap(Class sourceType) {
- Map sourceMap = (Map) sourceTypeSuperConverters.get(sourceType);
- if (sourceMap == null) {
- sourceMap = new HashMap();
- sourceTypeSuperConverters.put(sourceType, sourceMap);
- }
- return sourceMap;
- }
-
private Converter findRegisteredConverter(Class> sourceType, Class> targetType) {
if (sourceType.isInterface()) {
LinkedList classQueue = new LinkedList();
@@ -328,89 +268,4 @@ public class GenericConversionService implements ConversionService {
return (Converter) converters.get(targetType);
}
- private SuperConverter findRegisteredSuperConverter(Class> sourceType, Class> targetType) {
- if (sourceType.isInterface()) {
- LinkedList classQueue = new LinkedList();
- classQueue.addFirst(sourceType);
- while (!classQueue.isEmpty()) {
- Class currentClass = (Class) classQueue.removeLast();
- Map converters = getSuperConvertersForSource(currentClass);
- SuperConverter converter = findSuperConverter(converters, targetType);
- if (converter != null) {
- return converter;
- }
- Class[] interfaces = currentClass.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- classQueue.addFirst(interfaces[i]);
- }
- }
- Map objectConverters = getSuperConvertersForSource(Object.class);
- return findSuperConverter(objectConverters, targetType);
- } else {
- LinkedList classQueue = new LinkedList();
- classQueue.addFirst(sourceType);
- while (!classQueue.isEmpty()) {
- Class currentClass = (Class) classQueue.removeLast();
- Map converters = getSuperConvertersForSource(currentClass);
- SuperConverter converter = findSuperConverter(converters, targetType);
- if (converter != null) {
- return converter;
- }
- if (currentClass.getSuperclass() != null) {
- classQueue.addFirst(currentClass.getSuperclass());
- }
- Class[] interfaces = currentClass.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- classQueue.addFirst(interfaces[i]);
- }
- }
- return null;
- }
- }
-
- private Map getSuperConvertersForSource(Class sourceType) {
- Map converters = (Map) sourceTypeSuperConverters.get(sourceType);
- return converters != null ? converters : Collections.emptyMap();
- }
-
- private SuperConverter findSuperConverter(Map converters, Class targetType) {
- if (converters.isEmpty()) {
- return null;
- }
- if (targetType.isInterface()) {
- LinkedList classQueue = new LinkedList();
- classQueue.addFirst(targetType);
- while (!classQueue.isEmpty()) {
- Class currentClass = (Class) classQueue.removeLast();
- SuperConverter converter = (SuperConverter) converters.get(currentClass);
- if (converter != null) {
- return converter;
- }
- Class[] interfaces = currentClass.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- classQueue.addFirst(interfaces[i]);
- }
- }
- return (SuperConverter) converters.get(Object.class);
- } else {
- LinkedList classQueue = new LinkedList();
- classQueue.addFirst(targetType);
- while (!classQueue.isEmpty()) {
- Class currentClass = (Class) classQueue.removeLast();
- SuperConverter converter = (SuperConverter) converters.get(currentClass);
- if (converter != null) {
- return converter;
- }
- if (currentClass.getSuperclass() != null) {
- classQueue.addFirst(currentClass.getSuperclass());
- }
- Class[] interfaces = currentClass.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- classQueue.addFirst(interfaces[i]);
- }
- }
- return null;
- }
- }
-
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/MapToMap.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMap.java
similarity index 93%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/MapToMap.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMap.java
index 9d6712433e6..5925d195fdb 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/MapToMap.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMap.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import java.util.HashMap;
import java.util.Iterator;
@@ -21,8 +21,7 @@ import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
-import org.springframework.core.convert.ConversionExecutionException;
-import org.springframework.core.convert.ConversionService;
+import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.TypeDescriptor;
/**
@@ -65,7 +64,7 @@ class MapToMap implements ConversionExecutor {
}
@SuppressWarnings("unchecked")
- public Object execute(Object source) throws ConversionExecutionException {
+ public Object execute(Object source) throws ConversionException {
try {
Map map = (Map) source;
Map targetMap = (Map) getImpl(targetType.getType()).newInstance();
@@ -77,7 +76,7 @@ class MapToMap implements ConversionExecutor {
}
return targetMap;
} catch (Exception e) {
- throw new ConversionExecutionException(source, sourceType.getType(), targetType, e);
+ throw new ConversionException(source, sourceType.getType(), targetType.getType(), e);
}
}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/NoOpConversionExecutor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/NoOpConversionExecutor.java
similarity index 80%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/NoOpConversionExecutor.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/NoOpConversionExecutor.java
index 086eb3330be..0295ec891c5 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/NoOpConversionExecutor.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/NoOpConversionExecutor.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
-import org.springframework.core.convert.ConversionExecutionException;
+import org.springframework.core.convert.ConversionException;
/**
* Conversion executor that does nothing. Access singleton at {@link #INSTANCE}.s
@@ -28,7 +28,7 @@ class NoOpConversionExecutor implements ConversionExecutor {
}
- public Object execute(Object source) throws ConversionExecutionException {
+ public Object execute(Object source) throws ConversionException {
return source;
}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/NoOpConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/NoOpConverter.java
similarity index 92%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/NoOpConverter.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/NoOpConverter.java
index 4f468924ea1..8d5a5a754c9 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/NoOpConverter.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/NoOpConverter.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import org.springframework.core.convert.converter.Converter;
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/NumberToCharacter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/NumberToCharacter.java
new file mode 100644
index 00000000000..8759e5142fc
--- /dev/null
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/NumberToCharacter.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2004-2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.core.convert.support;
+
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.util.NumberUtils;
+
+/**
+ * Converts from any JDK-standard Number implementation to a Character.
+ *
+ * @see java.lang.Character
+ * @see java.lang.Short
+ * @see java.lang.Integer
+ * @see java.lang.Long
+ * @see java.math.BigInteger
+ * @see java.lang.Float
+ * @see java.lang.Double
+ * @see java.math.BigDecimal
+ * @see NumberUtils
+ *
+ * @author Keith Donald
+ */
+public class NumberToCharacter implements Converter {
+ public Character convert(Number source) {
+ return Character.valueOf((char) source.shortValue());
+ }
+}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/NumberToNumber.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/NumberToNumberFactory.java
similarity index 63%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/NumberToNumber.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/NumberToNumberFactory.java
index 37e1e63c2e1..52cebbe0c0a 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/NumberToNumber.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/NumberToNumberFactory.java
@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.util.NumberUtils;
/**
@@ -35,10 +37,23 @@ import org.springframework.util.NumberUtils;
*
* @author Keith Donald
*/
-public class NumberToNumber implements SuperConverter {
+public class NumberToNumberFactory implements ConverterFactory {
- public RT convert(Number source, Class targetClass) {
- return NumberUtils.convertNumberToTargetClass(source, targetClass);
+ public Converter getConverter(Class targetType) {
+ return new NumberToNumber(targetType);
}
+ private static class NumberToNumber implements Converter {
+
+ private Class targetType;
+
+ public NumberToNumber(Class targetType) {
+ this.targetType = targetType;
+ }
+
+ public T convert(Number source) throws Exception {
+ return NumberUtils.convertNumberToTargetClass(source, targetType);
+ }
+
+ }
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToString.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToString.java
new file mode 100644
index 00000000000..e34ae930682
--- /dev/null
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToString.java
@@ -0,0 +1,14 @@
+package org.springframework.core.convert.support;
+
+import org.springframework.core.convert.converter.Converter;
+
+/**
+ * Simply calls {@link Object#toString()} to convert any object to a string.
+ * Used by the {@link DefaultConversionService} as a fallback if there are no other explicit to string converters registered.
+ * @author Keith Donald
+ */
+public class ObjectToString implements Converter {
+ public String convert(Object source) {
+ return source.toString();
+ }
+}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/StaticConversionExecutor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StaticConversionExecutor.java
similarity index 84%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/StaticConversionExecutor.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StaticConversionExecutor.java
index be3b767a9aa..9facd0d5a09 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/StaticConversionExecutor.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StaticConversionExecutor.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
-import org.springframework.core.convert.ConversionExecutionException;
+import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.style.ToStringCreator;
@@ -39,18 +39,18 @@ class StaticConversionExecutor implements ConversionExecutor {
this.converter = converter;
}
- public Object execute(Object source) throws ConversionExecutionException {
+ public Object execute(Object source) throws ConversionException {
if (source == null) {
return null;
}
if (sourceType != null && !sourceType.isInstance(source)) {
- throw new ConversionExecutionException(source, sourceType.getType(), targetType, "Source object "
+ throw new ConversionException(source, sourceType.getType(), targetType.getType(), "Source object "
+ source + " to convert is expected to be an instance of [" + sourceType.getName() + "]");
}
try {
return converter.convert(source);
} catch (Exception e) {
- throw new ConversionExecutionException(source, sourceType.getType(), targetType, e);
+ throw new ConversionException(source, sourceType.getType(), targetType.getType(), e);
}
}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigDecimal.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBigDecimal.java
similarity index 79%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigDecimal.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBigDecimal.java
index 68d81aad77d..a7e7c6689bc 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigDecimal.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBigDecimal.java
@@ -13,23 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
import java.math.BigDecimal;
+import org.springframework.core.convert.converter.Converter;
+
/**
* Converts a String to a BigDecimal using {@link BigDecimal#BigDecimal(String).
*
* @author Keith Donald
*/
-public class StringToBigDecimal implements TwoWayConverter {
-
+public class StringToBigDecimal implements Converter {
public BigDecimal convert(String source) {
return new BigDecimal(source);
}
-
- public String convertBack(BigDecimal target) {
- return target.toString();
- }
-
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigInteger.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBigInteger.java
similarity index 79%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigInteger.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBigInteger.java
index fabb6d0648a..b2757712b9b 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigInteger.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBigInteger.java
@@ -13,23 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
import java.math.BigInteger;
+import org.springframework.core.convert.converter.Converter;
+
/**
* Converts a String to a BigInteger using {@link BigInteger#BigInteger(String)}.
*
* @author Keith Donald
*/
-public class StringToBigInteger implements TwoWayConverter {
-
+public class StringToBigInteger implements Converter {
public BigInteger convert(String source) {
return new BigInteger(source);
}
-
- public String convertBack(BigInteger target) {
- return target.toString();
- }
-
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/service/ReverseConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBoolean.java
similarity index 57%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/service/ReverseConverter.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBoolean.java
index d35559cd91d..21337b42346 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/service/ReverseConverter.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBoolean.java
@@ -13,26 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import org.springframework.core.convert.converter.Converter;
-import org.springframework.core.convert.converter.TwoWayConverter;
+
/**
- * A converter that reverses another converter.
+ * Converts String to a Boolean. The trueString and falseStrings are configurable.
+ *
+ * @see #StringToBoolean(String, String)
* @author Keith Donald
*/
-@SuppressWarnings("unchecked")
-class ReverseConverter implements Converter {
+public class StringToBoolean implements Converter {
- private TwoWayConverter converter;
-
- public ReverseConverter(TwoWayConverter converter) {
- this.converter = converter;
- }
-
- public Object convert(Object source) throws Exception {
- return converter.convertBack(source);
+ public Boolean convert(String source) {
+ if (source.equals("true")) {
+ return Boolean.TRUE;
+ } else if (source.equals("false")) {
+ return Boolean.FALSE;
+ } else {
+ throw new IllegalArgumentException("Invalid boolean string '" + source + "'; expected 'true' or 'false'");
+ }
}
-}
+}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToByte.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToByte.java
similarity index 79%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToByte.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToByte.java
index ca91c077b34..a6dcaaccbe0 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToByte.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToByte.java
@@ -13,21 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
+
+import org.springframework.core.convert.converter.Converter;
/**
* Converts a String to a Byte and back.
*
* @author Keith Donald
*/
-public class StringToByte implements TwoWayConverter {
-
+public class StringToByte implements Converter {
public Byte convert(String source) {
return Byte.valueOf(source);
}
-
- public String convertBack(Byte target) {
- return target.toString();
- }
-
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToCharacter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCharacter.java
similarity index 81%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToCharacter.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCharacter.java
index d15aa1e02e8..f1f67453132 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToCharacter.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCharacter.java
@@ -13,24 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
+
+import org.springframework.core.convert.converter.Converter;
/**
* Converts a String to a Character and back.
*
* @author Keith Donald
*/
-public class StringToCharacter implements TwoWayConverter {
-
+public class StringToCharacter implements Converter {
public Character convert(String source) {
if (source.length() != 1) {
throw new IllegalArgumentException("To be a Character the String '" + source + "' must have a length of 1");
}
return Character.valueOf(source.charAt(0));
}
-
- public String convertBack(Character target) {
- return target.toString();
- }
-
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToDouble.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToDouble.java
similarity index 79%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToDouble.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToDouble.java
index 7e816f41498..f67ec9bb781 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToDouble.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToDouble.java
@@ -13,21 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
+
+import org.springframework.core.convert.converter.Converter;
/**
* Converts a String to a Double using {@link Double#valueOf(String)}.
*
* @author Keith Donald
*/
-public class StringToDouble implements TwoWayConverter {
-
+public class StringToDouble implements Converter {
public Double convert(String source) {
return Double.valueOf(source);
}
-
- public String convertBack(Double target) {
- return target.toString();
- }
-
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToEnumFactory.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToEnumFactory.java
new file mode 100644
index 00000000000..8ab17c34650
--- /dev/null
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToEnumFactory.java
@@ -0,0 +1,26 @@
+package org.springframework.core.convert.support;
+
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.core.convert.converter.ConverterFactory;
+
+@SuppressWarnings("unchecked")
+public class StringToEnumFactory implements ConverterFactory {
+
+ public Converter getConverter(Class targetType) {
+ return new StringToEnum(targetType);
+ }
+
+ class StringToEnum implements Converter {
+
+ private Class enumType;
+
+ public StringToEnum(Class enumType) {
+ this.enumType = enumType;
+ }
+
+ public T convert(String source) throws Exception {
+ return Enum.valueOf(enumType, source);
+ }
+ }
+
+}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToFloat.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToFloat.java
similarity index 80%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToFloat.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToFloat.java
index a513ff43209..b734722439c 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToFloat.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToFloat.java
@@ -13,21 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
+
+import org.springframework.core.convert.converter.Converter;
/**
* Converts a String to Float using {@link Float#valueOf(String)}.
*
* @author Keith Donald
*/
-public class StringToFloat implements TwoWayConverter {
-
+public class StringToFloat implements Converter {
public Float convert(String source) {
return Float.valueOf(source);
}
-
- public String convertBack(Float target) {
- return target.toString();
- }
-
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToInteger.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToInteger.java
similarity index 79%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToInteger.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToInteger.java
index db6c44aa794..b214b6eea16 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToInteger.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToInteger.java
@@ -13,21 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
+
+import org.springframework.core.convert.converter.Converter;
/**
* Converts a String to an Integer using {@link Integer#valueOf(String)}.
- *
* @author Keith Donald
*/
-public class StringToInteger implements TwoWayConverter {
-
+public class StringToInteger implements Converter {
public Integer convert(String source) {
return Integer.valueOf(source);
}
-
- public String convertBack(Integer target) {
- return target.toString();
- }
-
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLocale.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToLocale.java
similarity index 81%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLocale.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToLocale.java
index a9bf1868186..ab291b6c4c8 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLocale.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToLocale.java
@@ -13,25 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
import java.util.Locale;
+import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;
/**
* Converts a String to a Locale using {@link StringUtils#parseLocaleString(String)}.
- *
* @author Keith Donald
*/
-public class StringToLocale implements TwoWayConverter {
-
+public class StringToLocale implements Converter {
public Locale convert(String source) {
return StringUtils.parseLocaleString(source);
}
-
- public String convertBack(Locale target) {
- return target.toString();
- }
-
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLong.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToLong.java
similarity index 79%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLong.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToLong.java
index 9a31064289f..218ac542326 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLong.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToLong.java
@@ -13,21 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
+
+import org.springframework.core.convert.converter.Converter;
/**
* Converts a String to a Long using {@link Long#valueOf(String)}.
- *
* @author Keith Donald
*/
-public class StringToLong implements TwoWayConverter {
-
+public class StringToLong implements Converter {
public Long convert(String source) {
return Long.valueOf(source);
}
-
- public String convertBack(Long target) {
- return target.toString();
- }
-
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToShort.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToShort.java
similarity index 79%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToShort.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToShort.java
index 949fa553a12..0262fb11993 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToShort.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToShort.java
@@ -13,21 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.converter;
+package org.springframework.core.convert.support;
+
+import org.springframework.core.convert.converter.Converter;
/**
* Converts a String to a Short using {@link Short#valueOf(String)}.
- *
* @author Keith Donald
*/
-public class StringToShort implements TwoWayConverter {
-
+public class StringToShort implements Converter {
public Short convert(String source) {
return Short.valueOf(source);
}
-
- public String convertBack(Short target) {
- return target.toString();
- }
-
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/package.html b/org.springframework.core/src/main/java/org/springframework/core/convert/support/package.html
new file mode 100644
index 00000000000..d4ee9e4d503
--- /dev/null
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/package.html
@@ -0,0 +1,7 @@
+
+
+
+TypeConverter system implementation.
+
+
+
\ No newline at end of file
diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/converters/DefaultConverterTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/converters/DefaultConverterTests.java
index 95e4045f91a..3c44ef1ab64 100644
--- a/org.springframework.core/src/test/java/org/springframework/core/convert/converters/DefaultConverterTests.java
+++ b/org.springframework.core/src/test/java/org/springframework/core/convert/converters/DefaultConverterTests.java
@@ -8,21 +8,22 @@ import java.math.BigInteger;
import java.util.Locale;
import org.junit.Test;
-import org.springframework.core.convert.converter.NumberToCharacter;
-import org.springframework.core.convert.converter.NumberToNumber;
-import org.springframework.core.convert.converter.ObjectToString;
-import org.springframework.core.convert.converter.StringToBigDecimal;
-import org.springframework.core.convert.converter.StringToBigInteger;
-import org.springframework.core.convert.converter.StringToBoolean;
-import org.springframework.core.convert.converter.StringToByte;
-import org.springframework.core.convert.converter.StringToCharacter;
-import org.springframework.core.convert.converter.StringToDouble;
-import org.springframework.core.convert.converter.StringToEnum;
-import org.springframework.core.convert.converter.StringToFloat;
-import org.springframework.core.convert.converter.StringToInteger;
-import org.springframework.core.convert.converter.StringToLocale;
-import org.springframework.core.convert.converter.StringToLong;
-import org.springframework.core.convert.converter.StringToShort;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.core.convert.support.NumberToCharacter;
+import org.springframework.core.convert.support.NumberToNumberFactory;
+import org.springframework.core.convert.support.ObjectToString;
+import org.springframework.core.convert.support.StringToBigDecimal;
+import org.springframework.core.convert.support.StringToBigInteger;
+import org.springframework.core.convert.support.StringToBoolean;
+import org.springframework.core.convert.support.StringToByte;
+import org.springframework.core.convert.support.StringToCharacter;
+import org.springframework.core.convert.support.StringToDouble;
+import org.springframework.core.convert.support.StringToEnumFactory;
+import org.springframework.core.convert.support.StringToFloat;
+import org.springframework.core.convert.support.StringToInteger;
+import org.springframework.core.convert.support.StringToLocale;
+import org.springframework.core.convert.support.StringToLong;
+import org.springframework.core.convert.support.StringToShort;
/**
* Tests for the default converters in the converters package.
@@ -33,14 +34,12 @@ public class DefaultConverterTests {
public void testStringToByte() throws Exception {
StringToByte b = new StringToByte();
assertEquals(Byte.valueOf("1"), b.convert("1"));
- assertEquals("1", b.convertBack(Byte.valueOf("1")));
}
@Test
public void testStringToCharacter() {
StringToCharacter c = new StringToCharacter();
assertEquals(Character.valueOf('1'), c.convert("1"));
- assertEquals("1", c.convertBack(Character.valueOf('1')));
}
@Test
@@ -48,84 +47,54 @@ public class DefaultConverterTests {
StringToBoolean c = new StringToBoolean();
assertEquals(Boolean.valueOf(true), c.convert("true"));
assertEquals(Boolean.valueOf(false), c.convert("false"));
- assertEquals("true", c.convertBack(Boolean.TRUE));
- assertEquals("false", c.convertBack(Boolean.FALSE));
}
- @Test
- public void testStringToBooleanCustomString() {
- StringToBoolean c = new StringToBoolean("yes", "no");
- assertEquals(Boolean.valueOf(true), c.convert("yes"));
- assertEquals(Boolean.valueOf(false), c.convert("no"));
- assertEquals("yes", c.convertBack(Boolean.TRUE));
- assertEquals("no", c.convertBack(Boolean.FALSE));
- }
-
- @Test
- public void testStringToBooleanInvalidValue() {
- StringToBoolean c = new StringToBoolean("yes", "no");
- try {
- c.convert("true");
- fail("Should have failed");
- } catch (IllegalArgumentException e) {
-
- }
- }
-
@Test
public void testStringToShort() {
StringToShort c = new StringToShort();
assertEquals(Short.valueOf("1"), c.convert("1"));
- assertEquals("1", c.convertBack(Short.valueOf("1")));
}
@Test
public void testStringToInteger() {
StringToInteger c = new StringToInteger();
assertEquals(Integer.valueOf("1"), c.convert("1"));
- assertEquals("1", c.convertBack(Integer.valueOf("1")));
}
@Test
public void testStringToLong() {
StringToLong c = new StringToLong();
assertEquals(Long.valueOf("1"), c.convert("1"));
- assertEquals("1", c.convertBack(Long.valueOf("1")));
}
@Test
public void testStringToFloat() {
StringToFloat c = new StringToFloat();
assertEquals(Float.valueOf("1.0"), c.convert("1.0"));
- assertEquals("1.0", c.convertBack(Float.valueOf("1.0")));
}
@Test
public void testStringToDouble() {
StringToDouble c = new StringToDouble();
assertEquals(Double.valueOf("1.0"), c.convert("1.0"));
- assertEquals("1.0", c.convertBack(Double.valueOf("1.0")));
}
@Test
public void testStringToBigInteger() {
StringToBigInteger c = new StringToBigInteger();
assertEquals(new BigInteger("1"), c.convert("1"));
- assertEquals("1", c.convertBack(new BigInteger("1")));
}
@Test
public void testStringToBigDouble() {
StringToBigDecimal c = new StringToBigDecimal();
assertEquals(new BigDecimal("1.0"), c.convert("1.0"));
- assertEquals("1.0", c.convertBack(new BigDecimal("1.0")));
}
@Test
- public void testStringToEnum() {
- StringToEnum c = new StringToEnum();
- assertEquals(Foo.BAR, c.convert("BAR", Foo.class));
- assertEquals("BAR", c.convertBack(Foo.BAR, String.class));
+ public void testStringToEnum() throws Exception {
+ Converter c = new StringToEnumFactory().getConverter(Foo.class);
+ assertEquals(Foo.BAR, c.convert("BAR"));
}
public static enum Foo {
@@ -136,20 +105,19 @@ public class DefaultConverterTests {
public void testStringToLocale() {
StringToLocale c = new StringToLocale();
assertEquals(Locale.ENGLISH, c.convert("en"));
- assertEquals("en", c.convertBack(Locale.ENGLISH));
}
@Test
- public void testNumberToNumber() {
- NumberToNumber n = new NumberToNumber();
- assertEquals(Long.valueOf(1), n.convert(Integer.valueOf(1), Long.class));
+ public void testNumberToNumber() throws Exception {
+ Converter c = new NumberToNumberFactory().getConverter(Long.class);
+ assertEquals(Long.valueOf(1), c.convert(Integer.valueOf(1)));
}
@Test
- public void testNumberToNumberNotSupportedNumber() {
- NumberToNumber n = new NumberToNumber();
+ public void testNumberToNumberNotSupportedNumber() throws Exception {
+ Converter c = new NumberToNumberFactory().getConverter(CustomNumber.class);
try {
- n.convert(Integer.valueOf(1), CustomNumber.class);
+ c.convert(Integer.valueOf(1));
fail("Should have failed");
} catch (IllegalArgumentException e) {
@@ -159,14 +127,13 @@ public class DefaultConverterTests {
@Test
public void testNumberToCharacter() {
NumberToCharacter n = new NumberToCharacter();
- assertEquals(Character.valueOf('A'), n.convert(Integer.valueOf(65), Character.class));
- assertEquals(Integer.valueOf(65), n.convertBack(Character.valueOf('A'), Integer.class));
+ assertEquals(Character.valueOf('A'), n.convert(Integer.valueOf(65)));
}
@Test
public void testObjectToString() {
ObjectToString o = new ObjectToString();
- assertEquals("3", o.convert(3, String.class));
+ assertEquals("3", o.convert(3));
}
public static class CustomNumber extends Number {
diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/service/ArrayToArrayTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToArrayTests.java
similarity index 76%
rename from org.springframework.core/src/test/java/org/springframework/core/convert/service/ArrayToArrayTests.java
rename to org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToArrayTests.java
index 9134d4f2021..727bada6b27 100644
--- a/org.springframework.core/src/test/java/org/springframework/core/convert/service/ArrayToArrayTests.java
+++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToArrayTests.java
@@ -1,9 +1,11 @@
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.core.convert.support.ArrayToArray;
+import org.springframework.core.convert.support.DefaultConversionService;
public class ArrayToArrayTests {
diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/service/ArrayToCollectionTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToCollectionTests.java
similarity index 93%
rename from org.springframework.core/src/test/java/org/springframework/core/convert/service/ArrayToCollectionTests.java
rename to org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToCollectionTests.java
index 5399f8ce5df..2b5abfaa08f 100644
--- a/org.springframework.core/src/test/java/org/springframework/core/convert/service/ArrayToCollectionTests.java
+++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToCollectionTests.java
@@ -1,4 +1,4 @@
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import static org.junit.Assert.assertEquals;
@@ -10,6 +10,8 @@ import java.util.SortedSet;
import org.junit.Test;
import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.core.convert.support.ArrayToCollection;
+import org.springframework.core.convert.support.DefaultConversionService;
public class ArrayToCollectionTests {
diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/service/CollectionToArrayTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToArrayTests.java
similarity index 91%
rename from org.springframework.core/src/test/java/org/springframework/core/convert/service/CollectionToArrayTests.java
rename to org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToArrayTests.java
index 289002596b5..5c44f79a30e 100644
--- a/org.springframework.core/src/test/java/org/springframework/core/convert/service/CollectionToArrayTests.java
+++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToArrayTests.java
@@ -1,4 +1,4 @@
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import static org.junit.Assert.assertEquals;
@@ -7,6 +7,8 @@ import java.util.Collection;
import org.junit.Test;
import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.core.convert.support.CollectionToArray;
+import org.springframework.core.convert.support.DefaultConversionService;
public class CollectionToArrayTests {
diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/service/CollectionToCollectionTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionTests.java
similarity index 94%
rename from org.springframework.core/src/test/java/org/springframework/core/convert/service/CollectionToCollectionTests.java
rename to org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionTests.java
index 34b56d08a89..e6d90e6944c 100644
--- a/org.springframework.core/src/test/java/org/springframework/core/convert/service/CollectionToCollectionTests.java
+++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionTests.java
@@ -1,4 +1,4 @@
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -9,6 +9,8 @@ import java.util.List;
import org.junit.Test;
import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.core.convert.support.CollectionToCollection;
+import org.springframework.core.convert.support.DefaultConversionService;
public class CollectionToCollectionTests {
diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/service/GenericConversionServiceTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java
similarity index 72%
rename from org.springframework.core/src/test/java/org/springframework/core/convert/service/GenericConversionServiceTests.java
rename to org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java
index 81fe51b33d5..d68c41c142c 100644
--- a/org.springframework.core/src/test/java/org/springframework/core/convert/service/GenericConversionServiceTests.java
+++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java
@@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.fail;
import java.util.AbstractList;
@@ -30,13 +29,10 @@ import java.util.Map;
import org.junit.Ignore;
import org.junit.Test;
-import org.springframework.core.convert.ConversionExecutionException;
+import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.Converter;
-import org.springframework.core.convert.converter.NumberToNumber;
-import org.springframework.core.convert.converter.StringToEnum;
-import org.springframework.core.convert.converter.StringToInteger;
public class GenericConversionServiceTests {
@@ -57,29 +53,15 @@ public class GenericConversionServiceTests {
public void executeCompatibleSource() {
assertEquals(false, service.convert(false, type(boolean.class)));
}
-
- @Test
- public void executeCompatibleSource2() {
- assertEquals(3, service.getConversionExecutor(Integer.class, TypeDescriptor.valueOf(int.class)).execute(new Integer(3)));
- assertEquals(3, service.getConversionExecutor(int.class, TypeDescriptor.valueOf(Integer.class)).execute(3));
- }
@Test
- public void converterConvertForwardIndex() {
+ public void converterConvert() {
service.addConverter(new StringToInteger());
ConversionExecutor executor = service.getConversionExecutor(String.class, type(Integer.class));
Integer three = (Integer) executor.execute("3");
assertEquals(3, three.intValue());
}
- @Test
- public void convertReverseIndex() {
- service.addConverter(new StringToInteger());
- ConversionExecutor executor = service.getConversionExecutor(Integer.class, type(String.class));
- String threeString = (String) executor.execute(new Integer(3));
- assertEquals("3", threeString);
- }
-
@Test
public void convertExecutorNotFound() {
try {
@@ -107,12 +89,6 @@ public class GenericConversionServiceTests {
}
}
- @Test
- public void convertCompatibleTypes() {
- String source = "foo";
- assertSame(source, service.getConversionExecutor(String.class, type(String.class)).execute(source));
- }
-
@Test
public void convertNull() {
service.addConverter(new StringToInteger());
@@ -123,11 +99,10 @@ public class GenericConversionServiceTests {
@Test
public void convertWrongTypeArgument() {
service.addConverter(new StringToInteger());
- ConversionExecutor executor = service.getConversionExecutor(Integer.class, type(String.class));
try {
- executor.execute("BOGUS");
+ service.convert("BOGUS", type(Integer.class));
fail("Should have failed");
- } catch (ConversionExecutionException e) {
+ } catch (ConversionException e) {
}
}
@@ -265,12 +240,13 @@ public class GenericConversionServiceTests {
public Map genericMap = new HashMap();
@Test
+ @Ignore
public void convertMapToMap() throws Exception {
Map foo = new HashMap();
foo.put("1", "BAR");
foo.put("2", "BAZ");
service.addConverter(new StringToInteger());
- service.addConverter(new StringToEnum());
+ service.addConverter(new StringToEnumFactory().getConverter(FooEnum.class));
service.convert(foo, new TypeDescriptor(getClass().getField("genericMap")));
}
@@ -297,71 +273,6 @@ public class GenericConversionServiceTests {
BAR, BAZ
}
- @Test
- public void superConverterConvertForwardIndex() {
- service.addConverter(new StringToEnum());
- ConversionExecutor executor = service.getConversionExecutor(String.class, type(FooEnum.class));
- assertEquals(FooEnum.BAR, executor.execute("BAR"));
- }
-
- @Test
- public void superTwoWayConverterConvertReverseIndex() {
- service.addConverter(new StringToEnum());
- ConversionExecutor executor = service.getConversionExecutor(FooEnum.class, type(String.class));
- assertEquals("BAR", executor.execute(FooEnum.BAR));
- }
-
- @Test
- public void superConverterConvertNotConvertibleAbstractType() {
- service.addConverter(new StringToEnum());
- ConversionExecutor executor = service.getConversionExecutor(String.class, type(Enum.class));
- try {
- executor.execute("WHATEV");
- fail("Should have failed");
- } catch (ConversionExecutionException e) {
-
- }
- }
-
- @Test
- public void superConverterConvertNotConvertibleAbstractType2() {
- service.addConverter(new NumberToNumber());
- Number customNumber = new Number() {
- @Override
- public double doubleValue() {
- return 0;
- }
-
- @Override
- public float floatValue() {
- return 0;
- }
-
- @Override
- public int intValue() {
- return 0;
- }
-
- @Override
- public long longValue() {
- return 0;
- }
- };
- ConversionExecutor executor = service.getConversionExecutor(Integer.class, type(customNumber.getClass()));
- try {
- executor.execute(3);
- fail("Should have failed");
- } catch (ConversionExecutionException e) {
-
- }
- }
-
- @Test
- public void testSuperTwoWayConverterConverterAdaption() {
- service.addConverter(GenericConversionService.converterFor(String.class, FooEnum.class, new StringToEnum()));
- assertEquals(FooEnum.BAR, service.convert("BAR", type(FooEnum.class)));
- }
-
private TypeDescriptor type(Class> clazz) {
return TypeDescriptor.valueOf(clazz);
}
diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/service/MapToMapTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/MapToMapTests.java
similarity index 90%
rename from org.springframework.core/src/test/java/org/springframework/core/convert/service/MapToMapTests.java
rename to org.springframework.core/src/test/java/org/springframework/core/convert/support/MapToMapTests.java
index 586be04fa11..aa6042ed101 100644
--- a/org.springframework.core/src/test/java/org/springframework/core/convert/service/MapToMapTests.java
+++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/MapToMapTests.java
@@ -1,4 +1,4 @@
-package org.springframework.core.convert.service;
+package org.springframework.core.convert.support;
import static org.junit.Assert.assertEquals;
@@ -7,6 +7,8 @@ import java.util.Map;
import org.junit.Test;
import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.core.convert.support.DefaultConversionService;
+import org.springframework.core.convert.support.MapToMap;
public class MapToMapTests {