diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.java b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.java
index 8b7128863f0..5c92ae6b4d4 100644
--- a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.java
+++ b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.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.aop.aspectj;
-import java.util.Iterator;
import java.util.List;
import org.springframework.aop.Advisor;
@@ -40,12 +39,11 @@ public abstract class AspectJProxyUtils {
* @param advisors Advisors available
* @return true if any special {@link Advisor Advisors} were added, otherwise false.
*/
- public static boolean makeAdvisorChainAspectJCapableIfNecessary(List advisors) {
+ public static boolean makeAdvisorChainAspectJCapableIfNecessary(List advisors) {
// Don't add advisors to an empty list; may indicate that proxying is just not required
if (!advisors.isEmpty()) {
boolean foundAspectJAdvice = false;
- for (Iterator it = advisors.iterator(); it.hasNext() && !foundAspectJAdvice; ) {
- Advisor advisor = (Advisor) it.next();
+ for (Advisor advisor : advisors) {
// Be careful not to get the Advice without a guard, as
// this might eagerly instantiate a non-singleton AspectJ aspect
if (isAspectJAdvice(advisor)) {
diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java
index 7231c9fd1c2..c3c6de33651 100644
--- a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java
+++ b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.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.
@@ -18,7 +18,6 @@ package org.springframework.aop.aspectj.annotation;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -138,8 +137,7 @@ public class BeanFactoryAspectJAdvisorsBuilder {
return Collections.EMPTY_LIST;
}
List advisors = new LinkedList();
- for (Iterator it = aspectNames.iterator(); it.hasNext();) {
- String aspectName = (String) it.next();
+ for (String aspectName : aspectNames) {
List cachedAdvisors = this.advisorsCache.get(aspectName);
if (cachedAdvisors != null) {
advisors.addAll(cachedAdvisors);
diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJAwareAdvisorAutoProxyCreator.java b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJAwareAdvisorAutoProxyCreator.java
index 76e9c47535b..0cb786cc255 100644
--- a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJAwareAdvisorAutoProxyCreator.java
+++ b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJAwareAdvisorAutoProxyCreator.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,7 +17,6 @@
package org.springframework.aop.aspectj.autoproxy;
import java.util.Comparator;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -65,27 +64,27 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
* advisor should run last.
*/
@Override
- protected List sortAdvisors(List advisors) {
+ @SuppressWarnings("unchecked")
+ protected List sortAdvisors(List advisors) {
// build list for sorting
- List partiallyComparableAdvisors = new LinkedList();
- for (Iterator it = advisors.iterator(); it.hasNext();) {
- Advisor element = (Advisor) it.next();
- PartiallyComparableAdvisorHolder advisor =
- new PartiallyComparableAdvisorHolder(element, DEFAULT_PRECEDENCE_COMPARATOR);
- partiallyComparableAdvisors.add(advisor);
+ List partiallyComparableAdvisors =
+ new LinkedList();
+ for (Advisor element : advisors) {
+ partiallyComparableAdvisors.add(
+ new PartiallyComparableAdvisorHolder(element, DEFAULT_PRECEDENCE_COMPARATOR));
}
// sort it
- List sorted = PartialOrder.sort(partiallyComparableAdvisors);
+ List sorted =
+ (List) PartialOrder.sort(partiallyComparableAdvisors);
if (sorted == null) {
- // TODO: work much harder to give a better error message here.
+ // TODO: work harder to give a better error message here.
throw new IllegalArgumentException("Advice precedence circularity error");
}
// extract results again
- List result = new LinkedList();
- for (Iterator it = sorted.iterator(); it.hasNext();) {
- PartiallyComparableAdvisorHolder pcAdvisor = (PartiallyComparableAdvisorHolder) it.next();
+ List result = new LinkedList();
+ for (PartiallyComparableAdvisorHolder pcAdvisor : sorted) {
result.add(pcAdvisor.getAdvisor());
}
@@ -98,18 +97,17 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
* and when using AspectJ-style advice.
*/
@Override
- protected void extendAdvisors(List candidateAdvisors) {
+ protected void extendAdvisors(List candidateAdvisors) {
AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(candidateAdvisors);
}
@Override
protected boolean shouldSkip(Class beanClass, String beanName) {
// TODO: Consider optimization by caching the list of the aspect names
- List candidtate = findCandidateAdvisors();
- for (Iterator it = candidtate.iterator(); it.hasNext();) {
- Advisor advisor = (Advisor) it.next();
+ List candidateAdvisors = findCandidateAdvisors();
+ for (Advisor advisor : candidateAdvisors) {
if (advisor instanceof AspectJPointcutAdvisor) {
- if(((AbstractAspectJAdvice) advisor.getAdvice()).getAspectName().equals(beanName)) {
+ if (((AbstractAspectJAdvice) advisor.getAdvice()).getAspectName().equals(beanName)) {
return true;
}
}
@@ -117,6 +115,7 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
return super.shouldSkip(beanClass, beanName);
}
+
/**
* Implements AspectJ PartialComparable interface for defining partial orderings.
*/
@@ -124,9 +123,9 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
private final Advisor advisor;
- private final Comparator comparator;
+ private final Comparator comparator;
- public PartiallyComparableAdvisorHolder(Advisor advisor, Comparator comparator) {
+ public PartiallyComparableAdvisorHolder(Advisor advisor, Comparator comparator) {
this.advisor = advisor;
this.comparator = comparator;
}
@@ -151,7 +150,7 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
sb.append(ClassUtils.getShortName(advice.getClass()));
sb.append(": ");
if (this.advisor instanceof Ordered) {
- sb.append("order " + ((Ordered) this.advisor).getOrder() + ", ");
+ sb.append("order ").append(((Ordered) this.advisor).getOrder()).append(", ");
}
if (advice instanceof AbstractAspectJAdvice) {
AbstractAspectJAdvice ajAdvice = (AbstractAspectJAdvice) advice;
diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java b/org.springframework.aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java
index 9a6b81d15b7..022c6fa1441 100644
--- a/org.springframework.aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java
+++ b/org.springframework.aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java
@@ -62,7 +62,8 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator
private ConfigurableBeanFactory beanFactory;
/** Internally used DefaultListableBeanFactory instances, keyed by bean name */
- private final Map internalBeanFactories = new HashMap();
+ private final Map internalBeanFactories =
+ new HashMap();
public final void setBeanFactory(BeanFactory beanFactory) {
@@ -121,15 +122,14 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator
* @return the internal BeanFactory to be used
*/
protected DefaultListableBeanFactory getInternalBeanFactoryForBean(String beanName) {
- DefaultListableBeanFactory internalBeanFactory = null;
synchronized (this.internalBeanFactories) {
- internalBeanFactory = (DefaultListableBeanFactory) this.internalBeanFactories.get(beanName);
+ DefaultListableBeanFactory internalBeanFactory = this.internalBeanFactories.get(beanName);
if (internalBeanFactory == null) {
internalBeanFactory = buildInternalBeanFactory(this.beanFactory);
this.internalBeanFactories.put(beanName, internalBeanFactory);
}
+ return internalBeanFactory;
}
- return internalBeanFactory;
}
/**
@@ -146,9 +146,8 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator
// Filter out BeanPostProcessors that are part of the AOP infrastructure,
// since those are only meant to apply to beans defined in the original factory.
- for (Iterator it = internalBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
- BeanPostProcessor postProcessor = (BeanPostProcessor) it.next();
- if (postProcessor instanceof AopInfrastructureBean) {
+ for (Iterator it = internalBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
+ if (it.next() instanceof AopInfrastructureBean) {
it.remove();
}
}
@@ -162,8 +161,8 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator
*/
public void destroy() {
synchronized (this.internalBeanFactories) {
- for (Iterator it = this.internalBeanFactories.values().iterator(); it.hasNext();) {
- ((DefaultListableBeanFactory) it.next()).destroySingletons();
+ for (DefaultListableBeanFactory bf : this.internalBeanFactories.values()) {
+ bf.destroySingletons();
}
}
}
diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java b/org.springframework.aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java
index 5c4339b8b83..0ab671d12fb 100644
--- a/org.springframework.aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java
+++ b/org.springframework.aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.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.
@@ -18,7 +18,6 @@ package org.springframework.aop.support;
import java.io.Serializable;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
import org.aopalliance.aop.Advice;
@@ -43,7 +42,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil
private final Advice advice;
- private final Set interfaces = new HashSet();
+ private final Set interfaces = new HashSet();
private int order = Integer.MAX_VALUE;
@@ -72,8 +71,8 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil
if (introducedInterfaces.length == 0) {
throw new IllegalArgumentException("IntroductionAdviceSupport implements no interfaces");
}
- for (int i = 0; i < introducedInterfaces.length; i++) {
- addInterface(introducedInterfaces[i]);
+ for (Class ifc : introducedInterfaces) {
+ addInterface(ifc);
}
}
}
@@ -103,12 +102,11 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil
}
public Class[] getInterfaces() {
- return (Class[]) this.interfaces.toArray(new Class[this.interfaces.size()]);
+ return this.interfaces.toArray(new Class[this.interfaces.size()]);
}
public void validateInterfaces() throws IllegalArgumentException {
- for (Iterator it = this.interfaces.iterator(); it.hasNext();) {
- Class ifc = (Class) it.next();
+ for (Class ifc : this.interfaces) {
if (this.advice instanceof DynamicIntroductionAdvice &&
!((DynamicIntroductionAdvice) this.advice).implementsInterface(ifc)) {
throw new IllegalArgumentException("DynamicIntroductionAdvice [" + this.advice + "] " +
diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/support/IntroductionInfoSupport.java b/org.springframework.aop/src/main/java/org/springframework/aop/support/IntroductionInfoSupport.java
index 21b25a85ad8..979e5c8819a 100644
--- a/org.springframework.aop/src/main/java/org/springframework/aop/support/IntroductionInfoSupport.java
+++ b/org.springframework.aop/src/main/java/org/springframework/aop/support/IntroductionInfoSupport.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,9 +19,9 @@ package org.springframework.aop.support;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
+import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.IdentityHashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -46,13 +46,9 @@ public class IntroductionInfoSupport implements IntroductionInfo, Serializable {
protected transient Log logger = LogFactory.getLog(getClass());
- /** Set of interface Classes */
- protected Set publishedInterfaces = new HashSet();
+ protected Set publishedInterfaces = new HashSet();
- /**
- * Methods that we know we should implement here: key is Method, value is Boolean.
- **/
- private transient Map rememberedMethods = createRememberedMethodMap();
+ private transient Map rememberedMethods = new IdentityHashMap(32);
/**
@@ -67,18 +63,17 @@ public class IntroductionInfoSupport implements IntroductionInfo, Serializable {
}
public Class[] getInterfaces() {
- return (Class[]) this.publishedInterfaces.toArray(new Class[this.publishedInterfaces.size()]);
+ return this.publishedInterfaces.toArray(new Class[this.publishedInterfaces.size()]);
}
/**
* Check whether the specified interfaces is a published introduction interface.
- * @param intf the interface to check
+ * @param ifc the interface to check
* @return whether the interface is part of this introduction
*/
- public boolean implementsInterface(Class intf) {
- for (Iterator it = this.publishedInterfaces.iterator(); it.hasNext();) {
- Class pubIntf = (Class) it.next();
- if (intf.isInterface() && intf.isAssignableFrom(pubIntf)) {
+ public boolean implementsInterface(Class ifc) {
+ for (Class pubIfc : this.publishedInterfaces) {
+ if (ifc.isInterface() && ifc.isAssignableFrom(pubIfc)) {
return true;
}
}
@@ -93,24 +88,20 @@ public class IntroductionInfoSupport implements IntroductionInfo, Serializable {
this.publishedInterfaces.addAll(ClassUtils.getAllInterfacesAsSet(delegate));
}
- private Map createRememberedMethodMap() {
- return new IdentityHashMap(32);
- }
-
/**
* Is this method on an introduced interface?
* @param mi the method invocation
* @return whether the invoked method is on an introduced interface
*/
protected final boolean isMethodOnIntroducedInterface(MethodInvocation mi) {
- Boolean rememberedResult = (Boolean) this.rememberedMethods.get(mi.getMethod());
+ Boolean rememberedResult = this.rememberedMethods.get(mi.getMethod());
if (rememberedResult != null) {
- return rememberedResult.booleanValue();
+ return rememberedResult;
}
else {
// Work it out and cache it.
boolean result = implementsInterface(mi.getMethod().getDeclaringClass());
- this.rememberedMethods.put(mi.getMethod(), (result ? Boolean.TRUE : Boolean.FALSE));
+ this.rememberedMethods.put(mi.getMethod(), result);
return result;
}
}
@@ -131,7 +122,7 @@ public class IntroductionInfoSupport implements IntroductionInfo, Serializable {
// Initialize transient fields.
this.logger = LogFactory.getLog(getClass());
- this.rememberedMethods = createRememberedMethodMap();
+ this.rememberedMethods = new IdentityHashMap(32);
}
}
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java b/org.springframework.beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java
index 64f5e776441..5bd63e88576 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java
@@ -103,16 +103,16 @@ public class CachedIntrospectionResults {
return;
}
synchronized (classCache) {
- for (Iterator it = classCache.keySet().iterator(); it.hasNext();) {
- Class beanClass = (Class) it.next();
+ for (Iterator it = classCache.keySet().iterator(); it.hasNext();) {
+ Class beanClass = it.next();
if (isUnderneathClassLoader(beanClass.getClassLoader(), classLoader)) {
it.remove();
}
}
}
synchronized (acceptedClassLoaders) {
- for (Iterator it = acceptedClassLoaders.iterator(); it.hasNext();) {
- ClassLoader registeredLoader = (ClassLoader) it.next();
+ for (Iterator it = acceptedClassLoaders.iterator(); it.hasNext();) {
+ ClassLoader registeredLoader = it.next();
if (isUnderneathClassLoader(registeredLoader, classLoader)) {
it.remove();
}
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java b/org.springframework.beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java
index b192230b2be..6dd3162d157 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java
@@ -79,15 +79,15 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
private boolean configValueEditorsActive = false;
- private boolean propertySpecificEditorsRegistered = false;
+ private Map defaultEditors;
- private Map defaultEditors;
+ private Map customEditors;
- private Map customEditors;
+ private Map customEditorsForPath;
- private Set sharedEditors;
+ private Set sharedEditors;
- private Map customEditorCache;
+ private Map customEditorCache;
//---------------------------------------------------------------------
@@ -127,7 +127,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
if (this.defaultEditors == null) {
doRegisterDefaultEditors();
}
- return (PropertyEditor) this.defaultEditors.get(requiredType);
+ return this.defaultEditors.get(requiredType);
}
/**
@@ -152,7 +152,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @see org.springframework.beans.propertyeditors.URLEditor
*/
private void doRegisterDefaultEditors() {
- this.defaultEditors = new HashMap(64);
+ this.defaultEditors = new HashMap(64);
// Simple editors, without parameterization capabilities.
// The JDK does not contain a default editor for any of these target types.
@@ -238,14 +238,16 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
if (requiredType == null && propertyPath == null) {
throw new IllegalArgumentException("Either requiredType or propertyPath is required");
}
- if (this.customEditors == null) {
- this.customEditors = new LinkedHashMap(16);
- }
if (propertyPath != null) {
- this.customEditors.put(propertyPath, new CustomEditorHolder(propertyEditor, requiredType));
- this.propertySpecificEditorsRegistered = true;
+ if (this.customEditorsForPath == null) {
+ this.customEditorsForPath = new LinkedHashMap(16);
+ }
+ this.customEditorsForPath.put(propertyPath, new CustomEditorHolder(propertyEditor, requiredType));
}
else {
+ if (this.customEditors == null) {
+ this.customEditors = new LinkedHashMap(16);
+ }
this.customEditors.put(requiredType, propertyEditor);
this.customEditorCache = null;
}
@@ -261,7 +263,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
public void registerSharedEditor(Class requiredType, PropertyEditor propertyEditor) {
registerCustomEditor(requiredType, null, propertyEditor);
if (this.sharedEditors == null) {
- this.sharedEditors = new HashSet();
+ this.sharedEditors = new HashSet();
}
this.sharedEditors.add(propertyEditor);
}
@@ -277,19 +279,16 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
}
public PropertyEditor findCustomEditor(Class requiredType, String propertyPath) {
- if (this.customEditors == null) {
- return null;
- }
Class requiredTypeToUse = requiredType;
if (propertyPath != null) {
- if (this.propertySpecificEditorsRegistered) {
+ if (this.customEditorsForPath != null) {
// Check property-specific editor first.
PropertyEditor editor = getCustomEditor(propertyPath, requiredType);
if (editor == null) {
- List strippedPaths = new LinkedList();
+ List strippedPaths = new LinkedList();
addStrippedPropertyPaths(strippedPaths, "", propertyPath);
- for (Iterator it = strippedPaths.iterator(); it.hasNext() && editor == null;) {
- String strippedPath = (String) it.next();
+ for (Iterator it = strippedPaths.iterator(); it.hasNext() && editor == null;) {
+ String strippedPath = it.next();
editor = getCustomEditor(strippedPath, requiredType);
}
}
@@ -315,25 +314,17 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @return whether a matching custom editor has been found
*/
public boolean hasCustomEditorForElement(Class elementType, String propertyPath) {
- if (this.customEditors == null) {
- return false;
- }
- if (propertyPath != null && this.propertySpecificEditorsRegistered) {
- for (Iterator it = this.customEditors.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- if (entry.getKey() instanceof String) {
- String regPath = (String) entry.getKey();
- if (PropertyAccessorUtils.matchesProperty(regPath, propertyPath)) {
- CustomEditorHolder editorHolder = (CustomEditorHolder) entry.getValue();
- if (editorHolder.getPropertyEditor(elementType) != null) {
- return true;
- }
+ if (propertyPath != null && this.customEditorsForPath != null) {
+ for (Map.Entry entry : this.customEditorsForPath.entrySet()) {
+ if (PropertyAccessorUtils.matchesProperty(entry.getKey(), propertyPath)) {
+ if (entry.getValue().getPropertyEditor(elementType) != null) {
+ return true;
}
}
}
}
// No property-specific editor -> check type-specific editor.
- return (elementType != null && this.customEditors.containsKey(elementType));
+ return (elementType != null && this.customEditors != null && this.customEditors.containsKey(elementType));
}
/**
@@ -358,7 +349,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @return the custom editor, or null if none specific for this property
*/
private PropertyEditor getCustomEditor(String propertyName, Class requiredType) {
- CustomEditorHolder holder = (CustomEditorHolder) this.customEditors.get(propertyName);
+ CustomEditorHolder holder = this.customEditorsForPath.get(propertyName);
return (holder != null ? holder.getPropertyEditor(requiredType) : null);
}
@@ -371,26 +362,26 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @see java.beans.PropertyEditor#getAsText()
*/
private PropertyEditor getCustomEditor(Class requiredType) {
- if (requiredType == null) {
+ if (requiredType == null || this.customEditors == null) {
return null;
}
// Check directly registered editor for type.
- PropertyEditor editor = (PropertyEditor) this.customEditors.get(requiredType);
+ PropertyEditor editor = this.customEditors.get(requiredType);
if (editor == null) {
// Check cached editor for type, registered for superclass or interface.
if (this.customEditorCache != null) {
- editor = (PropertyEditor) this.customEditorCache.get(requiredType);
+ editor = this.customEditorCache.get(requiredType);
}
if (editor == null) {
// Find editor for superclass or interface.
- for (Iterator it = this.customEditors.keySet().iterator(); it.hasNext() && editor == null;) {
- Object key = it.next();
- if (key instanceof Class && ((Class) key).isAssignableFrom(requiredType)) {
- editor = (PropertyEditor) this.customEditors.get(key);
+ for (Iterator it = this.customEditors.keySet().iterator(); it.hasNext() && editor == null;) {
+ Class key = it.next();
+ if (key.isAssignableFrom(requiredType)) {
+ editor = this.customEditors.get(key);
// Cache editor for search type, to avoid the overhead
// of repeated assignable-from checks.
if (this.customEditorCache == null) {
- this.customEditorCache = new HashMap();
+ this.customEditorCache = new HashMap();
}
this.customEditorCache.put(requiredType, editor);
}
@@ -407,14 +398,14 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @return the property type, or null if not determinable
*/
protected Class guessPropertyTypeFromEditors(String propertyName) {
- if (this.customEditors != null) {
- CustomEditorHolder editorHolder = (CustomEditorHolder) this.customEditors.get(propertyName);
+ if (this.customEditorsForPath != null) {
+ CustomEditorHolder editorHolder = this.customEditorsForPath.get(propertyName);
if (editorHolder == null) {
- List strippedPaths = new LinkedList();
+ List strippedPaths = new LinkedList();
addStrippedPropertyPaths(strippedPaths, "", propertyName);
- for (Iterator it = strippedPaths.iterator(); it.hasNext() && editorHolder == null;) {
- String strippedName = (String) it.next();
- editorHolder = (CustomEditorHolder) this.customEditors.get(strippedName);
+ for (Iterator it = strippedPaths.iterator(); it.hasNext() && editorHolder == null;) {
+ String strippedName = it.next();
+ editorHolder = this.customEditorsForPath.get(strippedName);
}
}
if (editorHolder != null) {
@@ -435,31 +426,28 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
String actualPropertyName =
(nestedProperty != null ? PropertyAccessorUtils.getPropertyName(nestedProperty) : null);
if (this.customEditors != null) {
- for (Iterator it = this.customEditors.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- if (entry.getKey() instanceof Class) {
- Class requiredType = (Class) entry.getKey();
- PropertyEditor editor = (PropertyEditor) entry.getValue();
- target.registerCustomEditor(requiredType, editor);
- }
- else if (entry.getKey() instanceof String) {
- String editorPath = (String) entry.getKey();
- CustomEditorHolder editorHolder = (CustomEditorHolder) entry.getValue();
- if (nestedProperty != null) {
- int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(editorPath);
- if (pos != -1) {
- String editorNestedProperty = editorPath.substring(0, pos);
- String editorNestedPath = editorPath.substring(pos + 1);
- if (editorNestedProperty.equals(nestedProperty) || editorNestedProperty.equals(actualPropertyName)) {
- target.registerCustomEditor(
- editorHolder.getRegisteredType(), editorNestedPath, editorHolder.getPropertyEditor());
- }
+ for (Map.Entry entry : this.customEditors.entrySet()) {
+ target.registerCustomEditor(entry.getKey(), entry.getValue());
+ }
+ }
+ if (this.customEditorsForPath != null) {
+ for (Map.Entry entry : this.customEditorsForPath.entrySet()) {
+ String editorPath = entry.getKey();
+ CustomEditorHolder editorHolder = entry.getValue();
+ if (nestedProperty != null) {
+ int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(editorPath);
+ if (pos != -1) {
+ String editorNestedProperty = editorPath.substring(0, pos);
+ String editorNestedPath = editorPath.substring(pos + 1);
+ if (editorNestedProperty.equals(nestedProperty) || editorNestedProperty.equals(actualPropertyName)) {
+ target.registerCustomEditor(
+ editorHolder.getRegisteredType(), editorNestedPath, editorHolder.getPropertyEditor());
}
}
- else {
- target.registerCustomEditor(
- editorHolder.getRegisteredType(), editorPath, editorHolder.getPropertyEditor());
- }
+ }
+ else {
+ target.registerCustomEditor(
+ editorHolder.getRegisteredType(), editorPath, editorHolder.getPropertyEditor());
}
}
}
@@ -473,7 +461,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @param nestedPath the current nested path
* @param propertyPath the property path to check for keys/indexes to strip
*/
- private void addStrippedPropertyPaths(List strippedPaths, String nestedPath, String propertyPath) {
+ private void addStrippedPropertyPaths(List strippedPaths, String nestedPath, String propertyPath) {
int startIndex = propertyPath.indexOf(PropertyAccessor.PROPERTY_KEY_PREFIX_CHAR);
if (startIndex != -1) {
int endIndex = propertyPath.indexOf(PropertyAccessor.PROPERTY_KEY_SUFFIX_CHAR);
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java b/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java
index 8f3c96e138e..4026ee055c0 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java
@@ -214,10 +214,11 @@ class TypeConverterDelegate {
msg.append("Cannot convert value of type [").append(ClassUtils.getDescriptiveType(newValue));
msg.append("] to required type [").append(ClassUtils.getQualifiedName(requiredType)).append("]");
if (propertyName != null) {
- msg.append(" for property '" + propertyName + "'");
+ msg.append(" for property '").append(propertyName).append("'");
}
if (editor != null) {
- msg.append(": PropertyEditor [" + editor.getClass().getName() + "] returned inappropriate value");
+ msg.append(": PropertyEditor [").append(editor.getClass().getName()).append(
+ "] returned inappropriate value");
}
else {
msg.append(": no matching editors or conversion strategy found");
@@ -242,7 +243,7 @@ class TypeConverterDelegate {
}
if (editor == null && requiredType != null) {
// No custom editor -> check BeanWrapperImpl's default editors.
- editor = (PropertyEditor) this.propertyEditorRegistry.getDefaultEditor(requiredType);
+ editor = this.propertyEditorRegistry.getDefaultEditor(requiredType);
if (editor == null && !String.class.equals(requiredType)) {
// No BeanWrapper default editor -> check standard JavaBean editor.
editor = BeanUtils.findEditorByConvention(requiredType);
@@ -394,6 +395,7 @@ class TypeConverterDelegate {
}
}
+ @SuppressWarnings("unchecked")
protected Collection convertToTypedCollection(
Collection original, String propertyName, MethodParameter methodParam) {
@@ -445,6 +447,7 @@ class TypeConverterDelegate {
return (actuallyConverted ? convertedCopy : original);
}
+ @SuppressWarnings("unchecked")
protected Map convertToTypedMap(Map original, String propertyName, MethodParameter methodParam) {
Class keyType = null;
Class valueType = null;
@@ -466,6 +469,7 @@ class TypeConverterDelegate {
logger.debug("Map of type [" + original.getClass().getName() +
"] returned null Iterator - injecting original Map as-is");
}
+ return original;
}
convertedCopy = CollectionFactory.createApproximateMap(original, original.size());
}
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java
index f2b4cbd4583..0265791aa18 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java
@@ -85,7 +85,7 @@ public abstract class BeanFactoryUtils {
* @see org.springframework.beans.factory.support.DefaultBeanNameGenerator
*/
public static boolean isGeneratedBeanName(String name) {
- return (name != null && name.indexOf(GENERATED_BEAN_NAME_SEPARATOR) != -1);
+ return (name != null && name.contains(GENERATED_BEAN_NAME_SEPARATOR));
}
/**
@@ -298,10 +298,10 @@ public abstract class BeanFactoryUtils {
* if 0 or more than 1 beans of the given type were found
* @throws BeansException if the bean could not be created
*/
- public static Object beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class type)
+ public static T beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class type)
throws BeansException {
- Map beansOfType = beansOfTypeIncludingAncestors(lbf, type);
+ Map beansOfType = beansOfTypeIncludingAncestors(lbf, type);
if (beansOfType.size() == 1) {
return beansOfType.values().iterator().next();
}
@@ -335,11 +335,11 @@ public abstract class BeanFactoryUtils {
* if 0 or more than 1 beans of the given type were found
* @throws BeansException if the bean could not be created
*/
- public static Object beanOfTypeIncludingAncestors(
- ListableBeanFactory lbf, Class type, boolean includeNonSingletons, boolean allowEagerInit)
- throws BeansException {
+ public static T beanOfTypeIncludingAncestors(
+ ListableBeanFactory lbf, Class type, boolean includeNonSingletons, boolean allowEagerInit)
+ throws BeansException {
- Map beansOfType = beansOfTypeIncludingAncestors(lbf, type, includeNonSingletons, allowEagerInit);
+ Map beansOfType = beansOfTypeIncludingAncestors(lbf, type, includeNonSingletons, allowEagerInit);
if (beansOfType.size() == 1) {
return beansOfType.values().iterator().next();
}
@@ -364,9 +364,9 @@ public abstract class BeanFactoryUtils {
* if 0 or more than 1 beans of the given type were found
* @throws BeansException if the bean could not be created
*/
- public static Object beanOfType(ListableBeanFactory lbf, Class type) throws BeansException {
+ public static T beanOfType(ListableBeanFactory lbf, Class type) throws BeansException {
Assert.notNull(lbf, "ListableBeanFactory must not be null");
- Map beansOfType = lbf.getBeansOfType(type);
+ Map beansOfType = lbf.getBeansOfType(type);
if (beansOfType.size() == 1) {
return beansOfType.values().iterator().next();
}
@@ -399,12 +399,12 @@ public abstract class BeanFactoryUtils {
* if 0 or more than 1 beans of the given type were found
* @throws BeansException if the bean could not be created
*/
- public static Object beanOfType(
- ListableBeanFactory lbf, Class type, boolean includeNonSingletons, boolean allowEagerInit)
- throws BeansException {
+ public static T beanOfType(
+ ListableBeanFactory lbf, Class type, boolean includeNonSingletons, boolean allowEagerInit)
+ throws BeansException {
Assert.notNull(lbf, "ListableBeanFactory must not be null");
- Map beansOfType = lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit);
+ Map beansOfType = lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit);
if (beansOfType.size() == 1) {
return beansOfType.values().iterator().next();
}
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java
index 0b16a0557e0..aea944f01b2 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java
@@ -16,7 +16,6 @@
package org.springframework.beans.factory.config;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -137,8 +136,7 @@ public class BeanDefinitionVisitor {
protected void visitPropertyValues(MutablePropertyValues pvs) {
PropertyValue[] pvArray = pvs.getPropertyValues();
- for (int i = 0; i < pvArray.length; i++) {
- PropertyValue pv = pvArray[i];
+ for (PropertyValue pv : pvArray) {
Object newVal = resolveValue(pv.getValue());
if (!ObjectUtils.nullSafeEquals(newVal, pv.getValue())) {
pvs.addPropertyValue(pv.getName(), newVal);
@@ -146,10 +144,8 @@ public class BeanDefinitionVisitor {
}
}
- protected void visitIndexedArgumentValues(Map ias) {
- for (Iterator it = ias.values().iterator(); it.hasNext();) {
- ConstructorArgumentValues.ValueHolder valueHolder =
- (ConstructorArgumentValues.ValueHolder) it.next();
+ protected void visitIndexedArgumentValues(Map ias) {
+ for (ConstructorArgumentValues.ValueHolder valueHolder : ias.values()) {
Object newVal = resolveValue(valueHolder.getValue());
if (!ObjectUtils.nullSafeEquals(newVal, valueHolder.getValue())) {
valueHolder.setValue(newVal);
@@ -157,10 +153,8 @@ public class BeanDefinitionVisitor {
}
}
- protected void visitGenericArgumentValues(List gas) {
- for (Iterator it = gas.iterator(); it.hasNext();) {
- ConstructorArgumentValues.ValueHolder valueHolder =
- (ConstructorArgumentValues.ValueHolder) it.next();
+ protected void visitGenericArgumentValues(List gas) {
+ for (ConstructorArgumentValues.ValueHolder valueHolder : gas) {
Object newVal = resolveValue(valueHolder.getValue());
if (!ObjectUtils.nullSafeEquals(newVal, valueHolder.getValue())) {
valueHolder.setValue(newVal);
@@ -212,6 +206,7 @@ public class BeanDefinitionVisitor {
return value;
}
+ @SuppressWarnings("unchecked")
protected void visitList(List listVal) {
for (int i = 0; i < listVal.size(); i++) {
Object elem = listVal.get(i);
@@ -222,11 +217,11 @@ public class BeanDefinitionVisitor {
}
}
+ @SuppressWarnings("unchecked")
protected void visitSet(Set setVal) {
Set newContent = new LinkedHashSet();
boolean entriesModified = false;
- for (Iterator it = setVal.iterator(); it.hasNext();) {
- Object elem = it.next();
+ for (Object elem : setVal) {
int elemHash = (elem != null ? elem.hashCode() : 0);
Object newVal = resolveValue(elem);
int newValHash = (newVal != null ? newVal.hashCode() : 0);
@@ -239,11 +234,11 @@ public class BeanDefinitionVisitor {
}
}
- protected void visitMap(Map mapVal) {
+ @SuppressWarnings("unchecked")
+ protected void visitMap(Map, ?> mapVal) {
Map newContent = new LinkedHashMap();
boolean entriesModified = false;
- for (Iterator it = mapVal.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ for (Map.Entry entry : mapVal.entrySet()) {
Object key = entry.getKey();
int keyHash = (key != null ? key.hashCode() : 0);
Object newKey = resolveValue(key);
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java
index 49eba911199..be9b43384b8 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java
@@ -322,11 +322,11 @@ public class ConstructorArgumentValues {
this.indexedArgumentValues.size() != that.indexedArgumentValues.size()) {
return false;
}
- Iterator it1 = this.genericArgumentValues.iterator();
- Iterator it2 = that.genericArgumentValues.iterator();
+ Iterator it1 = this.genericArgumentValues.iterator();
+ Iterator it2 = that.genericArgumentValues.iterator();
while (it1.hasNext() && it2.hasNext()) {
- ValueHolder vh1 = (ValueHolder) it1.next();
- ValueHolder vh2 = (ValueHolder) it2.next();
+ ValueHolder vh1 = it1.next();
+ ValueHolder vh2 = it2.next();
if (!vh1.contentEquals(vh2)) {
return false;
}
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java
index 07a14fbb6af..9c701cd08c4 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java
@@ -16,7 +16,6 @@
package org.springframework.beans.factory.config;
-import java.util.Iterator;
import java.util.Map;
import org.springframework.beans.BeanUtils;
@@ -45,7 +44,7 @@ import org.springframework.util.ClassUtils;
*/
public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClassLoaderAware, Ordered {
- private Map scopes;
+ private Map scopes;
private int order = Ordered.LOWEST_PRECEDENCE;
@@ -58,7 +57,7 @@ public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClas
* is expected to be the corresponding custom {@link Scope} instance
* or class name.
*/
- public void setScopes(Map scopes) {
+ public void setScopes(Map scopes) {
this.scopes = scopes;
}
@@ -77,31 +76,25 @@ public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClas
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (this.scopes != null) {
- for (Iterator it = this.scopes.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- Object key = entry.getKey();
- if (!(key instanceof String)) {
- throw new IllegalArgumentException(
- "Invalid scope key [" + key + "]: only Strings allowed");
- }
- String scopeName = (String) key;
+ for (Map.Entry entry : this.scopes.entrySet()) {
+ String scopeKey = entry.getKey();
Object value = entry.getValue();
if (value instanceof Scope) {
- beanFactory.registerScope(scopeName, (Scope) value);
+ beanFactory.registerScope(scopeKey, (Scope) value);
}
else if (value instanceof Class) {
Class scopeClass = (Class) value;
Assert.isAssignable(Scope.class, scopeClass);
- beanFactory.registerScope(scopeName, (Scope) BeanUtils.instantiateClass(scopeClass));
+ beanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));
}
else if (value instanceof String) {
Class scopeClass = ClassUtils.resolveClassName((String) value, this.beanClassLoader);
Assert.isAssignable(Scope.class, scopeClass);
- beanFactory.registerScope(scopeName, (Scope) BeanUtils.instantiateClass(scopeClass));
+ beanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));
}
else {
throw new IllegalArgumentException("Mapped value [" + value + "] for scope key [" +
- key + "] is not an instance of required type [" + Scope.class.getName() +
+ scopeKey + "] is not an instance of required type [" + Scope.class.getName() +
"] or a corresponding Class or String value indicating a Scope implementation");
}
}
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java
index 6d40aba2d69..557bea793ab 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.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,13 +17,11 @@
package org.springframework.beans.factory.config;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.TypeConverter;
import org.springframework.core.GenericCollectionTypeResolver;
-import org.springframework.core.JdkVersion;
/**
* Simple factory for shared List instances. Allows for central setup
@@ -71,6 +69,7 @@ public class ListFactoryBean extends AbstractFactoryBean {
}
@Override
+ @SuppressWarnings("unchecked")
protected Object createInstance() {
if (this.sourceList == null) {
throw new IllegalArgumentException("'sourceList' is required");
@@ -88,8 +87,8 @@ public class ListFactoryBean extends AbstractFactoryBean {
}
if (valueType != null) {
TypeConverter converter = getBeanTypeConverter();
- for (Iterator it = this.sourceList.iterator(); it.hasNext();) {
- result.add(converter.convertIfNecessary(it.next(), valueType));
+ for (Object elem : this.sourceList) {
+ result.add(converter.convertIfNecessary(elem, valueType));
}
}
else {
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.java
index a20f29120dc..b2a183b7f49 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.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,14 +16,12 @@
package org.springframework.beans.factory.config;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.TypeConverter;
import org.springframework.core.GenericCollectionTypeResolver;
-import org.springframework.core.JdkVersion;
/**
* Simple factory for shared Map instances. Allows for central setup
@@ -36,7 +34,7 @@ import org.springframework.core.JdkVersion;
*/
public class MapFactoryBean extends AbstractFactoryBean {
- private Map sourceMap;
+ private Map, ?> sourceMap;
private Class targetMapClass;
@@ -71,6 +69,7 @@ public class MapFactoryBean extends AbstractFactoryBean {
}
@Override
+ @SuppressWarnings("unchecked")
protected Object createInstance() {
if (this.sourceMap == null) {
throw new IllegalArgumentException("'sourceMap' is required");
@@ -90,8 +89,7 @@ public class MapFactoryBean extends AbstractFactoryBean {
}
if (keyType != null || valueType != null) {
TypeConverter converter = getBeanTypeConverter();
- for (Iterator it = this.sourceMap.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ for (Map.Entry entry : this.sourceMap.entrySet()) {
Object convertedKey = converter.convertIfNecessary(entry.getKey(), keyType);
Object convertedValue = converter.convertIfNecessary(entry.getValue(), valueType);
result.put(convertedKey, convertedValue);
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.java
index 4b62b57fa5d..692b528d73f 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.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.config;
-import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -70,6 +69,7 @@ public class SetFactoryBean extends AbstractFactoryBean {
}
@Override
+ @SuppressWarnings("unchecked")
protected Object createInstance() {
if (this.sourceSet == null) {
throw new IllegalArgumentException("'sourceSet' is required");
@@ -87,8 +87,8 @@ public class SetFactoryBean extends AbstractFactoryBean {
}
if (valueType != null) {
TypeConverter converter = getBeanTypeConverter();
- for (Iterator it = this.sourceSet.iterator(); it.hasNext();) {
- result.add(converter.convertIfNecessary(it.next(), valueType));
+ for (Object elem : this.sourceSet) {
+ result.add(converter.convertIfNecessary(elem, valueType));
}
}
else {
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
index b72628fbced..a3273e0b47b 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
@@ -1124,8 +1124,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
if (filtered == null) {
List pds =
new LinkedList(Arrays.asList(bw.getPropertyDescriptors()));
- for (Iterator it = pds.iterator(); it.hasNext();) {
- PropertyDescriptor pd = (PropertyDescriptor) it.next();
+ for (Iterator it = pds.iterator(); it.hasNext();) {
+ PropertyDescriptor pd = it.next();
if (isExcludedFromDependencyCheck(pd)) {
it.remove();
}
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java
index 52094305701..be822c9fcb0 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java
@@ -500,9 +500,9 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
// Remove destroyed bean from other beans' dependencies.
synchronized (this.dependentBeanMap) {
- for (Iterator it = this.dependentBeanMap.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- Set dependenciesToClean = (Set) entry.getValue();
+ for (Iterator>> it = this.dependentBeanMap.entrySet().iterator(); it.hasNext();) {
+ Map.Entry> entry = it.next();
+ Set dependenciesToClean = entry.getValue();
dependenciesToClean.remove(beanName);
if (dependenciesToClean.isEmpty()) {
it.remove();
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
index 907ede0a966..30a63594d78 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
@@ -20,7 +20,6 @@ import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -28,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
@@ -62,7 +62,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
private final boolean enforceDestroyMethod;
- private List beanPostProcessors;
+ private List beanPostProcessors;
/**
@@ -73,8 +73,8 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
* @param postProcessors the List of BeanPostProcessors
* (potentially DestructionAwareBeanPostProcessor), if any
*/
- public DisposableBeanAdapter(
- Object bean, String beanName, RootBeanDefinition beanDefinition, List postProcessors) {
+ public DisposableBeanAdapter(Object bean, String beanName, RootBeanDefinition beanDefinition,
+ List postProcessors) {
Assert.notNull(bean, "Bean must not be null");
this.bean = bean;
@@ -100,7 +100,8 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
* @param postProcessors the List of DestructionAwareBeanPostProcessors, if any
*/
private DisposableBeanAdapter(Object bean, String beanName, boolean invokeDisposableBean,
- String destroyMethodName, boolean enforceDestroyMethod, List postProcessors) {
+ String destroyMethodName, boolean enforceDestroyMethod,
+ List postProcessors) {
this.bean = bean;
this.beanName = beanName;
@@ -110,19 +111,19 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
this.beanPostProcessors = postProcessors;
}
+
/**
* Search for all DestructionAwareBeanPostProcessors in the List.
* @param postProcessors the List to search
* @return the filtered List of DestructionAwareBeanPostProcessors
*/
- private List filterPostProcessors(List postProcessors) {
- List filteredPostProcessors = null;
+ private List filterPostProcessors(List postProcessors) {
+ List filteredPostProcessors = null;
if (postProcessors != null && !postProcessors.isEmpty()) {
- filteredPostProcessors = new ArrayList(postProcessors.size());
- for (Iterator it = postProcessors.iterator(); it.hasNext();) {
- Object postProcessor = it.next();
+ filteredPostProcessors = new ArrayList(postProcessors.size());
+ for (BeanPostProcessor postProcessor : postProcessors) {
if (postProcessor instanceof DestructionAwareBeanPostProcessor) {
- filteredPostProcessors.add(postProcessor);
+ filteredPostProcessors.add((DestructionAwareBeanPostProcessor) postProcessor);
}
}
}
@@ -137,8 +138,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
public void destroy() {
if (this.beanPostProcessors != null && !this.beanPostProcessors.isEmpty()) {
for (int i = this.beanPostProcessors.size() - 1; i >= 0; i--) {
- ((DestructionAwareBeanPostProcessor) this.beanPostProcessors.get(i)).postProcessBeforeDestruction(
- this.bean, this.beanName);
+ this.beanPostProcessors.get(i).postProcessBeforeDestruction(this.bean, this.beanName);
}
}
@@ -237,11 +237,10 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
* filtering out non-serializable BeanPostProcessors.
*/
protected Object writeReplace() {
- List serializablePostProcessors = null;
+ List serializablePostProcessors = null;
if (this.beanPostProcessors != null) {
- serializablePostProcessors = new ArrayList();
- for (Iterator it = this.beanPostProcessors.iterator(); it.hasNext();) {
- Object postProcessor = it.next();
+ serializablePostProcessors = new ArrayList();
+ for (DestructionAwareBeanPostProcessor postProcessor : this.beanPostProcessors) {
if (postProcessor instanceof Serializable) {
serializablePostProcessors.add(postProcessor);
}
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java
index b7062a38630..908b2c99a9b 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java
@@ -18,10 +18,8 @@ package org.springframework.beans.factory.support;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
@@ -56,7 +54,7 @@ import org.springframework.util.StringUtils;
public class StaticListableBeanFactory implements ListableBeanFactory {
/** Map from bean name to bean instance */
- private final Map beans = new HashMap();
+ private final Map beans = new HashMap();
/**
@@ -99,13 +97,13 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
}
return bean;
}
-
- public Object getBean(String name, Class requiredType) throws BeansException {
+
+ public T getBean(String name, Class requiredType) throws BeansException {
Object bean = getBean(name);
if (requiredType != null && !requiredType.isAssignableFrom(bean.getClass())) {
throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
}
- return bean;
+ return (T) bean;
}
public Object getBean(String name, Object[] args) throws BeansException {
@@ -181,22 +179,19 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
public String[] getBeanNamesForType(Class type, boolean includeNonSingletons, boolean includeFactoryBeans) {
boolean isFactoryType = (type != null && FactoryBean.class.isAssignableFrom(type));
- List matches = new ArrayList();
- Set keys = this.beans.keySet();
- Iterator it = keys.iterator();
- while (it.hasNext()) {
- String name = (String) it.next();
+ List matches = new ArrayList();
+ for (String name : this.beans.keySet()) {
Object beanInstance = this.beans.get(name);
if (beanInstance instanceof FactoryBean && !isFactoryType) {
if (includeFactoryBeans) {
Class objectType = ((FactoryBean) beanInstance).getObjectType();
- if (objectType != null && type.isAssignableFrom(objectType)) {
+ if (objectType != null && (type == null || type.isAssignableFrom(objectType))) {
matches.add(name);
}
}
}
else {
- if (type.isInstance(beanInstance)) {
+ if (type == null || type.isInstance(beanInstance)) {
matches.add(name);
}
}
@@ -204,22 +199,19 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
return StringUtils.toStringArray(matches);
}
- public Map getBeansOfType(Class type) throws BeansException {
+ public Map getBeansOfType(Class type) throws BeansException {
return getBeansOfType(type, true, true);
}
- public Map getBeansOfType(Class type, boolean includeNonSingletons, boolean includeFactoryBeans)
+ public Map getBeansOfType(Class type, boolean includeNonSingletons, boolean includeFactoryBeans)
throws BeansException {
boolean isFactoryType = (type != null && FactoryBean.class.isAssignableFrom(type));
- Map matches = new HashMap();
+ Map matches = new HashMap();
- Iterator it = this.beans.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry entry = (Map.Entry) it.next();
- String beanName = (String) entry.getKey();
+ for (Map.Entry entry : beans.entrySet()) {
+ String beanName = entry.getKey();
Object beanInstance = entry.getValue();
-
// Is bean a FactoryBean?
if (beanInstance instanceof FactoryBean && !isFactoryType) {
if (includeFactoryBeans) {
@@ -227,19 +219,19 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
FactoryBean factory = (FactoryBean) beanInstance;
Class objectType = factory.getObjectType();
if ((includeNonSingletons || factory.isSingleton()) &&
- objectType != null && type.isAssignableFrom(objectType)) {
- matches.put(beanName, getBean(beanName));
+ objectType != null && (type == null || type.isAssignableFrom(objectType))) {
+ matches.put(beanName, getBean(beanName, type));
}
}
}
else {
- if (type.isInstance(beanInstance)) {
+ if (type == null || type.isInstance(beanInstance)) {
// If type to match is FactoryBean, return FactoryBean itself.
// Else, return bean instance.
if (isFactoryType) {
beanName = FACTORY_BEAN_PREFIX + beanName;
}
- matches.put(beanName, beanInstance);
+ matches.put(beanName, (T) beanInstance);
}
}
}
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 1f72ce98f58..e8a1c45e700 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
@@ -19,7 +19,6 @@ package org.springframework.beans.factory.xml;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -737,9 +736,8 @@ public class BeanDefinitionParserDelegate {
String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE);
ReplaceOverride replaceOverride = new ReplaceOverride(name, callback);
// Look for arg-type match elements.
- List argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT);
- for (Iterator it = argTypeEles.iterator(); it.hasNext();) {
- Element argTypeEle = (Element) it.next();
+ List argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT);
+ for (Element argTypeEle : argTypeEles) {
replaceOverride.addTypeIdentifier(argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE));
}
replaceOverride.setSource(extractSource(replacedMethodEle));
@@ -1109,17 +1107,15 @@ public class BeanDefinitionParserDelegate {
String defaultKeyTypeClassName = mapEle.getAttribute(KEY_TYPE_ATTRIBUTE);
String defaultValueTypeClassName = mapEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
- List entryEles = DomUtils.getChildElementsByTagName(mapEle, ENTRY_ELEMENT);
+ List entryEles = DomUtils.getChildElementsByTagName(mapEle, ENTRY_ELEMENT);
ManagedMap map = new ManagedMap(entryEles.size());
map.setMergeEnabled(parseMergeAttribute(mapEle));
map.setSource(extractSource(mapEle));
- for (Iterator it = entryEles.iterator(); it.hasNext();) {
- Element entryEle = (Element) it.next();
+ for (Element entryEle : entryEles) {
// Should only have one value child element: ref, value, list, etc.
// Optionally, there might be a key child element.
NodeList entrySubNodes = entryEle.getChildNodes();
-
Element keyEle = null;
Element valueEle = null;
for (int j = 0; j < entrySubNodes.getLength(); j++) {
@@ -1254,14 +1250,12 @@ public class BeanDefinitionParserDelegate {
props.setSource(extractSource(propsEle));
props.setMergeEnabled(parseMergeAttribute(propsEle));
- List propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT);
- for (Iterator it = propEles.iterator(); it.hasNext();) {
- Element propEle = (Element) it.next();
+ List propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT);
+ for (Element propEle : propEles) {
String key = propEle.getAttribute(KEY_ATTRIBUTE);
// Trim the text value to avoid unwanted whitespace
// caused by typical XML formatting.
String value = DomUtils.getTextValue(propEle).trim();
-
TypedStringValue keyHolder = new TypedStringValue(key);
keyHolder.setSource(extractSource(propEle));
TypedStringValue valueHolder = new TypedStringValue(value);
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.java b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.java
index e882687024c..9f88973578e 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.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.
@@ -117,8 +117,8 @@ public class CustomCollectionEditor extends PropertyEditorSupport {
// Convert Collection elements.
Collection source = (Collection) value;
Collection target = createCollection(this.collectionType, source.size());
- for (Iterator it = source.iterator(); it.hasNext();) {
- target.add(convertElement(it.next()));
+ for (Object elem : source) {
+ target.add(convertElement(elem));
}
super.setValue(target);
}
diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java
index ef5ac892208..d66eca4f17c 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.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,7 +17,6 @@
package org.springframework.beans.propertyeditors;
import java.beans.PropertyEditorSupport;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.SortedMap;
@@ -105,10 +104,9 @@ public class CustomMapEditor extends PropertyEditorSupport {
}
else if (value instanceof Map) {
// Convert Map elements.
- Map source = (Map) value;
+ Map, ?> source = (Map) value;
Map target = createMap(this.mapType, source.size());
- for (Iterator it = source.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ for (Map.Entry entry : source.entrySet()) {
target.put(convertKey(entry.getKey()), convertValue(entry.getValue()));
}
super.setValue(target);
diff --git a/org.springframework.context.support/src/main/java/org/springframework/scheduling/commonj/TimerManagerFactoryBean.java b/org.springframework.context.support/src/main/java/org/springframework/scheduling/commonj/TimerManagerFactoryBean.java
index 572b2d96773..3a312234753 100644
--- a/org.springframework.context.support/src/main/java/org/springframework/scheduling/commonj/TimerManagerFactoryBean.java
+++ b/org.springframework.context.support/src/main/java/org/springframework/scheduling/commonj/TimerManagerFactoryBean.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.
@@ -65,7 +65,7 @@ public class TimerManagerFactoryBean extends JndiLocatorSupport
private ScheduledTimerListener[] scheduledTimerListeners;
- private final List timers = new LinkedList();
+ private final List timers = new LinkedList();
/**
@@ -145,20 +145,20 @@ public class TimerManagerFactoryBean extends JndiLocatorSupport
}
if (this.scheduledTimerListeners != null) {
- for (int i = 0; i < this.scheduledTimerListeners.length; i++) {
- ScheduledTimerListener scheduledTask = this.scheduledTimerListeners[i];
+ for (ScheduledTimerListener scheduledTask : this.scheduledTimerListeners) {
Timer timer = null;
if (scheduledTask.isOneTimeTask()) {
timer = this.timerManager.schedule(scheduledTask.getTimerListener(), scheduledTask.getDelay());
}
else {
if (scheduledTask.isFixedRate()) {
- timer = this.timerManager.scheduleAtFixedRate(
- scheduledTask.getTimerListener(), scheduledTask.getDelay(), scheduledTask.getPeriod());
+ timer = this.timerManager
+ .scheduleAtFixedRate(scheduledTask.getTimerListener(), scheduledTask.getDelay(),
+ scheduledTask.getPeriod());
}
else {
- timer = this.timerManager.schedule(
- scheduledTask.getTimerListener(), scheduledTask.getDelay(), scheduledTask.getPeriod());
+ timer = this.timerManager.schedule(scheduledTask.getTimerListener(), scheduledTask.getDelay(),
+ scheduledTask.getPeriod());
}
}
this.timers.add(timer);
@@ -231,8 +231,7 @@ public class TimerManagerFactoryBean extends JndiLocatorSupport
*/
public void destroy() {
// Cancel all registered timers.
- for (Iterator it = this.timers.iterator(); it.hasNext();) {
- Timer timer = (Timer) it.next();
+ for (Timer timer : this.timers) {
try {
timer.cancel();
}
diff --git a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java
index 04ea6c3253d..e3473520fc6 100644
--- a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java
+++ b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java
@@ -18,7 +18,6 @@ package org.springframework.scheduling.quartz;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -63,11 +62,11 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
private String[] jobSchedulingDataLocations;
- private List jobDetails;
+ private List jobDetails;
- private Map calendars;
+ private Map calendars;
- private List triggers;
+ private List triggers;
private SchedulerListener[] schedulerListeners;
@@ -132,7 +131,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
public void setJobDetails(JobDetail[] jobDetails) {
// Use modifiable ArrayList here, to allow for further adding of
// JobDetail objects during autodetection of JobDetailAwareTriggers.
- this.jobDetails = new ArrayList(Arrays.asList(jobDetails));
+ this.jobDetails = new ArrayList(Arrays.asList(jobDetails));
}
/**
@@ -143,7 +142,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
* @see org.quartz.Calendar
* @see org.quartz.Trigger#setCalendarName
*/
- public void setCalendars(Map calendars) {
+ public void setCalendars(Map calendars) {
this.calendars = calendars;
}
@@ -242,37 +241,33 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
ClassLoadHelper clh = new ResourceLoaderClassLoadHelper(this.resourceLoader);
clh.initialize();
JobSchedulingDataProcessor dataProcessor = new JobSchedulingDataProcessor(clh, true, true);
- for (int i = 0; i < this.jobSchedulingDataLocations.length; i++) {
- dataProcessor.processFileAndScheduleJobs(
- this.jobSchedulingDataLocations[i], getScheduler(), this.overwriteExistingJobs);
+ for (String location : this.jobSchedulingDataLocations) {
+ dataProcessor.processFileAndScheduleJobs(location, getScheduler(), this.overwriteExistingJobs);
}
}
// Register JobDetails.
if (this.jobDetails != null) {
- for (Iterator it = this.jobDetails.iterator(); it.hasNext();) {
- JobDetail jobDetail = (JobDetail) it.next();
+ for (JobDetail jobDetail : this.jobDetails) {
addJobToScheduler(jobDetail);
}
}
else {
// Create empty list for easier checks when registering triggers.
- this.jobDetails = new LinkedList();
+ this.jobDetails = new LinkedList();
}
// Register Calendars.
if (this.calendars != null) {
- for (Iterator it = this.calendars.keySet().iterator(); it.hasNext();) {
- String calendarName = (String) it.next();
- Calendar calendar = (Calendar) this.calendars.get(calendarName);
+ for (String calendarName : this.calendars.keySet()) {
+ Calendar calendar = this.calendars.get(calendarName);
getScheduler().addCalendar(calendarName, calendar, true, true);
}
}
// Register Triggers.
if (this.triggers != null) {
- for (Iterator it = this.triggers.iterator(); it.hasNext();) {
- Trigger trigger = (Trigger) it.next();
+ for (Trigger trigger : this.triggers) {
addTriggerToScheduler(trigger);
}
}
@@ -292,8 +287,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
throw (SchedulerException) ex;
}
if (ex instanceof Exception) {
- throw new SchedulerException(
- "Registration of jobs and triggers failed: " + ex.getMessage(), (Exception) ex);
+ throw new SchedulerException("Registration of jobs and triggers failed: " + ex.getMessage(), ex);
}
throw new SchedulerException("Registration of jobs and triggers failed: " + ex.getMessage());
}
@@ -371,28 +365,28 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
*/
protected void registerListeners() throws SchedulerException {
if (this.schedulerListeners != null) {
- for (int i = 0; i < this.schedulerListeners.length; i++) {
- getScheduler().addSchedulerListener(this.schedulerListeners[i]);
+ for (SchedulerListener listener : this.schedulerListeners) {
+ getScheduler().addSchedulerListener(listener);
}
}
if (this.globalJobListeners != null) {
- for (int i = 0; i < this.globalJobListeners.length; i++) {
- getScheduler().addGlobalJobListener(this.globalJobListeners[i]);
+ for (JobListener listener : this.globalJobListeners) {
+ getScheduler().addGlobalJobListener(listener);
}
}
if (this.jobListeners != null) {
- for (int i = 0; i < this.jobListeners.length; i++) {
- getScheduler().addJobListener(this.jobListeners[i]);
+ for (JobListener listener : this.jobListeners) {
+ getScheduler().addJobListener(listener);
}
}
if (this.globalTriggerListeners != null) {
- for (int i = 0; i < this.globalTriggerListeners.length; i++) {
- getScheduler().addGlobalTriggerListener(this.globalTriggerListeners[i]);
+ for (TriggerListener listener : this.globalTriggerListeners) {
+ getScheduler().addGlobalTriggerListener(listener);
}
}
if (this.triggerListeners != null) {
- for (int i = 0; i < this.triggerListeners.length; i++) {
- getScheduler().addTriggerListener(this.triggerListeners[i]);
+ for (TriggerListener listener : this.triggerListeners) {
+ getScheduler().addTriggerListener(listener);
}
}
}
diff --git a/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java b/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java
index de62f4ed0b9..21301fdd6c4 100644
--- a/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java
+++ b/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java
@@ -17,7 +17,6 @@
package org.springframework.context.annotation;
import java.lang.annotation.Annotation;
-import java.util.Iterator;
import java.util.Set;
import java.util.regex.Pattern;
@@ -134,8 +133,7 @@ public class ComponentScanBeanDefinitionParser implements BeanDefinitionParser {
Object source = readerContext.extractSource(element);
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);
- for (Iterator it = beanDefinitions.iterator(); it.hasNext();) {
- BeanDefinitionHolder beanDefHolder = (BeanDefinitionHolder) it.next();
+ for (BeanDefinitionHolder beanDefHolder : beanDefinitions) {
compositeDef.addNestedComponent(new BeanComponentDefinition(beanDefHolder));
}
diff --git a/org.springframework.context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java b/org.springframework.context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java
index b60efbf1366..0e604329830 100644
--- a/org.springframework.context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java
+++ b/org.springframework.context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java
@@ -108,7 +108,7 @@ public abstract class AbstractApplicationEventMulticaster implements Application
* @return a Collection of ApplicationListeners
* @see org.springframework.context.ApplicationListener
*/
- protected Collection getApplicationListeners() {
+ protected Collection getApplicationListeners() {
return this.applicationListeners;
}
diff --git a/org.springframework.context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java b/org.springframework.context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java
index 179e0761fac..a1348bdc880 100644
--- a/org.springframework.context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java
+++ b/org.springframework.context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.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,8 +16,6 @@
package org.springframework.context.event;
-import java.util.Iterator;
-
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.task.SyncTaskExecutor;
@@ -71,8 +69,7 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM
public void multicastEvent(final ApplicationEvent event) {
- for (Iterator it = getApplicationListeners().iterator(); it.hasNext();) {
- final ApplicationListener listener = (ApplicationListener) it.next();
+ for (final ApplicationListener listener : getApplicationListeners()) {
getTaskExecutor().execute(new Runnable() {
public void run() {
listener.onApplicationEvent(event);
diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java b/org.springframework.context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java
index 9258ae646a8..04eae2b9ea2 100644
--- a/org.springframework.context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java
+++ b/org.springframework.context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java
@@ -22,7 +22,6 @@ import java.io.InputStreamReader;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -112,10 +111,11 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
private ResourceLoader resourceLoader = new DefaultResourceLoader();
/** Cache to hold filename lists per Locale */
- private final Map cachedFilenames = new HashMap();
+ private final Map>> cachedFilenames =
+ new HashMap>>();
/** Cache to hold already loaded properties per filename */
- private final Map cachedProperties = new HashMap();
+ private final Map cachedProperties = new HashMap();
/** Cache to hold merged loaded properties per basename */
private final Map cachedMergedProperties = new HashMap();
@@ -271,10 +271,9 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
}
}
else {
- for (int i = 0; i < this.basenames.length; i++) {
- List filenames = calculateAllFilenames(this.basenames[i], locale);
- for (int j = 0; j < filenames.size(); j++) {
- String filename = (String) filenames.get(j);
+ for (String basename : this.basenames) {
+ List filenames = calculateAllFilenames(basename, locale);
+ for (String filename : filenames) {
PropertiesHolder propHolder = getProperties(filename);
String result = propHolder.getProperty(code);
if (result != null) {
@@ -300,8 +299,8 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
}
}
else {
- for (int i = 0; i < this.basenames.length; i++) {
- List filenames = calculateAllFilenames(this.basenames[i], locale);
+ for (String basename : this.basenames) {
+ List filenames = calculateAllFilenames(basename, locale);
for (int j = 0; j < filenames.size(); j++) {
String filename = (String) filenames.get(j);
PropertiesHolder propHolder = getProperties(filename);
@@ -357,21 +356,20 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
* @see #setFallbackToSystemLocale
* @see #calculateFilenamesForLocale
*/
- protected List calculateAllFilenames(String basename, Locale locale) {
+ protected List calculateAllFilenames(String basename, Locale locale) {
synchronized (this.cachedFilenames) {
- Map localeMap = (Map) this.cachedFilenames.get(basename);
+ Map> localeMap = this.cachedFilenames.get(basename);
if (localeMap != null) {
- List filenames = (List) localeMap.get(locale);
+ List filenames = localeMap.get(locale);
if (filenames != null) {
return filenames;
}
}
- List filenames = new ArrayList(7);
+ List filenames = new ArrayList(7);
filenames.addAll(calculateFilenamesForLocale(basename, locale));
if (this.fallbackToSystemLocale && !locale.equals(Locale.getDefault())) {
- List fallbackFilenames = calculateFilenamesForLocale(basename, Locale.getDefault());
- for (Iterator it = fallbackFilenames.iterator(); it.hasNext();) {
- String fallbackFilename = (String) it.next();
+ List fallbackFilenames = calculateFilenamesForLocale(basename, Locale.getDefault());
+ for (String fallbackFilename : fallbackFilenames) {
if (!filenames.contains(fallbackFilename)) {
// Entry for fallback locale that isn't already in filenames list.
filenames.add(fallbackFilename);
@@ -383,7 +381,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
localeMap.put(locale, filenames);
}
else {
- localeMap = new HashMap();
+ localeMap = new HashMap>();
localeMap.put(locale, filenames);
this.cachedFilenames.put(basename, localeMap);
}
@@ -400,8 +398,8 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
* @param locale the locale
* @return the List of filenames to check
*/
- protected List calculateFilenamesForLocale(String basename, Locale locale) {
- List result = new ArrayList(3);
+ protected List calculateFilenamesForLocale(String basename, Locale locale) {
+ List result = new ArrayList(3);
String language = locale.getLanguage();
String country = locale.getCountry();
String variant = locale.getVariant();
@@ -434,7 +432,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
*/
protected PropertiesHolder getProperties(String filename) {
synchronized (this.cachedProperties) {
- PropertiesHolder propHolder = (PropertiesHolder) this.cachedProperties.get(filename);
+ PropertiesHolder propHolder = this.cachedProperties.get(filename);
if (propHolder != null &&
(propHolder.getRefreshTimestamp() < 0 ||
propHolder.getRefreshTimestamp() > System.currentTimeMillis() - this.cacheMillis)) {
@@ -603,7 +601,8 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
private long refreshTimestamp = -1;
/** Cache to hold already generated MessageFormats per message code */
- private final Map cachedMessageFormats = new HashMap();
+ private final Map> cachedMessageFormats =
+ new HashMap>();
public PropertiesHolder(Properties properties, long fileTimestamp) {
this.properties = properties;
@@ -641,9 +640,9 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
return null;
}
synchronized (this.cachedMessageFormats) {
- Map localeMap = (Map) this.cachedMessageFormats.get(code);
+ Map localeMap = this.cachedMessageFormats.get(code);
if (localeMap != null) {
- MessageFormat result = (MessageFormat) localeMap.get(locale);
+ MessageFormat result = localeMap.get(locale);
if (result != null) {
return result;
}
@@ -651,7 +650,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
String msg = this.properties.getProperty(code);
if (msg != null) {
if (localeMap == null) {
- localeMap = new HashMap();
+ localeMap = new HashMap();
this.cachedMessageFormats.put(code, localeMap);
}
MessageFormat result = createMessageFormat(msg, locale);
diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/StaticMessageSource.java b/org.springframework.context/src/main/java/org/springframework/context/support/StaticMessageSource.java
index 06ab664bf45..af803213c8d 100644
--- a/org.springframework.context/src/main/java/org/springframework/context/support/StaticMessageSource.java
+++ b/org.springframework.context/src/main/java/org/springframework/context/support/StaticMessageSource.java
@@ -18,7 +18,6 @@ package org.springframework.context.support;
import java.text.MessageFormat;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
@@ -37,12 +36,12 @@ import org.springframework.util.Assert;
public class StaticMessageSource extends AbstractMessageSource {
/** Map from 'code + locale' keys to message Strings */
- private final Map messages = new HashMap();
+ private final Map messages = new HashMap();
@Override
protected MessageFormat resolveCode(String code, Locale locale) {
- return (MessageFormat) this.messages.get(code + "_" + locale.toString());
+ return this.messages.get(code + "_" + locale.toString());
}
/**
@@ -65,13 +64,12 @@ public class StaticMessageSource extends AbstractMessageSource {
* Associate the given message values with the given keys as codes.
* @param messages the messages to register, with messages codes
* as keys and message texts as values
- * @param locale the locale that the messages should be found within
+ * @param locale the locale that the messages should be found within
*/
- public void addMessages(Map messages, Locale locale) {
+ public void addMessages(Map messages, Locale locale) {
Assert.notNull(messages, "Messages Map must not be null");
- for (Iterator it = messages.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- addMessage(entry.getKey().toString(), locale, entry.getValue().toString());
+ for (Map.Entry entry : messages.entrySet()) {
+ addMessage(entry.getKey(), locale, entry.getValue());
}
}
diff --git a/org.springframework.context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java b/org.springframework.context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java
index 8f8de2a10c4..71d824b09e3 100644
--- a/org.springframework.context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java
+++ b/org.springframework.context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java
@@ -16,10 +16,8 @@
package org.springframework.jmx.support;
-import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
-
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.JMException;
@@ -106,7 +104,7 @@ public class MBeanRegistrationSupport {
/**
* The beans that have been registered by this exporter.
*/
- protected final Set registeredBeans = new LinkedHashSet();
+ protected final Set registeredBeans = new LinkedHashSet();
/**
* The action take when registering an MBean and finding that it already exists.
@@ -207,8 +205,8 @@ public class MBeanRegistrationSupport {
* Unregisters all beans that have been registered by an instance of this class.
*/
protected void unregisterBeans() {
- for (Iterator it = this.registeredBeans.iterator(); it.hasNext();) {
- doUnregister((ObjectName) it.next());
+ for (ObjectName objectName : this.registeredBeans) {
+ doUnregister(objectName);
}
this.registeredBeans.clear();
}
@@ -242,7 +240,7 @@ public class MBeanRegistrationSupport {
* Return the {@link ObjectName ObjectNames} of all registered beans.
*/
protected final ObjectName[] getRegisteredObjectNames() {
- return (ObjectName[]) this.registeredBeans.toArray(new ObjectName[this.registeredBeans.size()]);
+ return this.registeredBeans.toArray(new ObjectName[this.registeredBeans.size()]);
}
diff --git a/org.springframework.context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java b/org.springframework.context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java
index 1f31c84cc21..76e10b61328 100644
--- a/org.springframework.context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java
+++ b/org.springframework.context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java
@@ -168,7 +168,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
final DefaultListableBeanFactory scriptBeanFactory = new DefaultListableBeanFactory();
/** Map from bean name String to ScriptSource object */
- private final Map scriptSourceCache = new HashMap();
+ private final Map scriptSourceCache = new HashMap();
/**
@@ -202,9 +202,8 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
// Filter out BeanPostProcessors that are part of the AOP infrastructure,
// since those are only meant to apply to beans defined in the original factory.
- for (Iterator it = this.scriptBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
- BeanPostProcessor postProcessor = (BeanPostProcessor) it.next();
- if (postProcessor instanceof AopInfrastructureBean) {
+ for (Iterator it = this.scriptBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
+ if (it.next() instanceof AopInfrastructureBean) {
it.remove();
}
}
@@ -233,8 +232,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
String scriptedObjectBeanName = SCRIPTED_OBJECT_NAME_PREFIX + beanName;
prepareScriptBeans(bd, scriptFactoryBeanName, scriptedObjectBeanName);
- ScriptFactory scriptFactory =
- (ScriptFactory) this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
+ ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
ScriptSource scriptSource =
getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
Class[] interfaces = scriptFactory.getScriptInterfaces();
@@ -284,8 +282,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
String scriptedObjectBeanName = SCRIPTED_OBJECT_NAME_PREFIX + beanName;
prepareScriptBeans(bd, scriptFactoryBeanName, scriptedObjectBeanName);
- ScriptFactory scriptFactory =
- (ScriptFactory) this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
+ ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
ScriptSource scriptSource =
getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
boolean isFactoryBean = false;
@@ -334,8 +331,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
this.scriptBeanFactory.registerBeanDefinition(
scriptFactoryBeanName, createScriptFactoryBeanDefinition(bd));
- ScriptFactory scriptFactory =
- (ScriptFactory) this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
+ ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
ScriptSource scriptSource =
getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
Class[] interfaces = scriptFactory.getScriptInterfaces();
@@ -410,7 +406,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
*/
protected ScriptSource getScriptSource(String beanName, String scriptSourceLocator) {
synchronized (this.scriptSourceCache) {
- ScriptSource scriptSource = (ScriptSource) this.scriptSourceCache.get(beanName);
+ ScriptSource scriptSource = this.scriptSourceCache.get(beanName);
if (scriptSource == null) {
scriptSource = convertToScriptSource(beanName, scriptSourceLocator, this.resourceLoader);
this.scriptSourceCache.put(beanName, scriptSource);
@@ -457,8 +453,8 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
protected Class createConfigInterface(BeanDefinition bd, Class[] interfaces) {
InterfaceMaker maker = new InterfaceMaker();
PropertyValue[] pvs = bd.getPropertyValues().getPropertyValues();
- for (int i = 0; i < pvs.length; i++) {
- String propertyName = pvs[i].getName();
+ for (PropertyValue pv : pvs) {
+ String propertyName = pv.getName();
Class propertyType = BeanUtils.findPropertyType(propertyName, interfaces);
String setterName = "set" + StringUtils.capitalize(propertyName);
Signature signature = new Signature(setterName, Type.VOID_TYPE, new Type[] {Type.getType(propertyType)});
diff --git a/org.springframework.context/src/main/java/org/springframework/ui/context/support/ResourceBundleThemeSource.java b/org.springframework.context/src/main/java/org/springframework/ui/context/support/ResourceBundleThemeSource.java
index ccff153411a..9ba069d9215 100644
--- a/org.springframework.context/src/main/java/org/springframework/ui/context/support/ResourceBundleThemeSource.java
+++ b/org.springframework.context/src/main/java/org/springframework/ui/context/support/ResourceBundleThemeSource.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,7 +17,6 @@
package org.springframework.ui.context.support;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.apache.commons.logging.Log;
@@ -51,7 +50,7 @@ public class ResourceBundleThemeSource implements HierarchicalThemeSource {
private String basenamePrefix = "";
/** Map from theme name to Theme instance */
- private final Map themeCache = new HashMap();
+ private final Map themeCache = new HashMap();
public void setParentThemeSource(ThemeSource parent) {
@@ -60,9 +59,8 @@ public class ResourceBundleThemeSource implements HierarchicalThemeSource {
// Update existing Theme objects.
// Usually there shouldn't be any at the time of this call.
synchronized (this.themeCache) {
- Iterator it = this.themeCache.values().iterator();
- while (it.hasNext()) {
- initParent((Theme) it.next());
+ for (Theme theme : this.themeCache.values()) {
+ initParent(theme);
}
}
}
@@ -100,7 +98,7 @@ public class ResourceBundleThemeSource implements HierarchicalThemeSource {
return null;
}
synchronized (this.themeCache) {
- Theme theme = (Theme) this.themeCache.get(themeName);
+ Theme theme = this.themeCache.get(themeName);
if (theme == null) {
String basename = this.basenamePrefix + themeName;
MessageSource messageSource = createMessageSource(basename);
diff --git a/org.springframework.context/src/main/java/org/springframework/validation/AbstractBindingResult.java b/org.springframework.context/src/main/java/org/springframework/validation/AbstractBindingResult.java
index 6d19a1fc85c..6add9ee9e26 100644
--- a/org.springframework.context/src/main/java/org/springframework/validation/AbstractBindingResult.java
+++ b/org.springframework.context/src/main/java/org/springframework/validation/AbstractBindingResult.java
@@ -21,7 +21,6 @@ import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -46,9 +45,9 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
private MessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver();
- private final List errors = new LinkedList();
+ private final List errors = new LinkedList();
- private final Set suppressedFields = new HashSet();
+ private final Set suppressedFields = new HashSet();
/**
@@ -146,16 +145,15 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
}
@Override
- public List getAllErrors() {
+ public List getAllErrors() {
return Collections.unmodifiableList(this.errors);
}
- public List getGlobalErrors() {
- List result = new LinkedList();
- for (Iterator it = this.errors.iterator(); it.hasNext();) {
- Object error = it.next();
- if (!(error instanceof FieldError)) {
- result.add(error);
+ public List getGlobalErrors() {
+ List result = new LinkedList();
+ for (ObjectError objectError : this.errors) {
+ if (!(objectError instanceof FieldError)) {
+ result.add(objectError);
}
}
return Collections.unmodifiableList(result);
@@ -163,8 +161,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
@Override
public ObjectError getGlobalError() {
- for (Iterator it = this.errors.iterator(); it.hasNext();) {
- ObjectError objectError = (ObjectError) it.next();
+ for (ObjectError objectError : this.errors) {
if (!(objectError instanceof FieldError)) {
return objectError;
}
@@ -172,12 +169,11 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
return null;
}
- public List getFieldErrors() {
- List result = new LinkedList();
- for (Iterator it = this.errors.iterator(); it.hasNext();) {
- Object error = it.next();
- if (error instanceof FieldError) {
- result.add(error);
+ public List getFieldErrors() {
+ List result = new LinkedList();
+ for (ObjectError objectError : this.errors) {
+ if (objectError instanceof FieldError) {
+ result.add((FieldError) objectError);
}
}
return Collections.unmodifiableList(result);
@@ -185,23 +181,21 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
@Override
public FieldError getFieldError() {
- for (Iterator it = this.errors.iterator(); it.hasNext();) {
- Object error = it.next();
- if (error instanceof FieldError) {
- return (FieldError) error;
+ for (ObjectError objectError : this.errors) {
+ if (objectError instanceof FieldError) {
+ return (FieldError) objectError;
}
}
return null;
}
@Override
- public List getFieldErrors(String field) {
- List result = new LinkedList();
+ public List getFieldErrors(String field) {
+ List result = new LinkedList();
String fixedField = fixedField(field);
- for (Iterator it = this.errors.iterator(); it.hasNext();) {
- Object error = it.next();
- if (error instanceof FieldError && isMatchingFieldError(fixedField, (FieldError) error)) {
- result.add(error);
+ for (ObjectError objectError : this.errors) {
+ if (objectError instanceof FieldError && isMatchingFieldError(fixedField, (FieldError) objectError)) {
+ result.add((FieldError) objectError);
}
}
return Collections.unmodifiableList(result);
@@ -210,12 +204,11 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
@Override
public FieldError getFieldError(String field) {
String fixedField = fixedField(field);
- for (Iterator it = this.errors.iterator(); it.hasNext();) {
- Object error = it.next();
- if (error instanceof FieldError) {
- FieldError fe = (FieldError) error;
- if (isMatchingFieldError(fixedField, fe)) {
- return fe;
+ for (ObjectError objectError : this.errors) {
+ if (objectError instanceof FieldError) {
+ FieldError fieldError = (FieldError) objectError;
+ if (isMatchingFieldError(fixedField, fieldError)) {
+ return fieldError;
}
}
}
@@ -223,17 +216,12 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
}
public Object getFieldValue(String field) {
- FieldError fe = getFieldError(field);
+ FieldError fieldError = getFieldError(field);
// Use rejected value in case of error, current bean property value else.
- Object value = null;
- if (fe != null) {
- value = fe.getRejectedValue();
- }
- else {
- value = getActualFieldValue(fixedField(field));
- }
+ Object value = (fieldError != null ? fieldError.getRejectedValue() :
+ getActualFieldValue(fixedField(field)));
// Apply formatting, but not on binding failures like type mismatches.
- if (fe == null || !fe.isBindingFailure()) {
+ if (fieldError == null || !fieldError.isBindingFailure()) {
value = formatFieldValue(field, value);
}
return value;
@@ -277,8 +265,8 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
* @see org.springframework.web.servlet.tags.BindTag
* @see org.springframework.web.servlet.mvc.SimpleFormController
*/
- public Map getModel() {
- Map model = new HashMap(2);
+ public Map getModel() {
+ Map model = new HashMap(2);
// Errors instance, even if no errors.
model.put(MODEL_KEY_PREFIX + getObjectName(), this);
// Mapping from name to target object.
diff --git a/org.springframework.context/src/main/java/org/springframework/validation/BindingResult.java b/org.springframework.context/src/main/java/org/springframework/validation/BindingResult.java
index d67847a1e41..9f981813f18 100644
--- a/org.springframework.context/src/main/java/org/springframework/validation/BindingResult.java
+++ b/org.springframework.context/src/main/java/org/springframework/validation/BindingResult.java
@@ -75,7 +75,7 @@ public interface BindingResult extends Errors {
* @see org.springframework.web.servlet.tags.BindTag
* @see org.springframework.web.servlet.mvc.SimpleFormController
*/
- Map getModel();
+ Map getModel();
/**
* Extract the raw field value for the given field.
diff --git a/org.springframework.context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java b/org.springframework.context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java
index e7df7aeb0c5..593e992b4ca 100644
--- a/org.springframework.context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java
+++ b/org.springframework.context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.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.
@@ -18,7 +18,6 @@ package org.springframework.validation;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.springframework.util.StringUtils;
@@ -121,19 +120,17 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial
* @return the list of codes
*/
public String[] resolveMessageCodes(String errorCode, String objectName, String field, Class fieldType) {
- List codeList = new ArrayList();
- List fieldList = new ArrayList();
+ List codeList = new ArrayList();
+ List fieldList = new ArrayList();
buildFieldList(field, fieldList);
- for (Iterator it = fieldList.iterator(); it.hasNext();) {
- String fieldInList = (String) it.next();
+ for (String fieldInList : fieldList) {
codeList.add(postProcessMessageCode(errorCode + CODE_SEPARATOR + objectName + CODE_SEPARATOR + fieldInList));
}
int dotIndex = field.lastIndexOf('.');
if (dotIndex != -1) {
buildFieldList(field.substring(dotIndex + 1), fieldList);
}
- for (Iterator it = fieldList.iterator(); it.hasNext();) {
- String fieldInList = (String) it.next();
+ for (String fieldInList : fieldList) {
codeList.add(postProcessMessageCode(errorCode + CODE_SEPARATOR + fieldInList));
}
if (fieldType != null) {
@@ -147,7 +144,7 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial
* Add both keyed and non-keyed entries for the supplied field
* to the supplied field list.
*/
- protected void buildFieldList(String field, List fieldList) {
+ protected void buildFieldList(String field, List fieldList) {
fieldList.add(field);
String plainField = field;
int keyIndex = plainField.lastIndexOf('[');
diff --git a/org.springframework.context/src/main/java/org/springframework/validation/Errors.java b/org.springframework.context/src/main/java/org/springframework/validation/Errors.java
index 5cd482afd0c..a8cf6e12226 100644
--- a/org.springframework.context/src/main/java/org/springframework/validation/Errors.java
+++ b/org.springframework.context/src/main/java/org/springframework/validation/Errors.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.
@@ -194,7 +194,7 @@ public interface Errors {
* Get all errors, both global and field ones.
* @return List of {@link ObjectError} instances
*/
- List getAllErrors();
+ List getAllErrors();
/**
* Are there any global errors?
@@ -214,7 +214,7 @@ public interface Errors {
* Get all global errors.
* @return List of ObjectError instances
*/
- List getGlobalErrors();
+ List getGlobalErrors();
/**
* Get the first global error, if any.
@@ -240,7 +240,7 @@ public interface Errors {
* Get all errors associated with a field.
* @return a List of {@link FieldError} instances
*/
- List getFieldErrors();
+ List getFieldErrors();
/**
* Get the first error associated with a field, if any.
@@ -269,7 +269,7 @@ public interface Errors {
* @param field the field name
* @return a List of {@link FieldError} instances
*/
- List getFieldErrors(String field);
+ List getFieldErrors(String field);
/**
* Get the first error associated with the given field, if any.
diff --git a/org.springframework.core/src/main/java/org/springframework/core/Constants.java b/org.springframework.core/src/main/java/org/springframework/core/Constants.java
index a405a605783..c18b8d28952 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/Constants.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/Constants.java
@@ -19,7 +19,6 @@ package org.springframework.core;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -50,7 +49,7 @@ public class Constants {
private final String className;
/** Map from String field name to object value */
- private final Map fieldCache = new HashMap();
+ private final Map fieldCache = new HashMap();
/**
@@ -63,8 +62,7 @@ public class Constants {
Assert.notNull(clazz);
this.className = clazz.getName();
Field[] fields = clazz.getFields();
- for (int i = 0; i < fields.length; i++) {
- Field field = fields[i];
+ for (Field field : fields) {
if (ReflectionUtils.isPublicStaticFinal(field)) {
String name = field.getName();
try {
@@ -97,7 +95,7 @@ public class Constants {
* Exposes the field cache to subclasses:
* a Map from String field name to object value.
*/
- protected final Map getFieldCache() {
+ protected final Map getFieldCache() {
return this.fieldCache;
}
@@ -159,11 +157,10 @@ public class Constants {
* @param namePrefix prefix of the constant names to search (may be null)
* @return the set of constant names
*/
- public Set getNames(String namePrefix) {
+ public Set getNames(String namePrefix) {
String prefixToUse = (namePrefix != null ? namePrefix.trim().toUpperCase(Locale.ENGLISH) : "");
- Set names = new HashSet();
- for (Iterator it = this.fieldCache.keySet().iterator(); it.hasNext();) {
- String code = (String) it.next();
+ Set names = new HashSet();
+ for (String code : this.fieldCache.keySet()) {
if (code.startsWith(prefixToUse)) {
names.add(code);
}
@@ -178,7 +175,7 @@ public class Constants {
* @return the set of values
* @see #propertyToConstantNamePrefix
*/
- public Set getNamesForProperty(String propertyName) {
+ public Set getNamesForProperty(String propertyName) {
return getNames(propertyToConstantNamePrefix(propertyName));
}
@@ -194,9 +191,8 @@ public class Constants {
*/
public Set getNamesForSuffix(String nameSuffix) {
String suffixToUse = (nameSuffix != null ? nameSuffix.trim().toUpperCase(Locale.ENGLISH) : "");
- Set names = new HashSet();
- for (Iterator it = this.fieldCache.keySet().iterator(); it.hasNext();) {
- String code = (String) it.next();
+ Set names = new HashSet();
+ for (String code : this.fieldCache.keySet()) {
if (code.endsWith(suffixToUse)) {
names.add(code);
}
@@ -215,11 +211,10 @@ public class Constants {
* @param namePrefix prefix of the constant names to search (may be null)
* @return the set of values
*/
- public Set getValues(String namePrefix) {
+ public Set