made ConversionExecutor internal; removed other unused operations from public SPI
This commit is contained in:
parent
bf7a947559
commit
d7c90cff14
|
|
@ -16,10 +16,10 @@
|
||||||
package org.springframework.core.convert;
|
package org.springframework.core.convert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A service interface for type conversion. This is the entry point into the convert system. Call one of the
|
* A service interface for type conversion. This is the entry point into the convert system.
|
||||||
* <i>executeConversion</i> operations to perform a thread-safe type conversion using
|
* <p>
|
||||||
* this system. Call one of the <i>getConversionExecutor</i> operations to obtain
|
* Call {@link #executeConversion(Object, TypeDescriptor)} to perform a thread-safe type conversion using
|
||||||
* a thread-safe {@link ConversionExecutor} command for later use.
|
* this system.
|
||||||
*
|
*
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
*/
|
*/
|
||||||
|
|
@ -28,47 +28,21 @@ public interface ConversionService {
|
||||||
/**
|
/**
|
||||||
* Returns true if objects of sourceType can be converted to targetType.
|
* Returns true if objects of sourceType can be converted to targetType.
|
||||||
* @param source the source to convert from (may be null)
|
* @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
|
* @return true if a conversion can be performed, false if not
|
||||||
*/
|
*/
|
||||||
public boolean canConvert(Class<?> sourceType, TypeDescriptor targetType);
|
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.
|
* Convert the source to targetType.
|
||||||
* @param source the source to convert from (may be null)
|
* @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 the converted object, an instance of the <code>targetType</code>, or <code>null</code> if a null source
|
* @return the converted object, an instance of {@link TypeDescriptor#getType()}</code>, or <code>null</code> if a null source
|
||||||
* was provided
|
* 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
|
* source to an instance of targetType
|
||||||
* @throws ConversionException if an exception occurred during the conversion process
|
* @throws ConversionException if an exception occurred during the conversion process
|
||||||
*/
|
*/
|
||||||
public Object executeConversion(Object source, TypeDescriptor targetType) throws ConversionExecutorNotFoundException,
|
public Object executeConversion(Object source, TypeDescriptor targetType);
|
||||||
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 <code>null</code> if no such name exists
|
|
||||||
*/
|
|
||||||
public Class<?> getType(String name);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
package org.springframework.core.convert.service;
|
package org.springframework.core.convert.service;
|
||||||
|
|
||||||
import org.springframework.core.convert.ConversionExecutionException;
|
import org.springframework.core.convert.ConversionExecutionException;
|
||||||
import org.springframework.core.convert.ConversionExecutor;
|
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
|
|
||||||
|
|
@ -26,7 +25,7 @@ import org.springframework.core.convert.TypeDescriptor;
|
||||||
*/
|
*/
|
||||||
abstract class AbstractCollectionConverter implements ConversionExecutor {
|
abstract class AbstractCollectionConverter implements ConversionExecutor {
|
||||||
|
|
||||||
private ConversionService conversionService;
|
private GenericConversionService conversionService;
|
||||||
|
|
||||||
private ConversionExecutor elementConverter;
|
private ConversionExecutor elementConverter;
|
||||||
|
|
||||||
|
|
@ -34,7 +33,7 @@ abstract class AbstractCollectionConverter implements ConversionExecutor {
|
||||||
|
|
||||||
private TypeDescriptor targetCollectionType;
|
private TypeDescriptor targetCollectionType;
|
||||||
|
|
||||||
public AbstractCollectionConverter(TypeDescriptor sourceCollectionType, TypeDescriptor targetCollectionType, ConversionService conversionService) {
|
public AbstractCollectionConverter(TypeDescriptor sourceCollectionType, TypeDescriptor targetCollectionType, GenericConversionService conversionService) {
|
||||||
this.conversionService = conversionService;
|
this.conversionService = conversionService;
|
||||||
this.sourceCollectionType = sourceCollectionType;
|
this.sourceCollectionType = sourceCollectionType;
|
||||||
this.targetCollectionType = targetCollectionType;
|
this.targetCollectionType = targetCollectionType;
|
||||||
|
|
@ -61,7 +60,7 @@ abstract class AbstractCollectionConverter implements ConversionExecutor {
|
||||||
return targetCollectionType.getElementType();
|
return targetCollectionType.getElementType();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ConversionService getConversionService() {
|
protected GenericConversionService getConversionService() {
|
||||||
return conversionService;
|
return conversionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package org.springframework.core.convert.service;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.springframework.core.convert.ConversionExecutor;
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ import java.lang.reflect.Array;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.springframework.core.convert.ConversionExecutor;
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package org.springframework.core.convert.service;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.springframework.core.convert.ConversionExecutor;
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,9 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* 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
|
* 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
|
* @param source the source to convert
|
||||||
* @throws ConversionExecutionException if an exception occurs during type conversion
|
* @throws ConversionExecutionException if an exception occurs during type conversion
|
||||||
*/
|
*/
|
||||||
public Object execute(Object source) throws ConversionExecutionException;
|
public Object execute(Object source);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +49,6 @@ public class DefaultConversionService extends GenericConversionService {
|
||||||
*/
|
*/
|
||||||
public DefaultConversionService() {
|
public DefaultConversionService() {
|
||||||
addDefaultConverters();
|
addDefaultConverters();
|
||||||
addDefaultAliases();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -73,21 +72,4 @@ public class DefaultConversionService extends GenericConversionService {
|
||||||
addConverter(new ObjectToString());
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -26,10 +26,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.core.GenericTypeResolver;
|
import org.springframework.core.GenericTypeResolver;
|
||||||
import org.springframework.core.convert.ConversionException;
|
|
||||||
import org.springframework.core.convert.ConversionExecutor;
|
|
||||||
import org.springframework.core.convert.ConversionExecutorNotFoundException;
|
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
|
import org.springframework.core.convert.ConverterNotFoundException;
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.core.convert.converter.ConverterInfo;
|
import org.springframework.core.convert.converter.ConverterInfo;
|
||||||
|
|
@ -61,11 +59,6 @@ public class GenericConversionService implements ConversionService {
|
||||||
*/
|
*/
|
||||||
private final Map sourceTypeSuperConverters = new HashMap();
|
private final Map sourceTypeSuperConverters = new HashMap();
|
||||||
|
|
||||||
/**
|
|
||||||
* Indexes classes by well-known aliases.
|
|
||||||
*/
|
|
||||||
private final Map aliasMap = new HashMap<String, Class<?>>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An optional parent conversion service.
|
* An optional parent conversion service.
|
||||||
*/
|
*/
|
||||||
|
|
@ -132,48 +125,41 @@ public class GenericConversionService implements ConversionService {
|
||||||
return new SuperTwoWayConverterConverter(converter, sourceType, targetType);
|
return new SuperTwoWayConverterConverter(converter, sourceType, targetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a convenient alias for the target type. {@link #getType(String)} can then be used to lookup the type given
|
|
||||||
* the alias.
|
|
||||||
* @see #getType(String)
|
|
||||||
*/
|
|
||||||
public void addAlias(String alias, Class targetType) {
|
|
||||||
aliasMap.put(alias, targetType);
|
|
||||||
}
|
|
||||||
|
|
||||||
// implementing ConversionService
|
// implementing ConversionService
|
||||||
|
|
||||||
public boolean canConvert(Class<?> sourceType, TypeDescriptor targetType) {
|
public boolean canConvert(Class<?> sourceType, TypeDescriptor targetType) {
|
||||||
try {
|
ConversionExecutor executor = getConversionExecutor(sourceType, targetType);
|
||||||
getConversionExecutor(sourceType, targetType);
|
if (executor != null) {
|
||||||
return true;
|
return true;
|
||||||
} catch (ConversionExecutorNotFoundException e) {
|
} else {
|
||||||
return false;
|
if (parent != null) {
|
||||||
|
return parent.canConvert(sourceType, targetType);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canConvert(Object source, TypeDescriptor targetType) {
|
public Object executeConversion(Object source, TypeDescriptor targetType) {
|
||||||
if (source == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
getConversionExecutor(source.getClass(), targetType);
|
|
||||||
return true;
|
|
||||||
} catch (ConversionExecutorNotFoundException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object executeConversion(Object source, TypeDescriptor targetType)
|
|
||||||
throws ConversionExecutorNotFoundException, ConversionException {
|
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return getConversionExecutor(source.getClass(), targetType).execute(source);
|
ConversionExecutor executor = getConversionExecutor(source.getClass(), targetType);
|
||||||
|
if (executor != null) {
|
||||||
|
return executor.execute(source);
|
||||||
|
} else {
|
||||||
|
if (parent != null) {
|
||||||
|
return parent.executeConversion(source, targetType);
|
||||||
|
} else {
|
||||||
|
throw new ConverterNotFoundException(source.getClass(), targetType,
|
||||||
|
"No converter found that can convert from sourceType [" + source.getClass().getName()
|
||||||
|
+ "] to targetType [" + targetType.getName() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConversionExecutor getConversionExecutor(Class sourceClass, TypeDescriptor targetType)
|
ConversionExecutor getConversionExecutor(Class sourceClass, TypeDescriptor targetType)
|
||||||
throws ConversionExecutorNotFoundException {
|
throws ConverterNotFoundException {
|
||||||
Assert.notNull(sourceClass, "The sourceType to convert from is required");
|
Assert.notNull(sourceClass, "The sourceType to convert from is required");
|
||||||
Assert.notNull(targetType, "The targetType to convert to is required");
|
Assert.notNull(targetType, "The targetType to convert to is required");
|
||||||
TypeDescriptor sourceType = TypeDescriptor.valueOf(sourceClass);
|
TypeDescriptor sourceType = TypeDescriptor.valueOf(sourceClass);
|
||||||
|
|
@ -193,21 +179,21 @@ public class GenericConversionService implements ConversionService {
|
||||||
if (sourceType.isCollection()) {
|
if (sourceType.isCollection()) {
|
||||||
return new CollectionToArray(sourceType, targetType, this);
|
return new CollectionToArray(sourceType, targetType, this);
|
||||||
} else {
|
} else {
|
||||||
throw new ConversionExecutorNotFoundException(sourceType, targetType, "Object to Array conversion not yet supported");
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sourceType.isCollection()) {
|
if (sourceType.isCollection()) {
|
||||||
if (targetType.isCollection()) {
|
if (targetType.isCollection()) {
|
||||||
return new CollectionToCollection(sourceType, targetType, this);
|
return new CollectionToCollection(sourceType, targetType, this);
|
||||||
} else {
|
} else {
|
||||||
throw new ConversionExecutorNotFoundException(sourceType, targetType, "Object to Collection conversion not yet supported");
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sourceType.isMap()) {
|
if (sourceType.isMap()) {
|
||||||
if (targetType.isMap()) {
|
if (targetType.isMap()) {
|
||||||
return new MapToMap(sourceType, targetType, this);
|
return new MapToMap(sourceType, targetType, this);
|
||||||
} else {
|
} else {
|
||||||
throw new ConversionExecutorNotFoundException(sourceType, targetType, "Object to Map conversion not yet supported");
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Converter converter = findRegisteredConverter(sourceClass, targetType.getType());
|
Converter converter = findRegisteredConverter(sourceClass, targetType.getType());
|
||||||
|
|
@ -217,28 +203,10 @@ public class GenericConversionService implements ConversionService {
|
||||||
SuperConverter superConverter = findRegisteredSuperConverter(sourceClass, targetType.getType());
|
SuperConverter superConverter = findRegisteredSuperConverter(sourceClass, targetType.getType());
|
||||||
if (superConverter != null) {
|
if (superConverter != null) {
|
||||||
return new StaticSuperConversionExecutor(sourceType, targetType, superConverter);
|
return new StaticSuperConversionExecutor(sourceType, targetType, superConverter);
|
||||||
}
|
|
||||||
if (parent != null) {
|
|
||||||
return parent.getConversionExecutor(sourceClass, targetType);
|
|
||||||
} else {
|
} else {
|
||||||
if (sourceType.isAssignableTo(targetType)) {
|
if (sourceType.isAssignableTo(targetType)) {
|
||||||
return new StaticConversionExecutor(sourceType, targetType, NoOpConverter.INSTANCE);
|
return new StaticConversionExecutor(sourceType, targetType, NoOpConverter.INSTANCE);
|
||||||
}
|
}
|
||||||
throw new ConversionExecutorNotFoundException(sourceType, targetType,
|
|
||||||
"No ConversionExecutor found for converting from sourceType [" + sourceType.getName()
|
|
||||||
+ "] to targetType [" + targetType.getName() + "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class getType(String name) throws IllegalArgumentException {
|
|
||||||
Class clazz = (Class) aliasMap.get(name);
|
|
||||||
if (clazz != null) {
|
|
||||||
return clazz;
|
|
||||||
} else {
|
|
||||||
if (parent != null) {
|
|
||||||
return parent.getType(name);
|
|
||||||
} else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import java.util.SortedMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.springframework.core.convert.ConversionExecutionException;
|
import org.springframework.core.convert.ConversionExecutionException;
|
||||||
import org.springframework.core.convert.ConversionExecutor;
|
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
|
|
||||||
|
|
@ -36,7 +35,7 @@ class MapToMap implements ConversionExecutor {
|
||||||
|
|
||||||
private TypeDescriptor targetType;
|
private TypeDescriptor targetType;
|
||||||
|
|
||||||
private ConversionService conversionService;
|
private GenericConversionService conversionService;
|
||||||
|
|
||||||
private EntryConverter entryConverter;
|
private EntryConverter entryConverter;
|
||||||
|
|
||||||
|
|
@ -46,7 +45,7 @@ class MapToMap implements ConversionExecutor {
|
||||||
* @param targetType the target map type
|
* @param targetType the target map type
|
||||||
* @param conversionService the conversion service
|
* @param conversionService the conversion service
|
||||||
*/
|
*/
|
||||||
public MapToMap(TypeDescriptor sourceType, TypeDescriptor targetType, ConversionService conversionService) {
|
public MapToMap(TypeDescriptor sourceType, TypeDescriptor targetType, GenericConversionService conversionService) {
|
||||||
this.sourceType = sourceType;
|
this.sourceType = sourceType;
|
||||||
this.targetType = targetType;
|
this.targetType = targetType;
|
||||||
this.conversionService = conversionService;
|
this.conversionService = conversionService;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
package org.springframework.core.convert.service;
|
package org.springframework.core.convert.service;
|
||||||
|
|
||||||
import org.springframework.core.convert.ConversionExecutionException;
|
import org.springframework.core.convert.ConversionExecutionException;
|
||||||
import org.springframework.core.convert.ConversionExecutor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conversion executor that does nothing. Access singleton at {@link #INSTANCE}.s
|
* Conversion executor that does nothing. Access singleton at {@link #INSTANCE}.s
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
package org.springframework.core.convert.service;
|
package org.springframework.core.convert.service;
|
||||||
|
|
||||||
import org.springframework.core.convert.ConversionExecutionException;
|
import org.springframework.core.convert.ConversionExecutionException;
|
||||||
import org.springframework.core.convert.ConversionExecutor;
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.core.style.ToStringCreator;
|
import org.springframework.core.style.ToStringCreator;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
package org.springframework.core.convert.service;
|
package org.springframework.core.convert.service;
|
||||||
|
|
||||||
import org.springframework.core.convert.ConversionExecutionException;
|
import org.springframework.core.convert.ConversionExecutionException;
|
||||||
import org.springframework.core.convert.ConversionExecutor;
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.core.convert.converter.SuperConverter;
|
import org.springframework.core.convert.converter.SuperConverter;
|
||||||
import org.springframework.core.style.ToStringCreator;
|
import org.springframework.core.style.ToStringCreator;
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,7 @@ import java.util.Map;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.core.convert.ConversionExecutionException;
|
import org.springframework.core.convert.ConversionExecutionException;
|
||||||
import org.springframework.core.convert.ConversionExecutor;
|
import org.springframework.core.convert.ConverterNotFoundException;
|
||||||
import org.springframework.core.convert.ConversionExecutorNotFoundException;
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.core.convert.converter.NumberToNumber;
|
import org.springframework.core.convert.converter.NumberToNumber;
|
||||||
|
|
@ -84,9 +83,9 @@ public class GenericConversionServiceTests {
|
||||||
@Test
|
@Test
|
||||||
public void convertExecutorNotFound() {
|
public void convertExecutorNotFound() {
|
||||||
try {
|
try {
|
||||||
service.getConversionExecutor(String.class, type(Integer.class));
|
service.executeConversion("3", type(Integer.class));
|
||||||
fail("Should have thrown an exception");
|
fail("Should have thrown an exception");
|
||||||
} catch (ConversionExecutorNotFoundException e) {
|
} catch (ConverterNotFoundException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -161,9 +160,9 @@ public class GenericConversionServiceTests {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
ConversionExecutor executor = service.getConversionExecutor(String.class, type(Integer.class));
|
service.executeConversion("3", type(Integer.class));
|
||||||
fail("Should have failed");
|
fail("Should have failed");
|
||||||
} catch (ConversionExecutorNotFoundException e) {
|
} catch (ConverterNotFoundException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
package org.springframework.expression.spel.support;
|
package org.springframework.expression.spel.support;
|
||||||
|
|
||||||
import org.springframework.core.convert.ConversionException;
|
import org.springframework.core.convert.ConversionException;
|
||||||
import org.springframework.core.convert.ConversionExecutorNotFoundException;
|
import org.springframework.core.convert.ConverterNotFoundException;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.core.convert.service.DefaultConversionService;
|
import org.springframework.core.convert.service.DefaultConversionService;
|
||||||
|
|
@ -53,7 +53,7 @@ public class StandardTypeConverter implements TypeConverter {
|
||||||
public Object convertValue(Object value, TypeDescriptor typeDescriptor) throws EvaluationException {
|
public Object convertValue(Object value, TypeDescriptor typeDescriptor) throws EvaluationException {
|
||||||
try {
|
try {
|
||||||
return conversionService.executeConversion(value, typeDescriptor);
|
return conversionService.executeConversion(value, typeDescriptor);
|
||||||
} catch (ConversionExecutorNotFoundException cenfe) {
|
} catch (ConverterNotFoundException cenfe) {
|
||||||
throw new SpelException(cenfe, SpelMessages.TYPE_CONVERSION_ERROR, value.getClass(), typeDescriptor.asString());
|
throw new SpelException(cenfe, SpelMessages.TYPE_CONVERSION_ERROR, value.getClass(), typeDescriptor.asString());
|
||||||
} catch (ConversionException ce) {
|
} catch (ConversionException ce) {
|
||||||
throw new SpelException(ce, SpelMessages.TYPE_CONVERSION_ERROR, value.getClass(), typeDescriptor.asString());
|
throw new SpelException(ce, SpelMessages.TYPE_CONVERSION_ERROR, value.getClass(), typeDescriptor.asString());
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package org.springframework.expression.spel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.core.convert.ConversionExecutor;
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.core.convert.service.DefaultConversionService;
|
import org.springframework.core.convert.service.DefaultConversionService;
|
||||||
import org.springframework.core.convert.service.GenericConversionService;
|
import org.springframework.core.convert.service.GenericConversionService;
|
||||||
|
|
@ -65,17 +64,14 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
|
||||||
// ArrayList containing List<Integer> to List<String>
|
// ArrayList containing List<Integer> to List<String>
|
||||||
Class<?> clazz = typeDescriptorForListOfString.getElementType();
|
Class<?> clazz = typeDescriptorForListOfString.getElementType();
|
||||||
assertEquals(String.class,clazz);
|
assertEquals(String.class,clazz);
|
||||||
ConversionExecutor executor = tcs.getConversionExecutor(ArrayList.class, typeDescriptorForListOfString);
|
List l = (List) tcs.executeConversion(listOfInteger, typeDescriptorForListOfString);
|
||||||
assertNotNull(executor);
|
|
||||||
List l = (List)executor.execute(listOfInteger);
|
|
||||||
assertNotNull(l);
|
assertNotNull(l);
|
||||||
|
|
||||||
// ArrayList containing List<String> to List<Integer>
|
// ArrayList containing List<String> to List<Integer>
|
||||||
clazz = typeDescriptorForListOfInteger.getElementType();
|
clazz = typeDescriptorForListOfInteger.getElementType();
|
||||||
assertEquals(Integer.class,clazz);
|
assertEquals(Integer.class,clazz);
|
||||||
executor = tcs.getConversionExecutor(ArrayList.class, typeDescriptorForListOfInteger);
|
|
||||||
assertNotNull(executor);
|
l = (List) tcs.executeConversion(listOfString, typeDescriptorForListOfString);
|
||||||
l = (List)executor.execute(listOfString);
|
|
||||||
assertNotNull(l);
|
assertNotNull(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue