diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionService.java b/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionService.java index 372e41fb2df..782f78d8bd0 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionService.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionService.java @@ -16,10 +16,10 @@ package org.springframework.core.convert; /** - * A service interface for type conversion. This is the entry point into the convert system. Call one of the - * executeConversion operations to perform a thread-safe type conversion using - * this system. Call one of the getConversionExecutor operations to obtain - * a thread-safe {@link ConversionExecutor} command for later use. + * A service interface for type conversion. This is the entry point into the convert system. + *
+ * Call {@link #executeConversion(Object, TypeDescriptor)} to perform a thread-safe type conversion using
+ * this system.
*
* @author Keith Donald
*/
@@ -28,47 +28,21 @@ public interface ConversionService {
/**
* Returns true if objects of sourceType can be converted to targetType.
* @param source the source to convert from (may be null)
- * @param targetType the target type to convert to
+ * @param targetType context about the target type to convert to
* @return true if a conversion can be performed, false if not
*/
public boolean canConvert(Class> sourceType, TypeDescriptor targetType);
- /**
- * Returns true if the source can be converted to targetType.
- * @param source the source to convert from (may be null)
- * @param targetType the target type to convert to
- * @return true if a conversion can be performed, false if not
- */
- public boolean canConvert(Object source, TypeDescriptor targetType);
-
/**
* Convert the source to targetType.
* @param source the source to convert from (may be null)
- * @param targetType the target type to convert to
- * @return the converted object, an instance of the targetType, or null if a null source
+ * @param targetType context about the target type to convert to
+ * @return the converted object, an instance of {@link TypeDescriptor#getType()}, or null if a null source
* was provided
- * @throws ConversionExecutorNotFoundException if no suitable conversion executor could be found to convert the
+ * @throws ConverterNotFoundException if no suitable conversion executor could be found to convert the
* source to an instance of targetType
* @throws ConversionException if an exception occurred during the conversion process
*/
- public Object executeConversion(Object source, TypeDescriptor targetType) throws ConversionExecutorNotFoundException,
- ConversionException;
-
- /**
- * Get a ConversionExecutor that converts objects from sourceType to targetType.
- * The returned ConversionExecutor is thread-safe and may safely be cached for later use by client code.
- * @param sourceType the source type to convert from (required)
- * @param targetType the target type to convert to (required)
- * @return the executor that can execute instance type conversion, never null
- * @throws ConversionExecutorNotFoundException when no suitable conversion executor could be found
- */
- public ConversionExecutor getConversionExecutor(Class> sourceType, TypeDescriptor targetType)
- throws ConversionExecutorNotFoundException;
-
- /**
- * Get a type by its name; may be the fully-qualified class name or a registered type alias such as 'int'.
- * @return the class, or null if no such name exists
- */
- public Class> getType(String name);
+ public Object executeConversion(Object source, TypeDescriptor targetType);
}
\ No newline at end of file
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java b/org.springframework.core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java
new file mode 100644
index 00000000000..8856a84101c
--- /dev/null
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+/**
+ * Thrown when a conversion executor could not be found in a conversion service.
+ *
+ * @author Keith Donald
+ */
+public class ConverterNotFoundException extends ConversionException {
+
+ private Class> sourceType;
+
+ private TypeDescriptor targetType;
+
+ /**
+ * Creates a new conversion executor not found exception.
+ * @param sourceType the source type requested to convert from
+ * @param targetType the target type requested to convert to
+ * @param message a descriptive message
+ */
+ public ConverterNotFoundException(Class> sourceType, TypeDescriptor targetType, String message) {
+ super(message);
+ this.sourceType = sourceType;
+ this.targetType = targetType;
+ }
+
+ /**
+ * Returns the source type that was requested to convert from.
+ */
+ public Class> getSourceType() {
+ return sourceType;
+ }
+
+ /**
+ * Returns the target type that was requested to convert to.
+ */
+ public TypeDescriptor getTargetType() {
+ return targetType;
+ }
+}
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/service/AbstractCollectionConverter.java
index a43fa91155a..a5ef6262e97 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/service/AbstractCollectionConverter.java
@@ -16,7 +16,6 @@
package org.springframework.core.convert.service;
import org.springframework.core.convert.ConversionExecutionException;
-import org.springframework.core.convert.ConversionExecutor;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
@@ -26,7 +25,7 @@ import org.springframework.core.convert.TypeDescriptor;
*/
abstract class AbstractCollectionConverter implements ConversionExecutor {
- private ConversionService conversionService;
+ private GenericConversionService conversionService;
private ConversionExecutor elementConverter;
@@ -34,7 +33,7 @@ abstract class AbstractCollectionConverter implements ConversionExecutor {
private TypeDescriptor targetCollectionType;
- public AbstractCollectionConverter(TypeDescriptor sourceCollectionType, TypeDescriptor targetCollectionType, ConversionService conversionService) {
+ public AbstractCollectionConverter(TypeDescriptor sourceCollectionType, TypeDescriptor targetCollectionType, GenericConversionService conversionService) {
this.conversionService = conversionService;
this.sourceCollectionType = sourceCollectionType;
this.targetCollectionType = targetCollectionType;
@@ -61,7 +60,7 @@ abstract class AbstractCollectionConverter implements ConversionExecutor {
return targetCollectionType.getElementType();
}
- protected ConversionService getConversionService() {
+ protected GenericConversionService getConversionService() {
return conversionService;
}
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/service/ArrayToCollection.java
index d971a645ce2..e21315f5617 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/service/ArrayToCollection.java
@@ -18,7 +18,6 @@ package org.springframework.core.convert.service;
import java.lang.reflect.Array;
import java.util.Collection;
-import org.springframework.core.convert.ConversionExecutor;
import org.springframework.core.convert.TypeDescriptor;
/**
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/service/CollectionToArray.java
index b7e2ed98dba..d70bdae5159 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/service/CollectionToArray.java
@@ -19,7 +19,6 @@ import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
-import org.springframework.core.convert.ConversionExecutor;
import org.springframework.core.convert.TypeDescriptor;
/**
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/service/CollectionToCollection.java
index a5921926cb0..b189b547035 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/service/CollectionToCollection.java
@@ -18,7 +18,6 @@ package org.springframework.core.convert.service;
import java.util.Collection;
import java.util.Iterator;
-import org.springframework.core.convert.ConversionExecutor;
import org.springframework.core.convert.TypeDescriptor;
/**
diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/service/ConversionExecutor.java
similarity index 87%
rename from org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutor.java
rename to org.springframework.core/src/main/java/org/springframework/core/convert/service/ConversionExecutor.java
index 3059f003b72..a84bbe5019c 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutor.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/convert/service/ConversionExecutor.java
@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.core.convert;
+package org.springframework.core.convert.service;
+
+import org.springframework.core.convert.ConversionExecutionException;
/**
* A command parameterized with the information necessary to perform a conversion of a source input to a
@@ -29,6 +31,6 @@ public interface ConversionExecutor {
* @param source the source to convert
* @throws ConversionExecutionException if an exception occurs during type conversion
*/
- public Object execute(Object source) throws ConversionExecutionException;
+ public Object execute(Object source);
}
\ No newline at end of file
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/service/DefaultConversionService.java
index a149217bf58..73e28ea151a 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/service/DefaultConversionService.java
@@ -49,7 +49,6 @@ public class DefaultConversionService extends GenericConversionService {
*/
public DefaultConversionService() {
addDefaultConverters();
- addDefaultAliases();
}
/**
@@ -73,21 +72,4 @@ public class DefaultConversionService extends GenericConversionService {
addConverter(new ObjectToString());
}
- protected void addDefaultAliases() {
- addAlias("string", String.class);
- addAlias("byte", Byte.class);
- addAlias("boolean", Boolean.class);
- addAlias("char", Character.class);
- addAlias("short", Short.class);
- addAlias("int", Integer.class);
- addAlias("long", Long.class);
- addAlias("float", Float.class);
- addAlias("double", Double.class);
- addAlias("bigInt", BigInteger.class);
- addAlias("bigDecimal", BigDecimal.class);
- addAlias("locale", Locale.class);
- addAlias("enum", Enum.class);
- addAlias("date", Date.class);
- }
-
}
\ No newline at end of file
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/service/GenericConversionService.java
index 74d19fdcc08..8cee88e12eb 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/service/GenericConversionService.java
@@ -26,10 +26,8 @@ import java.util.List;
import java.util.Map;
import org.springframework.core.GenericTypeResolver;
-import org.springframework.core.convert.ConversionException;
-import org.springframework.core.convert.ConversionExecutor;
-import org.springframework.core.convert.ConversionExecutorNotFoundException;
import org.springframework.core.convert.ConversionService;
+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.ConverterInfo;
@@ -61,11 +59,6 @@ public class GenericConversionService implements ConversionService {
*/
private final Map sourceTypeSuperConverters = new HashMap();
- /**
- * Indexes classes by well-known aliases.
- */
- private final Map aliasMap = new HashMap