From e4ce547934f438e518c56c45f3bd4b69ef8fffba Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 27 Nov 2008 17:35:44 +0000 Subject: [PATCH] Java 5 code style git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@342 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../AspectJAdviceParameterNameDiscoverer.java | 66 +++++--------- .../aop/config/AopConfigUtils.java | 48 +++-------- .../config/ConfigBeanDefinitionParser.java | 64 ++++---------- .../aop/framework/ProxyCreatorSupport.java | 14 ++- .../DefaultAdvisorAdapterRegistry.java | 16 ++-- .../BeanFactoryAdvisorRetrievalHelper.java | 4 +- .../aop/support/NameMatchMethodPointcut.java | 25 ++---- .../beans/BeanWrapperImpl.java | 2 +- .../beans/PropertyMatches.java | 8 +- .../config/PropertyOverrideConfigurer.java | 2 +- .../parsing/BeanComponentDefinition.java | 12 +-- .../parsing/CompositeComponentDefinition.java | 7 +- .../serviceloader/ServiceListFactoryBean.java | 10 +-- .../support/BeanDefinitionValueResolver.java | 6 +- .../factory/support/ReplaceOverride.java | 15 ++-- .../factory/support/RootBeanDefinition.java | 6 +- .../xml/BeanDefinitionParserDelegate.java | 4 +- .../DefaultBeanDefinitionDocumentReader.java | 4 +- .../FreeMarkerConfigurationFactory.java | 22 ++--- .../support/AbstractMessageSource.java | 14 +-- .../support/NotificationListenerHolder.java | 20 ++--- .../support/RemoteInvocationUtils.java | 4 +- .../validation/AbstractErrors.java | 26 +++--- .../org/springframework/core/Conventions.java | 10 +-- .../support/ResourceArrayPropertyEditor.java | 14 ++- .../util/AutoPopulatingList.java | 86 +++++++++---------- .../springframework/util/ReflectionUtils.java | 32 ++++--- .../org/springframework/util/StopWatch.java | 25 +++--- .../metadata/GenericCallMetaDataProvider.java | 51 ++++------- .../core/metadata/TableMetaDataContext.java | 4 +- .../BeanPropertySqlParameterSource.java | 10 +-- .../SQLStateSQLExceptionTranslator.java | 10 +-- .../connection/SingleConnectionFactory.java | 14 +-- ...ransactionAwareConnectionFactoryProxy.java | 8 +- .../AbstractJmsListeningContainer.java | 2 +- .../config/TxAdviceBeanDefinitionParser.java | 24 +++--- .../web/portlet/GenericPortletBean.java | 8 +- .../web/portlet/HandlerExecutionChain.java | 29 ++++--- .../handler/AbstractHandlerMapping.java | 4 +- .../web/bind/EscapedErrors.java | 33 +++---- .../web/servlet/HandlerExecutionChain.java | 24 +++--- .../web/servlet/HttpServletBean.java | 8 +- .../handler/AbstractHandlerMapping.java | 4 +- .../handler/BeanNameUrlHandlerMapping.java | 2 +- .../servlet/support/WebContentGenerator.java | 6 +- .../web/servlet/tags/form/ErrorsTag.java | 3 +- .../servlet/view/InternalResourceView.java | 4 +- .../ContextExposingHttpServletRequest.java | 8 +- .../web/filter/GenericFilterBean.java | 8 +- 49 files changed, 353 insertions(+), 477 deletions(-) diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java index 31c6471673e..7a9dba9612e 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -16,6 +16,7 @@ package org.springframework.aop.aspectj; +import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.ArrayList; @@ -30,7 +31,6 @@ import org.aspectj.weaver.tools.PointcutParser; import org.aspectj.weaver.tools.PointcutPrimitive; import org.springframework.core.ParameterNameDiscoverer; -import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; /** @@ -118,8 +118,6 @@ import org.springframework.util.StringUtils; */ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscoverer { - private static final String ANNOTATION_CLASS_NAME = "java.lang.annotation.Annotation"; - private static final String THIS_JOIN_POINT = "thisJoinPoint"; private static final String THIS_JOIN_POINT_STATIC_PART = "thisJoinPointStaticPart"; @@ -133,10 +131,8 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov private static final int STEP_REFERENCE_PCUT_BINDING = 7; private static final int STEP_FINISHED = 8; - private static final Set singleValuedAnnotationPcds = new HashSet(); - private static final Set nonReferencePointcutTokens = new HashSet(); - - private static Class annotationClass; + private static final Set singleValuedAnnotationPcds = new HashSet(); + private static final Set nonReferencePointcutTokens = new HashSet(); static { @@ -157,15 +153,6 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov nonReferencePointcutTokens.add("and"); nonReferencePointcutTokens.add("or"); nonReferencePointcutTokens.add("not"); - - try { - annotationClass = ClassUtils.forName(ANNOTATION_CLASS_NAME, - AspectJAdviceParameterNameDiscoverer.class.getClassLoader()); - } - catch (ClassNotFoundException ex) { - // Running on < JDK 1.5, this is OK... - annotationClass = null; - } } @@ -192,8 +179,6 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov private int numberOfRemainingUnboundArguments; - private int algorithmicStep = STEP_JOIN_POINT_BINDING; - /** * Create a new discoverer that attempts to discover parameter names @@ -241,7 +226,6 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov this.argumentTypes = method.getParameterTypes(); this.numberOfRemainingUnboundArguments = this.argumentTypes.length; this.parameterNameBindings = new String[this.numberOfRemainingUnboundArguments]; - this.algorithmicStep = STEP_JOIN_POINT_BINDING; int minimumNumberUnboundArgs = 0; if (this.returningName != null) { @@ -256,8 +240,9 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov } try { - while ((this.numberOfRemainingUnboundArguments > 0) && (this.algorithmicStep < STEP_FINISHED)) { - switch (this.algorithmicStep++) { + int algorithmicStep = STEP_JOIN_POINT_BINDING; + while ((this.numberOfRemainingUnboundArguments > 0) && algorithmicStep < STEP_FINISHED) { + switch (algorithmicStep++) { case STEP_JOIN_POINT_BINDING: if (!maybeBindThisJoinPoint()) { maybeBindThisJoinPointStaticPart(); @@ -282,7 +267,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov maybeBindReferencePointcutParameter(); break; default: - throw new IllegalStateException("Unknown algorithmic step: " + (this.algorithmicStep - 1)); + throw new IllegalStateException("Unknown algorithmic step: " + (algorithmicStep - 1)); } } } @@ -429,7 +414,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov *

Some more support from AspectJ in doing this exercise would be nice... :) */ private void maybeBindAnnotationsFromPointcutExpression() { - List varNames = new ArrayList(); + List varNames = new ArrayList(); String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " "); for (int i = 0; i < tokens.length; i++) { String toMatch = tokens[i]; @@ -458,7 +443,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov /** * Match the given list of extracted variable names to argument slots. */ - private void bindAnnotationsFromVarNames(List varNames) { + private void bindAnnotationsFromVarNames(List varNames) { if (!varNames.isEmpty()) { // we have work to do... int numAnnotationSlots = countNumberOfUnboundAnnotationArguments(); @@ -470,7 +455,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov else if (numAnnotationSlots == 1) { if (varNames.size() == 1) { // it's a match - findAndBind(annotationClass, (String) varNames.get(0)); + findAndBind(Annotation.class, varNames.get(0)); } else { // multiple candidate vars, but only one slot @@ -495,8 +480,8 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov if (Character.isJavaIdentifierStart(candidateToken.charAt(0)) && Character.isLowerCase(candidateToken.charAt(0))) { char[] tokenChars = candidateToken.toCharArray(); - for (int i = 0; i < tokenChars.length; i++) { - if (!Character.isJavaIdentifierPart(tokenChars[i])) { + for (char tokenChar : tokenChars) { + if (!Character.isJavaIdentifierPart(tokenChar)) { return null; } } @@ -511,11 +496,10 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov * Given an args pointcut body (could be args or at_args), * add any candidate variable names to the given list. */ - private void maybeExtractVariableNamesFromArgs(String argsSpec, List varNames) { + private void maybeExtractVariableNamesFromArgs(String argsSpec, List varNames) { if (argsSpec == null) { return; } - String[] tokens = StringUtils.tokenizeToStringArray(argsSpec, ","); for (int i = 0; i < tokens.length; i++) { tokens[i] = StringUtils.trimWhitespace(tokens[i]); @@ -536,7 +520,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov + " unbound args at this(),target(),args() binding stage, with no way to determine between them"); } - List varNames = new ArrayList(); + List varNames = new ArrayList(); String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " "); for (int i = 0; i < tokens.length; i++) { if (tokens[i].equals("this") || @@ -553,12 +537,11 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov else if (tokens[i].equals("args") || tokens[i].startsWith("args(")) { PointcutBody body = getPointcutBody(tokens, i); i += body.numTokensConsumed; - List candidateVarNames = new ArrayList(); + List candidateVarNames = new ArrayList(); maybeExtractVariableNamesFromArgs(body.text, candidateVarNames); // we may have found some var names that were bound in previous primitive args binding step, // filter them out... - for (Iterator iter = candidateVarNames.iterator(); iter.hasNext();) { - String varName = (String) iter.next(); + for (String varName : candidateVarNames) { if (!alreadyBound(varName)) { varNames.add(varName); } @@ -574,7 +557,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov else if (varNames.size() == 1) { for (int j = 0; j < this.parameterNameBindings.length; j++) { if (isUnbound(j)) { - bindParameterName(j, (String) varNames.get(0)); + bindParameterName(j, varNames.get(0)); break; } } @@ -588,7 +571,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov + " unbound args at reference pointcut binding stage, with no way to determine between them"); } - List varNames = new ArrayList(); + List varNames = new ArrayList(); String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " "); for (int i = 0; i < tokens.length; i++) { String toMatch = tokens[i]; @@ -634,7 +617,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov else if (varNames.size() == 1) { for (int j = 0; j < this.parameterNameBindings.length; j++) { if (isUnbound(j)) { - bindParameterName(j, (String) varNames.get(0)); + bindParameterName(j, varNames.get(0)); break; } } @@ -700,7 +683,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov } if (numUnboundPrimitives == 1) { // Look for arg variable and bind it if we find exactly one... - List varNames = new ArrayList(); + List varNames = new ArrayList(); String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " "); for (int i = 0; i < tokens.length; i++) { if (tokens[i].equals("args") || tokens[i].startsWith("args(")) { @@ -751,14 +734,9 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov } private int countNumberOfUnboundAnnotationArguments() { - if (annotationClass == null) { - // We're running on a JDK < 1.5 - return 0; - } - int count = 0; for (int i = 0; i < this.argumentTypes.length; i++) { - if (isUnbound(i) && isSubtypeOf(annotationClass, i)) { + if (isUnbound(i) && isSubtypeOf(Annotation.class, i)) { count++; } } diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java b/org.springframework.aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java index db962395399..155c43253c9 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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,15 +19,14 @@ package org.springframework.aop.config; import java.util.ArrayList; import java.util.List; +import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator; import org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator; import org.springframework.aop.framework.autoproxy.InfrastructureAdvisorAutoProxyCreator; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.core.JdkVersion; import org.springframework.core.Ordered; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; /** * Utility class for handling registration of AOP auto-proxy creators. @@ -52,26 +51,18 @@ public abstract class AopConfigUtils { public static final String AUTO_PROXY_CREATOR_BEAN_NAME = "org.springframework.aop.config.internalAutoProxyCreator"; - /** - * The class name of the AnnotationAwareAspectJAutoProxyCreator class. - * Only available with AspectJ and Java 5. - */ - private static final String ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME = - "org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"; - - /** * Stores the auto proxy creator classes in escalation order. */ - private static final List APC_PRIORITY_LIST = new ArrayList(); + private static final List APC_PRIORITY_LIST = new ArrayList(); /** * Setup the escalation list. */ static { - APC_PRIORITY_LIST.add(InfrastructureAdvisorAutoProxyCreator.class.getName()); - APC_PRIORITY_LIST.add(AspectJAwareAdvisorAutoProxyCreator.class.getName()); - APC_PRIORITY_LIST.add(ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME); + APC_PRIORITY_LIST.add(InfrastructureAdvisorAutoProxyCreator.class); + APC_PRIORITY_LIST.add(AspectJAwareAdvisorAutoProxyCreator.class); + APC_PRIORITY_LIST.add(AnnotationAwareAspectJAutoProxyCreator.class); } @@ -96,8 +87,7 @@ public abstract class AopConfigUtils { } public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) { - Class cls = getAspectJAnnotationAutoProxyCreatorClassIfPossible(); - return registerOrEscalateApcAsRequired(cls, registry, source); + return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source); } public static void forceAutoProxyCreatorToUseClassProxying(BeanDefinitionRegistry registry) { @@ -114,7 +104,7 @@ public abstract class AopConfigUtils { BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME); if (!cls.getName().equals(apcDefinition.getBeanClassName())) { int currentPriority = findPriorityForClass(apcDefinition.getBeanClassName()); - int requiredPriority = findPriorityForClass(cls.getName()); + int requiredPriority = findPriorityForClass(cls); if (currentPriority < requiredPriority) { apcDefinition.setBeanClassName(cls.getName()); } @@ -123,32 +113,20 @@ public abstract class AopConfigUtils { } RootBeanDefinition beanDefinition = new RootBeanDefinition(cls); beanDefinition.setSource(source); - beanDefinition.getPropertyValues().addPropertyValue("order", new Integer(Ordered.HIGHEST_PRECEDENCE)); + beanDefinition.getPropertyValues().addPropertyValue("order", Ordered.HIGHEST_PRECEDENCE); beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); registry.registerBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME, beanDefinition); return beanDefinition; } - private static Class getAspectJAnnotationAutoProxyCreatorClassIfPossible() { - if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) { - throw new IllegalStateException( - "AnnotationAwareAspectJAutoProxyCreator is only available on Java 1.5 and higher"); - } - try { - return ClassUtils.forName( - ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME, AopConfigUtils.class.getClassLoader()); - } - catch (Throwable ex) { - throw new IllegalStateException("Unable to load Java 1.5 dependent class [" + - ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME + "]", ex); - } + private static int findPriorityForClass(Class clazz) { + return APC_PRIORITY_LIST.indexOf(clazz); } private static int findPriorityForClass(String className) { - Assert.notNull(className, "Class name must not be null"); for (int i = 0; i < APC_PRIORITY_LIST.size(); i++) { - String str = (String) APC_PRIORITY_LIST.get(i); - if (className.equals(str)) { + Class clazz = APC_PRIORITY_LIST.get(i); + if (clazz.getName().equals(className)) { return i; } } diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java b/org.springframework.aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java index 8c1a84d0b20..55e24954224 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java @@ -61,68 +61,37 @@ import org.springframework.util.xml.DomUtils; class ConfigBeanDefinitionParser implements BeanDefinitionParser { private static final String ASPECT = "aspect"; - private static final String EXPRESSION = "expression"; - private static final String ID = "id"; - private static final String POINTCUT = "pointcut"; - private static final String ADVICE_BEAN_NAME = "adviceBeanName"; - private static final String ADVISOR = "advisor"; - private static final String ADVICE_REF = "advice-ref"; - private static final String POINTCUT_REF = "pointcut-ref"; - private static final String REF = "ref"; - private static final String BEFORE = "before"; - private static final String DECLARE_PARENTS = "declare-parents"; - private static final String TYPE_PATTERN = "types-matching"; - private static final String DEFAULT_IMPL = "default-impl"; - private static final String DELEGATE_REF = "delegate-ref"; - private static final String IMPLEMENT_INTERFACE = "implement-interface"; - private static final String AFTER = "after"; - private static final String AFTER_RETURNING_ELEMENT = "after-returning"; - private static final String AFTER_THROWING_ELEMENT = "after-throwing"; - private static final String AROUND = "around"; - private static final String RETURNING = "returning"; - private static final String RETURNING_PROPERTY = "returningName"; - private static final String THROWING = "throwing"; - private static final String THROWING_PROPERTY = "throwingName"; - private static final String ARG_NAMES = "arg-names"; - private static final String ARG_NAMES_PROPERTY = "argumentNames"; - private static final String ASPECT_NAME_PROPERTY = "aspectName"; - private static final String DECLARATION_ORDER_PROPERTY = "declarationOrder"; - private static final String ORDER_PROPERTY = "order"; - private static final int METHOD_INDEX = 0; - private static final int POINTCUT_INDEX = 1; - private static final int ASPECT_INSTANCE_FACTORY_INDEX = 2; - private ParseState parseState = new ParseState(); @@ -232,12 +201,12 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { try { this.parseState.push(new AspectEntry(aspectId, aspectName)); - List beanDefinitions = new ArrayList(); - List beanReferences = new ArrayList(); + List beanDefinitions = new ArrayList(); + List beanReferences = new ArrayList(); - List declareParents = DomUtils.getChildElementsByTagName(aspectElement, DECLARE_PARENTS); + List declareParents = DomUtils.getChildElementsByTagName(aspectElement, DECLARE_PARENTS); for (int i = METHOD_INDEX; i < declareParents.size(); i++) { - Element declareParentsElement = (Element) declareParents.get(i); + Element declareParentsElement = declareParents.get(i); beanDefinitions.add(parseDeclareParents(declareParentsElement, parserContext)); } @@ -268,9 +237,8 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { aspectElement, aspectId, beanDefinitions, beanReferences, parserContext); parserContext.pushContainingComponent(aspectComponentDefinition); - List pointcuts = DomUtils.getChildElementsByTagName(aspectElement, POINTCUT); - for (int i = 0; i < pointcuts.size(); i++) { - Element pointcutElement = (Element) pointcuts.get(i); + List pointcuts = DomUtils.getChildElementsByTagName(aspectElement, POINTCUT); + for (Element pointcutElement : pointcuts) { parsePointcut(pointcutElement, parserContext); } @@ -282,10 +250,11 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { } private AspectComponentDefinition createAspectComponentDefinition( - Element aspectElement, String aspectId, List beanDefs, List beanRefs, ParserContext parserContext) { + Element aspectElement, String aspectId, List beanDefs, + List beanRefs, ParserContext parserContext) { - BeanDefinition[] beanDefArray = (BeanDefinition[]) beanDefs.toArray(new BeanDefinition[beanDefs.size()]); - BeanReference[] beanRefArray = (BeanReference[]) beanRefs.toArray(new BeanReference[beanRefs.size()]); + BeanDefinition[] beanDefArray = beanDefs.toArray(new BeanDefinition[beanDefs.size()]); + BeanReference[] beanRefArray = beanRefs.toArray(new BeanReference[beanRefs.size()]); Object source = parserContext.extractSource(aspectElement); return new AspectComponentDefinition(aspectId, beanDefArray, beanRefArray, source); } @@ -345,7 +314,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { */ private AbstractBeanDefinition parseAdvice( String aspectName, int order, Element aspectElement, Element adviceElement, ParserContext parserContext, - List beanDefinitions, List beanReferences) { + List beanDefinitions, List beanReferences) { try { this.parseState.push(new AdviceEntry(adviceElement.getLocalName())); @@ -394,15 +363,14 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { */ private AbstractBeanDefinition createAdviceDefinition( Element adviceElement, ParserContext parserContext, String aspectName, int order, - RootBeanDefinition methodDef, RootBeanDefinition aspectFactoryDef, List beanDefinitions, List beanReferences) { + RootBeanDefinition methodDef, RootBeanDefinition aspectFactoryDef, + List beanDefinitions, List beanReferences) { RootBeanDefinition adviceDefinition = new RootBeanDefinition(getAdviceClass(adviceElement)); adviceDefinition.setSource(parserContext.extractSource(adviceElement)); - adviceDefinition.getPropertyValues().addPropertyValue( - ASPECT_NAME_PROPERTY, aspectName); - adviceDefinition.getPropertyValues().addPropertyValue( - DECLARATION_ORDER_PROPERTY, new Integer(order)); + adviceDefinition.getPropertyValues().addPropertyValue(ASPECT_NAME_PROPERTY, aspectName); + adviceDefinition.getPropertyValues().addPropertyValue(DECLARATION_ORDER_PROPERTY, order); if (adviceElement.hasAttribute(RETURNING)) { adviceDefinition.getPropertyValues().addPropertyValue( @@ -423,7 +391,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { Object pointcut = parsePointcutProperty(adviceElement, parserContext); if (pointcut instanceof BeanDefinition) { cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcut); - beanDefinitions.add(pointcut); + beanDefinitions.add((BeanDefinition) pointcut); } else if (pointcut instanceof String) { RuntimeBeanReference pointcutRef = new RuntimeBeanReference((String) pointcut); diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java b/org.springframework.aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java index 29ee8db36b2..c5eeb924ec9 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -31,11 +31,9 @@ import org.springframework.util.Assert; */ public class ProxyCreatorSupport extends AdvisedSupport { - /** The AopProxyFactory to use */ private AopProxyFactory aopProxyFactory; - /** List of AdvisedSupportListener */ - private List listeners = new LinkedList(); + private List listeners = new LinkedList(); /** Set to true when the first AOP proxy has been created */ private boolean active = false; @@ -112,8 +110,8 @@ public class ProxyCreatorSupport extends AdvisedSupport { */ private void activate() { this.active = true; - for (int i = 0; i < this.listeners.size(); i++) { - ((AdvisedSupportListener) this.listeners.get(i)).activated(this); + for (AdvisedSupportListener listener : this.listeners) { + listener.activated(this); } } @@ -126,8 +124,8 @@ public class ProxyCreatorSupport extends AdvisedSupport { super.adviceChanged(); synchronized (this) { if (this.active) { - for (int i = 0; i < this.listeners.size(); i++) { - ((AdvisedSupportListener) this.listeners.get(i)).adviceChanged(this); + for (AdvisedSupportListener listener : this.listeners) { + listener.adviceChanged(this); } } } diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java b/org.springframework.aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java index 4f9bf03ea15..8ac6e5c3e86 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -39,7 +39,7 @@ import org.springframework.aop.support.DefaultPointcutAdvisor; */ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Serializable { - private final List adapters = new ArrayList(3); + private final List adapters = new ArrayList(3); /** @@ -64,9 +64,8 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se // So well-known it doesn't even need an adapter. return new DefaultPointcutAdvisor(advice); } - for (int i = 0; i < this.adapters.size(); i++) { + for (AdvisorAdapter adapter : this.adapters) { // Check that it is supported. - AdvisorAdapter adapter = (AdvisorAdapter) this.adapters.get(i); if (adapter.supportsAdvice(advice)) { return new DefaultPointcutAdvisor(advice); } @@ -75,13 +74,12 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se } public MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException { - List interceptors = new ArrayList(3); + List interceptors = new ArrayList(3); Advice advice = advisor.getAdvice(); if (advice instanceof MethodInterceptor) { - interceptors.add(advice); + interceptors.add((MethodInterceptor) advice); } - for (int i = 0; i < this.adapters.size(); i++) { - AdvisorAdapter adapter = (AdvisorAdapter) this.adapters.get(i); + for (AdvisorAdapter adapter : this.adapters) { if (adapter.supportsAdvice(advice)) { interceptors.add(adapter.getInterceptor(advisor)); } @@ -89,7 +87,7 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se if (interceptors.isEmpty()) { throw new UnknownAdviceTypeException(advisor.getAdvice()); } - return (MethodInterceptor[]) interceptors.toArray(new MethodInterceptor[interceptors.size()]); + return interceptors.toArray(new MethodInterceptor[interceptors.size()]); } public void registerAdvisorAdapter(AdvisorAdapter adapter) { diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java b/org.springframework.aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java index 49a964f1b27..40001813695 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java @@ -62,7 +62,7 @@ public class BeanFactoryAdvisorRetrievalHelper { * @return the list of {@link org.springframework.aop.Advisor} beans * @see #isEligibleBean */ - public List findAdvisorBeans() { + public List findAdvisorBeans() { // Determine list of advisor bean names, if not cached already. String[] advisorNames = null; synchronized (this) { @@ -76,7 +76,7 @@ public class BeanFactoryAdvisorRetrievalHelper { } } if (advisorNames.length == 0) { - return new LinkedList(); + return new LinkedList(); } List advisors = new LinkedList(); diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java b/org.springframework.aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java index defd5da16ea..44a03380ff4 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2008 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. @@ -20,6 +20,7 @@ import java.io.Serializable; import java.lang.reflect.Method; import java.util.LinkedList; import java.util.List; +import java.util.Arrays; import org.springframework.util.ObjectUtils; import org.springframework.util.PatternMatchUtils; @@ -36,7 +37,7 @@ import org.springframework.util.PatternMatchUtils; */ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut implements Serializable { - private List mappedNames = new LinkedList(); + private List mappedNames = new LinkedList(); /** @@ -45,7 +46,7 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme * @see #setMappedNames */ public void setMappedName(String mappedName) { - setMappedNames(new String[] { mappedName }); + setMappedNames(new String[] {mappedName}); } /** @@ -54,11 +55,9 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme * the pointcut matches. */ public void setMappedNames(String[] mappedNames) { - this.mappedNames = new LinkedList(); + this.mappedNames = new LinkedList(); if (mappedNames != null) { - for (int i = 0; i < mappedNames.length; i++) { - this.mappedNames.add(mappedNames[i]); - } + this.mappedNames.addAll(Arrays.asList(mappedNames)); } } @@ -72,16 +71,13 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme * @return this pointcut to allow for multiple additions in one line */ public NameMatchMethodPointcut addMethodName(String name) { - // TODO in a future release, consider a way of letting proxies - // cause advice changed events. this.mappedNames.add(name); return this; } public boolean matches(Method method, Class targetClass) { - for (int i = 0; i < this.mappedNames.size(); i++) { - String mappedName = (String) this.mappedNames.get(i); + for (String mappedName : this.mappedNames) { if (mappedName.equals(method.getName()) || isMatch(method.getName(), mappedName)) { return true; } @@ -105,11 +101,8 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme @Override public boolean equals(Object other) { - if (this == other) { - return true; - } - return (other instanceof NameMatchMethodPointcut && - ObjectUtils.nullSafeEquals(this.mappedNames, ((NameMatchMethodPointcut) other).mappedNames)); + return (this == other || (other instanceof NameMatchMethodPointcut && + ObjectUtils.nullSafeEquals(this.mappedNames, ((NameMatchMethodPointcut) other).mappedNames))); } @Override diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java b/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java index eefda590f03..45375f0381e 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java @@ -481,7 +481,7 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra private PropertyTokenHolder getPropertyNameTokens(String propertyName) { PropertyTokenHolder tokens = new PropertyTokenHolder(); String actualName = null; - List keys = new ArrayList(2); + List keys = new ArrayList(2); int searchIndex = 0; while (searchIndex != -1) { int keyStart = propertyName.indexOf(PROPERTY_KEY_PREFIX, searchIndex); diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/PropertyMatches.java b/org.springframework.beans/src/main/java/org/springframework/beans/PropertyMatches.java index 688f5dff9d6..0c682906509 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/PropertyMatches.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/PropertyMatches.java @@ -129,10 +129,10 @@ final class PropertyMatches { * @param maxDistance the maximum distance to accept */ private String[] calculateMatches(PropertyDescriptor[] propertyDescriptors, int maxDistance) { - List candidates = new ArrayList(); - for (int i = 0; i < propertyDescriptors.length; i++) { - if (propertyDescriptors[i].getWriteMethod() != null) { - String possibleAlternative = propertyDescriptors[i].getName(); + List candidates = new ArrayList(); + for (PropertyDescriptor pd : propertyDescriptors) { + if (pd.getWriteMethod() != null) { + String possibleAlternative = pd.getName(); if (calculateStringDistance(this.propertyName, possibleAlternative) <= maxDistance) { candidates.add(possibleAlternative); } diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java index 33129b5ad47..f937b646d3c 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java @@ -71,7 +71,7 @@ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer { private boolean ignoreInvalidKeys = false; /** Contains names of beans that have overrides */ - private Set beanNames = Collections.synchronizedSet(new HashSet()); + private Set beanNames = Collections.synchronizedSet(new HashSet()); /** diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java index 38e3b2f36e6..83dcab0f14d 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java @@ -73,8 +73,8 @@ public class BeanComponentDefinition extends BeanDefinitionHolder implements Com private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) { - List innerBeans = new ArrayList(); - List references = new ArrayList(); + List innerBeans = new ArrayList(); + List references = new ArrayList(); PropertyValues propertyValues = beanDefinition.getPropertyValues(); for (int i = 0; i < propertyValues.getPropertyValues().length; i++) { PropertyValue propertyValue = propertyValues.getPropertyValues()[i]; @@ -83,14 +83,14 @@ public class BeanComponentDefinition extends BeanDefinitionHolder implements Com innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition()); } else if (value instanceof BeanDefinition) { - innerBeans.add(value); + innerBeans.add((BeanDefinition) value); } else if (value instanceof BeanReference) { - references.add(value); + references.add((BeanReference) value); } } - this.innerBeanDefinitions = (BeanDefinition[]) innerBeans.toArray(new BeanDefinition[innerBeans.size()]); - this.beanReferences = (BeanReference[]) references.toArray(new BeanReference[references.size()]); + this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]); + this.beanReferences = references.toArray(new BeanReference[references.size()]); } diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java index 3e09f027f2b..e8589d08896 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2008 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. @@ -36,7 +36,7 @@ public class CompositeComponentDefinition extends AbstractComponentDefinition { private final Object source; - private final List nestedComponents = new LinkedList(); + private final List nestedComponents = new LinkedList(); /** @@ -74,8 +74,7 @@ public class CompositeComponentDefinition extends AbstractComponentDefinition { * @return the array of nested components, or an empty array if none */ public ComponentDefinition[] getNestedComponents() { - return (ComponentDefinition[]) - this.nestedComponents.toArray(new ComponentDefinition[this.nestedComponents.size()]); + return this.nestedComponents.toArray(new ComponentDefinition[this.nestedComponents.size()]); } } diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceListFactoryBean.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceListFactoryBean.java index b8cc3e77f24..b23cd70ee0e 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceListFactoryBean.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceListFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -16,7 +16,6 @@ package org.springframework.beans.factory.serviceloader; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.ServiceLoader; @@ -36,10 +35,9 @@ public class ServiceListFactoryBean extends AbstractServiceLoaderBasedFactoryBea @Override protected Object getObjectToExpose(ServiceLoader serviceLoader) { - List result = new LinkedList(); - Iterator it = serviceLoader.iterator(); - while (it.hasNext()) { - result.add(it.next()); + List result = new LinkedList(); + for (Object loaderObject : serviceLoader) { + result.add(loaderObject); } return result; } diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java index 408010e8589..4e0d9b6b54b 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java @@ -295,7 +295,7 @@ class BeanDefinitionValueResolver { * For each element in the ManagedList, resolve reference if necessary. */ private List resolveManagedList(Object argName, List ml) { - List resolved = new ArrayList(ml.size()); + List resolved = new ArrayList(ml.size()); for (int i = 0; i < ml.size(); i++) { resolved.add( resolveValueIfNecessary( @@ -309,7 +309,7 @@ class BeanDefinitionValueResolver { * For each element in the ManagedList, resolve reference if necessary. */ private Set resolveManagedSet(Object argName, Set ms) { - Set resolved = new LinkedHashSet(ms.size()); + Set resolved = new LinkedHashSet(ms.size()); int i = 0; for (Object m : ms) { resolved.add(resolveValueIfNecessary( @@ -323,7 +323,7 @@ class BeanDefinitionValueResolver { * For each element in the ManagedMap, resolve reference if necessary. */ private Map resolveManagedMap(Object argName, Map mm) { - Map resolved = new LinkedHashMap(mm.size()); + Map resolved = new LinkedHashMap(mm.size()); for (Map.Entry entry : mm.entrySet()) { Object resolvedKey = resolveValueIfNecessary(argName, entry.getKey()); Object resolvedValue = resolveValueIfNecessary( diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java index 12c82a5c632..3faa967b2b9 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -35,13 +35,10 @@ import org.springframework.util.ObjectUtils; * @since 1.1 */ public class ReplaceOverride extends MethodOverride { - + private final String methodReplacerBeanName; - - /** - * List of String. Identifying signatures. - */ - private List typeIdentifiers = new LinkedList(); + + private List typeIdentifiers = new LinkedList(); /** @@ -90,8 +87,8 @@ public class ReplaceOverride extends MethodOverride { return false; } for (int i = 0; i < this.typeIdentifiers.size(); i++) { - String identifier = (String) this.typeIdentifiers.get(i); - if (method.getParameterTypes()[i].getName().indexOf(identifier) == -1) { + String identifier = this.typeIdentifiers.get(i); + if (!method.getParameterTypes()[i].getName().contains(identifier)) { // This parameter cannot match. return false; } diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java index e687273f91a..cde55ea74d4 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java @@ -45,11 +45,11 @@ import org.springframework.beans.factory.config.ConstructorArgumentValues; */ public class RootBeanDefinition extends AbstractBeanDefinition { - private final Set externallyManagedConfigMembers = Collections.synchronizedSet(new HashSet()); + private final Set externallyManagedConfigMembers = Collections.synchronizedSet(new HashSet()); - private final Set externallyManagedInitMethods = Collections.synchronizedSet(new HashSet()); + private final Set externallyManagedInitMethods = Collections.synchronizedSet(new HashSet()); - private final Set externallyManagedDestroyMethods = Collections.synchronizedSet(new HashSet()); + private final Set externallyManagedDestroyMethods = Collections.synchronizedSet(new HashSet()); /** Package-visible field for caching the resolved constructor or factory method */ volatile Object resolvedConstructorOrFactoryMethod; diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java index e8a1c45e700..95fa690ea78 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java @@ -238,7 +238,7 @@ public class BeanDefinitionParserDelegate { /** * Stores all used bean names so we can enforce uniqueness on a per file basis. */ - private final Set usedNames = new HashSet(); + private final Set usedNames = new HashSet(); /** @@ -366,7 +366,7 @@ public class BeanDefinitionParserDelegate { String id = ele.getAttribute(ID_ATTRIBUTE); String nameAttr = ele.getAttribute(NAME_ATTRIBUTE); - List aliases = new ArrayList(); + List aliases = new ArrayList(); if (StringUtils.hasLength(nameAttr)) { String[] nameArr = StringUtils.tokenizeToStringArray(nameAttr, BEAN_NAME_DELIMITERS); aliases.addAll(Arrays.asList(nameArr)); diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java index aeba1cdfcf9..f5a08e5bb58 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java @@ -170,12 +170,12 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume if (ResourcePatternUtils.isUrl(location)) { try { - Set actualResources = new LinkedHashSet(4); + Set actualResources = new LinkedHashSet (4); int importCount = getReaderContext().getReader().loadBeanDefinitions(location, actualResources); if (logger.isDebugEnabled()) { logger.debug("Imported " + importCount + " bean definitions from URL location [" + location + "]"); } - Resource[] actResArray = (Resource[]) actualResources.toArray(new Resource[actualResources.size()]); + Resource[] actResArray = actualResources.toArray(new Resource[actualResources.size()]); getReaderContext().fireImportProcessed(location, actResArray, extractSource(ele)); } catch (BeanDefinitionStoreException ex) { diff --git a/org.springframework.context.support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java b/org.springframework.context.support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java index 2739dfca9b2..d937ec3e205 100644 --- a/org.springframework.context.support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java +++ b/org.springframework.context.support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2008 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. @@ -80,15 +80,15 @@ public class FreeMarkerConfigurationFactory { private Properties freemarkerSettings; - private Map freemarkerVariables; + private Map freemarkerVariables; private String defaultEncoding; - private final List templateLoaders = new ArrayList(); + private final List templateLoaders = new ArrayList(); - private List preTemplateLoaders; + private List preTemplateLoaders; - private List postTemplateLoaders; + private List postTemplateLoaders; private String[] templateLoaderPaths; @@ -121,7 +121,7 @@ public class FreeMarkerConfigurationFactory { * to FreeMarker's Configuration.setAllSharedVariables() method. * @see freemarker.template.Configuration#setAllSharedVariables */ - public void setFreemarkerVariables(Map variables) { + public void setFreemarkerVariables(Map variables) { this.freemarkerVariables = variables; } @@ -300,8 +300,8 @@ public class FreeMarkerConfigurationFactory { // Register default template loaders. if (this.templateLoaderPaths != null) { - for (int i = 0; i < this.templateLoaderPaths.length; i++) { - this.templateLoaders.add(getTemplateLoaderForPath(this.templateLoaderPaths[i])); + for (String path : this.templateLoaderPaths) { + this.templateLoaders.add(getTemplateLoaderForPath(path)); } } postProcessTemplateLoaders(this.templateLoaders); @@ -393,16 +393,16 @@ public class FreeMarkerConfigurationFactory { * @param templateLoaders the final List of TemplateLoader instances * @return the aggregate TemplateLoader */ - protected TemplateLoader getAggregateTemplateLoader(List templateLoaders) { + protected TemplateLoader getAggregateTemplateLoader(List templateLoaders) { int loaderCount = templateLoaders.size(); switch (loaderCount) { case 0: logger.info("No FreeMarker TemplateLoaders specified"); return null; case 1: - return (TemplateLoader) templateLoaders.get(0); + return templateLoaders.get(0); default: - TemplateLoader[] loaders = (TemplateLoader[]) templateLoaders.toArray(new TemplateLoader[loaderCount]); + TemplateLoader[] loaders = templateLoaders.toArray(new TemplateLoader[loaderCount]); return new MultiTemplateLoader(loaders); } } diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractMessageSource.java b/org.springframework.context/src/main/java/org/springframework/context/support/AbstractMessageSource.java index dd3a4ea1a5c..a9a6edc84e0 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractMessageSource.java +++ b/org.springframework.context/src/main/java/org/springframework/context/support/AbstractMessageSource.java @@ -143,8 +143,8 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme if (codes == null) { codes = new String[0]; } - for (int i = 0; i < codes.length; i++) { - String msg = getMessageInternal(codes[i], resolvable.getArguments(), locale); + for (String code : codes) { + String msg = getMessageInternal(code, resolvable.getArguments(), locale); if (msg != null) { return msg; } @@ -291,13 +291,13 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme if (args == null) { return new Object[0]; } - List resolvedArgs = new ArrayList(args.length); - for (int i = 0; i < args.length; i++) { - if (args[i] instanceof MessageSourceResolvable) { - resolvedArgs.add(getMessage((MessageSourceResolvable) args[i], locale)); + List resolvedArgs = new ArrayList(args.length); + for (Object arg : args) { + if (arg instanceof MessageSourceResolvable) { + resolvedArgs.add(getMessage((MessageSourceResolvable) arg, locale)); } else { - resolvedArgs.add(args[i]); + resolvedArgs.add(arg); } } return resolvedArgs.toArray(new Object[resolvedArgs.size()]); diff --git a/org.springframework.context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java b/org.springframework.context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java index 48576f9dba1..ee0dd33b5c0 100644 --- a/org.springframework.context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java +++ b/org.springframework.context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java @@ -16,10 +16,9 @@ package org.springframework.jmx.support; -import java.util.Iterator; +import java.util.Arrays; import java.util.LinkedHashSet; import java.util.Set; - import javax.management.MalformedObjectNameException; import javax.management.NotificationFilter; import javax.management.NotificationListener; @@ -46,7 +45,7 @@ public class NotificationListenerHolder { private Object handback; - protected Set mappedObjectNames; + protected Set mappedObjectNames; /** @@ -122,15 +121,8 @@ public class NotificationListenerHolder { * @see #setMappedObjectName */ public void setMappedObjectNames(Object[] mappedObjectNames) { - if (mappedObjectNames != null) { - this.mappedObjectNames = new LinkedHashSet(mappedObjectNames.length); - for (int i = 0; i < mappedObjectNames.length; i++) { - this.mappedObjectNames.add(mappedObjectNames[i]); - } - } - else { - this.mappedObjectNames = null; - } + this.mappedObjectNames = (mappedObjectNames != null ? + new LinkedHashSet(Arrays.asList(mappedObjectNames)) : null); } /** @@ -145,8 +137,8 @@ public class NotificationListenerHolder { } ObjectName[] resolved = new ObjectName[this.mappedObjectNames.size()]; int i = 0; - for (Iterator it = this.mappedObjectNames.iterator(); it.hasNext();) { - resolved[i] = ObjectNameManager.getInstance(it.next()); + for (Object objectName : this.mappedObjectNames) { + resolved[i] = ObjectNameManager.getInstance(objectName); i++; } return resolved; diff --git a/org.springframework.context/src/main/java/org/springframework/remoting/support/RemoteInvocationUtils.java b/org.springframework.context/src/main/java/org/springframework/remoting/support/RemoteInvocationUtils.java index fadd3d85a17..7eb5c58c399 100644 --- a/org.springframework.context/src/main/java/org/springframework/remoting/support/RemoteInvocationUtils.java +++ b/org.springframework.context/src/main/java/org/springframework/remoting/support/RemoteInvocationUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -45,7 +45,7 @@ public abstract class RemoteInvocationUtils { public static void fillInClientStackTraceIfPossible(Throwable ex) { if (ex != null) { StackTraceElement[] clientStack = new Throwable().getStackTrace(); - Set visitedExceptions = new HashSet(); + Set visitedExceptions = new HashSet(); Throwable exToUpdate = ex; while (exToUpdate != null && !visitedExceptions.contains(exToUpdate)) { StackTraceElement[] serverStack = exToUpdate.getStackTrace(); diff --git a/org.springframework.context/src/main/java/org/springframework/validation/AbstractErrors.java b/org.springframework.context/src/main/java/org/springframework/validation/AbstractErrors.java index 0fdd75a4309..ea2dbe54608 100644 --- a/org.springframework.context/src/main/java/org/springframework/validation/AbstractErrors.java +++ b/org.springframework.context/src/main/java/org/springframework/validation/AbstractErrors.java @@ -19,7 +19,6 @@ package org.springframework.validation; import java.io.Serializable; import java.util.Collections; import java.util.EmptyStackException; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Stack; @@ -38,7 +37,7 @@ public abstract class AbstractErrors implements Errors, Serializable { private String nestedPath = ""; - private final Stack nestedPathStack = new Stack(); + private final Stack nestedPathStack = new Stack(); public void setNestedPath(String nestedPath) { @@ -57,7 +56,7 @@ public abstract class AbstractErrors implements Errors, Serializable { public void popNestedPath() throws IllegalArgumentException { try { - String formerNestedPath = (String) this.nestedPathStack.pop(); + String formerNestedPath = this.nestedPathStack.pop(); doSetNestedPath(formerNestedPath); } catch (EmptyStackException ex) { @@ -131,8 +130,8 @@ public abstract class AbstractErrors implements Errors, Serializable { return getAllErrors().size(); } - public List getAllErrors() { - List result = new LinkedList(); + public List getAllErrors() { + List result = new LinkedList(); result.addAll(getGlobalErrors()); result.addAll(getFieldErrors()); return Collections.unmodifiableList(result); @@ -172,13 +171,12 @@ public abstract class AbstractErrors implements Errors, Serializable { return getFieldErrors(field).size(); } - public List getFieldErrors(String field) { - List fieldErrors = getFieldErrors(); - List result = new LinkedList(); + public List getFieldErrors(String field) { + List fieldErrors = getFieldErrors(); + List result = new LinkedList(); String fixedField = fixedField(field); - for (Iterator it = fieldErrors.iterator(); it.hasNext();) { - Object error = it.next(); - if (isMatchingFieldError(fixedField, (FieldError) error)) { + for (FieldError error : fieldErrors) { + if (isMatchingFieldError(fixedField, error)) { result.add(error); } } @@ -198,6 +196,7 @@ public abstract class AbstractErrors implements Errors, Serializable { } return null; } + /** * Check whether the given FieldError matches the given field. * @param field the field that we are looking up FieldErrors for @@ -214,9 +213,8 @@ public abstract class AbstractErrors implements Errors, Serializable { public String toString() { StringBuilder sb = new StringBuilder(getClass().getName()); sb.append(": ").append(getErrorCount()).append(" errors"); - Iterator it = getAllErrors().iterator(); - while (it.hasNext()) { - sb.append('\n').append(it.next()); + for (ObjectError error : getAllErrors()) { + sb.append('\n').append(error); } return sb.toString(); } diff --git a/org.springframework.core/src/main/java/org/springframework/core/Conventions.java b/org.springframework.core/src/main/java/org/springframework/core/Conventions.java index b3eb8c99292..7cc5f09dcdf 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/Conventions.java +++ b/org.springframework.core/src/main/java/org/springframework/core/Conventions.java @@ -48,7 +48,7 @@ public abstract class Conventions { * Set of interfaces that are supposed to be ignored * when searching for the 'primary' interface of a proxy. */ - private static final Set ignoredInterfaces = new HashSet(); + private static final Set ignoredInterfaces = new HashSet(); static { ignoredInterfaces.add(Serializable.class); @@ -212,15 +212,14 @@ public abstract class Conventions { */ public static String attributeNameToPropertyName(String attributeName) { Assert.notNull(attributeName, "'attributeName' must not be null"); - if (attributeName.indexOf("-") == -1) { + if (!attributeName.contains("-")) { return attributeName; } char[] chars = attributeName.toCharArray(); char[] result = new char[chars.length -1]; // not completely accurate but good guess int currPos = 0; boolean upperCaseNext = false; - for (int i = 0; i < chars.length; i++) { - char c = chars[i]; + for (char c : chars) { if (c == '-') { upperCaseNext = true; } @@ -260,8 +259,7 @@ public abstract class Conventions { Class valueClass = value.getClass(); if (Proxy.isProxyClass(valueClass)) { Class[] ifcs = valueClass.getInterfaces(); - for (int i = 0; i < ifcs.length; i++) { - Class ifc = ifcs[i]; + for (Class ifc : ifcs) { if (!ignoredInterfaces.contains(ifc)) { return ifc; } diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java b/org.springframework.core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java index f23d093ec62..358941ff346 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java +++ b/org.springframework.core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Iterator; import java.util.List; import org.springframework.core.io.Resource; @@ -94,17 +93,15 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport { public void setValue(Object value) throws IllegalArgumentException { if (value instanceof Collection || (value instanceof Object[] && !(value instanceof Resource[]))) { Collection input = (value instanceof Collection ? (Collection) value : Arrays.asList((Object[]) value)); - List merged = new ArrayList(); - for (Iterator it = input.iterator(); it.hasNext();) { - Object element = it.next(); + List merged = new ArrayList(); + for (Object element : input) { if (element instanceof String) { // A location pattern: resolve it into a Resource array. // Might point to a single resource or to multiple resources. String pattern = resolvePath((String) element).trim(); try { Resource[] resources = this.resourcePatternResolver.getResources(pattern); - for (int i = 0; i < resources.length; i++) { - Resource resource = resources[i]; + for (Resource resource : resources) { if (!merged.contains(resource)) { merged.add(resource); } @@ -117,8 +114,9 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport { } else if (element instanceof Resource) { // A Resource object: add it to the result. - if (!merged.contains(element)) { - merged.add(element); + Resource resource = (Resource) element; + if (!merged.contains(resource)) { + merged.add(resource); } } else { diff --git a/org.springframework.core/src/main/java/org/springframework/util/AutoPopulatingList.java b/org.springframework.core/src/main/java/org/springframework/util/AutoPopulatingList.java index 0d57e9511b9..e100e44273f 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/AutoPopulatingList.java +++ b/org.springframework.core/src/main/java/org/springframework/util/AutoPopulatingList.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -39,18 +39,18 @@ import java.util.ListIterator; * @author Juergen Hoeller * @since 2.0 */ -public class AutoPopulatingList implements List, Serializable { +public class AutoPopulatingList implements List, Serializable { /** * The {@link List} that all operations are eventually delegated to. */ - private final List backingList; + private final List backingList; /** * The {@link ElementFactory} to use to create new {@link List} elements * on demand. */ - private final ElementFactory elementFactory; + private final ElementFactory elementFactory; /** @@ -58,8 +58,8 @@ public class AutoPopulatingList implements List, Serializable { * {@link ArrayList} and adds new instances of the supplied {@link Class element Class} * to the backing {@link List} on demand. */ - public AutoPopulatingList(Class elementClass) { - this(new ArrayList(), elementClass); + public AutoPopulatingList(Class elementClass) { + this(new ArrayList(), elementClass); } /** @@ -67,23 +67,23 @@ public class AutoPopulatingList implements List, Serializable { * and adds new instances of the supplied {@link Class element Class} to the backing * {@link List} on demand. */ - public AutoPopulatingList(List backingList, Class elementClass) { - this(backingList, new ReflectiveElementFactory(elementClass)); + public AutoPopulatingList(List backingList, Class elementClass) { + this(backingList, new ReflectiveElementFactory(elementClass)); } /** * Creates a new AutoPopulatingList that is backed by a standard * {@link ArrayList} and creates new elements on demand using the supplied {@link ElementFactory}. */ - public AutoPopulatingList(ElementFactory elementFactory) { - this(new ArrayList(), elementFactory); + public AutoPopulatingList(ElementFactory elementFactory) { + this(new ArrayList(), elementFactory); } /** * Creates a new AutoPopulatingList that is backed by the supplied {@link List} * and creates new elements on demand using the supplied {@link ElementFactory}. */ - public AutoPopulatingList(List backingList, ElementFactory elementFactory) { + public AutoPopulatingList(List backingList, ElementFactory elementFactory) { Assert.notNull(backingList, "Backing List must not be null"); Assert.notNull(elementFactory, "Element factory must not be null"); this.backingList = backingList; @@ -91,19 +91,19 @@ public class AutoPopulatingList implements List, Serializable { } - public void add(int index, Object element) { + public void add(int index, E element) { this.backingList.add(index, element); } - public boolean add(Object o) { + public boolean add(E o) { return this.backingList.add(o); } - public boolean addAll(Collection c) { + public boolean addAll(Collection c) { return this.backingList.addAll(c); } - public boolean addAll(int index, Collection c) { + public boolean addAll(int index, Collection c) { return this.backingList.addAll(index, c); } @@ -119,19 +119,13 @@ public class AutoPopulatingList implements List, Serializable { return this.backingList.containsAll(c); } - @Override - public boolean equals(Object o) { - return this.backingList.equals(o); - } - /** * Get the element at the supplied index, creating it if there is * no element at that index. */ - public Object get(int index) { + public E get(int index) { int backingListSize = this.backingList.size(); - - Object element = null; + E element = null; if (index < backingListSize) { element = this.backingList.get(index); if (element == null) { @@ -149,11 +143,6 @@ public class AutoPopulatingList implements List, Serializable { return element; } - @Override - public int hashCode() { - return this.backingList.hashCode(); - } - public int indexOf(Object o) { return this.backingList.indexOf(o); } @@ -162,7 +151,7 @@ public class AutoPopulatingList implements List, Serializable { return this.backingList.isEmpty(); } - public Iterator iterator() { + public Iterator iterator() { return this.backingList.iterator(); } @@ -170,15 +159,15 @@ public class AutoPopulatingList implements List, Serializable { return this.backingList.lastIndexOf(o); } - public ListIterator listIterator() { + public ListIterator listIterator() { return this.backingList.listIterator(); } - public ListIterator listIterator(int index) { + public ListIterator listIterator(int index) { return this.backingList.listIterator(index); } - public Object remove(int index) { + public E remove(int index) { return this.backingList.remove(index); } @@ -186,15 +175,15 @@ public class AutoPopulatingList implements List, Serializable { return this.backingList.remove(o); } - public boolean removeAll(Collection c) { + public boolean removeAll(Collection c) { return this.backingList.removeAll(c); } - public boolean retainAll(Collection c) { + public boolean retainAll(Collection c) { return this.backingList.retainAll(c); } - public Object set(int index, Object element) { + public E set(int index, E element) { return this.backingList.set(index, element); } @@ -202,7 +191,7 @@ public class AutoPopulatingList implements List, Serializable { return this.backingList.size(); } - public List subList(int fromIndex, int toIndex) { + public List subList(int fromIndex, int toIndex) { return this.backingList.subList(fromIndex, toIndex); } @@ -210,16 +199,27 @@ public class AutoPopulatingList implements List, Serializable { return this.backingList.toArray(); } - public Object[] toArray(Object[] a) { + public T[] toArray(T[] a) { return this.backingList.toArray(a); } + @Override + public boolean equals(Object other) { + return this.backingList.equals(other); + } + + @Override + public int hashCode() { + return this.backingList.hashCode(); + } + + /** * Factory interface for creating elements for an index-based access * data structure such as a {@link java.util.List}. */ - public interface ElementFactory { + public interface ElementFactory { /** * Create the element for the supplied index. @@ -227,7 +227,7 @@ public class AutoPopulatingList implements List, Serializable { * @throws ElementInstantiationException if the instantiation process failed * (any exception thrown by a target constructor should be propagated as-is) */ - Object createElement(int index) throws ElementInstantiationException; + E createElement(int index) throws ElementInstantiationException; } @@ -247,18 +247,18 @@ public class AutoPopulatingList implements List, Serializable { * using Class.newInstance() on a given element class. * @see java.lang.Class#newInstance() */ - private static class ReflectiveElementFactory implements ElementFactory, Serializable { + private static class ReflectiveElementFactory implements ElementFactory, Serializable { - private final Class elementClass; + private final Class elementClass; - public ReflectiveElementFactory(Class elementClass) { + public ReflectiveElementFactory(Class elementClass) { Assert.notNull(elementClass, "Element clas must not be null"); Assert.isTrue(!elementClass.isInterface(), "Element class must not be an interface type"); Assert.isTrue(!Modifier.isAbstract(elementClass.getModifiers()), "Element class cannot be an abstract class"); this.elementClass = elementClass; } - public Object createElement(int index) { + public E createElement(int index) { try { return this.elementClass.newInstance(); } diff --git a/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java b/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java index 6ede41ffd82..c8218286254 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -67,10 +67,9 @@ public abstract class ReflectionUtils { Class searchType = clazz; while (!Object.class.equals(searchType) && searchType != null) { Field[] fields = searchType.getDeclaredFields(); - for (int i = 0; i < fields.length; i++) { - Field field = fields[i]; - if ((name == null || name.equals(field.getName())) - && (type == null || type.equals(field.getType()))) { + for (Field field : fields) { + if ((name == null || name.equals(field.getName())) && + (type == null || type.equals(field.getType()))) { return field; } } @@ -152,8 +151,7 @@ public abstract class ReflectionUtils { Class searchType = clazz; while (!Object.class.equals(searchType) && searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); - for (int i = 0; i < methods.length; i++) { - Method method = methods[i]; + for (Method method : methods) { if (name.equals(method.getName()) && (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) { return method; @@ -454,16 +452,16 @@ public abstract class ReflectionUtils { // Keep backing up the inheritance hierarchy. do { Method[] methods = targetClass.getDeclaredMethods(); - for (int i = 0; i < methods.length; i++) { - if (mf != null && !mf.matches(methods[i])) { + for (Method method : methods) { + if (mf != null && !mf.matches(method)) { continue; } try { - mc.doWith(methods[i]); + mc.doWith(method); } catch (IllegalAccessException ex) { throw new IllegalStateException( - "Shouldn't be illegal to access method '" + methods[i].getName() + "': " + ex); + "Shouldn't be illegal to access method '" + method.getName() + "': " + ex); } } targetClass = targetClass.getSuperclass(); @@ -476,13 +474,13 @@ public abstract class ReflectionUtils { * Leaf class methods are included first. */ public static Method[] getAllDeclaredMethods(Class leafClass) throws IllegalArgumentException { - final List list = new ArrayList(32); + final List methods = new ArrayList(32); doWithMethods(leafClass, new MethodCallback() { public void doWith(Method method) { - list.add(method); + methods.add(method); } }); - return (Method[]) list.toArray(new Method[list.size()]); + return methods.toArray(new Method[methods.size()]); } @@ -510,17 +508,17 @@ public abstract class ReflectionUtils { do { // Copy each field declared on this class unless it's static or file. Field[] fields = targetClass.getDeclaredFields(); - for (int i = 0; i < fields.length; i++) { + for (Field field : fields) { // Skip static and final fields. - if (ff != null && !ff.matches(fields[i])) { + if (ff != null && !ff.matches(field)) { continue; } try { - fc.doWith(fields[i]); + fc.doWith(field); } catch (IllegalAccessException ex) { throw new IllegalStateException( - "Shouldn't be illegal to access field '" + fields[i].getName() + "': " + ex); + "Shouldn't be illegal to access field '" + field.getName() + "': " + ex); } } targetClass = targetClass.getSuperclass(); diff --git a/org.springframework.core/src/main/java/org/springframework/util/StopWatch.java b/org.springframework.core/src/main/java/org/springframework/util/StopWatch.java index 3fd8b191466..c03589c15b0 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/StopWatch.java +++ b/org.springframework.core/src/main/java/org/springframework/util/StopWatch.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-20078the original author or authors. + * Copyright 2002-2008 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. @@ -48,8 +48,7 @@ public class StopWatch { private boolean keepTaskList = true; - /** List of TaskInfo objects */ - private final List taskList = new LinkedList(); + private final List taskList = new LinkedList(); /** Start time of the current task */ private long startTimeMillis; @@ -187,7 +186,7 @@ public class StopWatch { if (!this.keepTaskList) { throw new UnsupportedOperationException("Task info is not being kept!"); } - return (TaskInfo[]) this.taskList.toArray(new TaskInfo[this.taskList.size()]); + return this.taskList.toArray(new TaskInfo[this.taskList.size()]); } @@ -209,7 +208,6 @@ public class StopWatch { sb.append("No task info kept"); } else { - TaskInfo[] tasks = getTaskInfo(); sb.append("-----------------------------------------\n"); sb.append("ms % Task name\n"); sb.append("-----------------------------------------\n"); @@ -219,10 +217,10 @@ public class StopWatch { NumberFormat pf = NumberFormat.getPercentInstance(); pf.setMinimumIntegerDigits(3); pf.setGroupingUsed(false); - for (int i = 0; i < tasks.length; i++) { - sb.append(nf.format(tasks[i].getTimeMillis()) + " "); - sb.append(pf.format(tasks[i].getTimeSeconds() / getTotalTimeSeconds()) + " "); - sb.append(tasks[i].getTaskName() + "\n"); + for (TaskInfo task : getTaskInfo()) { + sb.append(nf.format(task.getTimeMillis())).append(" "); + sb.append(pf.format(task.getTimeSeconds() / getTotalTimeSeconds())).append(" "); + sb.append(task.getTaskName()).append("\n"); } } return sb.toString(); @@ -236,11 +234,10 @@ public class StopWatch { public String toString() { StringBuilder sb = new StringBuilder(shortSummary()); if (this.keepTaskList) { - TaskInfo[] tasks = getTaskInfo(); - for (int i = 0; i < tasks.length; i++) { - sb.append("; [" + tasks[i].getTaskName() + "] took " + tasks[i].getTimeMillis()); - long percent = Math.round((100.0 * tasks[i].getTimeSeconds()) / getTotalTimeSeconds()); - sb.append(" = " + percent + "%"); + for (TaskInfo task : getTaskInfo()) { + sb.append("; [").append(task.getTaskName()).append("] took ").append(task.getTimeMillis()); + long percent = Math.round((100.0 * task.getTimeSeconds()) / getTotalTimeSeconds()); + sb.append(" = ").append(percent).append("%"); } } else { diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java index 424c573c18e..d9ae416578b 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -26,10 +26,10 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.jdbc.core.SqlInOutParameter; import org.springframework.jdbc.core.SqlOutParameter; import org.springframework.jdbc.core.SqlParameter; -import org.springframework.jdbc.core.SqlInOutParameter; -import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.util.StringUtils; /** @@ -279,15 +279,11 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { metaDataSchemaName + "/" + metaDataProcedureName); } try { - procs = databaseMetaData.getProcedures( - metaDataCatalogName, - metaDataSchemaName, - metaDataProcedureName); - List found = new ArrayList(); + procs = databaseMetaData.getProcedures(metaDataCatalogName, metaDataSchemaName, metaDataProcedureName); + List found = new ArrayList(); while (procs.next()) { - found.add(procs.getString("PROCEDURE_CAT") + - "."+procs.getString("PROCEDURE_SCHEM") + - "."+procs.getString("PROCEDURE_NAME")); + found.add(procs.getString("PROCEDURE_CAT") + "." + procs.getString("PROCEDURE_SCHEM") + + "." + procs.getString("PROCEDURE_NAME")); } procs.close(); if (found.size() > 1) { @@ -304,10 +300,7 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { } procs = databaseMetaData.getProcedureColumns( - metaDataCatalogName, - metaDataSchemaName, - metaDataProcedureName, - null); + metaDataCatalogName, metaDataSchemaName, metaDataProcedureName, null); while (procs.next()) { String columnName = procs.getString("COLUMN_NAME"); int columnType = procs.getInt("COLUMN_TYPE"); @@ -327,36 +320,30 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { } } else { - CallParameterMetaData meta = new CallParameterMetaData( - columnName, - columnType, - procs.getInt("DATA_TYPE"), - procs.getString("TYPE_NAME"), - procs.getBoolean("NULLABLE") + CallParameterMetaData meta = new CallParameterMetaData(columnName, columnType, + procs.getInt("DATA_TYPE"), procs.getString("TYPE_NAME"), procs.getBoolean("NULLABLE") ); callParameterMetaData.add(meta); if (logger.isDebugEnabled()) { - logger.debug("Retrieved metadata: " - + meta.getParameterName() + - " " + meta.getParameterType() + - " " + meta.getSqlType() + - " " + meta.getTypeName() + - " " + meta.isNullable() + logger.debug("Retrieved metadata: " + meta.getParameterName() + " " + + meta.getParameterType() + " " + meta.getSqlType() + + " " + meta.getTypeName() + " " + meta.isNullable() ); } } } } - catch (SQLException se) { - logger.warn("Error while retreiving metadata for procedure columns: " + se.getMessage()); + catch (SQLException ex) { + logger.warn("Error while retrieving metadata for procedure columns: " + ex); } finally { try { - if (procs != null) + if (procs != null) { procs.close(); + } } - catch (SQLException se) { - logger.warn("Problem closing resultset for procedure column metadata " + se.getMessage()); + catch (SQLException ex) { + logger.warn("Problem closing ResultSet for procedure column metadata: " + ex); } } } diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java index d62e0d9ec7b..feb81535255 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -192,7 +192,7 @@ public class TableMetaDataContext { if (declaredColumns.size() > 0) { return new ArrayList(declaredColumns); } - Set keys = new HashSet(generatedKeyNames.length); + Set keys = new HashSet(generatedKeyNames.length); for (String key : generatedKeyNames) { keys.add(key.toUpperCase()); } diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java index 8739bcfc5c5..76062a8c6bf 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java @@ -75,14 +75,14 @@ public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource { */ public String[] getReadablePropertyNames() { if (this.propertyNames == null) { - List names = new ArrayList(); + List names = new ArrayList(); PropertyDescriptor[] props = this.beanWrapper.getPropertyDescriptors(); - for (int i = 0; i < props.length; i++) { - if (this.beanWrapper.isReadableProperty(props[i].getName())) { - names.add(props[i].getName()); + for (PropertyDescriptor pd : props) { + if (this.beanWrapper.isReadableProperty(pd.getName())) { + names.add(pd.getName()); } } - this.propertyNames = (String[]) names.toArray(new String[names.size()]); + this.propertyNames = names.toArray(new String[names.size()]); } return this.propertyNames; } diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java index bd7863fd1f0..666b39ef8c1 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java @@ -44,15 +44,15 @@ import org.springframework.jdbc.BadSqlGrammarException; */ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLExceptionTranslator { - private static final Set BAD_SQL_GRAMMAR_CODES = new HashSet(8); + private static final Set BAD_SQL_GRAMMAR_CODES = new HashSet(8); - private static final Set DATA_INTEGRITY_VIOLATION_CODES = new HashSet(8); + private static final Set DATA_INTEGRITY_VIOLATION_CODES = new HashSet(8); - private static final Set DATA_ACCESS_RESOURCE_FAILURE_CODES = new HashSet(8); + private static final Set DATA_ACCESS_RESOURCE_FAILURE_CODES = new HashSet(8); - private static final Set TRANSIENT_DATA_ACCESS_RESOURCE_CODES = new HashSet(8); + private static final Set TRANSIENT_DATA_ACCESS_RESOURCE_CODES = new HashSet(8); - private static final Set CONCURRENCY_FAILURE_CODES = new HashSet(4); + private static final Set CONCURRENCY_FAILURE_CODES = new HashSet(4); static { diff --git a/org.springframework.jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java b/org.springframework.jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java index 921f109a6a4..1f311119b12 100644 --- a/org.springframework.jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java +++ b/org.springframework.jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java @@ -394,8 +394,8 @@ public class SingleConnectionFactory */ protected Session createSession(Connection con, Integer mode) throws JMSException { // Determine JMS API arguments... - boolean transacted = (mode.intValue() == Session.SESSION_TRANSACTED); - int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode.intValue()); + boolean transacted = (mode == Session.SESSION_TRANSACTED); + int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode); // Now actually call the appropriate JMS factory method... if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection) { return ((QueueConnection) con).createQueueSession(transacted, ackMode); @@ -444,7 +444,7 @@ public class SingleConnectionFactory * @return the wrapped Connection */ protected Connection getSharedConnectionProxy(Connection target) { - List classes = new ArrayList(3); + List classes = new ArrayList(3); classes.add(Connection.class); if (target instanceof QueueConnection) { classes.add(QueueConnection.class); @@ -454,7 +454,7 @@ public class SingleConnectionFactory } return (Connection) Proxy.newProxyInstance( Connection.class.getClassLoader(), - (Class[]) classes.toArray(new Class[classes.size()]), + classes.toArray(new Class[classes.size()]), new SharedConnectionInvocationHandler(target)); } @@ -477,7 +477,7 @@ public class SingleConnectionFactory } else if (method.getName().equals("hashCode")) { // Use hashCode of Connection proxy. - return new Integer(System.identityHashCode(proxy)); + return System.identityHashCode(proxy); } else if (method.getName().equals("toString")) { return "Shared JMS Connection: " + this.target; @@ -527,9 +527,9 @@ public class SingleConnectionFactory } else if (method.getName().equals("createSession") || method.getName().equals("createQueueSession") || method.getName().equals("createTopicSession")) { - boolean transacted = ((Boolean) args[0]).booleanValue(); + boolean transacted = (Boolean) args[0]; Integer ackMode = (Integer) args[1]; - Integer mode = (transacted ? new Integer(Session.SESSION_TRANSACTED) : ackMode); + Integer mode = (transacted ? Session.SESSION_TRANSACTED : ackMode); Session session = getSession(this.target, mode); if (session != null) { if (!method.getReturnType().isInstance(session)) { diff --git a/org.springframework.jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java b/org.springframework.jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java index 598664cbb22..143c41cc9f8 100644 --- a/org.springframework.jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java +++ b/org.springframework.jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java @@ -192,7 +192,7 @@ public class TransactionAwareConnectionFactoryProxy * @return the wrapped Connection */ private Connection getTransactionAwareConnectionProxy(Connection target) { - List classes = new ArrayList(3); + List classes = new ArrayList(3); classes.add(Connection.class); if (target instanceof QueueConnection) { classes.add(QueueConnection.class); @@ -202,7 +202,7 @@ public class TransactionAwareConnectionFactoryProxy } return (Connection) Proxy.newProxyInstance( Connection.class.getClassLoader(), - (Class[]) classes.toArray(new Class[classes.size()]), + classes.toArray(new Class[classes.size()]), new TransactionAwareConnectionInvocationHandler(target)); } @@ -263,7 +263,7 @@ public class TransactionAwareConnectionFactoryProxy } private Session getCloseSuppressingSessionProxy(Session target) { - List classes = new ArrayList(3); + List classes = new ArrayList(3); classes.add(SessionProxy.class); if (target instanceof QueueSession) { classes.add(QueueSession.class); @@ -273,7 +273,7 @@ public class TransactionAwareConnectionFactoryProxy } return (Session) Proxy.newProxyInstance( SessionProxy.class.getClassLoader(), - (Class[]) classes.toArray(new Class[classes.size()]), + classes.toArray(new Class[classes.size()]), new CloseSuppressingSessionInvocationHandler(target)); } } diff --git a/org.springframework.jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java b/org.springframework.jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java index b50d889f411..74f9e7581b2 100644 --- a/org.springframework.jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java +++ b/org.springframework.jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java @@ -77,7 +77,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess private boolean running = false; - private final List pausedTasks = new LinkedList(); + private final List pausedTasks = new LinkedList(); protected final Object lifecycleMonitor = new Object(); diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java index 7c57e9268c3..ea7bfd77801 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -94,13 +94,11 @@ class TxAdviceBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { } private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext parserContext) { - List methods = DomUtils.getChildElementsByTagName(attrEle, "method"); + List methods = DomUtils.getChildElementsByTagName(attrEle, "method"); ManagedMap transactionAttributeMap = new ManagedMap(methods.size()); transactionAttributeMap.setSource(parserContext.extractSource(attrEle)); - for (int i = 0; i < methods.size(); i++) { - Element methodEle = (Element) methods.get(i); - + for (Element methodEle : methods) { String name = methodEle.getAttribute("name"); TypedStringValue nameHolder = new TypedStringValue(name); nameHolder.setSource(parserContext.extractSource(methodEle)); @@ -125,10 +123,10 @@ class TxAdviceBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { } } if (StringUtils.hasText(readOnly)) { - attribute.setReadOnly(Boolean.valueOf(methodEle.getAttribute(READ_ONLY)).booleanValue()); + attribute.setReadOnly(Boolean.valueOf(methodEle.getAttribute(READ_ONLY))); } - List rollbackRules = new LinkedList(); + List rollbackRules = new LinkedList(); if (methodEle.hasAttribute(ROLLBACK_FOR)) { String rollbackForValue = methodEle.getAttribute(ROLLBACK_FOR); addRollbackRuleAttributesTo(rollbackRules,rollbackForValue); @@ -148,17 +146,17 @@ class TxAdviceBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { return attributeSourceDefinition; } - private void addRollbackRuleAttributesTo(List rollbackRules, String rollbackForValue) { + private void addRollbackRuleAttributesTo(List rollbackRules, String rollbackForValue) { String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(rollbackForValue); - for (int i = 0; i < exceptionTypeNames.length; i++) { - rollbackRules.add(new RollbackRuleAttribute(StringUtils.trimWhitespace(exceptionTypeNames[i]))); + for (String typeName : exceptionTypeNames) { + rollbackRules.add(new RollbackRuleAttribute(StringUtils.trimWhitespace(typeName))); } } - private void addNoRollbackRuleAttributesTo(List rollbackRules, String noRollbackForValue) { + private void addNoRollbackRuleAttributesTo(List rollbackRules, String noRollbackForValue) { String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(noRollbackForValue); - for (int i = 0; i < exceptionTypeNames.length; i++) { - rollbackRules.add(new NoRollbackRuleAttribute(StringUtils.trimWhitespace(exceptionTypeNames[i]))); + for (String typeName : exceptionTypeNames) { + rollbackRules.add(new NoRollbackRuleAttribute(StringUtils.trimWhitespace(typeName))); } } diff --git a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/GenericPortletBean.java b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/GenericPortletBean.java index e722cb77842..3ace247159f 100644 --- a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/GenericPortletBean.java +++ b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/GenericPortletBean.java @@ -72,7 +72,7 @@ public abstract class GenericPortletBean extends GenericPortlet { * Set of required properties (Strings) that must be supplied as * config parameters to this portlet. */ - private final Set requiredProperties = new HashSet(); + private final Set requiredProperties = new HashSet(); /** @@ -174,11 +174,11 @@ public abstract class GenericPortletBean extends GenericPortlet { * we can't accept default values * @throws PortletException if any required properties are missing */ - private PortletConfigPropertyValues(PortletConfig config, Set requiredProperties) + private PortletConfigPropertyValues(PortletConfig config, Set requiredProperties) throws PortletException { - Set missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ? - new HashSet(requiredProperties) : null; + Set missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ? + new HashSet(requiredProperties) : null; Enumeration en = config.getInitParameterNames(); while (en.hasMoreElements()) { diff --git a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/HandlerExecutionChain.java b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/HandlerExecutionChain.java index eb50e316009..e36a622a015 100644 --- a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/HandlerExecutionChain.java +++ b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/HandlerExecutionChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -17,6 +17,7 @@ package org.springframework.web.portlet; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.springframework.util.CollectionUtils; @@ -36,7 +37,7 @@ public class HandlerExecutionChain { private HandlerInterceptor[] interceptors; - private List interceptorList; + private List interceptorList; /** @@ -57,7 +58,7 @@ public class HandlerExecutionChain { if (handler instanceof HandlerExecutionChain) { HandlerExecutionChain originalChain = (HandlerExecutionChain) handler; this.handler = originalChain.getHandler(); - this.interceptorList = new ArrayList(); + this.interceptorList = new ArrayList(); CollectionUtils.mergeArrayIntoCollection(originalChain.getInterceptors(), this.interceptorList); CollectionUtils.mergeArrayIntoCollection(interceptors, this.interceptorList); } @@ -84,20 +85,16 @@ public class HandlerExecutionChain { public void addInterceptors(HandlerInterceptor[] interceptors) { if (interceptors != null) { initInterceptorList(); - for (int i = 0; i < interceptors.length; i++) { - this.interceptorList.add(interceptors[i]); - } + this.interceptorList.addAll(Arrays.asList(interceptors)); } } private void initInterceptorList() { if (this.interceptorList == null) { - this.interceptorList = new ArrayList(); + this.interceptorList = new ArrayList(); } if (this.interceptors != null) { - for (int i = 0; i < this.interceptors.length; i++) { - this.interceptorList.add(this.interceptors[i]); - } + this.interceptorList.addAll(Arrays.asList(this.interceptors)); this.interceptors = null; } } @@ -108,10 +105,18 @@ public class HandlerExecutionChain { */ public HandlerInterceptor[] getInterceptors() { if (this.interceptors == null && this.interceptorList != null) { - this.interceptors = (HandlerInterceptor[]) - this.interceptorList.toArray(new HandlerInterceptor[this.interceptorList.size()]); + this.interceptors = this.interceptorList.toArray(new HandlerInterceptor[this.interceptorList.size()]); } return this.interceptors; } + + /** + * Delegates to the handler's toString(). + */ + @Override + public String toString() { + return String.valueOf(this.handler); + } + } diff --git a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/AbstractHandlerMapping.java b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/AbstractHandlerMapping.java index 9a3ef4624ec..c6791ceedd9 100644 --- a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/AbstractHandlerMapping.java +++ b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/AbstractHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -49,7 +49,7 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport private Object defaultHandler; - private final List interceptors = new ArrayList(); + private final List interceptors = new ArrayList(); private boolean applyWebRequestInterceptorsToRenderPhaseOnly = true; diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/bind/EscapedErrors.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/bind/EscapedErrors.java index 111f27ee0f6..03230048e93 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/bind/EscapedErrors.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/bind/EscapedErrors.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2008 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. @@ -17,7 +17,6 @@ package org.springframework.web.bind; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.springframework.validation.Errors; @@ -117,7 +116,7 @@ public class EscapedErrors implements Errors { return this.source.getErrorCount(); } - public List getAllErrors() { + public List getAllErrors() { return escapeObjectErrors(this.source.getAllErrors()); } @@ -129,7 +128,7 @@ public class EscapedErrors implements Errors { return this.source.getGlobalErrorCount(); } - public List getGlobalErrors() { + public List getGlobalErrors() { return escapeObjectErrors(this.source.getGlobalErrors()); } @@ -145,7 +144,7 @@ public class EscapedErrors implements Errors { return this.source.getFieldErrorCount(); } - public List getFieldErrors() { + public List getFieldErrors() { return this.source.getFieldErrors(); } @@ -161,12 +160,12 @@ public class EscapedErrors implements Errors { return this.source.getFieldErrorCount(field); } - public List getFieldErrors(String field) { + public List getFieldErrors(String field) { return escapeObjectErrors(this.source.getFieldErrors(field)); } public FieldError getFieldError(String field) { - return (FieldError) escapeObjectError(this.source.getFieldError(field)); + return escapeObjectError(this.source.getFieldError(field)); } public Object getFieldValue(String field) { @@ -178,7 +177,8 @@ public class EscapedErrors implements Errors { return this.source.getFieldType(field); } - private ObjectError escapeObjectError(ObjectError source) { + @SuppressWarnings("unchecked") + private T escapeObjectError(T source) { if (source == null) { return null; } @@ -188,20 +188,21 @@ public class EscapedErrors implements Errors { if (value instanceof String) { value = HtmlUtils.htmlEscape((String) value); } - return new FieldError( + return (T) new FieldError( fieldError.getObjectName(), fieldError.getField(), value, fieldError.isBindingFailure(), fieldError.getCodes(), fieldError.getArguments(), HtmlUtils.htmlEscape(fieldError.getDefaultMessage())); } - return new ObjectError( - source.getObjectName(), source.getCodes(), source.getArguments(), - HtmlUtils.htmlEscape(source.getDefaultMessage())); + else { + return (T) new ObjectError( + source.getObjectName(), source.getCodes(), source.getArguments(), + HtmlUtils.htmlEscape(source.getDefaultMessage())); + } } - private List escapeObjectErrors(List source) { - List escaped = new ArrayList(source.size()); - for (Iterator it = source.iterator(); it.hasNext();) { - ObjectError objectError = (ObjectError)it.next(); + private List escapeObjectErrors(List source) { + List escaped = new ArrayList(source.size()); + for (T objectError : source) { escaped.add(escapeObjectError(objectError)); } return escaped; diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java index 10dc3be9d7a..371f7d470e9 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -17,6 +17,7 @@ package org.springframework.web.servlet; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.springframework.util.CollectionUtils; @@ -35,7 +36,7 @@ public class HandlerExecutionChain { private HandlerInterceptor[] interceptors; - private List interceptorList; + private List interceptorList; /** @@ -56,7 +57,7 @@ public class HandlerExecutionChain { if (handler instanceof HandlerExecutionChain) { HandlerExecutionChain originalChain = (HandlerExecutionChain) handler; this.handler = originalChain.getHandler(); - this.interceptorList = new ArrayList(); + this.interceptorList = new ArrayList(); CollectionUtils.mergeArrayIntoCollection(originalChain.getInterceptors(), this.interceptorList); CollectionUtils.mergeArrayIntoCollection(interceptors, this.interceptorList); } @@ -83,20 +84,16 @@ public class HandlerExecutionChain { public void addInterceptors(HandlerInterceptor[] interceptors) { if (interceptors != null) { initInterceptorList(); - for (int i = 0; i < interceptors.length; i++) { - this.interceptorList.add(interceptors[i]); - } + this.interceptorList.addAll(Arrays.asList(interceptors)); } } private void initInterceptorList() { if (this.interceptorList == null) { - this.interceptorList = new ArrayList(); + this.interceptorList = new ArrayList(); } if (this.interceptors != null) { - for (int i = 0; i < this.interceptors.length; i++) { - this.interceptorList.add(this.interceptors[i]); - } + this.interceptorList.addAll(Arrays.asList(this.interceptors)); this.interceptors = null; } } @@ -107,17 +104,18 @@ public class HandlerExecutionChain { */ public HandlerInterceptor[] getInterceptors() { if (this.interceptors == null && this.interceptorList != null) { - this.interceptors = (HandlerInterceptor[]) - this.interceptorList.toArray(new HandlerInterceptor[this.interceptorList.size()]); + this.interceptors = this.interceptorList.toArray(new HandlerInterceptor[this.interceptorList.size()]); } return this.interceptors; } + /** * Delegates to the handler's toString(). */ @Override public String toString() { - return String.valueOf(handler); + return String.valueOf(this.handler); } + } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HttpServletBean.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HttpServletBean.java index 03099e4e38c..1d994096ed7 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HttpServletBean.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HttpServletBean.java @@ -81,7 +81,7 @@ public abstract class HttpServletBean extends HttpServlet { * Set of required properties (Strings) that must be supplied as * config parameters to this servlet. */ - private final Set requiredProperties = new HashSet(); + private final Set requiredProperties = new HashSet(); /** @@ -187,11 +187,11 @@ public abstract class HttpServletBean extends HttpServlet { * we can't accept default values * @throws ServletException if any required properties are missing */ - public ServletConfigPropertyValues(ServletConfig config, Set requiredProperties) + public ServletConfigPropertyValues(ServletConfig config, Set requiredProperties) throws ServletException { - Set missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ? - new HashSet(requiredProperties) : null; + Set missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ? + new HashSet(requiredProperties) : null; Enumeration en = config.getInitParameterNames(); while (en.hasMoreElements()) { diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java index 171a227715a..e1b1f1da77a 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -52,7 +52,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport private Object defaultHandler; - private final List interceptors = new ArrayList(); + private final List interceptors = new ArrayList(); private HandlerInterceptor[] adaptedInterceptors; diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMapping.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMapping.java index 1aed150e6dd..ceb3d7d926b 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMapping.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMapping.java @@ -55,7 +55,7 @@ public class BeanNameUrlHandlerMapping extends AbstractDetectingUrlHandlerMappin */ @Override protected String[] determineUrlsForHandler(String beanName) { - List urls = new ArrayList(); + List urls = new ArrayList(); if (beanName.startsWith("/")) { urls.add(beanName); } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java index f8f6e883adf..eb9dec91987 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java @@ -65,7 +65,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { /** Set of supported HTTP methods */ - private Set supportedMethods; + private Set supportedMethods; private boolean requireSession = false; @@ -97,7 +97,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { */ public WebContentGenerator(boolean restrictDefaultSupportedMethods) { if (restrictDefaultSupportedMethods) { - this.supportedMethods = new HashSet(4); + this.supportedMethods = new HashSet(4); this.supportedMethods.add(METHOD_GET); this.supportedMethods.add(METHOD_HEAD); this.supportedMethods.add(METHOD_POST); @@ -111,7 +111,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { */ public final void setSupportedMethods(String[] methods) { if (methods != null) { - this.supportedMethods = new HashSet(Arrays.asList(methods)); + this.supportedMethods = new HashSet(Arrays.asList(methods)); } else { this.supportedMethods = null; diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java index cd9b41da14c..825a2877a9c 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java @@ -19,7 +19,6 @@ package org.springframework.web.servlet.tags.form; import java.util.ArrayList; import java.util.Arrays; import java.util.List; - import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.BodyTag; @@ -169,7 +168,7 @@ public class ErrorsTag extends AbstractHtmlElementBodyTag implements BodyTag { */ @Override protected void exposeAttributes() throws JspException { - List errorMessages = new ArrayList(); + List errorMessages = new ArrayList(); errorMessages.addAll(Arrays.asList(getBindStatus().getErrorMessages())); this.oldMessages = this.pageContext.getAttribute(MESSAGES_ATTRIBUTE, PageContext.PAGE_SCOPE); this.pageContext.setAttribute(MESSAGES_ATTRIBUTE, errorMessages, PageContext.PAGE_SCOPE); diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java index 072cbdf4251..47f88699209 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java @@ -74,7 +74,7 @@ public class InternalResourceView extends AbstractUrlBasedView { private boolean exposeContextBeansAsAttributes = false; - private Set exposedContextBeanNames; + private Set exposedContextBeanNames; private boolean preventDispatchLoop = false; @@ -158,7 +158,7 @@ public class InternalResourceView extends AbstractUrlBasedView { * flag on but do not list specific bean names for this property. */ public void setExposedContextBeanNames(String[] exposedContextBeanNames) { - this.exposedContextBeanNames = new HashSet(Arrays.asList(exposedContextBeanNames)); + this.exposedContextBeanNames = new HashSet(Arrays.asList(exposedContextBeanNames)); } /** diff --git a/org.springframework.web/src/main/java/org/springframework/web/context/support/ContextExposingHttpServletRequest.java b/org.springframework.web/src/main/java/org/springframework/web/context/support/ContextExposingHttpServletRequest.java index 355681fc02b..9f86cc92431 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/context/support/ContextExposingHttpServletRequest.java +++ b/org.springframework.web/src/main/java/org/springframework/web/context/support/ContextExposingHttpServletRequest.java @@ -37,9 +37,9 @@ public class ContextExposingHttpServletRequest extends HttpServletRequestWrapper private final WebApplicationContext webApplicationContext; - private final Set exposedContextBeanNames; + private final Set exposedContextBeanNames; - private Set explicitAttributes; + private Set explicitAttributes; /** @@ -60,7 +60,7 @@ public class ContextExposingHttpServletRequest extends HttpServletRequestWrapper * Set are eligible for exposure as attributes) */ public ContextExposingHttpServletRequest( - HttpServletRequest originalRequest, WebApplicationContext context, Set exposedContextBeanNames) { + HttpServletRequest originalRequest, WebApplicationContext context, Set exposedContextBeanNames) { super(originalRequest); Assert.notNull(context, "WebApplicationContext must not be null"); @@ -93,7 +93,7 @@ public class ContextExposingHttpServletRequest extends HttpServletRequestWrapper public void setAttribute(String name, Object value) { super.setAttribute(name, value); if (this.explicitAttributes == null) { - this.explicitAttributes = new HashSet(8); + this.explicitAttributes = new HashSet(8); } this.explicitAttributes.add(name); } diff --git a/org.springframework.web/src/main/java/org/springframework/web/filter/GenericFilterBean.java b/org.springframework.web/src/main/java/org/springframework/web/filter/GenericFilterBean.java index d4e1fa8c06a..1572d63f3f7 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/filter/GenericFilterBean.java +++ b/org.springframework.web/src/main/java/org/springframework/web/filter/GenericFilterBean.java @@ -83,7 +83,7 @@ public abstract class GenericFilterBean implements * Set of required properties (Strings) that must be supplied as * config parameters to this filter. */ - private final Set requiredProperties = new HashSet(); + private final Set requiredProperties = new HashSet(); /* The FilterConfig of this filter */ private FilterConfig filterConfig; @@ -275,11 +275,11 @@ public abstract class GenericFilterBean implements * we can't accept default values * @throws ServletException if any required properties are missing */ - public FilterConfigPropertyValues(FilterConfig config, Set requiredProperties) + public FilterConfigPropertyValues(FilterConfig config, Set requiredProperties) throws ServletException { - Set missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ? - new HashSet(requiredProperties) : null; + Set missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ? + new HashSet(requiredProperties) : null; Enumeration en = config.getInitParameterNames(); while (en.hasMoreElements()) {