polishing
This commit is contained in:
parent
bc06ffb6b8
commit
cc0bd730eb
|
|
@ -102,8 +102,8 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||||
* but would complicate the code. And it would work only for static pointcuts.
|
* but would complicate the code. And it would work only for static pointcuts.
|
||||||
*/
|
*/
|
||||||
protected ReflectiveMethodInvocation(
|
protected ReflectiveMethodInvocation(
|
||||||
Object proxy, Object target, Method method, Object[] arguments,
|
Object proxy, Object target, Method method, Object[] arguments,
|
||||||
Class targetClass, List<Object> interceptorsAndDynamicMethodMatchers) {
|
Class targetClass, List<Object> interceptorsAndDynamicMethodMatchers) {
|
||||||
|
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import org.springframework.core.NestedRuntimeException;
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public abstract class ConversionException extends NestedRuntimeException {
|
public abstract class ConversionException extends NestedRuntimeException {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,13 @@ package org.springframework.core.convert;
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public final class ConversionFailedException extends ConversionException {
|
public final class ConversionFailedException extends ConversionException {
|
||||||
|
|
||||||
private final TypeDescriptor sourceType;
|
private final TypeDescriptor sourceType;
|
||||||
|
|
||||||
private final TypeDescriptor targetType;
|
private final TypeDescriptor targetType;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new conversion exception.
|
* Create a new conversion exception.
|
||||||
* @param value the value we tried to convert
|
* @param value the value we tried to convert
|
||||||
|
|
@ -37,11 +37,13 @@ public final class ConversionFailedException extends ConversionException {
|
||||||
* @param cause the cause of the conversion failure
|
* @param cause the cause of the conversion failure
|
||||||
*/
|
*/
|
||||||
public ConversionFailedException(TypeDescriptor sourceType, TypeDescriptor targetType, Object value, Throwable cause) {
|
public ConversionFailedException(TypeDescriptor sourceType, TypeDescriptor targetType, Object value, Throwable cause) {
|
||||||
super(buildDefaultMessage(value, sourceType, targetType, cause), cause);
|
super("Unable to convert value " + value + " from type [" + sourceType.getName() + "] to type [" +
|
||||||
|
targetType.getName() + "]; reason = '" + cause.getMessage() + "'", cause);
|
||||||
this.sourceType = sourceType;
|
this.sourceType = sourceType;
|
||||||
this.targetType = targetType;
|
this.targetType = targetType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the source type we tried to convert the value from.
|
* Return the source type we tried to convert the value from.
|
||||||
*/
|
*/
|
||||||
|
|
@ -56,10 +58,4 @@ public final class ConversionFailedException extends ConversionException {
|
||||||
return this.targetType;
|
return this.targetType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String buildDefaultMessage(Object value, TypeDescriptor sourceType, TypeDescriptor targetType,
|
|
||||||
Throwable cause) {
|
|
||||||
return "Unable to convert value " + value + " from type [" + sourceType.getName() + "] to type ["
|
|
||||||
+ targetType.getName() + "]; reason = '" + cause.getMessage() + "'";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -26,6 +26,7 @@ import org.springframework.core.GenericCollectionTypeResolver;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context about a type to convert to.
|
* Context about a type to convert to.
|
||||||
|
|
@ -42,6 +43,7 @@ public class TypeDescriptor {
|
||||||
*/
|
*/
|
||||||
public static final TypeDescriptor NULL = new TypeDescriptor();
|
public static final TypeDescriptor NULL = new TypeDescriptor();
|
||||||
|
|
||||||
|
|
||||||
private Class<?> type;
|
private Class<?> type;
|
||||||
|
|
||||||
private TypeDescriptor elementType;
|
private TypeDescriptor elementType;
|
||||||
|
|
@ -52,6 +54,7 @@ public class TypeDescriptor {
|
||||||
|
|
||||||
private Annotation[] cachedFieldAnnotations;
|
private Annotation[] cachedFieldAnnotations;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new descriptor for the given type.
|
* Create a new descriptor for the given type.
|
||||||
* <p>Use this constructor when a conversion point comes from a source such as a Map
|
* <p>Use this constructor when a conversion point comes from a source such as a Map
|
||||||
|
|
@ -99,6 +102,7 @@ public class TypeDescriptor {
|
||||||
this.elementType = elementType;
|
this.elementType = elementType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the wrapped MethodParameter, if any.
|
* Return the wrapped MethodParameter, if any.
|
||||||
* <p>Note: Either MethodParameter or Field is available.
|
* <p>Note: Either MethodParameter or Field is available.
|
||||||
|
|
@ -124,11 +128,14 @@ public class TypeDescriptor {
|
||||||
public Class<?> getType() {
|
public Class<?> getType() {
|
||||||
if (this.type != null) {
|
if (this.type != null) {
|
||||||
return this.type;
|
return this.type;
|
||||||
} else if (this.field != null) {
|
}
|
||||||
|
else if (this.field != null) {
|
||||||
return this.field.getType();
|
return this.field.getType();
|
||||||
} else if (this.methodParameter != null) {
|
}
|
||||||
|
else if (this.methodParameter != null) {
|
||||||
return this.methodParameter.getParameterType();
|
return this.methodParameter.getParameterType();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -139,7 +146,7 @@ public class TypeDescriptor {
|
||||||
*/
|
*/
|
||||||
public Class<?> getObjectType() {
|
public Class<?> getObjectType() {
|
||||||
Class<?> type = getType();
|
Class<?> type = getType();
|
||||||
return type != null ? ClassUtils.resolvePrimitiveIfNecessary(type) : type;
|
return (type != null ? ClassUtils.resolvePrimitiveIfNecessary(type) : type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -147,8 +154,7 @@ public class TypeDescriptor {
|
||||||
* @param type the type to test against
|
* @param type the type to test against
|
||||||
*/
|
*/
|
||||||
public boolean typeEquals(Class<?> type) {
|
public boolean typeEquals(Class<?> type) {
|
||||||
Class<?> thisType = getType();
|
return ObjectUtils.nullSafeEquals(getType(), type);
|
||||||
return thisType != null ? thisType.equals(type) : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -158,7 +164,8 @@ public class TypeDescriptor {
|
||||||
Class<?> type = getType();
|
Class<?> type = getType();
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
return getType().getName();
|
return getType().getName();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -198,14 +205,17 @@ public class TypeDescriptor {
|
||||||
* Return the element type as a type descriptor.
|
* Return the element type as a type descriptor.
|
||||||
*/
|
*/
|
||||||
public TypeDescriptor getElementTypeDescriptor() {
|
public TypeDescriptor getElementTypeDescriptor() {
|
||||||
if (elementType != null) {
|
if (this.elementType != null) {
|
||||||
return elementType;
|
return this.elementType;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (isArray()) {
|
if (isArray()) {
|
||||||
return TypeDescriptor.valueOf(getArrayComponentType());
|
return TypeDescriptor.valueOf(getArrayComponentType());
|
||||||
} else if (isCollection()) {
|
}
|
||||||
|
else if (isCollection()) {
|
||||||
return TypeDescriptor.valueOf(getCollectionElementType());
|
return TypeDescriptor.valueOf(getCollectionElementType());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return TypeDescriptor.NULL;
|
return TypeDescriptor.NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -232,9 +242,11 @@ public class TypeDescriptor {
|
||||||
public Class<?> getMapKeyType() {
|
public Class<?> getMapKeyType() {
|
||||||
if (this.field != null) {
|
if (this.field != null) {
|
||||||
return GenericCollectionTypeResolver.getMapKeyFieldType(field);
|
return GenericCollectionTypeResolver.getMapKeyFieldType(field);
|
||||||
} else if (this.methodParameter != null) {
|
}
|
||||||
|
else if (this.methodParameter != null) {
|
||||||
return GenericCollectionTypeResolver.getMapKeyParameterType(this.methodParameter);
|
return GenericCollectionTypeResolver.getMapKeyParameterType(this.methodParameter);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -246,9 +258,11 @@ public class TypeDescriptor {
|
||||||
public Class<?> getMapValueType() {
|
public Class<?> getMapValueType() {
|
||||||
if (this.field != null) {
|
if (this.field != null) {
|
||||||
return GenericCollectionTypeResolver.getMapValueFieldType(this.field);
|
return GenericCollectionTypeResolver.getMapValueFieldType(this.field);
|
||||||
} else if (this.methodParameter != null) {
|
}
|
||||||
|
else if (this.methodParameter != null) {
|
||||||
return GenericCollectionTypeResolver.getMapValueParameterType(this.methodParameter);
|
return GenericCollectionTypeResolver.getMapValueParameterType(this.methodParameter);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -276,9 +290,11 @@ public class TypeDescriptor {
|
||||||
this.cachedFieldAnnotations = this.field.getAnnotations();
|
this.cachedFieldAnnotations = this.field.getAnnotations();
|
||||||
}
|
}
|
||||||
return this.cachedFieldAnnotations;
|
return this.cachedFieldAnnotations;
|
||||||
} else if (this.methodParameter != null) {
|
}
|
||||||
|
else if (this.methodParameter != null) {
|
||||||
return this.methodParameter.getParameterAnnotations();
|
return this.methodParameter.getParameterAnnotations();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return new Annotation[0];
|
return new Annotation[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -324,6 +340,28 @@ public class TypeDescriptor {
|
||||||
return type != null && ClassUtils.isAssignable(targetType.getType(), type);
|
return type != null && ClassUtils.isAssignable(targetType.getType(), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Class<?> getArrayComponentType() {
|
||||||
|
return getType().getComponentType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private Class<?> getCollectionElementType() {
|
||||||
|
if (this.type != null) {
|
||||||
|
return GenericCollectionTypeResolver.getCollectionType((Class<? extends Collection>) this.type);
|
||||||
|
}
|
||||||
|
else if (this.field != null) {
|
||||||
|
return GenericCollectionTypeResolver.getCollectionFieldType(this.field);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return GenericCollectionTypeResolver.getCollectionParameterType(this.methodParameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTypeAssignableTo(Class<?> clazz) {
|
||||||
|
Class<?> type = getType();
|
||||||
|
return (type != null && ClassUtils.isAssignable(clazz, type));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a textual representation of the type descriptor (eg. Map<String,Foo>) for use in messages
|
* @return a textual representation of the type descriptor (eg. Map<String,Foo>) for use in messages
|
||||||
*/
|
*/
|
||||||
|
|
@ -332,7 +370,8 @@ public class TypeDescriptor {
|
||||||
if (isArray()) {
|
if (isArray()) {
|
||||||
// TODO should properly handle multi dimensional arrays
|
// TODO should properly handle multi dimensional arrays
|
||||||
stringValue.append(getArrayComponentType().getName()).append("[]");
|
stringValue.append(getArrayComponentType().getName()).append("[]");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Class<?> clazz = getType();
|
Class<?> clazz = getType();
|
||||||
if (clazz == null) {
|
if (clazz == null) {
|
||||||
return "null";
|
return "null";
|
||||||
|
|
@ -355,27 +394,23 @@ public class TypeDescriptor {
|
||||||
return stringValue.toString();
|
return stringValue.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal helpers
|
public String toString() {
|
||||||
|
if (this == TypeDescriptor.NULL) {
|
||||||
private Class<?> getArrayComponentType() {
|
return "[TypeDescriptor.NULL]";
|
||||||
return getType().getComponentType();
|
}
|
||||||
}
|
else {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
@SuppressWarnings("unchecked")
|
builder.append("[TypeDescriptor ");
|
||||||
private Class<?> getCollectionElementType() {
|
Annotation[] anns = getAnnotations();
|
||||||
if (this.type != null) {
|
for (Annotation ann : anns) {
|
||||||
return GenericCollectionTypeResolver.getCollectionType((Class<? extends Collection>) this.type);
|
builder.append("@").append(ann.annotationType().getName()).append(' ');
|
||||||
} else if (this.field != null) {
|
}
|
||||||
return GenericCollectionTypeResolver.getCollectionFieldType(this.field);
|
builder.append(getType().getName());
|
||||||
} else {
|
builder.append("]");
|
||||||
return GenericCollectionTypeResolver.getCollectionParameterType(this.methodParameter);
|
return builder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTypeAssignableTo(Class<?> clazz) {
|
|
||||||
Class<?> type = getType();
|
|
||||||
return (type != null && ClassUtils.isAssignable(clazz, type));
|
|
||||||
}
|
|
||||||
|
|
||||||
// static factory methods
|
// static factory methods
|
||||||
|
|
||||||
|
|
@ -407,20 +442,4 @@ public class TypeDescriptor {
|
||||||
return new TypeDescriptor(type, elementType);
|
return new TypeDescriptor(type, elementType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
if (this == TypeDescriptor.NULL) {
|
|
||||||
return "[TypeDescriptor.NULL]";
|
|
||||||
} else {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("[TypeDescriptor ");
|
|
||||||
Annotation[] anns = getAnnotations();
|
|
||||||
for (Annotation ann : anns) {
|
|
||||||
builder.append("@" + ann.annotationType().getName()).append(' ');
|
|
||||||
}
|
|
||||||
builder.append(getType().getName());
|
|
||||||
builder.append("]");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,7 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Map<Class<?>, Map<Class<?>, MatchableConverters>> converters = new HashMap<Class<?>, Map<Class<?>, MatchableConverters>>(
|
private final Map<Class<?>, Map<Class<?>, MatchableConverters>> converters = new HashMap<Class<?>, Map<Class<?>, MatchableConverters>>(36);
|
||||||
36);
|
|
||||||
|
|
||||||
// implementing ConverterRegistry
|
// implementing ConverterRegistry
|
||||||
|
|
||||||
|
|
@ -182,7 +181,8 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||||
GenericConverter converter = findConverterForClassPair(sourceType, targetType);
|
GenericConverter converter = findConverterForClassPair(sourceType, targetType);
|
||||||
if (converter != null) {
|
if (converter != null) {
|
||||||
return converter;
|
return converter;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return getDefaultConverter(sourceType, targetType);
|
return getDefaultConverter(sourceType, targetType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -199,11 +199,13 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||||
protected GenericConverter getDefaultConverter(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
protected GenericConverter getDefaultConverter(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||||
if (sourceType.isAssignableTo(targetType)) {
|
if (sourceType.isAssignableTo(targetType)) {
|
||||||
return NO_OP_CONVERTER;
|
return NO_OP_CONVERTER;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal helpers
|
// internal helpers
|
||||||
|
|
||||||
private Class<?>[] getRequiredTypeInfo(Object converter, Class<?> genericIfc) {
|
private Class<?>[] getRequiredTypeInfo(Object converter, Class<?> genericIfc) {
|
||||||
|
|
@ -256,7 +258,8 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||||
}
|
}
|
||||||
Map<Class<?>, MatchableConverters> objectConverters = getTargetConvertersForSource(Object.class);
|
Map<Class<?>, MatchableConverters> objectConverters = getTargetConvertersForSource(Object.class);
|
||||||
return getMatchingConverterForTarget(sourceType, targetType, objectConverters);
|
return getMatchingConverterForTarget(sourceType, targetType, objectConverters);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>();
|
LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>();
|
||||||
classQueue.addFirst(sourceObjectType);
|
classQueue.addFirst(sourceObjectType);
|
||||||
while (!classQueue.isEmpty()) {
|
while (!classQueue.isEmpty()) {
|
||||||
|
|
@ -271,7 +274,8 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||||
if (componentType.getSuperclass() != null) {
|
if (componentType.getSuperclass() != null) {
|
||||||
classQueue.addFirst(Array.newInstance(componentType.getSuperclass(), 0).getClass());
|
classQueue.addFirst(Array.newInstance(componentType.getSuperclass(), 0).getClass());
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Class<?>[] interfaces = currentClass.getInterfaces();
|
Class<?>[] interfaces = currentClass.getInterfaces();
|
||||||
for (Class<?> ifc : interfaces) {
|
for (Class<?> ifc : interfaces) {
|
||||||
classQueue.addFirst(ifc);
|
classQueue.addFirst(ifc);
|
||||||
|
|
@ -295,6 +299,7 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||||
|
|
||||||
private GenericConverter getMatchingConverterForTarget(TypeDescriptor sourceType, TypeDescriptor targetType,
|
private GenericConverter getMatchingConverterForTarget(TypeDescriptor sourceType, TypeDescriptor targetType,
|
||||||
Map<Class<?>, MatchableConverters> converters) {
|
Map<Class<?>, MatchableConverters> converters) {
|
||||||
|
|
||||||
Class<?> targetObjectType = targetType.getObjectType();
|
Class<?> targetObjectType = targetType.getObjectType();
|
||||||
if (targetObjectType.isInterface()) {
|
if (targetObjectType.isInterface()) {
|
||||||
LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>();
|
LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>();
|
||||||
|
|
@ -312,7 +317,8 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return matchConverter(converters.get(Object.class), sourceType, targetType);
|
return matchConverter(converters.get(Object.class), sourceType, targetType);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>();
|
LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>();
|
||||||
classQueue.addFirst(targetObjectType);
|
classQueue.addFirst(targetObjectType);
|
||||||
while (!classQueue.isEmpty()) {
|
while (!classQueue.isEmpty()) {
|
||||||
|
|
@ -343,9 +349,11 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||||
|
|
||||||
private GenericConverter matchConverter(MatchableConverters matchable, TypeDescriptor sourceFieldType,
|
private GenericConverter matchConverter(MatchableConverters matchable, TypeDescriptor sourceFieldType,
|
||||||
TypeDescriptor targetFieldType) {
|
TypeDescriptor targetFieldType) {
|
||||||
|
|
||||||
return matchable != null ? matchable.matchConverter(sourceFieldType, targetFieldType) : null;
|
return matchable != null ? matchable.matchConverter(sourceFieldType, targetFieldType) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private final class ConverterAdapter implements GenericConverter {
|
private final class ConverterAdapter implements GenericConverter {
|
||||||
|
|
||||||
|
|
@ -374,6 +382,7 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private final class ConverterFactoryAdapter implements GenericConverter {
|
private final class ConverterFactoryAdapter implements GenericConverter {
|
||||||
|
|
||||||
|
|
@ -400,9 +409,9 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.typeInfo[0].getName() + " -> " + this.typeInfo[1].getName() + " : " + this.converterFactory.toString();
|
return this.typeInfo[0].getName() + " -> " + this.typeInfo[1].getName() + " : " + this.converterFactory.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class MatchableConverters {
|
private static class MatchableConverters {
|
||||||
|
|
||||||
private LinkedList<ConditionalGenericConverter> conditionalConverters;
|
private LinkedList<ConditionalGenericConverter> conditionalConverters;
|
||||||
|
|
@ -458,7 +467,6 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||||
return this.defaultConverter.toString();
|
return this.defaultConverter.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -213,7 +213,7 @@ public abstract class CollectionUtils {
|
||||||
* or <code>null</code> if none or more than one such value found
|
* or <code>null</code> if none or more than one such value found
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T findValueOfType(Collection collection, Class<T> type) {
|
public static <T> T findValueOfType(Collection<?> collection, Class<T> type) {
|
||||||
if (isEmpty(collection)) {
|
if (isEmpty(collection)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -239,11 +239,11 @@ public abstract class CollectionUtils {
|
||||||
* @return a value of one of the given types found if there is a clear match,
|
* @return a value of one of the given types found if there is a clear match,
|
||||||
* or <code>null</code> if none or more than one such value found
|
* or <code>null</code> if none or more than one such value found
|
||||||
*/
|
*/
|
||||||
public static Object findValueOfType(Collection collection, Class[] types) {
|
public static Object findValueOfType(Collection<?> collection, Class<?>[] types) {
|
||||||
if (isEmpty(collection) || ObjectUtils.isEmpty(types)) {
|
if (isEmpty(collection) || ObjectUtils.isEmpty(types)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Class type : types) {
|
for (Class<?> type : types) {
|
||||||
Object value = findValueOfType(collection, type);
|
Object value = findValueOfType(collection, type);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return value;
|
return value;
|
||||||
|
|
@ -264,8 +264,7 @@ public abstract class CollectionUtils {
|
||||||
}
|
}
|
||||||
boolean hasCandidate = false;
|
boolean hasCandidate = false;
|
||||||
Object candidate = null;
|
Object candidate = null;
|
||||||
for (Iterator it = collection.iterator(); it.hasNext();) {
|
for (Object elem : collection) {
|
||||||
Object elem = it.next();
|
|
||||||
if (!hasCandidate) {
|
if (!hasCandidate) {
|
||||||
hasCandidate = true;
|
hasCandidate = true;
|
||||||
candidate = elem;
|
candidate = elem;
|
||||||
|
|
@ -286,6 +285,7 @@ public abstract class CollectionUtils {
|
||||||
return new EnumerationIterator<E>(enumeration);
|
return new EnumerationIterator<E>(enumeration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterator wrapping an Enumeration.
|
* Iterator wrapping an Enumeration.
|
||||||
*/
|
*/
|
||||||
|
|
@ -298,15 +298,16 @@ public abstract class CollectionUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return enumeration.hasMoreElements();
|
return this.enumeration.hasMoreElements();
|
||||||
}
|
}
|
||||||
|
|
||||||
public E next() {
|
public E next() {
|
||||||
return enumeration.nextElement();
|
return this.enumeration.nextElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() throws UnsupportedOperationException {
|
public void remove() throws UnsupportedOperationException {
|
||||||
throw new UnsupportedOperationException("Not supported");
|
throw new UnsupportedOperationException("Not supported");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,8 @@ import org.springframework.expression.spel.SpelMessage;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of the {@link TypeConverter} interface, delegating to a core Spring {@link ConversionService}.
|
* Default implementation of the {@link TypeConverter} interface,
|
||||||
|
* delegating to a core Spring {@link ConversionService}.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
|
|
@ -37,12 +38,18 @@ import org.springframework.util.Assert;
|
||||||
*/
|
*/
|
||||||
public class StandardTypeConverter implements TypeConverter {
|
public class StandardTypeConverter implements TypeConverter {
|
||||||
|
|
||||||
private static ConversionService DEFAULT_INSTANCE;
|
private static ConversionService defaultConversionService;
|
||||||
|
|
||||||
private final ConversionService conversionService;
|
private final ConversionService conversionService;
|
||||||
|
|
||||||
|
|
||||||
public StandardTypeConverter() {
|
public StandardTypeConverter() {
|
||||||
this.conversionService = getDefaultConversionService();
|
synchronized (this) {
|
||||||
|
if (defaultConversionService == null) {
|
||||||
|
defaultConversionService = ConversionServiceFactory.createDefaultConversionService();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.conversionService = defaultConversionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StandardTypeConverter(ConversionService conversionService) {
|
public StandardTypeConverter(ConversionService conversionService) {
|
||||||
|
|
@ -50,6 +57,7 @@ public class StandardTypeConverter implements TypeConverter {
|
||||||
this.conversionService = conversionService;
|
this.conversionService = conversionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
|
public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
|
||||||
return this.conversionService.canConvert(sourceType, targetType);
|
return this.conversionService.canConvert(sourceType, targetType);
|
||||||
}
|
}
|
||||||
|
|
@ -57,21 +65,15 @@ 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 this.conversionService.convert(value, TypeDescriptor.forObject(value), typeDescriptor);
|
return this.conversionService.convert(value, TypeDescriptor.forObject(value), typeDescriptor);
|
||||||
} catch (ConverterNotFoundException cenfe) {
|
}
|
||||||
throw new SpelEvaluationException(cenfe, SpelMessage.TYPE_CONVERSION_ERROR, value != null ? value
|
catch (ConverterNotFoundException cenfe) {
|
||||||
.getClass() : null, typeDescriptor.asString());
|
throw new SpelEvaluationException(cenfe, SpelMessage.TYPE_CONVERSION_ERROR,
|
||||||
} catch (ConversionException ce) {
|
(value != null ? value.getClass() : null), typeDescriptor.asString());
|
||||||
throw new SpelEvaluationException(ce, SpelMessage.TYPE_CONVERSION_ERROR, value != null ? value.getClass()
|
}
|
||||||
: null, typeDescriptor.asString());
|
catch (ConversionException ce) {
|
||||||
|
throw new SpelEvaluationException(ce, SpelMessage.TYPE_CONVERSION_ERROR,
|
||||||
|
(value != null ? value.getClass() : null), typeDescriptor.asString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConversionService getDefaultConversionService() {
|
|
||||||
synchronized(this) {
|
|
||||||
if (DEFAULT_INSTANCE == null) {
|
|
||||||
DEFAULT_INSTANCE = ConversionServiceFactory.createDefaultConversionService();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DEFAULT_INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -19,7 +19,6 @@ package org.springframework.orm.hibernate3;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
|
@ -70,7 +69,7 @@ public class LocalDataSourceConnectionProvider implements ConnectionProvider {
|
||||||
* Return the DataSource that this ConnectionProvider wraps.
|
* Return the DataSource that this ConnectionProvider wraps.
|
||||||
*/
|
*/
|
||||||
public DataSource getDataSource() {
|
public DataSource getDataSource() {
|
||||||
return dataSource;
|
return this.dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ public abstract class SessionFactoryUtils {
|
||||||
* @see HibernateTemplate
|
* @see HibernateTemplate
|
||||||
*/
|
*/
|
||||||
public static Session getSession(SessionFactory sessionFactory, boolean allowCreate)
|
public static Session getSession(SessionFactory sessionFactory, boolean allowCreate)
|
||||||
throws DataAccessResourceFailureException, IllegalStateException {
|
throws DataAccessResourceFailureException, IllegalStateException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return doGetSession(sessionFactory, null, null, allowCreate);
|
return doGetSession(sessionFactory, null, null, allowCreate);
|
||||||
|
|
@ -251,7 +251,7 @@ public abstract class SessionFactoryUtils {
|
||||||
* @throws IllegalStateException if no thread-bound Session found and allowCreate false
|
* @throws IllegalStateException if no thread-bound Session found and allowCreate false
|
||||||
*/
|
*/
|
||||||
public static Session doGetSession(SessionFactory sessionFactory, boolean allowCreate)
|
public static Session doGetSession(SessionFactory sessionFactory, boolean allowCreate)
|
||||||
throws HibernateException, IllegalStateException {
|
throws HibernateException, IllegalStateException {
|
||||||
|
|
||||||
return doGetSession(sessionFactory, null, null, allowCreate);
|
return doGetSession(sessionFactory, null, null, allowCreate);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue