diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java b/org.springframework.aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java index 45fdcc88e2a..458cc465180 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java @@ -102,8 +102,8 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea * but would complicate the code. And it would work only for static pointcuts. */ protected ReflectiveMethodInvocation( - Object proxy, Object target, Method method, Object[] arguments, - Class targetClass, List interceptorsAndDynamicMethodMatchers) { + Object proxy, Object target, Method method, Object[] arguments, + Class targetClass, List interceptorsAndDynamicMethodMatchers) { this.proxy = proxy; this.target = target; diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionException.java b/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionException.java index a30bc9aa1bd..4ddf15d8390 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionException.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionException.java @@ -24,7 +24,6 @@ import org.springframework.core.NestedRuntimeException; * @author Keith Donald * @since 3.0 */ -@SuppressWarnings("serial") public abstract class ConversionException extends NestedRuntimeException { /** diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionFailedException.java b/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionFailedException.java index 6c6c2e5264a..0f83803f434 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionFailedException.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionFailedException.java @@ -22,13 +22,13 @@ package org.springframework.core.convert; * @author Keith Donald * @since 3.0 */ -@SuppressWarnings("serial") public final class ConversionFailedException extends ConversionException { private final TypeDescriptor sourceType; private final TypeDescriptor targetType; + /** * Create a new conversion exception. * @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 */ 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.targetType = targetType; } + /** * Return the source type we tried to convert the value from. */ @@ -56,10 +58,4 @@ public final class ConversionFailedException extends ConversionException { 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() + "'"; - } - -} \ No newline at end of file +} diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index aa1c0f46e67..8448b1e841a 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -26,6 +26,7 @@ import org.springframework.core.GenericCollectionTypeResolver; import org.springframework.core.MethodParameter; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.ObjectUtils; /** * Context about a type to convert to. @@ -42,6 +43,7 @@ public class TypeDescriptor { */ public static final TypeDescriptor NULL = new TypeDescriptor(); + private Class type; private TypeDescriptor elementType; @@ -52,6 +54,7 @@ public class TypeDescriptor { private Annotation[] cachedFieldAnnotations; + /** * Create a new descriptor for the given type. *

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; } + /** * Return the wrapped MethodParameter, if any. *

Note: Either MethodParameter or Field is available. @@ -124,11 +128,14 @@ public class TypeDescriptor { public Class getType() { if (this.type != null) { return this.type; - } else if (this.field != null) { + } + else if (this.field != null) { return this.field.getType(); - } else if (this.methodParameter != null) { + } + else if (this.methodParameter != null) { return this.methodParameter.getParameterType(); - } else { + } + else { return null; } } @@ -139,7 +146,7 @@ public class TypeDescriptor { */ public Class getObjectType() { 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 */ public boolean typeEquals(Class type) { - Class thisType = getType(); - return thisType != null ? thisType.equals(type) : false; + return ObjectUtils.nullSafeEquals(getType(), type); } /** @@ -158,7 +164,8 @@ public class TypeDescriptor { Class type = getType(); if (type != null) { return getType().getName(); - } else { + } + else { return null; } } @@ -198,14 +205,17 @@ public class TypeDescriptor { * Return the element type as a type descriptor. */ public TypeDescriptor getElementTypeDescriptor() { - if (elementType != null) { - return elementType; - } else { + if (this.elementType != null) { + return this.elementType; + } + else { if (isArray()) { return TypeDescriptor.valueOf(getArrayComponentType()); - } else if (isCollection()) { + } + else if (isCollection()) { return TypeDescriptor.valueOf(getCollectionElementType()); - } else { + } + else { return TypeDescriptor.NULL; } } @@ -232,9 +242,11 @@ public class TypeDescriptor { public Class getMapKeyType() { if (this.field != null) { return GenericCollectionTypeResolver.getMapKeyFieldType(field); - } else if (this.methodParameter != null) { + } + else if (this.methodParameter != null) { return GenericCollectionTypeResolver.getMapKeyParameterType(this.methodParameter); - } else { + } + else { return null; } } @@ -246,9 +258,11 @@ public class TypeDescriptor { public Class getMapValueType() { if (this.field != null) { return GenericCollectionTypeResolver.getMapValueFieldType(this.field); - } else if (this.methodParameter != null) { + } + else if (this.methodParameter != null) { return GenericCollectionTypeResolver.getMapValueParameterType(this.methodParameter); - } else { + } + else { return null; } } @@ -276,9 +290,11 @@ public class TypeDescriptor { this.cachedFieldAnnotations = this.field.getAnnotations(); } return this.cachedFieldAnnotations; - } else if (this.methodParameter != null) { + } + else if (this.methodParameter != null) { return this.methodParameter.getParameterAnnotations(); - } else { + } + else { return new Annotation[0]; } } @@ -324,6 +340,28 @@ public class TypeDescriptor { 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) 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) for use in messages */ @@ -332,7 +370,8 @@ public class TypeDescriptor { if (isArray()) { // TODO should properly handle multi dimensional arrays stringValue.append(getArrayComponentType().getName()).append("[]"); - } else { + } + else { Class clazz = getType(); if (clazz == null) { return "null"; @@ -355,27 +394,23 @@ public class TypeDescriptor { return stringValue.toString(); } - // internal helpers - - private Class getArrayComponentType() { - return getType().getComponentType(); - } - - @SuppressWarnings("unchecked") - private Class getCollectionElementType() { - if (this.type != null) { - return GenericCollectionTypeResolver.getCollectionType((Class) this.type); - } else if (this.field != null) { - return GenericCollectionTypeResolver.getCollectionFieldType(this.field); - } else { - return GenericCollectionTypeResolver.getCollectionParameterType(this.methodParameter); + 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("@").append(ann.annotationType().getName()).append(' '); + } + builder.append(getType().getName()); + builder.append("]"); + return builder.toString(); } } - private boolean isTypeAssignableTo(Class clazz) { - Class type = getType(); - return (type != null && ClassUtils.isAssignable(clazz, type)); - } // static factory methods @@ -406,21 +441,5 @@ public class TypeDescriptor { public static TypeDescriptor collection(Class type, TypeDescriptor 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(); - } - } - + } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index 7b4a05fef77..81dfa12df4b 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -62,8 +62,7 @@ public class GenericConversionService implements ConversionService, ConverterReg } }; - private final Map, Map, MatchableConverters>> converters = new HashMap, Map, MatchableConverters>>( - 36); + private final Map, Map, MatchableConverters>> converters = new HashMap, Map, MatchableConverters>>(36); // implementing ConverterRegistry @@ -182,7 +181,8 @@ public class GenericConversionService implements ConversionService, ConverterReg GenericConverter converter = findConverterForClassPair(sourceType, targetType); if (converter != null) { return converter; - } else { + } + else { return getDefaultConverter(sourceType, targetType); } } @@ -199,11 +199,13 @@ public class GenericConversionService implements ConversionService, ConverterReg protected GenericConverter getDefaultConverter(TypeDescriptor sourceType, TypeDescriptor targetType) { if (sourceType.isAssignableTo(targetType)) { return NO_OP_CONVERTER; - } else { + } + else { return null; } } + // internal helpers private Class[] getRequiredTypeInfo(Object converter, Class genericIfc) { @@ -256,7 +258,8 @@ public class GenericConversionService implements ConversionService, ConverterReg } Map, MatchableConverters> objectConverters = getTargetConvertersForSource(Object.class); return getMatchingConverterForTarget(sourceType, targetType, objectConverters); - } else { + } + else { LinkedList> classQueue = new LinkedList>(); classQueue.addFirst(sourceObjectType); while (!classQueue.isEmpty()) { @@ -271,7 +274,8 @@ public class GenericConversionService implements ConversionService, ConverterReg if (componentType.getSuperclass() != null) { classQueue.addFirst(Array.newInstance(componentType.getSuperclass(), 0).getClass()); } - } else { + } + else { Class[] interfaces = currentClass.getInterfaces(); for (Class ifc : interfaces) { classQueue.addFirst(ifc); @@ -295,6 +299,7 @@ public class GenericConversionService implements ConversionService, ConverterReg private GenericConverter getMatchingConverterForTarget(TypeDescriptor sourceType, TypeDescriptor targetType, Map, MatchableConverters> converters) { + Class targetObjectType = targetType.getObjectType(); if (targetObjectType.isInterface()) { LinkedList> classQueue = new LinkedList>(); @@ -312,7 +317,8 @@ public class GenericConversionService implements ConversionService, ConverterReg } } return matchConverter(converters.get(Object.class), sourceType, targetType); - } else { + } + else { LinkedList> classQueue = new LinkedList>(); classQueue.addFirst(targetObjectType); while (!classQueue.isEmpty()) { @@ -343,9 +349,11 @@ public class GenericConversionService implements ConversionService, ConverterReg private GenericConverter matchConverter(MatchableConverters matchable, TypeDescriptor sourceFieldType, TypeDescriptor targetFieldType) { + return matchable != null ? matchable.matchConverter(sourceFieldType, targetFieldType) : null; } + @SuppressWarnings("unchecked") private final class ConverterAdapter implements GenericConverter { @@ -374,6 +382,7 @@ public class GenericConversionService implements ConversionService, ConverterReg } } + @SuppressWarnings("unchecked") private final class ConverterFactoryAdapter implements GenericConverter { @@ -400,9 +409,9 @@ public class GenericConversionService implements ConversionService, ConverterReg public String toString() { return this.typeInfo[0].getName() + " -> " + this.typeInfo[1].getName() + " : " + this.converterFactory.toString(); } - } + private static class MatchableConverters { private LinkedList conditionalConverters; @@ -458,7 +467,6 @@ public class GenericConversionService implements ConversionService, ConverterReg return this.defaultConverter.toString(); } } - } -} \ No newline at end of file +} diff --git a/org.springframework.core/src/main/java/org/springframework/util/CollectionUtils.java b/org.springframework.core/src/main/java/org/springframework/util/CollectionUtils.java index 2d92dcabc63..14c8d87e116 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/CollectionUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/util/CollectionUtils.java @@ -213,7 +213,7 @@ public abstract class CollectionUtils { * or null if none or more than one such value found */ @SuppressWarnings("unchecked") - public static T findValueOfType(Collection collection, Class type) { + public static T findValueOfType(Collection collection, Class type) { if (isEmpty(collection)) { 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, * or null 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)) { return null; } - for (Class type : types) { + for (Class type : types) { Object value = findValueOfType(collection, type); if (value != null) { return value; @@ -264,8 +264,7 @@ public abstract class CollectionUtils { } boolean hasCandidate = false; Object candidate = null; - for (Iterator it = collection.iterator(); it.hasNext();) { - Object elem = it.next(); + for (Object elem : collection) { if (!hasCandidate) { hasCandidate = true; candidate = elem; @@ -286,6 +285,7 @@ public abstract class CollectionUtils { return new EnumerationIterator(enumeration); } + /** * Iterator wrapping an Enumeration. */ @@ -298,15 +298,16 @@ public abstract class CollectionUtils { } public boolean hasNext() { - return enumeration.hasMoreElements(); + return this.enumeration.hasMoreElements(); } public E next() { - return enumeration.nextElement(); + return this.enumeration.nextElement(); } public void remove() throws UnsupportedOperationException { throw new UnsupportedOperationException("Not supported"); } } + } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java index 939068fca79..55cb486069d 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java @@ -28,7 +28,8 @@ import org.springframework.expression.spel.SpelMessage; 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 Andy Clement @@ -37,12 +38,18 @@ import org.springframework.util.Assert; */ public class StandardTypeConverter implements TypeConverter { - private static ConversionService DEFAULT_INSTANCE; + private static ConversionService defaultConversionService; private final ConversionService conversionService; + public StandardTypeConverter() { - this.conversionService = getDefaultConversionService(); + synchronized (this) { + if (defaultConversionService == null) { + defaultConversionService = ConversionServiceFactory.createDefaultConversionService(); + } + } + this.conversionService = defaultConversionService; } public StandardTypeConverter(ConversionService conversionService) { @@ -50,6 +57,7 @@ public class StandardTypeConverter implements TypeConverter { this.conversionService = conversionService; } + public boolean canConvert(Class sourceType, Class 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 { try { return this.conversionService.convert(value, TypeDescriptor.forObject(value), typeDescriptor); - } catch (ConverterNotFoundException cenfe) { - throw new SpelEvaluationException(cenfe, 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()); + } + catch (ConverterNotFoundException cenfe) { + throw new SpelEvaluationException(cenfe, 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; - } } diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/LocalDataSourceConnectionProvider.java b/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/LocalDataSourceConnectionProvider.java index 9b3fbc37640..29a711b3337 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/LocalDataSourceConnectionProvider.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/LocalDataSourceConnectionProvider.java @@ -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"); * 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.SQLException; import java.util.Properties; - import javax.sql.DataSource; import org.hibernate.HibernateException; @@ -70,7 +69,7 @@ public class LocalDataSourceConnectionProvider implements ConnectionProvider { * Return the DataSource that this ConnectionProvider wraps. */ public DataSource getDataSource() { - return dataSource; + return this.dataSource; } /** diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java b/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java index f269c007104..7ee2a4d662a 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java @@ -194,7 +194,7 @@ public abstract class SessionFactoryUtils { * @see HibernateTemplate */ public static Session getSession(SessionFactory sessionFactory, boolean allowCreate) - throws DataAccessResourceFailureException, IllegalStateException { + throws DataAccessResourceFailureException, IllegalStateException { try { 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 */ public static Session doGetSession(SessionFactory sessionFactory, boolean allowCreate) - throws HibernateException, IllegalStateException { + throws HibernateException, IllegalStateException { return doGetSession(sessionFactory, null, null, allowCreate); }