diff --git a/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java index b359453d0d0..8dd40490e9b 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java @@ -63,6 +63,7 @@ public interface ConversionService { * @param targetType context about the target type to convert to (required) * @return true if conversion can be bypassed * @throws IllegalArgumentException if targetType is null + * @since 3.2 */ boolean canBypassConvert(Class> sourceType, Class> targetType); @@ -74,6 +75,7 @@ public interface ConversionService { * @param targetType context about the target type to convert to (required) * @return true if conversion can be bypassed * @throws IllegalArgumentException if targetType is null + * @since 3.2 */ boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType); diff --git a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index 7e119c34548..c4969fdb568 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -257,6 +257,7 @@ public class TypeDescriptor { * @param superType the super type to cast to (can be {@code null} * @return a new TypeDescriptor for the up-cast type * @throws IllegalArgumentException if this type is not assignable to the super-type + * @since 3.2 */ public TypeDescriptor upcast(Class> superType) { if (superType == null) { diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalConversion.java b/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalConverter.java similarity index 91% rename from spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalConversion.java rename to spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalConverter.java index 1196b26fc4f..94aacd6261f 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalConversion.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2002-2012 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. @@ -33,18 +33,18 @@ import org.springframework.core.convert.TypeDescriptor; * implementation might return {@code true} if the target Account class defines a * {@code public static findAccount(String)} method. * - * @author Keith Donald * @author Phillip Webb + * @author Keith Donald * @since 3.2 * @see Converter * @see GenericConverter * @see ConverterFactory * @see ConditionalGenericConverter */ -public interface ConditionalConversion { +public interface ConditionalConverter { /** - * Should the converter from {@code sourceType} to {@code targetType} currently under + * Should the conversion from {@code sourceType} to {@code targetType} currently under * consideration be selected? * * @param sourceType the type descriptor of the field we are converting from diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalGenericConverter.java b/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalGenericConverter.java index fc7ce7a1ab0..d65d7bb3e9a 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalGenericConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalGenericConverter.java @@ -18,19 +18,18 @@ package org.springframework.core.convert.converter; import org.springframework.core.convert.TypeDescriptor; - /** * A {@link GenericConverter} that may conditionally execute based on attributes of the * {@code source} and {@code target} {@link TypeDescriptor}. See - * {@link ConditionalConversion} for details. + * {@link ConditionalConverter} for details. * * @author Keith Donald * @author Phillip Webb * @since 3.0 * @see GenericConverter - * @see ConditionalConversion + * @see ConditionalConverter */ public interface ConditionalGenericConverter extends GenericConverter, - ConditionalConversion { + ConditionalConverter { } diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java b/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java index a7b1a68d031..6710b666abf 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java @@ -20,11 +20,11 @@ package org.springframework.core.convert.converter; * A converter converts a source object of type S to a target of type T. * Implementations of this interface are thread-safe and can be shared. * - *
Implementations may additionally implement {@link ConditionalConversion}. + *
Implementations may additionally implement {@link ConditionalConverter}.
*
* @author Keith Donald
* @since 3.0
- * @see ConditionalConversion
+ * @see ConditionalConverter
* @param Implementations may additionally implement {@link ConditionalConversion}.
+ * Implementations may additionally implement {@link ConditionalConverter}.
*
* @author Keith Donald
* @since 3.0
- * @see ConditionalConversion
+ * @see ConditionalConverter
* @param This interface should generally not be used when the simpler {@link Converter} or
* {@link ConverterFactory} interfaces are sufficient.
*
- * Implementations may additionally implement {@link ConditionalConversion}.
+ * Implementations may additionally implement {@link ConditionalConverter}.
*
* @author Keith Donald
* @author Juergen Hoeller
@@ -42,7 +42,7 @@ import java.util.Set;
* @see TypeDescriptor
* @see Converter
* @see ConverterFactory
- * @see ConditionalConversion
+ * @see ConditionalConverter
*/
public interface GenericConverter {
@@ -50,7 +50,7 @@ public interface GenericConverter {
* Return the source and target types which this converter can convert between. Each
* entry is a convertible source-to-target type pair.
*
- * For {@link ConditionalConversion conditional} converters this method may return
+ * For {@link ConditionalConverter conditional} converters this method may return
* {@code null} to indicate all source-to-target pairs should be considered. *
*/
Set The source type
* @param The source type converters created by this factory can convert from
* @param and targetType converts between; declare these generic types.");
+ Assert.notNull(typeInfo, "Unable to the determine sourceType and targetType " +
+ " converts between; declare these generic types.");
addConverter(new ConverterAdapter(typeInfo, converter));
}
@@ -99,8 +99,9 @@ public class GenericConversionService implements ConfigurableConversionService {
public void addConverterFactory(ConverterFactory, ?> converterFactory) {
GenericConverter.ConvertiblePair typeInfo = getRequiredTypeInfo(converterFactory, ConverterFactory.class);
if (typeInfo == null) {
- throw new IllegalArgumentException("Unable to the determine sourceType and targetRangeType R which " +
- "your ConverterFactory converts between; declare these generic types.");
+ throw new IllegalArgumentException("Unable to the determine sourceType and " +
+ "targetRangeType R which your ConverterFactory converts between; " +
+ "declare these generic types.");
}
addConverter(new ConverterFactoryAdapter(typeInfo, converterFactory));
}
@@ -114,7 +115,9 @@ public class GenericConversionService implements ConfigurableConversionService {
public boolean canConvert(Class> sourceType, Class> targetType) {
Assert.notNull(targetType, "The targetType to convert to cannot be null");
- return canConvert(sourceType != null ? TypeDescriptor.valueOf(sourceType) : null, TypeDescriptor.valueOf(targetType));
+ return canConvert(sourceType != null ?
+ TypeDescriptor.valueOf(sourceType) : null,
+ TypeDescriptor.valueOf(targetType));
}
public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
@@ -128,8 +131,9 @@ public class GenericConversionService implements ConfigurableConversionService {
public boolean canBypassConvert(Class> sourceType, Class> targetType) {
Assert.notNull(targetType, "The targetType to convert to cannot be null");
- return canBypassConvert(sourceType != null ? TypeDescriptor.valueOf(sourceType)
- : null, TypeDescriptor.valueOf(targetType));
+ return canBypassConvert(sourceType != null ?
+ TypeDescriptor.valueOf(sourceType) : null,
+ TypeDescriptor.valueOf(targetType));
}
public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
@@ -166,8 +170,11 @@ public class GenericConversionService implements ConfigurableConversionService {
}
/**
- * Convenience operation for converting a source object to the specified targetType, where the targetType is a descriptor that provides additional conversion context.
- * Simply delegates to {@link #convert(Object, TypeDescriptor, TypeDescriptor)} and encapsulates the construction of the sourceType descriptor using {@link TypeDescriptor#forObject(Object)}.
+ * Convenience operation for converting a source object to the specified targetType,
+ * where the targetType is a descriptor that provides additional conversion context.
+ * Simply delegates to {@link #convert(Object, TypeDescriptor, TypeDescriptor)} and
+ * encapsulates the construction of the sourceType descriptor using
+ * {@link TypeDescriptor#forObject(Object)}.
* @param source the source object
* @param targetType the target type
* @return the converted value
@@ -206,7 +213,8 @@ public class GenericConversionService implements ConfigurableConversionService {
* Subclasses may override.
* @param sourceType the source type to convert from
* @param targetType the target type to convert to
- * @return the generic converter that will perform the conversion, or {@code null} if no suitable converter was found
+ * @return the generic converter that will perform the conversion, or {@code null} if
+ * no suitable converter was found
* @see #getDefaultConverter(TypeDescriptor, TypeDescriptor)
*/
protected GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) {
@@ -305,9 +313,8 @@ public class GenericConversionService implements ConfigurableConversionService {
if(!this.typeInfo.getTargetType().equals(targetType.getObjectType())) {
return false;
}
- if (this.converter instanceof ConditionalConversion) {
- return ((ConditionalConversion) this.converter).matches(sourceType,
- targetType);
+ if (this.converter instanceof ConditionalConverter) {
+ return ((ConditionalConverter) this.converter).matches(sourceType, targetType);
}
return true;
}
@@ -320,8 +327,9 @@ public class GenericConversionService implements ConfigurableConversionService {
}
public String toString() {
- return this.typeInfo.getSourceType().getName() + " -> " + this.typeInfo.getTargetType().getName() +
- " : " + this.converter.toString();
+ return this.typeInfo.getSourceType().getName() + " -> " +
+ this.typeInfo.getTargetType().getName() + " : " +
+ this.converter.toString();
}
}
@@ -349,14 +357,13 @@ public class GenericConversionService implements ConfigurableConversionService {
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
boolean matches = true;
- if (this.converterFactory instanceof ConditionalConversion) {
- matches = ((ConditionalConversion) this.converterFactory).matches(
- sourceType, targetType);
+ if (this.converterFactory instanceof ConditionalConverter) {
+ matches = ((ConditionalConverter) this.converterFactory).matches(sourceType, targetType);
}
if(matches) {
- Converter, ?> converter = converterFactory.getConverter(targetType.getType());
- if(converter instanceof ConditionalConversion) {
- matches = ((ConditionalConversion) converter).matches(sourceType, targetType);
+ Converter, ?> converter = this.converterFactory.getConverter(targetType.getType());
+ if(converter instanceof ConditionalConverter) {
+ matches = ((ConditionalConverter) converter).matches(sourceType, targetType);
}
}
return matches;
@@ -370,8 +377,9 @@ public class GenericConversionService implements ConfigurableConversionService {
}
public String toString() {
- return this.typeInfo.getSourceType().getName() + " -> " + this.typeInfo.getTargetType().getName() +
- " : " + this.converterFactory.toString();
+ return this.typeInfo.getSourceType().getName() + " -> " +
+ this.typeInfo.getTargetType().getName() + " : " +
+ this.converterFactory.toString();
}
}
@@ -437,7 +445,7 @@ public class GenericConversionService implements ConfigurableConversionService {
public void add(GenericConverter converter) {
Set