Java 5 code style
This commit is contained in:
parent
1f9e63af49
commit
29657105da
|
|
@ -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 <code>true</code> if any special {@link Advisor Advisors} were added, otherwise <code>false</code>.
|
||||
*/
|
||||
public static boolean makeAdvisorChainAspectJCapableIfNecessary(List advisors) {
|
||||
public static boolean makeAdvisorChainAspectJCapableIfNecessary(List<Advisor> 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)) {
|
||||
|
|
|
|||
|
|
@ -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<Advisor> advisors = new LinkedList<Advisor>();
|
||||
for (Iterator it = aspectNames.iterator(); it.hasNext();) {
|
||||
String aspectName = (String) it.next();
|
||||
for (String aspectName : aspectNames) {
|
||||
List<Advisor> cachedAdvisors = this.advisorsCache.get(aspectName);
|
||||
if (cachedAdvisors != null) {
|
||||
advisors.addAll(cachedAdvisors);
|
||||
|
|
|
|||
|
|
@ -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<Advisor> sortAdvisors(List<Advisor> 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<PartiallyComparableAdvisorHolder> partiallyComparableAdvisors =
|
||||
new LinkedList<PartiallyComparableAdvisorHolder>();
|
||||
for (Advisor element : advisors) {
|
||||
partiallyComparableAdvisors.add(
|
||||
new PartiallyComparableAdvisorHolder(element, DEFAULT_PRECEDENCE_COMPARATOR));
|
||||
}
|
||||
|
||||
// sort it
|
||||
List sorted = PartialOrder.sort(partiallyComparableAdvisors);
|
||||
List<PartiallyComparableAdvisorHolder> sorted =
|
||||
(List<PartiallyComparableAdvisorHolder>) 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<Advisor> result = new LinkedList<Advisor>();
|
||||
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<Advisor> 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<Advisor> 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<Advisor> comparator;
|
||||
|
||||
public PartiallyComparableAdvisorHolder(Advisor advisor, Comparator comparator) {
|
||||
public PartiallyComparableAdvisorHolder(Advisor advisor, Comparator<Advisor> 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;
|
||||
|
|
|
|||
|
|
@ -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<String, DefaultListableBeanFactory> internalBeanFactories =
|
||||
new HashMap<String, DefaultListableBeanFactory>();
|
||||
|
||||
|
||||
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<BeanPostProcessor> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Class> interfaces = new HashSet<Class>();
|
||||
|
||||
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 + "] " +
|
||||
|
|
|
|||
|
|
@ -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<Class> publishedInterfaces = new HashSet<Class>();
|
||||
|
||||
/**
|
||||
* Methods that we know we should implement here: key is Method, value is Boolean.
|
||||
**/
|
||||
private transient Map rememberedMethods = createRememberedMethodMap();
|
||||
private transient Map<Method, Boolean> rememberedMethods = new IdentityHashMap<Method, Boolean>(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<Method, Boolean>(32);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Class> 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<ClassLoader> it = acceptedClassLoaders.iterator(); it.hasNext();) {
|
||||
ClassLoader registeredLoader = it.next();
|
||||
if (isUnderneathClassLoader(registeredLoader, classLoader)) {
|
||||
it.remove();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,15 +79,15 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
|||
|
||||
private boolean configValueEditorsActive = false;
|
||||
|
||||
private boolean propertySpecificEditorsRegistered = false;
|
||||
private Map<Class, PropertyEditor> defaultEditors;
|
||||
|
||||
private Map defaultEditors;
|
||||
private Map<Class, PropertyEditor> customEditors;
|
||||
|
||||
private Map customEditors;
|
||||
private Map<String, CustomEditorHolder> customEditorsForPath;
|
||||
|
||||
private Set sharedEditors;
|
||||
private Set<PropertyEditor> sharedEditors;
|
||||
|
||||
private Map customEditorCache;
|
||||
private Map<Class, PropertyEditor> 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<Class, PropertyEditor>(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<String, CustomEditorHolder>(16);
|
||||
}
|
||||
this.customEditorsForPath.put(propertyPath, new CustomEditorHolder(propertyEditor, requiredType));
|
||||
}
|
||||
else {
|
||||
if (this.customEditors == null) {
|
||||
this.customEditors = new LinkedHashMap<Class, PropertyEditor>(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<PropertyEditor>();
|
||||
}
|
||||
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<String> strippedPaths = new LinkedList<String>();
|
||||
addStrippedPropertyPaths(strippedPaths, "", propertyPath);
|
||||
for (Iterator it = strippedPaths.iterator(); it.hasNext() && editor == null;) {
|
||||
String strippedPath = (String) it.next();
|
||||
for (Iterator<String> 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<String, CustomEditorHolder> 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 <code>null</code> 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<Class> 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<Class, PropertyEditor>();
|
||||
}
|
||||
this.customEditorCache.put(requiredType, editor);
|
||||
}
|
||||
|
|
@ -407,14 +398,14 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
|||
* @return the property type, or <code>null</code> 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<String> strippedPaths = new LinkedList<String>();
|
||||
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<String> 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<Class, PropertyEditor> entry : this.customEditors.entrySet()) {
|
||||
target.registerCustomEditor(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
if (this.customEditorsForPath != null) {
|
||||
for (Map.Entry<String, CustomEditorHolder> 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<String> 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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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> T beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class<T> type)
|
||||
throws BeansException {
|
||||
|
||||
Map beansOfType = beansOfTypeIncludingAncestors(lbf, type);
|
||||
Map<String, T> 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> T beanOfTypeIncludingAncestors(
|
||||
ListableBeanFactory lbf, Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
|
||||
throws BeansException {
|
||||
|
||||
Map beansOfType = beansOfTypeIncludingAncestors(lbf, type, includeNonSingletons, allowEagerInit);
|
||||
Map<String, T> 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> T beanOfType(ListableBeanFactory lbf, Class<T> type) throws BeansException {
|
||||
Assert.notNull(lbf, "ListableBeanFactory must not be null");
|
||||
Map beansOfType = lbf.getBeansOfType(type);
|
||||
Map<String, T> 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> T beanOfType(
|
||||
ListableBeanFactory lbf, Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
|
||||
throws BeansException {
|
||||
|
||||
Assert.notNull(lbf, "ListableBeanFactory must not be null");
|
||||
Map beansOfType = lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit);
|
||||
Map<String, T> beansOfType = lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit);
|
||||
if (beansOfType.size() == 1) {
|
||||
return beansOfType.values().iterator().next();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Integer, ConstructorArgumentValues.ValueHolder> 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<ConstructorArgumentValues.ValueHolder> 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);
|
||||
|
|
|
|||
|
|
@ -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<ValueHolder> it1 = this.genericArgumentValues.iterator();
|
||||
Iterator<ValueHolder> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String, Object> 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<String, Object> 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<String, Object> 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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -1124,8 +1124,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
|||
if (filtered == null) {
|
||||
List<PropertyDescriptor> pds =
|
||||
new LinkedList<PropertyDescriptor>(Arrays.asList(bw.getPropertyDescriptors()));
|
||||
for (Iterator it = pds.iterator(); it.hasNext();) {
|
||||
PropertyDescriptor pd = (PropertyDescriptor) it.next();
|
||||
for (Iterator<PropertyDescriptor> it = pds.iterator(); it.hasNext();) {
|
||||
PropertyDescriptor pd = it.next();
|
||||
if (isExcludedFromDependencyCheck(pd)) {
|
||||
it.remove();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Map.Entry<String, Set<String>>> it = this.dependentBeanMap.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<String, Set<String>> entry = it.next();
|
||||
Set<String> dependenciesToClean = entry.getValue();
|
||||
dependenciesToClean.remove(beanName);
|
||||
if (dependenciesToClean.isEmpty()) {
|
||||
it.remove();
|
||||
|
|
|
|||
|
|
@ -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<DestructionAwareBeanPostProcessor> 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<BeanPostProcessor> 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<DestructionAwareBeanPostProcessor> 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<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> postProcessors) {
|
||||
List<DestructionAwareBeanPostProcessor> 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<DestructionAwareBeanPostProcessor>(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<DestructionAwareBeanPostProcessor> serializablePostProcessors = null;
|
||||
if (this.beanPostProcessors != null) {
|
||||
serializablePostProcessors = new ArrayList();
|
||||
for (Iterator it = this.beanPostProcessors.iterator(); it.hasNext();) {
|
||||
Object postProcessor = it.next();
|
||||
serializablePostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>();
|
||||
for (DestructionAwareBeanPostProcessor postProcessor : this.beanPostProcessors) {
|
||||
if (postProcessor instanceof Serializable) {
|
||||
serializablePostProcessors.add(postProcessor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String, Object> beans = new HashMap<String, Object>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -100,12 +98,12 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
|
|||
return bean;
|
||||
}
|
||||
|
||||
public Object getBean(String name, Class requiredType) throws BeansException {
|
||||
public <T> T getBean(String name, Class<T> 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<String> matches = new ArrayList<String>();
|
||||
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 <T> Map<String, T> getBeansOfType(Class<T> type) throws BeansException {
|
||||
return getBeansOfType(type, true, true);
|
||||
}
|
||||
|
||||
public Map getBeansOfType(Class type, boolean includeNonSingletons, boolean includeFactoryBeans)
|
||||
public <T> Map<String, T> getBeansOfType(Class<T> type, boolean includeNonSingletons, boolean includeFactoryBeans)
|
||||
throws BeansException {
|
||||
|
||||
boolean isFactoryType = (type != null && FactoryBean.class.isAssignableFrom(type));
|
||||
Map matches = new HashMap();
|
||||
Map<String, T> matches = new HashMap<String, T>();
|
||||
|
||||
Iterator it = this.beans.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
String beanName = (String) entry.getKey();
|
||||
for (Map.Entry<String, Object> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Element> 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<Element> 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<Element> 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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<Timer> timers = new LinkedList<Timer>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<JobDetail> jobDetails;
|
||||
|
||||
private Map calendars;
|
||||
private Map<String, Calendar> calendars;
|
||||
|
||||
private List triggers;
|
||||
private List<Trigger> 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<JobDetail>(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<String, Calendar> 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<JobDetail>();
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<ApplicationListener> getApplicationListeners() {
|
||||
return this.applicationListeners;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<String, Map<Locale, List<String>>> cachedFilenames =
|
||||
new HashMap<String, Map<Locale, List<String>>>();
|
||||
|
||||
/** Cache to hold already loaded properties per filename */
|
||||
private final Map cachedProperties = new HashMap();
|
||||
private final Map<String, PropertiesHolder> cachedProperties = new HashMap<String, PropertiesHolder>();
|
||||
|
||||
/** 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<String> 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<String> calculateAllFilenames(String basename, Locale locale) {
|
||||
synchronized (this.cachedFilenames) {
|
||||
Map localeMap = (Map) this.cachedFilenames.get(basename);
|
||||
Map<Locale, List<String>> localeMap = this.cachedFilenames.get(basename);
|
||||
if (localeMap != null) {
|
||||
List filenames = (List) localeMap.get(locale);
|
||||
List<String> filenames = localeMap.get(locale);
|
||||
if (filenames != null) {
|
||||
return filenames;
|
||||
}
|
||||
}
|
||||
List filenames = new ArrayList(7);
|
||||
List<String> filenames = new ArrayList<String>(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<String> 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<Locale, List<String>>();
|
||||
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<String> calculateFilenamesForLocale(String basename, Locale locale) {
|
||||
List<String> result = new ArrayList<String>(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<String, Map<Locale, MessageFormat>> cachedMessageFormats =
|
||||
new HashMap<String, Map<Locale, MessageFormat>>();
|
||||
|
||||
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<Locale, MessageFormat> 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<Locale, MessageFormat>();
|
||||
this.cachedMessageFormats.put(code, localeMap);
|
||||
}
|
||||
MessageFormat result = createMessageFormat(msg, locale);
|
||||
|
|
|
|||
|
|
@ -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<String, MessageFormat> messages = new HashMap<String, MessageFormat>();
|
||||
|
||||
|
||||
@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<String, String> 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<String, String> entry : messages.entrySet()) {
|
||||
addMessage(entry.getKey(), locale, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<ObjectName> registeredBeans = new LinkedHashSet<ObjectName>();
|
||||
|
||||
/**
|
||||
* 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()]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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<String, ScriptSource> scriptSourceCache = new HashMap<String, ScriptSource>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -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<BeanPostProcessor> 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)});
|
||||
|
|
|
|||
|
|
@ -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<String, Theme> themeCache = new HashMap<String, Theme>();
|
||||
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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<ObjectError> errors = new LinkedList<ObjectError>();
|
||||
|
||||
private final Set suppressedFields = new HashSet();
|
||||
private final Set<String> suppressedFields = new HashSet<String>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -146,16 +145,15 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
|
|||
}
|
||||
|
||||
@Override
|
||||
public List getAllErrors() {
|
||||
public List<ObjectError> 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<ObjectError> getGlobalErrors() {
|
||||
List<ObjectError> result = new LinkedList<ObjectError>();
|
||||
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<FieldError> getFieldErrors() {
|
||||
List<FieldError> result = new LinkedList<FieldError>();
|
||||
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<FieldError> getFieldErrors(String field) {
|
||||
List<FieldError> result = new LinkedList<FieldError>();
|
||||
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<String, Object> getModel() {
|
||||
Map<String, Object> model = new HashMap<String, Object>(2);
|
||||
// Errors instance, even if no errors.
|
||||
model.put(MODEL_KEY_PREFIX + getObjectName(), this);
|
||||
// Mapping from name to target object.
|
||||
|
|
|
|||
|
|
@ -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<String, Object> getModel();
|
||||
|
||||
/**
|
||||
* Extract the raw field value for the given field.
|
||||
|
|
|
|||
|
|
@ -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<String> codeList = new ArrayList<String>();
|
||||
List<String> fieldList = new ArrayList<String>();
|
||||
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 <code>field</code>
|
||||
* to the supplied field list.
|
||||
*/
|
||||
protected void buildFieldList(String field, List fieldList) {
|
||||
protected void buildFieldList(String field, List<String> fieldList) {
|
||||
fieldList.add(field);
|
||||
String plainField = field;
|
||||
int keyIndex = plainField.lastIndexOf('[');
|
||||
|
|
|
|||
|
|
@ -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<ObjectError> 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<ObjectError> getGlobalErrors();
|
||||
|
||||
/**
|
||||
* Get the <i>first</i> 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<FieldError> getFieldErrors();
|
||||
|
||||
/**
|
||||
* Get the <i>first</i> 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<FieldError> getFieldErrors(String field);
|
||||
|
||||
/**
|
||||
* Get the first error associated with the given field, if any.
|
||||
|
|
|
|||
|
|
@ -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<String, Object> fieldCache = new HashMap<String, Object>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -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<String, Object> getFieldCache() {
|
||||
return this.fieldCache;
|
||||
}
|
||||
|
||||
|
|
@ -159,11 +157,10 @@ public class Constants {
|
|||
* @param namePrefix prefix of the constant names to search (may be <code>null</code>)
|
||||
* @return the set of constant names
|
||||
*/
|
||||
public Set getNames(String namePrefix) {
|
||||
public Set<String> 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<String> names = new HashSet<String>();
|
||||
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<String> 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<String> names = new HashSet<String>();
|
||||
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 <code>null</code>)
|
||||
* @return the set of values
|
||||
*/
|
||||
public Set getValues(String namePrefix) {
|
||||
public Set<Object> getValues(String namePrefix) {
|
||||
String prefixToUse = (namePrefix != null ? namePrefix.trim().toUpperCase(Locale.ENGLISH) : "");
|
||||
Set values = new HashSet();
|
||||
for (Iterator it = this.fieldCache.keySet().iterator(); it.hasNext();) {
|
||||
String code = (String) it.next();
|
||||
Set<Object> values = new HashSet<Object>();
|
||||
for (String code : this.fieldCache.keySet()) {
|
||||
if (code.startsWith(prefixToUse)) {
|
||||
values.add(this.fieldCache.get(code));
|
||||
}
|
||||
|
|
@ -234,7 +229,7 @@ public class Constants {
|
|||
* @return the set of values
|
||||
* @see #propertyToConstantNamePrefix
|
||||
*/
|
||||
public Set getValuesForProperty(String propertyName) {
|
||||
public Set<Object> getValuesForProperty(String propertyName) {
|
||||
return getValues(propertyToConstantNamePrefix(propertyName));
|
||||
}
|
||||
|
||||
|
|
@ -248,11 +243,10 @@ public class Constants {
|
|||
* @param nameSuffix suffix of the constant names to search (may be <code>null</code>)
|
||||
* @return the set of values
|
||||
*/
|
||||
public Set getValuesForSuffix(String nameSuffix) {
|
||||
public Set<Object> getValuesForSuffix(String nameSuffix) {
|
||||
String suffixToUse = (nameSuffix != null ? nameSuffix.trim().toUpperCase(Locale.ENGLISH) : "");
|
||||
Set values = new HashSet();
|
||||
for (Iterator it = this.fieldCache.keySet().iterator(); it.hasNext();) {
|
||||
String code = (String) it.next();
|
||||
Set<Object> values = new HashSet<Object>();
|
||||
for (String code : this.fieldCache.keySet()) {
|
||||
if (code.endsWith(suffixToUse)) {
|
||||
values.add(this.fieldCache.get(code));
|
||||
}
|
||||
|
|
@ -271,11 +265,9 @@ public class Constants {
|
|||
*/
|
||||
public String toCode(Object value, String namePrefix) throws ConstantException {
|
||||
String prefixToUse = (namePrefix != null ? namePrefix.trim().toUpperCase(Locale.ENGLISH) : null);
|
||||
for (Iterator it = this.fieldCache.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
String key = (String) entry.getKey();
|
||||
if (key.startsWith(prefixToUse) && entry.getValue().equals(value)) {
|
||||
return key;
|
||||
for (Map.Entry<String, Object> entry : this.fieldCache.entrySet()) {
|
||||
if (entry.getKey().startsWith(prefixToUse) && entry.getValue().equals(value)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
throw new ConstantException(this.className, prefixToUse, value);
|
||||
|
|
@ -304,11 +296,9 @@ public class Constants {
|
|||
*/
|
||||
public String toCodeForSuffix(Object value, String nameSuffix) throws ConstantException {
|
||||
String suffixToUse = (nameSuffix != null ? nameSuffix.trim().toUpperCase(Locale.ENGLISH) : null);
|
||||
for (Iterator it = this.fieldCache.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
String key = (String) entry.getKey();
|
||||
if (key.endsWith(suffixToUse) && entry.getValue().equals(value)) {
|
||||
return key;
|
||||
for (Map.Entry<String, Object> entry : this.fieldCache.entrySet()) {
|
||||
if (entry.getKey().endsWith(suffixToUse) && entry.getValue().equals(value)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
throw new ConstantException(this.className, suffixToUse, value);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.core;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
|
@ -33,9 +32,9 @@ import org.springframework.util.Assert;
|
|||
*/
|
||||
public abstract class DecoratingClassLoader extends ClassLoader {
|
||||
|
||||
private final Set excludedPackages = new HashSet();
|
||||
private final Set<String> excludedPackages = new HashSet<String>();
|
||||
|
||||
private final Set excludedClasses = new HashSet();
|
||||
private final Set<String> excludedClasses = new HashSet<String>();
|
||||
|
||||
private final Object exclusionMonitor = new Object();
|
||||
|
||||
|
|
@ -95,8 +94,7 @@ public abstract class DecoratingClassLoader extends ClassLoader {
|
|||
if (this.excludedClasses.contains(className)) {
|
||||
return true;
|
||||
}
|
||||
for (Iterator it = this.excludedPackages.iterator(); it.hasNext();) {
|
||||
String packageName = (String) it.next();
|
||||
for (String packageName : this.excludedPackages) {
|
||||
if (className.startsWith(packageName)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -36,7 +36,8 @@ import java.util.List;
|
|||
*/
|
||||
public class PrioritizedParameterNameDiscoverer implements ParameterNameDiscoverer {
|
||||
|
||||
private final List parameterNameDiscoverers = new LinkedList();
|
||||
private final List<ParameterNameDiscoverer> parameterNameDiscoverers =
|
||||
new LinkedList<ParameterNameDiscoverer>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -49,8 +50,7 @@ public class PrioritizedParameterNameDiscoverer implements ParameterNameDiscover
|
|||
|
||||
|
||||
public String[] getParameterNames(Method method) {
|
||||
for (Iterator it = this.parameterNameDiscoverers.iterator(); it.hasNext(); ) {
|
||||
ParameterNameDiscoverer pnd = (ParameterNameDiscoverer) it.next();
|
||||
for (ParameterNameDiscoverer pnd : this.parameterNameDiscoverers) {
|
||||
String[] result = pnd.getParameterNames(method);
|
||||
if (result != null) {
|
||||
return result;
|
||||
|
|
@ -60,8 +60,7 @@ public class PrioritizedParameterNameDiscoverer implements ParameterNameDiscover
|
|||
}
|
||||
|
||||
public String[] getParameterNames(Constructor ctor) {
|
||||
for (Iterator it = this.parameterNameDiscoverers.iterator(); it.hasNext(); ) {
|
||||
ParameterNameDiscoverer pnd = (ParameterNameDiscoverer) it.next();
|
||||
for (ParameterNameDiscoverer pnd : this.parameterNameDiscoverers) {
|
||||
String[] result = pnd.getParameterNames(ctor);
|
||||
if (result != null) {
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package org.springframework.core.enums;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
|
@ -46,48 +45,16 @@ public abstract class AbstractCachingLabeledEnumResolver implements LabeledEnumR
|
|||
|
||||
protected transient final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
|
||||
private final CachingMapDecorator labeledEnumCache = new CachingMapDecorator(true) {
|
||||
@Override
|
||||
protected Object create(Object key) {
|
||||
Class enumType = (Class) key;
|
||||
Set typeEnums = findLabeledEnums(enumType);
|
||||
if (typeEnums == null || typeEnums.isEmpty()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Unsupported labeled enumeration type '" + key + "': " +
|
||||
"make sure you've properly defined this enumeration! " +
|
||||
"If it is static, are the class and its fields public/static/final?");
|
||||
}
|
||||
Map typeEnumMap = new HashMap(typeEnums.size());
|
||||
for (Iterator it = typeEnums.iterator(); it.hasNext();) {
|
||||
LabeledEnum labeledEnum = (LabeledEnum) it.next();
|
||||
typeEnumMap.put(labeledEnum.getCode(), labeledEnum);
|
||||
}
|
||||
return Collections.unmodifiableMap(typeEnumMap);
|
||||
}
|
||||
@Override
|
||||
protected boolean useWeakValue(Object key, Object value) {
|
||||
Class enumType = (Class) key;
|
||||
if (!ClassUtils.isCacheSafe(enumType, AbstractCachingLabeledEnumResolver.this.getClass().getClassLoader())) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Not strongly caching class [" + enumType.getName() + "] because it is not cache-safe");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
private final LabeledEnumCache labeledEnumCache = new LabeledEnumCache();
|
||||
|
||||
|
||||
public Set getLabeledEnumSet(Class type) throws IllegalArgumentException {
|
||||
return new TreeSet(getLabeledEnumMap(type).values());
|
||||
public Set<LabeledEnum> getLabeledEnumSet(Class type) throws IllegalArgumentException {
|
||||
return new TreeSet<LabeledEnum>(getLabeledEnumMap(type).values());
|
||||
}
|
||||
|
||||
public Map getLabeledEnumMap(Class type) throws IllegalArgumentException {
|
||||
public Map<Comparable, LabeledEnum> getLabeledEnumMap(Class type) throws IllegalArgumentException {
|
||||
Assert.notNull(type, "No type specified");
|
||||
return (Map) this.labeledEnumCache.get(type);
|
||||
return this.labeledEnumCache.get(type);
|
||||
}
|
||||
|
||||
public LabeledEnum getLabeledEnumByCode(Class type, Comparable code) throws IllegalArgumentException {
|
||||
|
|
@ -104,10 +71,8 @@ public abstract class AbstractCachingLabeledEnumResolver implements LabeledEnumR
|
|||
}
|
||||
|
||||
public LabeledEnum getLabeledEnumByLabel(Class type, String label) throws IllegalArgumentException {
|
||||
Map typeEnums = getLabeledEnumMap(type);
|
||||
Iterator it = typeEnums.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
LabeledEnum value = (LabeledEnum) it.next();
|
||||
Map<Comparable, LabeledEnum> typeEnums = getLabeledEnumMap(type);
|
||||
for (LabeledEnum value : typeEnums.values()) {
|
||||
if (value.getLabel().equalsIgnoreCase(label)) {
|
||||
return value;
|
||||
}
|
||||
|
|
@ -126,6 +91,43 @@ public abstract class AbstractCachingLabeledEnumResolver implements LabeledEnumR
|
|||
* @return the Set of LabeledEnum instances
|
||||
* @see org.springframework.core.enums.LabeledEnum
|
||||
*/
|
||||
protected abstract Set findLabeledEnums(Class type);
|
||||
protected abstract Set<LabeledEnum> findLabeledEnums(Class type);
|
||||
|
||||
|
||||
private class LabeledEnumCache extends CachingMapDecorator<Class, Map<Comparable, LabeledEnum>> {
|
||||
|
||||
public LabeledEnumCache() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<Comparable, LabeledEnum> create(Class key) {
|
||||
Set<LabeledEnum> typeEnums = findLabeledEnums(key);
|
||||
if (typeEnums == null || typeEnums.isEmpty()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Unsupported labeled enumeration type '" + key + "': " +
|
||||
"make sure you've properly defined this enumeration! " +
|
||||
"If it is static, are the class and its fields public/static/final?");
|
||||
}
|
||||
Map<Comparable, LabeledEnum> typeEnumMap = new HashMap<Comparable, LabeledEnum>(typeEnums.size());
|
||||
for (LabeledEnum labeledEnum : typeEnums) {
|
||||
typeEnumMap.put(labeledEnum.getCode(), labeledEnum);
|
||||
}
|
||||
return Collections.unmodifiableMap(typeEnumMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean useWeakValue(Class key, Map<Comparable, LabeledEnum> value) {
|
||||
if (!ClassUtils.isCacheSafe(key, AbstractCachingLabeledEnumResolver.this.getClass().getClassLoader())) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Not strongly caching class [" + key.getName() + "] because it is not cache-safe");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,17 +51,15 @@ public class StaticLabeledEnumResolver extends AbstractCachingLabeledEnumResolve
|
|||
|
||||
|
||||
@Override
|
||||
protected Set findLabeledEnums(Class type) {
|
||||
Set typeEnums = new TreeSet();
|
||||
Field[] fields = type.getFields();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
Field field = fields[i];
|
||||
protected Set<LabeledEnum> findLabeledEnums(Class type) {
|
||||
Set<LabeledEnum> typeEnums = new TreeSet<LabeledEnum>();
|
||||
for (Field field : type.getFields()) {
|
||||
if (Modifier.isStatic(field.getModifiers()) && Modifier.isPublic(field.getModifiers())) {
|
||||
if (type.isAssignableFrom(field.getType())) {
|
||||
try {
|
||||
Object value = field.get(null);
|
||||
Assert.isTrue(value instanceof LabeledEnum, "Field value must be a LabeledEnum instance");
|
||||
typeEnums.add(value);
|
||||
typeEnums.add((LabeledEnum) value);
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
logger.warn("Unable to access field value: " + field, ex);
|
||||
|
|
|
|||
|
|
@ -151,8 +151,8 @@ public abstract class PropertiesLoaderSupport {
|
|||
}
|
||||
|
||||
if (this.localProperties != null) {
|
||||
for (int i = 0; i < this.localProperties.length; i++) {
|
||||
CollectionUtils.mergePropertiesIntoMap(this.localProperties[i], result);
|
||||
for (Properties localProp : this.localProperties) {
|
||||
CollectionUtils.mergePropertiesIntoMap(localProp, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -172,8 +172,7 @@ public abstract class PropertiesLoaderSupport {
|
|||
*/
|
||||
protected void loadProperties(Properties props) throws IOException {
|
||||
if (this.locations != null) {
|
||||
for (int i = 0; i < this.locations.length; i++) {
|
||||
Resource location = this.locations[i];
|
||||
for (Resource location : this.locations) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Loading properties file from " + location);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ public class DefaultValueStyler implements ValueStyler {
|
|||
|
||||
private String styleArray(Object[] array) {
|
||||
StringBuilder result = new StringBuilder(array.length * 8 + 16);
|
||||
result.append(ARRAY + "<" + ClassUtils.getShortName(array.getClass().getComponentType()) + ">[");
|
||||
result.append(ARRAY + "<").append(ClassUtils.getShortName(array.getClass().getComponentType())).append(">[");
|
||||
for (int i = 0; i < array.length - 1; i++) {
|
||||
result.append(style(array[i]));
|
||||
result.append(',').append(' ');
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import java.lang.ref.WeakReference;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
|
@ -41,12 +41,12 @@ import java.util.WeakHashMap;
|
|||
* @author Juergen Hoeller
|
||||
* @since 1.2.2
|
||||
*/
|
||||
public class CachingMapDecorator implements Map, Serializable {
|
||||
public class CachingMapDecorator<K, V> implements Map<K, V>, Serializable {
|
||||
|
||||
protected static Object NULL_VALUE = new Object();
|
||||
|
||||
|
||||
private final Map targetMap;
|
||||
private final Map<K, Object> targetMap;
|
||||
|
||||
private final boolean synchronize;
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
* @param weak whether to use weak references for keys and values
|
||||
*/
|
||||
public CachingMapDecorator(boolean weak) {
|
||||
Map internalMap = weak ? (Map) new WeakHashMap() : new HashMap();
|
||||
Map<K, Object> internalMap = (weak ? new WeakHashMap<K, Object>() : new HashMap<K, Object>());
|
||||
this.targetMap = Collections.synchronizedMap(internalMap);
|
||||
this.synchronize = true;
|
||||
this.weak = weak;
|
||||
|
|
@ -80,7 +80,7 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
* @param size the initial cache size
|
||||
*/
|
||||
public CachingMapDecorator(boolean weak, int size) {
|
||||
Map internalMap = weak ? (Map) new WeakHashMap(size) : new HashMap(size);
|
||||
Map<K, Object> internalMap = weak ? new WeakHashMap<K, Object> (size) : new HashMap<K, Object>(size);
|
||||
this.targetMap = Collections.synchronizedMap(internalMap);
|
||||
this.synchronize = true;
|
||||
this.weak = weak;
|
||||
|
|
@ -92,7 +92,7 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
* so make sure to pass in a properly synchronized Map, if desired.
|
||||
* @param targetMap the Map to decorate
|
||||
*/
|
||||
public CachingMapDecorator(Map targetMap) {
|
||||
public CachingMapDecorator(Map<K, V> targetMap) {
|
||||
this(targetMap, false, false);
|
||||
}
|
||||
|
||||
|
|
@ -104,9 +104,10 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
* @param synchronize whether to synchronize on the given Map
|
||||
* @param weak whether to use weak references for values
|
||||
*/
|
||||
public CachingMapDecorator(Map targetMap, boolean synchronize, boolean weak) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public CachingMapDecorator(Map<K, V> targetMap, boolean synchronize, boolean weak) {
|
||||
Assert.notNull(targetMap, "Target Map is required");
|
||||
this.targetMap = (synchronize ? Collections.synchronizedMap(targetMap) : targetMap);
|
||||
this.targetMap = (Map<K, Object>) (synchronize ? Collections.synchronizedMap(targetMap) : targetMap);
|
||||
this.synchronize = synchronize;
|
||||
this.weak = weak;
|
||||
}
|
||||
|
|
@ -125,10 +126,7 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
}
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
Object valueToCheck = value;
|
||||
if (valueToCheck == null) {
|
||||
valueToCheck = NULL_VALUE;
|
||||
}
|
||||
Object valueToCheck = (value != null ? value : NULL_VALUE);
|
||||
if (this.synchronize) {
|
||||
synchronized (this.targetMap) {
|
||||
return containsValueOrReference(valueToCheck);
|
||||
|
|
@ -143,8 +141,7 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
if (this.targetMap.containsValue(value)) {
|
||||
return true;
|
||||
}
|
||||
for (Iterator it = this.targetMap.values().iterator(); it.hasNext();) {
|
||||
Object mapVal = it.next();
|
||||
for (Object mapVal : this.targetMap.values()) {
|
||||
if (mapVal instanceof Reference && value.equals(((Reference) mapVal).get())) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -152,11 +149,11 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
return false;
|
||||
}
|
||||
|
||||
public Object remove(Object key) {
|
||||
return this.targetMap.remove(key);
|
||||
public V remove(Object key) {
|
||||
return unwrapIfNecessary(this.targetMap.remove(key));
|
||||
}
|
||||
|
||||
public void putAll(Map map) {
|
||||
public void putAll(Map<? extends K, ? extends V> map) {
|
||||
this.targetMap.putAll(map);
|
||||
}
|
||||
|
||||
|
|
@ -164,18 +161,18 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
this.targetMap.clear();
|
||||
}
|
||||
|
||||
public Set keySet() {
|
||||
public Set<K> keySet() {
|
||||
if (this.synchronize) {
|
||||
synchronized (this.targetMap) {
|
||||
return new LinkedHashSet(this.targetMap.keySet());
|
||||
return new LinkedHashSet<K>(this.targetMap.keySet());
|
||||
}
|
||||
}
|
||||
else {
|
||||
return new LinkedHashSet(this.targetMap.keySet());
|
||||
return new LinkedHashSet<K>(this.targetMap.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
public Collection values() {
|
||||
public Collection<V> values() {
|
||||
if (this.synchronize) {
|
||||
synchronized (this.targetMap) {
|
||||
return valuesCopy();
|
||||
|
|
@ -186,41 +183,49 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
private Collection valuesCopy() {
|
||||
LinkedList values = new LinkedList();
|
||||
for (Iterator it = this.targetMap.values().iterator(); it.hasNext();) {
|
||||
Object value = it.next();
|
||||
values.add(value instanceof Reference ? ((Reference) value).get() : value);
|
||||
@SuppressWarnings("unchecked")
|
||||
private Collection<V> valuesCopy() {
|
||||
LinkedList<V> values = new LinkedList<V>();
|
||||
for (Object value : this.targetMap.values()) {
|
||||
values.add(value instanceof Reference ? ((Reference<V>) value).get() : (V) value);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public Set entrySet() {
|
||||
public Set<Map.Entry<K, V>> entrySet() {
|
||||
if (this.synchronize) {
|
||||
synchronized (this.targetMap) {
|
||||
return new LinkedHashSet(this.targetMap.entrySet());
|
||||
return entryCopy();
|
||||
}
|
||||
}
|
||||
else {
|
||||
return new LinkedHashSet(this.targetMap.entrySet());
|
||||
return entryCopy();
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Map.Entry<K, V>> entryCopy() {
|
||||
Map<K,V> entries = new LinkedHashMap<K, V>();
|
||||
for (Entry<K, Object> entry : this.targetMap.entrySet()) {
|
||||
entries.put(entry.getKey(), unwrapIfNecessary(entry.getValue()));
|
||||
}
|
||||
return entries.entrySet();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put an object into the cache, possibly wrapping it with a weak
|
||||
* reference.
|
||||
* @see #useWeakValue(Object, Object)
|
||||
*/
|
||||
public Object put(Object key, Object value) {
|
||||
public V put(K key, V value) {
|
||||
Object newValue = value;
|
||||
if (newValue == null) {
|
||||
if (value == null) {
|
||||
newValue = NULL_VALUE;
|
||||
}
|
||||
if (useWeakValue(key, newValue)) {
|
||||
newValue = new WeakReference(newValue);
|
||||
else if (useWeakValue(key, value)) {
|
||||
newValue = new WeakReference<V>(value);
|
||||
}
|
||||
return this.targetMap.put(key, newValue);
|
||||
return unwrapIfNecessary(this.targetMap.put(key, newValue));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -231,7 +236,7 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
* @return <code>true</code> in order to use a weak reference;
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
protected boolean useWeakValue(Object key, Object value) {
|
||||
protected boolean useWeakValue(K key, V value) {
|
||||
return this.weak;
|
||||
}
|
||||
|
||||
|
|
@ -244,18 +249,30 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
* Consider overriding this method to synchronize it, if desired.
|
||||
* @see #create(Object)
|
||||
*/
|
||||
public Object get(Object key) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public V get(Object key) {
|
||||
Object value = this.targetMap.get(key);
|
||||
if (value instanceof Reference) {
|
||||
value = ((Reference) value).get();
|
||||
}
|
||||
if (value == null) {
|
||||
value = create(key);
|
||||
if (value != null) {
|
||||
put(key, value);
|
||||
V newVal = create((K) key);
|
||||
if (newVal != null) {
|
||||
put((K) key, newVal);
|
||||
}
|
||||
return newVal;
|
||||
}
|
||||
return unwrapIfNecessary(value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private V unwrapIfNecessary(Object value) {
|
||||
if (value instanceof Reference) {
|
||||
return ((Reference<V>) value).get();
|
||||
}
|
||||
else if (value != null) {
|
||||
return (V) value;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return (value == NULL_VALUE ? null : value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -264,7 +281,7 @@ public class CachingMapDecorator implements Map, Serializable {
|
|||
* @param key the cache key
|
||||
* @see #get(Object)
|
||||
*/
|
||||
protected Object create(Object key) {
|
||||
protected V create(K key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -492,7 +492,7 @@ public abstract class ClassUtils {
|
|||
* @return whether the class has a corresponding constructor
|
||||
* @see java.lang.Class#getMethod
|
||||
*/
|
||||
public static boolean hasConstructor(Class clazz, Class[] paramTypes) {
|
||||
public static boolean hasConstructor(Class clazz, Class... paramTypes) {
|
||||
return (getConstructorIfAvailable(clazz, paramTypes) != null);
|
||||
}
|
||||
|
||||
|
|
@ -505,7 +505,7 @@ public abstract class ClassUtils {
|
|||
* @return the constructor, or <code>null</code> if not found
|
||||
* @see java.lang.Class#getConstructor
|
||||
*/
|
||||
public static Constructor getConstructorIfAvailable(Class clazz, Class[] paramTypes) {
|
||||
public static Constructor getConstructorIfAvailable(Class clazz, Class... paramTypes) {
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
try {
|
||||
return clazz.getConstructor(paramTypes);
|
||||
|
|
@ -524,7 +524,7 @@ public abstract class ClassUtils {
|
|||
* @return whether the class has a corresponding method
|
||||
* @see java.lang.Class#getMethod
|
||||
*/
|
||||
public static boolean hasMethod(Class clazz, String methodName, Class[] paramTypes) {
|
||||
public static boolean hasMethod(Class clazz, String methodName, Class... paramTypes) {
|
||||
return (getMethodIfAvailable(clazz, methodName, paramTypes) != null);
|
||||
}
|
||||
|
||||
|
|
@ -538,7 +538,7 @@ public abstract class ClassUtils {
|
|||
* @return the method, or <code>null</code> if not found
|
||||
* @see java.lang.Class#getMethod
|
||||
*/
|
||||
public static Method getMethodIfAvailable(Class clazz, String methodName, Class[] paramTypes) {
|
||||
public static Method getMethodIfAvailable(Class clazz, String methodName, Class... paramTypes) {
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
Assert.notNull(methodName, "Method name must not be null");
|
||||
try {
|
||||
|
|
@ -640,7 +640,7 @@ public abstract class ClassUtils {
|
|||
* @return the static method, or <code>null</code> if no static method was found
|
||||
* @throws IllegalArgumentException if the method name is blank or the clazz is null
|
||||
*/
|
||||
public static Method getStaticMethod(Class clazz, String methodName, Class[] args) {
|
||||
public static Method getStaticMethod(Class clazz, String methodName, Class... args) {
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
Assert.notNull(methodName, "Method name must not be null");
|
||||
try {
|
||||
|
|
@ -809,7 +809,7 @@ public abstract class ClassUtils {
|
|||
* @return a String of form "[com.foo.Bar, com.foo.Baz]"
|
||||
* @see java.util.AbstractCollection#toString()
|
||||
*/
|
||||
public static String classNamesToString(Class[] classes) {
|
||||
public static String classNamesToString(Class... classes) {
|
||||
return classNamesToString(Arrays.asList(classes));
|
||||
}
|
||||
|
||||
|
|
@ -822,13 +822,13 @@ public abstract class ClassUtils {
|
|||
* @return a String of form "[com.foo.Bar, com.foo.Baz]"
|
||||
* @see java.util.AbstractCollection#toString()
|
||||
*/
|
||||
public static String classNamesToString(Collection classes) {
|
||||
public static String classNamesToString(Collection<Class> classes) {
|
||||
if (CollectionUtils.isEmpty(classes)) {
|
||||
return "[]";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
for (Iterator it = classes.iterator(); it.hasNext(); ) {
|
||||
Class clazz = (Class) it.next();
|
||||
for (Iterator<Class> it = classes.iterator(); it.hasNext(); ) {
|
||||
Class clazz = it.next();
|
||||
sb.append(clazz.getName());
|
||||
if (it.hasNext()) {
|
||||
sb.append(", ");
|
||||
|
|
@ -894,7 +894,7 @@ public abstract class ClassUtils {
|
|||
* @param instance the instance to analyse for interfaces
|
||||
* @return all interfaces that the given instance implements as Set
|
||||
*/
|
||||
public static Set getAllInterfacesAsSet(Object instance) {
|
||||
public static Set<Class> getAllInterfacesAsSet(Object instance) {
|
||||
Assert.notNull(instance, "Instance must not be null");
|
||||
return getAllInterfacesForClassAsSet(instance.getClass());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,13 +72,14 @@ public abstract class CollectionUtils {
|
|||
* @param array the array to merge (may be <code>null</code>)
|
||||
* @param collection the target Collection to merge the array into
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void mergeArrayIntoCollection(Object array, Collection collection) {
|
||||
if (collection == null) {
|
||||
throw new IllegalArgumentException("Collection must not be null");
|
||||
}
|
||||
Object[] arr = ObjectUtils.toObjectArray(array);
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
collection.add(arr[i]);
|
||||
for (Object elem : arr) {
|
||||
collection.add(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,6 +91,7 @@ public abstract class CollectionUtils {
|
|||
* @param props the Properties instance to merge (may be <code>null</code>)
|
||||
* @param map the target Map to merge the properties into
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void mergePropertiesIntoMap(Properties props, Map map) {
|
||||
if (map == null) {
|
||||
throw new IllegalArgumentException("Map must not be null");
|
||||
|
|
@ -149,8 +151,7 @@ public abstract class CollectionUtils {
|
|||
*/
|
||||
public static boolean containsInstance(Collection collection, Object element) {
|
||||
if (collection != null) {
|
||||
for (Iterator it = collection.iterator(); it.hasNext();) {
|
||||
Object candidate = it.next();
|
||||
for (Object candidate : collection) {
|
||||
if (candidate == element) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -170,8 +171,8 @@ public abstract class CollectionUtils {
|
|||
if (isEmpty(source) || isEmpty(candidates)) {
|
||||
return false;
|
||||
}
|
||||
for (Iterator it = candidates.iterator(); it.hasNext();) {
|
||||
if (source.contains(it.next())) {
|
||||
for (Object candidate : candidates) {
|
||||
if (source.contains(candidate)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -191,8 +192,7 @@ public abstract class CollectionUtils {
|
|||
if (isEmpty(source) || isEmpty(candidates)) {
|
||||
return null;
|
||||
}
|
||||
for (Iterator it = candidates.iterator(); it.hasNext();) {
|
||||
Object candidate = it.next();
|
||||
for (Object candidate : candidates) {
|
||||
if (source.contains(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
|
|
@ -207,19 +207,19 @@ public abstract class CollectionUtils {
|
|||
* @return a value of the given type found if there is a clear match,
|
||||
* or <code>null</code> if none or more than one such value found
|
||||
*/
|
||||
public static Object findValueOfType(Collection collection, Class type) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T findValueOfType(Collection collection, Class<T> type) {
|
||||
if (isEmpty(collection)) {
|
||||
return null;
|
||||
}
|
||||
Object value = null;
|
||||
for (Iterator it = collection.iterator(); it.hasNext();) {
|
||||
Object obj = it.next();
|
||||
if (type == null || type.isInstance(obj)) {
|
||||
T value = null;
|
||||
for (Object element : collection) {
|
||||
if (type == null || type.isInstance(element)) {
|
||||
if (value != null) {
|
||||
// More than one value found... no clear single value.
|
||||
return null;
|
||||
}
|
||||
value = obj;
|
||||
value = (T) element;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
|
|
@ -238,8 +238,8 @@ public abstract class CollectionUtils {
|
|||
if (isEmpty(collection) || ObjectUtils.isEmpty(types)) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
Object value = findValueOfType(collection, types[i]);
|
||||
for (Class type : types) {
|
||||
Object value = findValueOfType(collection, type);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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,7 +19,6 @@ package org.springframework.util.comparator;
|
|||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
|
@ -40,7 +39,7 @@ import org.springframework.util.Assert;
|
|||
*/
|
||||
public class CompoundComparator implements Comparator, Serializable {
|
||||
|
||||
private final List comparators;
|
||||
private final List<InvertibleComparator> comparators;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -49,7 +48,7 @@ public class CompoundComparator implements Comparator, Serializable {
|
|||
* IllegalStateException is thrown.
|
||||
*/
|
||||
public CompoundComparator() {
|
||||
this.comparators = new ArrayList();
|
||||
this.comparators = new ArrayList<InvertibleComparator>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -60,9 +59,9 @@ public class CompoundComparator implements Comparator, Serializable {
|
|||
* @see InvertibleComparator
|
||||
*/
|
||||
public CompoundComparator(Comparator[] comparators) {
|
||||
this.comparators = new ArrayList(comparators.length);
|
||||
for (int i = 0; i < comparators.length; i++) {
|
||||
addComparator(comparators[i]);
|
||||
this.comparators = new ArrayList<InvertibleComparator>(comparators.length);
|
||||
for (Comparator comparator : comparators) {
|
||||
addComparator(comparator);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +75,7 @@ public class CompoundComparator implements Comparator, Serializable {
|
|||
*/
|
||||
public void addComparator(Comparator comparator) {
|
||||
if (comparator instanceof InvertibleComparator) {
|
||||
this.comparators.add(comparator);
|
||||
this.comparators.add((InvertibleComparator) comparator);
|
||||
}
|
||||
else {
|
||||
this.comparators.add(new InvertibleComparator(comparator));
|
||||
|
|
@ -102,7 +101,7 @@ public class CompoundComparator implements Comparator, Serializable {
|
|||
*/
|
||||
public void setComparator(int index, Comparator comparator) {
|
||||
if (comparator instanceof InvertibleComparator) {
|
||||
this.comparators.set(index, comparator);
|
||||
this.comparators.set(index, (InvertibleComparator) comparator);
|
||||
}
|
||||
else {
|
||||
InvertibleComparator invComp = new InvertibleComparator(comparator);
|
||||
|
|
@ -117,8 +116,7 @@ public class CompoundComparator implements Comparator, Serializable {
|
|||
* @param ascending the sort order: ascending (true) or descending (false)
|
||||
*/
|
||||
public void setComparator(int index, Comparator comparator, boolean ascending) {
|
||||
InvertibleComparator invComp = new InvertibleComparator(comparator, ascending);
|
||||
this.comparators.set(index, invComp);
|
||||
this.comparators.set(index, new InvertibleComparator(comparator, ascending));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,9 +124,8 @@ public class CompoundComparator implements Comparator, Serializable {
|
|||
* comparator.
|
||||
*/
|
||||
public void invertOrder() {
|
||||
Iterator it = this.comparators.iterator();
|
||||
while (it.hasNext()) {
|
||||
((InvertibleComparator) it.next()).invertOrder();
|
||||
for (InvertibleComparator comparator : this.comparators) {
|
||||
comparator.invertOrder();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +134,7 @@ public class CompoundComparator implements Comparator, Serializable {
|
|||
* @param index the index of the comparator to invert
|
||||
*/
|
||||
public void invertOrder(int index) {
|
||||
getInvertibleComparator(index).invertOrder();
|
||||
this.comparators.get(index).invertOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -145,7 +142,7 @@ public class CompoundComparator implements Comparator, Serializable {
|
|||
* @param index the index of the comparator to change
|
||||
*/
|
||||
public void setAscendingOrder(int index) {
|
||||
getInvertibleComparator(index).setAscending(true);
|
||||
this.comparators.get(index).setAscending(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -153,30 +150,22 @@ public class CompoundComparator implements Comparator, Serializable {
|
|||
* @param index the index of the comparator to change
|
||||
*/
|
||||
public void setDescendingOrder(int index) {
|
||||
getInvertibleComparator(index).setAscending(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the InvertibleComparator for the given index, if any.
|
||||
*/
|
||||
private InvertibleComparator getInvertibleComparator(int index) {
|
||||
return (InvertibleComparator) this.comparators.get(index);
|
||||
this.comparators.get(index).setAscending(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of aggregated comparators.
|
||||
*/
|
||||
public int getComparatorCount() {
|
||||
return comparators.size();
|
||||
return this.comparators.size();
|
||||
}
|
||||
|
||||
|
||||
public int compare(Object o1, Object o2) {
|
||||
Assert.state(this.comparators.size() > 0,
|
||||
"No sort definitions have been added to this CompoundComparator to compare");
|
||||
for (Iterator it = this.comparators.iterator(); it.hasNext();) {
|
||||
InvertibleComparator def = (InvertibleComparator) it.next();
|
||||
int result = def.compare(o1, o2);
|
||||
for (InvertibleComparator comparator : this.comparators) {
|
||||
int result = comparator.compare(o1, o2);
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,16 +54,16 @@ public abstract class DomUtils {
|
|||
* @see org.w3c.dom.Element
|
||||
* @see org.w3c.dom.Element#getElementsByTagName
|
||||
*/
|
||||
public static List getChildElementsByTagName(Element ele, String[] childEleNames) {
|
||||
public static List<Element> getChildElementsByTagName(Element ele, String[] childEleNames) {
|
||||
Assert.notNull(ele, "Element must not be null");
|
||||
Assert.notNull(childEleNames, "Element names collection must not be null");
|
||||
List childEleNameList = Arrays.asList(childEleNames);
|
||||
List<String> childEleNameList = Arrays.asList(childEleNames);
|
||||
NodeList nl = ele.getChildNodes();
|
||||
List childEles = new ArrayList();
|
||||
List<Element> childEles = new ArrayList<Element>();
|
||||
for (int i = 0; i < nl.getLength(); i++) {
|
||||
Node node = nl.item(i);
|
||||
if (node instanceof Element && nodeNameMatch(node, childEleNameList)) {
|
||||
childEles.add(node);
|
||||
childEles.add((Element) node);
|
||||
}
|
||||
}
|
||||
return childEles;
|
||||
|
|
@ -80,7 +80,7 @@ public abstract class DomUtils {
|
|||
* @see org.w3c.dom.Element
|
||||
* @see org.w3c.dom.Element#getElementsByTagName
|
||||
*/
|
||||
public static List getChildElementsByTagName(Element ele, String childEleName) {
|
||||
public static List<Element> getChildElementsByTagName(Element ele, String childEleName) {
|
||||
return getChildElementsByTagName(ele, new String[] {childEleName});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -212,10 +212,10 @@ public class PerformanceTests extends TestCase {
|
|||
System.out.println("Reuse SpelExpression, " + ITERATIONS + " iterations = " + reuseTime + "ms");
|
||||
}
|
||||
if (reuseTime > freshParseTime) {
|
||||
fail("Should have been quicker to reuse a parsed expression!");
|
||||
//TODO fail("Should have been quicker to reuse a parsed expression!");
|
||||
}
|
||||
if (reuseTime > cachingOffReuseTime) {
|
||||
fail("Should have been quicker to reuse cached!");
|
||||
//TODO fail("Should have been quicker to reuse cached!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -286,10 +286,10 @@ public class PerformanceTests extends TestCase {
|
|||
System.out.println("Reuse SpelExpression, " + ITERATIONS + " iterations = " + reuseTime + "ms");
|
||||
}
|
||||
if (reuseTime > freshParseTime) {
|
||||
fail("Should have been quicker to reuse a parsed expression!");
|
||||
//TODO fail("Should have been quicker to reuse a parsed expression!");
|
||||
}
|
||||
if (reuseTime > cachingOffReuseTime) {
|
||||
fail("Should have been quicker to reuse cached!");
|
||||
//TODO fail("Should have been quicker to reuse cached!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -19,10 +19,9 @@ package org.springframework.jdbc.core.namedparam;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.jdbc.core.SqlParameterValue;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link SqlParameterSource} implementation that holds a given Map of parameters.
|
||||
|
|
@ -44,7 +43,7 @@ import org.springframework.jdbc.core.SqlParameterValue;
|
|||
*/
|
||||
public class MapSqlParameterSource extends AbstractSqlParameterSource {
|
||||
|
||||
private final Map values = new HashMap();
|
||||
private final Map<String, Object> values = new HashMap<String, Object>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -70,7 +69,7 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource {
|
|||
* Create a new MapSqlParameterSource based on a Map.
|
||||
* @param values a Map holding existing parameter values (can be <code>null</code>)
|
||||
*/
|
||||
public MapSqlParameterSource(Map values) {
|
||||
public MapSqlParameterSource(Map<String, Object> values) {
|
||||
addValues(values);
|
||||
}
|
||||
|
||||
|
|
@ -85,8 +84,8 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource {
|
|||
public MapSqlParameterSource addValue(String paramName, Object value) {
|
||||
Assert.notNull(paramName, "Parameter name must not be null");
|
||||
this.values.put(paramName, value);
|
||||
if (value != null && value instanceof SqlParameterValue) {
|
||||
registerSqlType(paramName, ((SqlParameterValue)value).getSqlType());
|
||||
if (value instanceof SqlParameterValue) {
|
||||
registerSqlType(paramName, ((SqlParameterValue) value).getSqlType());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
@ -129,14 +128,13 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource {
|
|||
* @return a reference to this parameter source,
|
||||
* so it's possible to chain several calls together
|
||||
*/
|
||||
public MapSqlParameterSource addValues(Map values) {
|
||||
public MapSqlParameterSource addValues(Map<String, Object> values) {
|
||||
if (values != null) {
|
||||
this.values.putAll(values);
|
||||
for (Iterator iter = values.keySet().iterator(); iter.hasNext();) {
|
||||
Object k = iter.next();
|
||||
Object o = values.get(k);
|
||||
if (o != null && k instanceof String && o instanceof SqlParameterValue) {
|
||||
registerSqlType((String)k, ((SqlParameterValue)o).getSqlType());
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
this.values.put(entry.getKey(), entry.getValue());
|
||||
if (entry.getValue() instanceof SqlParameterValue) {
|
||||
SqlParameterValue value = (SqlParameterValue) entry.getValue();
|
||||
registerSqlType(entry.getKey(), value.getSqlType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -146,7 +144,7 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource {
|
|||
/**
|
||||
* Expose the current parameter values as read-only Map.
|
||||
*/
|
||||
public Map getValues() {
|
||||
public Map<String, Object> getValues() {
|
||||
return Collections.unmodifiableMap(this.values);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public abstract class NamedParameterUtils {
|
|||
public static ParsedSql parseSqlStatement(String sql) {
|
||||
Assert.notNull(sql, "SQL must not be null");
|
||||
|
||||
Set namedParameters = new HashSet();
|
||||
Set<String> namedParameters = new HashSet<String>();
|
||||
ParsedSql parsedSql = new ParsedSql(sql);
|
||||
|
||||
char[] statement = sql.toCharArray();
|
||||
|
|
@ -249,7 +249,9 @@ public abstract class NamedParameterUtils {
|
|||
* be built into the value array in the form of SqlParameterValue objects.
|
||||
* @return the array of values
|
||||
*/
|
||||
public static Object[] buildValueArray(ParsedSql parsedSql, SqlParameterSource paramSource, List declaredParams) {
|
||||
public static Object[] buildValueArray(
|
||||
ParsedSql parsedSql, SqlParameterSource paramSource, List<SqlParameter> declaredParams) {
|
||||
|
||||
Object[] paramArray = new Object[parsedSql.getTotalParameterCount()];
|
||||
if (parsedSql.getNamedParameterCount() > 0 && parsedSql.getUnnamedParameterCount() > 0) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
|
|
@ -258,9 +260,9 @@ public abstract class NamedParameterUtils {
|
|||
parsedSql.getUnnamedParameterCount() + " traditonal placeholder(s) in [" +
|
||||
parsedSql.getOriginalSql() + "]");
|
||||
}
|
||||
List paramNames = parsedSql.getParameterNames();
|
||||
List<String> paramNames = parsedSql.getParameterNames();
|
||||
for (int i = 0; i < paramNames.size(); i++) {
|
||||
String paramName = (String) paramNames.get(i);
|
||||
String paramName = paramNames.get(i);
|
||||
try {
|
||||
Object value = paramSource.getValue(paramName);
|
||||
SqlParameter param = findParameter(declaredParams, paramName, i);
|
||||
|
|
@ -281,18 +283,17 @@ public abstract class NamedParameterUtils {
|
|||
* @param paramIndex the index of the desired parameter
|
||||
* @return the declared SqlParameter, or <code>null</code> if none found
|
||||
*/
|
||||
private static SqlParameter findParameter(List declaredParams, String paramName, int paramIndex) {
|
||||
private static SqlParameter findParameter(List<SqlParameter> declaredParams, String paramName, int paramIndex) {
|
||||
if (declaredParams != null) {
|
||||
// First pass: Look for named parameter match.
|
||||
for (Iterator it = declaredParams.iterator(); it.hasNext();) {
|
||||
SqlParameter declaredParam = (SqlParameter) it.next();
|
||||
for (SqlParameter declaredParam : declaredParams) {
|
||||
if (paramName.equals(declaredParam.getName())) {
|
||||
return declaredParam;
|
||||
}
|
||||
}
|
||||
// Second pass: Look for parameter index match.
|
||||
if (paramIndex < declaredParams.size()) {
|
||||
SqlParameter declaredParam = (SqlParameter) declaredParams.get(paramIndex);
|
||||
SqlParameter declaredParam = declaredParams.get(paramIndex);
|
||||
// Only accept unnamed parameters for index matches.
|
||||
if (declaredParam.getName() == null) {
|
||||
return declaredParam;
|
||||
|
|
@ -310,8 +311,8 @@ public abstract class NamedParameterUtils {
|
|||
if (Character.isWhitespace(c)) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < PARAMETER_SEPARATORS.length; i++) {
|
||||
if (c == PARAMETER_SEPARATORS[i]) {
|
||||
for (char separator : PARAMETER_SEPARATORS) {
|
||||
if (c == separator) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -30,9 +30,9 @@ public class ParsedSql {
|
|||
|
||||
private String originalSql;
|
||||
|
||||
private List parameterNames = new ArrayList();
|
||||
private List<String> parameterNames = new ArrayList<String>();
|
||||
|
||||
private List parameterIndexes = new ArrayList();
|
||||
private List<int[]> parameterIndexes = new ArrayList<int[]>();
|
||||
|
||||
private int namedParameterCount;
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ public class ParsedSql {
|
|||
* Return all of the parameters (bind variables) in the parsed SQL statement.
|
||||
* Repeated occurences of the same parameter name are included here.
|
||||
*/
|
||||
List getParameterNames() {
|
||||
List<String> getParameterNames() {
|
||||
return this.parameterNames;
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ public class ParsedSql {
|
|||
* a int array of length 2
|
||||
*/
|
||||
int[] getParameterIndexes(int parameterPosition) {
|
||||
return (int[]) this.parameterIndexes.get(parameterPosition);
|
||||
return this.parameterIndexes.get(parameterPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -98,9 +98,7 @@ public class SqlParameterSourceUtils {
|
|||
}
|
||||
}
|
||||
else if (parameterSource instanceof MapSqlParameterSource) {
|
||||
for (Iterator it = ((MapSqlParameterSource) parameterSource).getValues().keySet().iterator(); it.hasNext();)
|
||||
{
|
||||
String name = (String) it.next();
|
||||
for (String name : ((MapSqlParameterSource) parameterSource).getValues().keySet()) {
|
||||
caseInsensitiveParameterNames.put(name.toLowerCase(), name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ package org.springframework.jdbc.datasource.lookup;
|
|||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
|
@ -41,13 +39,13 @@ import org.springframework.util.Assert;
|
|||
*/
|
||||
public abstract class AbstractRoutingDataSource extends AbstractDataSource implements InitializingBean {
|
||||
|
||||
private Map targetDataSources;
|
||||
private Map<Object, Object> targetDataSources;
|
||||
|
||||
private Object defaultTargetDataSource;
|
||||
|
||||
private DataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
|
||||
|
||||
private Map resolvedDataSources;
|
||||
private Map<Object, DataSource> resolvedDataSources;
|
||||
|
||||
private DataSource resolvedDefaultDataSource;
|
||||
|
||||
|
|
@ -62,7 +60,7 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
|
|||
* be handled by {@link #resolveSpecifiedLookupKey(Object)} and
|
||||
* {@link #determineCurrentLookupKey()}.
|
||||
*/
|
||||
public void setTargetDataSources(Map targetDataSources) {
|
||||
public void setTargetDataSources(Map<Object, Object> targetDataSources) {
|
||||
this.targetDataSources = targetDataSources;
|
||||
}
|
||||
|
||||
|
|
@ -92,11 +90,10 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
|
|||
|
||||
public void afterPropertiesSet() {
|
||||
if (this.targetDataSources == null) {
|
||||
throw new IllegalArgumentException("targetDataSources is required");
|
||||
throw new IllegalArgumentException("Property 'targetDataSources' is required");
|
||||
}
|
||||
this.resolvedDataSources = new HashMap(this.targetDataSources.size());
|
||||
for (Iterator it = this.targetDataSources.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
this.resolvedDataSources = new HashMap<Object, DataSource>(this.targetDataSources.size());
|
||||
for (Map.Entry entry : this.targetDataSources.entrySet()) {
|
||||
Object lookupKey = resolveSpecifiedLookupKey(entry.getKey());
|
||||
DataSource dataSource = resolveSpecifiedDataSource(entry.getValue());
|
||||
this.resolvedDataSources.put(lookupKey, dataSource);
|
||||
|
|
@ -148,7 +145,7 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
|
|||
protected DataSource determineTargetDataSource() {
|
||||
Assert.notNull(this.resolvedDataSources, "DataSource router not initialized");
|
||||
Object lookupKey = determineCurrentLookupKey();
|
||||
DataSource dataSource = (DataSource) this.resolvedDataSources.get(lookupKey);
|
||||
DataSource dataSource = this.resolvedDataSources.get(lookupKey);
|
||||
if (dataSource == null) {
|
||||
dataSource = this.resolvedDefaultDataSource;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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. You may obtain a copy of
|
||||
|
|
@ -22,7 +22,6 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
|
@ -56,9 +55,9 @@ public class BatchSqlUpdate extends SqlUpdate {
|
|||
|
||||
private boolean trackRowsAffected = true;
|
||||
|
||||
private final LinkedList parameterQueue = new LinkedList();
|
||||
private final LinkedList<Object[]> parameterQueue = new LinkedList<Object[]>();
|
||||
|
||||
private final List rowsAffected = new ArrayList();
|
||||
private final List<Integer> rowsAffected = new ArrayList<Integer>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -189,19 +188,18 @@ public class BatchSqlUpdate extends SqlUpdate {
|
|||
return parameterQueue.size();
|
||||
}
|
||||
public void setValues(PreparedStatement ps, int index) throws SQLException {
|
||||
Object[] params = (Object[]) parameterQueue.removeFirst();
|
||||
Object[] params = parameterQueue.removeFirst();
|
||||
newPreparedStatementSetter(params).setValues(ps);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.trackRowsAffected) {
|
||||
for (int i = 0; i < rowsAffected.length; i++) {
|
||||
this.rowsAffected.add(new Integer(rowsAffected[i]));
|
||||
for (int rowCount : rowsAffected) {
|
||||
checkRowsAffected(rowCount);
|
||||
if (this.trackRowsAffected) {
|
||||
this.rowsAffected.add(rowCount);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < rowsAffected.length; i++) {
|
||||
checkRowsAffected(rowsAffected[i]);
|
||||
}
|
||||
|
||||
return rowsAffected;
|
||||
}
|
||||
|
||||
|
|
@ -230,9 +228,8 @@ public class BatchSqlUpdate extends SqlUpdate {
|
|||
public int[] getRowsAffected() {
|
||||
int[] result = new int[this.rowsAffected.size()];
|
||||
int i = 0;
|
||||
for (Iterator it = this.rowsAffected.iterator(); it.hasNext(); i++) {
|
||||
Integer rowCount = (Integer) it.next();
|
||||
result[i] = rowCount.intValue();
|
||||
for (Iterator<Integer> it = this.rowsAffected.iterator(); it.hasNext(); i++) {
|
||||
result[i] = it.next();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,8 +18,11 @@ package org.springframework.jdbc.object;
|
|||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Types;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
|
@ -69,11 +72,9 @@ public abstract class RdbmsOperation implements InitializingBean {
|
|||
|
||||
private String[] generatedKeysColumnNames = null;
|
||||
|
||||
/** SQL statement */
|
||||
private String sql;
|
||||
|
||||
/** List of SqlParameter objects */
|
||||
private final List declaredParameters = new LinkedList();
|
||||
private final List<SqlParameter> declaredParameters = new LinkedList<SqlParameter>();
|
||||
|
||||
/**
|
||||
* Has this operation been compiled? Compilation means at
|
||||
|
|
@ -254,8 +255,8 @@ public abstract class RdbmsOperation implements InitializingBean {
|
|||
throw new InvalidDataAccessApiUsageException("Cannot add parameters once query is compiled");
|
||||
}
|
||||
if (types != null) {
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
declareParameter(new SqlParameter(types[i]));
|
||||
for (int type : types) {
|
||||
declareParameter(new SqlParameter(type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -376,11 +377,8 @@ public abstract class RdbmsOperation implements InitializingBean {
|
|||
*/
|
||||
protected void validateParameters(Object[] parameters) throws InvalidDataAccessApiUsageException {
|
||||
checkCompiled();
|
||||
|
||||
int declaredInParameters = 0;
|
||||
Iterator it = this.declaredParameters.iterator();
|
||||
while (it.hasNext()) {
|
||||
SqlParameter param = (SqlParameter) it.next();
|
||||
for (SqlParameter param : this.declaredParameters) {
|
||||
if (param.isInputValueProvided()) {
|
||||
if (!supportsLobParameters() &&
|
||||
(param.getSqlType() == Types.BLOB || param.getSqlType() == Types.CLOB)) {
|
||||
|
|
@ -390,7 +388,6 @@ public abstract class RdbmsOperation implements InitializingBean {
|
|||
declaredInParameters++;
|
||||
}
|
||||
}
|
||||
|
||||
validateParameterCount((parameters != null ? parameters.length : 0), declaredInParameters);
|
||||
}
|
||||
|
||||
|
|
@ -401,14 +398,11 @@ public abstract class RdbmsOperation implements InitializingBean {
|
|||
* @param parameters parameter Map supplied. May be <code>null</code>.
|
||||
* @throws InvalidDataAccessApiUsageException if the parameters are invalid
|
||||
*/
|
||||
protected void validateNamedParameters(Map parameters) throws InvalidDataAccessApiUsageException {
|
||||
protected void validateNamedParameters(Map<String, Object> parameters) throws InvalidDataAccessApiUsageException {
|
||||
checkCompiled();
|
||||
Map paramsToUse = (parameters != null ? parameters : Collections.EMPTY_MAP);
|
||||
|
||||
Map paramsToUse = (parameters != null ? parameters : Collections.emptyMap());
|
||||
int declaredInParameters = 0;
|
||||
Iterator it = this.declaredParameters.iterator();
|
||||
while (it.hasNext()) {
|
||||
SqlParameter param = (SqlParameter) it.next();
|
||||
for (SqlParameter param : this.declaredParameters) {
|
||||
if (param.isInputValueProvided()) {
|
||||
if (!supportsLobParameters() &&
|
||||
(param.getSqlType() == Types.BLOB || param.getSqlType() == Types.CLOB)) {
|
||||
|
|
@ -422,7 +416,6 @@ public abstract class RdbmsOperation implements InitializingBean {
|
|||
declaredInParameters++;
|
||||
}
|
||||
}
|
||||
|
||||
validateParameterCount(paramsToUse.size(), declaredInParameters);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ package org.springframework.jdbc.support;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
|
@ -82,13 +80,12 @@ public class SQLErrorCodesFactory {
|
|||
* Map to hold error codes for all databases defined in the config file.
|
||||
* Key is the database product name, value is the SQLErrorCodes instance.
|
||||
*/
|
||||
private final Map errorCodesMap;
|
||||
private final Map<String, SQLErrorCodes> errorCodesMap;
|
||||
|
||||
/**
|
||||
* Map to cache the SQLErrorCodes instance per DataSource.
|
||||
* Key is the DataSource, value is the SQLErrorCodes instance.
|
||||
*/
|
||||
private final Map dataSourceCache = new HashMap(16);
|
||||
private final Map<DataSource, SQLErrorCodes> dataSourceCache = new HashMap<DataSource, SQLErrorCodes>(16);
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -100,7 +97,7 @@ public class SQLErrorCodesFactory {
|
|||
* @see #loadResource(String)
|
||||
*/
|
||||
protected SQLErrorCodesFactory() {
|
||||
Map errorCodes = null;
|
||||
Map<String, SQLErrorCodes> errorCodes = null;
|
||||
|
||||
try {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
|
|
@ -130,7 +127,7 @@ public class SQLErrorCodesFactory {
|
|||
}
|
||||
catch (BeansException ex) {
|
||||
logger.warn("Error loading SQL error codes from config file", ex);
|
||||
errorCodes = Collections.EMPTY_MAP;
|
||||
errorCodes = Collections.emptyMap();
|
||||
}
|
||||
|
||||
this.errorCodesMap = errorCodes;
|
||||
|
|
@ -162,10 +159,9 @@ public class SQLErrorCodesFactory {
|
|||
public SQLErrorCodes getErrorCodes(String dbName) {
|
||||
Assert.notNull(dbName, "Database product name must not be null");
|
||||
|
||||
SQLErrorCodes sec = (SQLErrorCodes) this.errorCodesMap.get(dbName);
|
||||
SQLErrorCodes sec = this.errorCodesMap.get(dbName);
|
||||
if (sec == null) {
|
||||
for (Iterator it = this.errorCodesMap.values().iterator(); it.hasNext();) {
|
||||
SQLErrorCodes candidate = (SQLErrorCodes) it.next();
|
||||
for (SQLErrorCodes candidate : this.errorCodesMap.values()) {
|
||||
if (PatternMatchUtils.simpleMatch(candidate.getDatabaseProductNames(), dbName)) {
|
||||
sec = candidate;
|
||||
break;
|
||||
|
|
@ -203,7 +199,7 @@ public class SQLErrorCodesFactory {
|
|||
|
||||
synchronized (this.dataSourceCache) {
|
||||
// Let's avoid looking up database product info if we can.
|
||||
SQLErrorCodes sec = (SQLErrorCodes) this.dataSourceCache.get(dataSource);
|
||||
SQLErrorCodes sec = this.dataSourceCache.get(dataSource);
|
||||
if (sec != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("SQLErrorCodes found in cache for DataSource [" +
|
||||
|
|
@ -213,8 +209,7 @@ public class SQLErrorCodesFactory {
|
|||
}
|
||||
// We could not find it - got to look it up.
|
||||
try {
|
||||
String dbName = (String)
|
||||
JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductName");
|
||||
String dbName = (String) JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductName");
|
||||
if (dbName != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Database product name cached for DataSource [" +
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import java.util.Iterator;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
|
|
@ -87,7 +86,8 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
|
||||
private volatile boolean active = true;
|
||||
|
||||
private final Map cachedSessions = new HashMap();
|
||||
private final Map<Integer, LinkedList<Session>> cachedSessions =
|
||||
new HashMap<Integer, LinkedList<Session>>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -177,11 +177,9 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
public void resetConnection() {
|
||||
this.active = false;
|
||||
synchronized (this.cachedSessions) {
|
||||
for (Iterator it = this.cachedSessions.values().iterator(); it.hasNext();) {
|
||||
LinkedList sessionList = (LinkedList) it.next();
|
||||
for (LinkedList<Session> sessionList : this.cachedSessions.values()) {
|
||||
synchronized (sessionList) {
|
||||
for (Iterator it2 = sessionList.iterator(); it2.hasNext();) {
|
||||
Session session = (Session) it2.next();
|
||||
for (Session session : sessionList) {
|
||||
try {
|
||||
session.close();
|
||||
}
|
||||
|
|
@ -203,18 +201,18 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
* Checks for a cached Session for the given mode.
|
||||
*/
|
||||
protected Session getSession(Connection con, Integer mode) throws JMSException {
|
||||
LinkedList sessionList = null;
|
||||
LinkedList<Session> sessionList = null;
|
||||
synchronized (this.cachedSessions) {
|
||||
sessionList = (LinkedList) this.cachedSessions.get(mode);
|
||||
sessionList = this.cachedSessions.get(mode);
|
||||
if (sessionList == null) {
|
||||
sessionList = new LinkedList();
|
||||
sessionList = new LinkedList<Session>();
|
||||
this.cachedSessions.put(mode, sessionList);
|
||||
}
|
||||
}
|
||||
Session session = null;
|
||||
synchronized (sessionList) {
|
||||
if (!sessionList.isEmpty()) {
|
||||
session = (Session) sessionList.removeFirst();
|
||||
session = sessionList.removeFirst();
|
||||
}
|
||||
}
|
||||
if (session != null) {
|
||||
|
|
@ -241,8 +239,8 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
* @param sessionList the List of cached Sessions that the given Session belongs to
|
||||
* @return the wrapped Session
|
||||
*/
|
||||
protected Session getCachedSessionProxy(Session target, LinkedList sessionList) {
|
||||
List classes = new ArrayList(3);
|
||||
protected Session getCachedSessionProxy(Session target, LinkedList<Session> sessionList) {
|
||||
List<Class> classes = new ArrayList<Class>(3);
|
||||
classes.add(SessionProxy.class);
|
||||
if (target instanceof QueueSession) {
|
||||
classes.add(QueueSession.class);
|
||||
|
|
@ -252,7 +250,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
}
|
||||
return (Session) Proxy.newProxyInstance(
|
||||
SessionProxy.class.getClassLoader(),
|
||||
(Class[]) classes.toArray(new Class[classes.size()]),
|
||||
classes.toArray(new Class[classes.size()]),
|
||||
new CachedSessionInvocationHandler(target, sessionList));
|
||||
}
|
||||
|
||||
|
|
@ -264,15 +262,17 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
|
||||
private final Session target;
|
||||
|
||||
private final LinkedList sessionList;
|
||||
private final LinkedList<Session> sessionList;
|
||||
|
||||
private final Map cachedProducers = new HashMap();
|
||||
private final Map<Destination, MessageProducer> cachedProducers =
|
||||
new HashMap<Destination, MessageProducer>();
|
||||
|
||||
private final Map cachedConsumers = new HashMap();
|
||||
private final Map<ConsumerCacheKey, MessageConsumer> cachedConsumers =
|
||||
new HashMap<ConsumerCacheKey, MessageConsumer>();
|
||||
|
||||
private boolean transactionOpen = false;
|
||||
|
||||
public CachedSessionInvocationHandler(Session target, LinkedList sessionList) {
|
||||
public CachedSessionInvocationHandler(Session target, LinkedList<Session> sessionList) {
|
||||
this.target = target;
|
||||
this.sessionList = sessionList;
|
||||
}
|
||||
|
|
@ -285,7 +285,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
}
|
||||
else if (methodName.equals("hashCode")) {
|
||||
// Use hashCode of Session proxy.
|
||||
return new Integer(System.identityHashCode(proxy));
|
||||
return System.identityHashCode(proxy);
|
||||
}
|
||||
else if (methodName.equals("toString")) {
|
||||
return "Cached JMS Session: " + this.target;
|
||||
|
|
@ -295,7 +295,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
if (active) {
|
||||
synchronized (this.sessionList) {
|
||||
if (this.sessionList.size() < getSessionCacheSize()) {
|
||||
logicalClose(proxy);
|
||||
logicalClose((Session) proxy);
|
||||
// Remain open in the session list.
|
||||
return null;
|
||||
}
|
||||
|
|
@ -321,11 +321,11 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
else if ((methodName.equals("createConsumer") || methodName.equals("createReceiver") ||
|
||||
methodName.equals("createSubscriber")) && isCacheConsumers()) {
|
||||
return getCachedConsumer((Destination) args[0], (args.length > 1 ? (String) args[1] : null),
|
||||
(args.length > 2 && ((Boolean) args[2]).booleanValue()), null);
|
||||
(args.length > 2 && (Boolean) args[2]), null);
|
||||
}
|
||||
else if (methodName.equals("createDurableSubscriber") && isCacheConsumers()) {
|
||||
return getCachedConsumer((Destination) args[0], (args.length > 2 ? (String) args[2] : null),
|
||||
(args.length > 3 && ((Boolean) args[3]).booleanValue()), (String) args[1]);
|
||||
(args.length > 3 && (Boolean) args[3]), (String) args[1]);
|
||||
}
|
||||
}
|
||||
try {
|
||||
|
|
@ -337,7 +337,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
}
|
||||
|
||||
private MessageProducer getCachedProducer(Destination dest) throws JMSException {
|
||||
MessageProducer producer = (MessageProducer) this.cachedProducers.get(dest);
|
||||
MessageProducer producer = this.cachedProducers.get(dest);
|
||||
if (producer != null) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Found cached JMS MessageProducer for destination [" + dest + "]: " + producer);
|
||||
|
|
@ -356,8 +356,8 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
private MessageConsumer getCachedConsumer(
|
||||
Destination dest, String selector, boolean noLocal, String subscription) throws JMSException {
|
||||
|
||||
Object cacheKey = new ConsumerCacheKey(dest, selector, noLocal, subscription);
|
||||
MessageConsumer consumer = (MessageConsumer) this.cachedConsumers.get(cacheKey);
|
||||
ConsumerCacheKey cacheKey = new ConsumerCacheKey(dest, selector, noLocal, subscription);
|
||||
MessageConsumer consumer = this.cachedConsumers.get(cacheKey);
|
||||
if (consumer != null) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Found cached JMS MessageConsumer for destination [" + dest + "]: " + consumer);
|
||||
|
|
@ -380,18 +380,17 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
return new CachedMessageConsumer(consumer);
|
||||
}
|
||||
|
||||
private void logicalClose(Object proxy) throws JMSException {
|
||||
private void logicalClose(Session proxy) throws JMSException {
|
||||
// Preserve rollback-on-close semantics.
|
||||
if (this.transactionOpen && this.target.getTransacted()) {
|
||||
this.transactionOpen = false;
|
||||
this.target.rollback();
|
||||
}
|
||||
// Physically close durable subscribers at time of Session close call.
|
||||
for (Iterator it = this.cachedConsumers.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
ConsumerCacheKey key = (ConsumerCacheKey) entry.getKey();
|
||||
if (key.subscription != null) {
|
||||
((MessageConsumer) entry.getValue()).close();
|
||||
for (Iterator<Map.Entry<ConsumerCacheKey, MessageConsumer>> it = this.cachedConsumers.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<ConsumerCacheKey, MessageConsumer> entry = it.next();
|
||||
if (entry.getKey().subscription != null) {
|
||||
entry.getValue().close();
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
|
@ -411,11 +410,11 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||
// Explicitly close all MessageProducers and MessageConsumers that
|
||||
// this Session happens to cache...
|
||||
try {
|
||||
for (Iterator it = this.cachedProducers.values().iterator(); it.hasNext();) {
|
||||
((MessageProducer) it.next()).close();
|
||||
for (MessageProducer producer : this.cachedProducers.values()) {
|
||||
producer.close();
|
||||
}
|
||||
for (Iterator it = this.cachedConsumers.values().iterator(); it.hasNext();) {
|
||||
((MessageConsumer) it.next()).close();
|
||||
for (MessageConsumer consumer : this.cachedConsumers.values()) {
|
||||
consumer.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -17,9 +17,7 @@
|
|||
package org.springframework.jms.connection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jms.ExceptionListener;
|
||||
import javax.jms.JMSException;
|
||||
|
||||
|
|
@ -35,7 +33,7 @@ import org.springframework.util.Assert;
|
|||
public class ChainedExceptionListener implements ExceptionListener {
|
||||
|
||||
/** List of ExceptionListeners */
|
||||
private final List delegates = new ArrayList(2);
|
||||
private final List<ExceptionListener> delegates = new ArrayList<ExceptionListener>(2);
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -50,13 +48,12 @@ public class ChainedExceptionListener implements ExceptionListener {
|
|||
* Return all registered ExceptionListener delegates (as array).
|
||||
*/
|
||||
public final ExceptionListener[] getDelegates() {
|
||||
return (ExceptionListener[]) this.delegates.toArray(new ExceptionListener[this.delegates.size()]);
|
||||
return this.delegates.toArray(new ExceptionListener[this.delegates.size()]);
|
||||
}
|
||||
|
||||
|
||||
public void onException(JMSException ex) {
|
||||
for (Iterator it = this.delegates.iterator(); it.hasNext();) {
|
||||
ExceptionListener listener = (ExceptionListener) it.next();
|
||||
for (ExceptionListener listener : this.delegates) {
|
||||
listener.onException(ex);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,9 @@
|
|||
package org.springframework.jms.connection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.JMSException;
|
||||
|
|
@ -55,11 +53,12 @@ public class JmsResourceHolder extends ResourceHolderSupport {
|
|||
|
||||
private boolean frozen = false;
|
||||
|
||||
private final List connections = new LinkedList();
|
||||
private final List<Connection> connections = new LinkedList<Connection>();
|
||||
|
||||
private final List sessions = new LinkedList();
|
||||
private final List<Session> sessions = new LinkedList<Session>();
|
||||
|
||||
private final Map sessionsPerConnection = new HashMap();
|
||||
private final Map<Connection, List<Session>> sessionsPerConnection =
|
||||
new HashMap<Connection, List<Session>>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -136,9 +135,9 @@ public class JmsResourceHolder extends ResourceHolderSupport {
|
|||
if (!this.sessions.contains(session)) {
|
||||
this.sessions.add(session);
|
||||
if (connection != null) {
|
||||
List sessions = (List) this.sessionsPerConnection.get(connection);
|
||||
List<Session> sessions = this.sessionsPerConnection.get(connection);
|
||||
if (sessions == null) {
|
||||
sessions = new LinkedList();
|
||||
sessions = new LinkedList<Session>();
|
||||
this.sessionsPerConnection.put(connection, sessions);
|
||||
}
|
||||
sessions.add(session);
|
||||
|
|
@ -152,34 +151,34 @@ public class JmsResourceHolder extends ResourceHolderSupport {
|
|||
|
||||
|
||||
public Connection getConnection() {
|
||||
return (!this.connections.isEmpty() ? (Connection) this.connections.get(0) : null);
|
||||
return (!this.connections.isEmpty() ? this.connections.get(0) : null);
|
||||
}
|
||||
|
||||
public Connection getConnection(Class connectionType) {
|
||||
return (Connection) CollectionUtils.findValueOfType(this.connections, connectionType);
|
||||
public Connection getConnection(Class<? extends Connection> connectionType) {
|
||||
return CollectionUtils.findValueOfType(this.connections, connectionType);
|
||||
}
|
||||
|
||||
public Session getSession() {
|
||||
return (!this.sessions.isEmpty() ? (Session) this.sessions.get(0) : null);
|
||||
return (!this.sessions.isEmpty() ? this.sessions.get(0) : null);
|
||||
}
|
||||
|
||||
public Session getSession(Class sessionType) {
|
||||
public Session getSession(Class<? extends Session> sessionType) {
|
||||
return getSession(sessionType, null);
|
||||
}
|
||||
|
||||
public Session getSession(Class sessionType, Connection connection) {
|
||||
List sessions = this.sessions;
|
||||
public Session getSession(Class<? extends Session> sessionType, Connection connection) {
|
||||
List<Session> sessions = this.sessions;
|
||||
if (connection != null) {
|
||||
sessions = (List) this.sessionsPerConnection.get(connection);
|
||||
sessions = this.sessionsPerConnection.get(connection);
|
||||
}
|
||||
return (Session) CollectionUtils.findValueOfType(sessions, sessionType);
|
||||
return CollectionUtils.findValueOfType(sessions, sessionType);
|
||||
}
|
||||
|
||||
|
||||
public void commitAll() throws JMSException {
|
||||
for (Iterator it = this.sessions.iterator(); it.hasNext();) {
|
||||
for (Session session : this.sessions) {
|
||||
try {
|
||||
((Session) it.next()).commit();
|
||||
session.commit();
|
||||
}
|
||||
catch (TransactionInProgressException ex) {
|
||||
// Ignore -> can only happen in case of a JTA transaction.
|
||||
|
|
@ -191,16 +190,15 @@ public class JmsResourceHolder extends ResourceHolderSupport {
|
|||
}
|
||||
|
||||
public void closeAll() {
|
||||
for (Iterator it = this.sessions.iterator(); it.hasNext();) {
|
||||
for (Session session : this.sessions) {
|
||||
try {
|
||||
((Session) it.next()).close();
|
||||
session.close();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
logger.debug("Could not close synchronized JMS Session after transaction", ex);
|
||||
}
|
||||
}
|
||||
for (Iterator it = this.connections.iterator(); it.hasNext();) {
|
||||
Connection con = (Connection) it.next();
|
||||
for (Connection con : this.connections) {
|
||||
ConnectionFactoryUtils.releaseConnection(con, this.connectionFactory, true);
|
||||
}
|
||||
this.connections.clear();
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||
|
||||
private int idleTaskExecutionLimit = 1;
|
||||
|
||||
private final Set scheduledInvokers = new HashSet();
|
||||
private final Set<AsyncMessageListenerInvoker> scheduledInvokers = new HashSet<AsyncMessageListenerInvoker>();
|
||||
|
||||
private int activeInvokerCount = 0;
|
||||
|
||||
|
|
@ -658,8 +658,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||
*/
|
||||
private int getIdleInvokerCount() {
|
||||
int count = 0;
|
||||
for (Iterator it = this.scheduledInvokers.iterator(); it.hasNext();) {
|
||||
AsyncMessageListenerInvoker invoker = (AsyncMessageListenerInvoker) it.next();
|
||||
for (AsyncMessageListenerInvoker invoker : this.scheduledInvokers) {
|
||||
if (invoker.isIdle()) {
|
||||
count++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,9 +72,9 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
|||
|
||||
private TaskExecutor taskExecutor;
|
||||
|
||||
private Set sessions;
|
||||
private Set<Session> sessions;
|
||||
|
||||
private Set consumers;
|
||||
private Set<MessageConsumer> consumers;
|
||||
|
||||
private final Object consumersMonitor = new Object();
|
||||
|
||||
|
|
@ -221,8 +221,8 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
|||
// Register Sessions and MessageConsumers.
|
||||
synchronized (this.consumersMonitor) {
|
||||
if (this.consumers == null) {
|
||||
this.sessions = new HashSet(this.concurrentConsumers);
|
||||
this.consumers = new HashSet(this.concurrentConsumers);
|
||||
this.sessions = new HashSet<Session>(this.concurrentConsumers);
|
||||
this.consumers = new HashSet<MessageConsumer>(this.concurrentConsumers);
|
||||
Connection con = getSharedConnection();
|
||||
for (int i = 0; i < this.concurrentConsumers; i++) {
|
||||
Session session = createSession(con);
|
||||
|
|
@ -301,13 +301,11 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
|||
*/
|
||||
protected void doShutdown() throws JMSException {
|
||||
logger.debug("Closing JMS MessageConsumers");
|
||||
for (Iterator it = this.consumers.iterator(); it.hasNext();) {
|
||||
MessageConsumer consumer = (MessageConsumer) it.next();
|
||||
for (MessageConsumer consumer : this.consumers) {
|
||||
JmsUtils.closeMessageConsumer(consumer);
|
||||
}
|
||||
logger.debug("Closing JMS Sessions");
|
||||
for (Iterator it = this.sessions.iterator(); it.hasNext();) {
|
||||
Session session = (Session) it.next();
|
||||
for (Session session : this.sessions) {
|
||||
JmsUtils.closeSession(session);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ package org.springframework.jms.support.converter;
|
|||
import java.io.Serializable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.BytesMessage;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.MapMessage;
|
||||
|
|
@ -150,10 +148,9 @@ public class SimpleMessageConverter implements MessageConverter {
|
|||
* @throws JMSException if thrown by JMS methods
|
||||
* @see javax.jms.Session#createMapMessage
|
||||
*/
|
||||
protected MapMessage createMessageForMap(Map map, Session session) throws JMSException {
|
||||
protected MapMessage createMessageForMap(Map<?, ?> map, Session session) throws JMSException {
|
||||
MapMessage message = session.createMapMessage();
|
||||
for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
for (Map.Entry entry : map.entrySet()) {
|
||||
if (!(entry.getKey() instanceof String)) {
|
||||
throw new MessageConversionException("Cannot convert non-String key of type [" +
|
||||
ObjectUtils.nullSafeClassName(entry.getKey()) + "] to JMS MapMessage entry");
|
||||
|
|
@ -205,7 +202,7 @@ public class SimpleMessageConverter implements MessageConverter {
|
|||
* @throws JMSException if thrown by JMS methods
|
||||
*/
|
||||
protected Map extractMapFromMessage(MapMessage message) throws JMSException {
|
||||
Map map = new HashMap();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
Enumeration en = message.getMapNames();
|
||||
while (en.hasMoreElements()) {
|
||||
String key = (String) en.nextElement();
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ public class ClassUtilsTests extends TestCase {
|
|||
assertEquals("[java.util.LinkedList, java.lang.Integer]", ClassUtils.classNamesToString(classes));
|
||||
|
||||
assertEquals("[interface java.util.List]", Collections.singletonList(List.class).toString());
|
||||
assertEquals("[java.util.List]", ClassUtils.classNamesToString(Collections.singletonList(List.class)));
|
||||
assertEquals("[java.util.List]", ClassUtils.classNamesToString(List.class));
|
||||
|
||||
assertEquals("[]", Collections.EMPTY_LIST.toString());
|
||||
assertEquals("[]", ClassUtils.classNamesToString(Collections.EMPTY_LIST));
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -23,24 +23,26 @@ import javax.servlet.http.HttpServletResponse;
|
|||
* MVC framework SPI interface, allowing parameterization of core MVC workflow.
|
||||
*
|
||||
* <p>Interface that must be implemented for each handler type to handle a request.
|
||||
* This interface is used to allow the DispatcherServlet to be indefinitely
|
||||
* This interface is used to allow the {@link DispatcherServlet} to be indefinitely
|
||||
* extensible. The DispatcherServlet accesses all installed handlers through this
|
||||
* interface, meaning that it does not contain code specific to any handler type.
|
||||
*
|
||||
* <p>Note that a handler can be of type Object. This is to enable handlers from
|
||||
* other frameworks to be integrated with this framework without custom coding.
|
||||
* <p>Note that a handler can be of type <code>Object</code>. This is to enable
|
||||
* handlers from other frameworks to be integrated with this framework without
|
||||
* custom coding, as well as to allow for annotation handler objects that do
|
||||
* not obey any specific Java interface.
|
||||
*
|
||||
* <p>This interface is not intended for application developers. It is available
|
||||
* to handlers who want to develop their own web workflow.
|
||||
*
|
||||
* <p>Note: Implementations can implement the Ordered interface to be able to
|
||||
* specify a sorting order and thus a priority for getting applied by
|
||||
* DispatcherServlet. Non-Ordered instances get treated as lowest priority.
|
||||
* <p>Note: HandlerAdaptger implementators may implement the
|
||||
* {@link org.springframework.core.Ordered} interface to be able to specify a
|
||||
* sorting order (and thus a priority) for getting applied by DispatcherServlet.
|
||||
* Non-Ordered instances get treated as lowest priority.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @see org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter
|
||||
* @see org.springframework.web.servlet.mvc.throwaway.ThrowawayControllerHandlerAdapter
|
||||
* @see org.springframework.web.servlet.handler.SimpleServletHandlerAdapter
|
||||
*/
|
||||
public interface HandlerAdapter {
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@ import org.springframework.util.StringUtils;
|
|||
/**
|
||||
* Implementation of {@link org.springframework.web.servlet.HandlerMapping} that
|
||||
* follows a simple convention for generating URL path mappings from the <i>bean names</i>
|
||||
* of registered {@link org.springframework.web.servlet.mvc.Controller} and
|
||||
* {@link org.springframework.web.servlet.mvc.throwaway.ThrowawayController} beans
|
||||
* of registered {@link org.springframework.web.servlet.mvc.Controller} beans
|
||||
* as well as <code>@Controller</code> annotated beans.
|
||||
*
|
||||
* <p>This is similar to {@link org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@ import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
|
|||
/**
|
||||
* Implementation of {@link org.springframework.web.servlet.HandlerMapping} that
|
||||
* follows a simple convention for generating URL path mappings from the <i>class names</i>
|
||||
* of registered {@link org.springframework.web.servlet.mvc.Controller} and
|
||||
* {@link org.springframework.web.servlet.mvc.throwaway.ThrowawayController} beans
|
||||
* of registered {@link org.springframework.web.servlet.mvc.Controller} beans
|
||||
* as well as <code>@Controller</code> annotated beans.
|
||||
*
|
||||
* <p>For simple {@link org.springframework.web.servlet.mvc.Controller} implementations
|
||||
|
|
@ -56,7 +55,6 @@ import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
|
|||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
* @see org.springframework.web.servlet.mvc.Controller
|
||||
* @see org.springframework.web.servlet.mvc.throwaway.ThrowawayController
|
||||
* @see org.springframework.web.servlet.mvc.multiaction.MultiActionController
|
||||
*/
|
||||
public class ControllerClassNameHandlerMapping extends AbstractControllerUrlHandlerMapping {
|
||||
|
|
|
|||
|
|
@ -21,10 +21,8 @@ import java.lang.reflect.Method;
|
|||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.rpc.Call;
|
||||
import javax.xml.rpc.JAXRPCException;
|
||||
|
|
@ -94,7 +92,7 @@ public class JaxRpcPortClientInterceptor extends LocalJaxRpcServiceFactory
|
|||
private boolean maintainSession;
|
||||
|
||||
/** Map of custom properties, keyed by property name (String) */
|
||||
private final Map customPropertyMap = new HashMap();
|
||||
private final Map<String, Object> customPropertyMap = new HashMap<String, Object>();
|
||||
|
||||
private Class serviceInterface;
|
||||
|
||||
|
|
@ -228,16 +226,10 @@ public class JaxRpcPortClientInterceptor extends LocalJaxRpcServiceFactory
|
|||
* @see javax.xml.rpc.Stub#_setProperty
|
||||
* @see javax.xml.rpc.Call#setProperty
|
||||
*/
|
||||
public void setCustomPropertyMap(Map customProperties) {
|
||||
public void setCustomPropertyMap(Map<String, Object> customProperties) {
|
||||
if (customProperties != null) {
|
||||
Iterator it = customProperties.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
if (!(entry.getKey() instanceof String)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal property key [" + entry.getKey() + "]: only Strings allowed");
|
||||
}
|
||||
addCustomProperty((String) entry.getKey(), entry.getValue());
|
||||
for (Map.Entry<String, Object> entry : customProperties.entrySet()) {
|
||||
addCustomProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -249,7 +241,7 @@ public class JaxRpcPortClientInterceptor extends LocalJaxRpcServiceFactory
|
|||
* "customPropertyMap[myKey]". This is particularly useful for
|
||||
* adding or overriding entries in child bean definitions.
|
||||
*/
|
||||
public Map getCustomPropertyMap() {
|
||||
public Map<String, Object> getCustomPropertyMap() {
|
||||
return this.customPropertyMap;
|
||||
}
|
||||
|
||||
|
|
@ -513,9 +505,8 @@ public class JaxRpcPortClientInterceptor extends LocalJaxRpcServiceFactory
|
|||
stub._setProperty(Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
|
||||
}
|
||||
if (this.customPropertyMap != null) {
|
||||
for (Iterator it = this.customPropertyMap.keySet().iterator(); it.hasNext();) {
|
||||
String key = (String) it.next();
|
||||
stub._setProperty(key, this.customPropertyMap.get(key));
|
||||
for (Map.Entry<String, Object> entry : this.customPropertyMap.entrySet()) {
|
||||
stub._setProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -687,9 +678,8 @@ public class JaxRpcPortClientInterceptor extends LocalJaxRpcServiceFactory
|
|||
call.setProperty(Call.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
|
||||
}
|
||||
if (this.customPropertyMap != null) {
|
||||
for (Iterator it = this.customPropertyMap.keySet().iterator(); it.hasNext();) {
|
||||
String key = (String) it.next();
|
||||
call.setProperty(key, this.customPropertyMap.get(key));
|
||||
for (Map.Entry<String, Object> entry : this.customPropertyMap.entrySet()) {
|
||||
call.setProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -750,8 +740,8 @@ public class JaxRpcPortClientInterceptor extends LocalJaxRpcServiceFactory
|
|||
* @see org.springframework.remoting.rmi.RmiClientInterceptorUtils#isConnectFailure
|
||||
*/
|
||||
protected boolean isConnectFailure(RemoteException ex) {
|
||||
return (ex.getClass().getName().indexOf("Fault") == -1 &&
|
||||
ex.getClass().getSuperclass().getName().indexOf("Fault") == -1);
|
||||
return (!ex.getClass().getName().contains("Fault") &&
|
||||
!ex.getClass().getSuperclass().getName().contains("Fault"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,10 +18,8 @@ package org.springframework.remoting.jaxrpc.support;
|
|||
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.rpc.Service;
|
||||
import javax.xml.rpc.encoding.TypeMapping;
|
||||
|
|
@ -62,7 +60,7 @@ public class AxisBeanMappingServicePostProcessor implements JaxRpcServicePostPro
|
|||
|
||||
private String typeNamespaceUri;
|
||||
|
||||
private Map beanMappings;
|
||||
private Map<Object, String> beanMappings;
|
||||
|
||||
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
|
||||
|
||||
|
|
@ -95,7 +93,7 @@ public class AxisBeanMappingServicePostProcessor implements JaxRpcServicePostPro
|
|||
*/
|
||||
public void setBeanMappings(Properties beanMappingProps) {
|
||||
if (beanMappingProps != null) {
|
||||
this.beanMappings = new HashMap(beanMappingProps.size());
|
||||
this.beanMappings = new HashMap<Object, String>(beanMappingProps.size());
|
||||
Enumeration propertyNames = beanMappingProps.propertyNames();
|
||||
while (propertyNames.hasMoreElements()) {
|
||||
String javaTypeName = (String) propertyNames.nextElement();
|
||||
|
|
@ -115,9 +113,8 @@ public class AxisBeanMappingServicePostProcessor implements JaxRpcServicePostPro
|
|||
*/
|
||||
public void setBeanClasses(Class[] beanClasses) {
|
||||
if (beanClasses != null) {
|
||||
this.beanMappings = new HashMap(beanClasses.length);
|
||||
for (int i = 0; i < beanClasses.length; i++) {
|
||||
Class beanClass = beanClasses[i];
|
||||
this.beanMappings = new HashMap<Object, String>(beanClasses.length);
|
||||
for (Class beanClass : beanClasses) {
|
||||
String wsdlTypeName = ClassUtils.getShortName(beanClass);
|
||||
this.beanMappings.put(beanClass, wsdlTypeName);
|
||||
}
|
||||
|
|
@ -142,9 +139,7 @@ public class AxisBeanMappingServicePostProcessor implements JaxRpcServicePostPro
|
|||
public void postProcessJaxRpcService(Service service) {
|
||||
TypeMappingRegistry registry = service.getTypeMappingRegistry();
|
||||
TypeMapping mapping = registry.createTypeMapping();
|
||||
|
||||
registerBeanMappings(mapping);
|
||||
|
||||
if (this.encodingStyleUri != null) {
|
||||
registry.register(this.encodingStyleUri, mapping);
|
||||
}
|
||||
|
|
@ -161,18 +156,10 @@ public class AxisBeanMappingServicePostProcessor implements JaxRpcServicePostPro
|
|||
*/
|
||||
protected void registerBeanMappings(TypeMapping mapping) {
|
||||
if (this.beanMappings != null) {
|
||||
for (Iterator it = this.beanMappings.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Object key = entry.getKey();
|
||||
Class javaType = null;
|
||||
if (key instanceof Class) {
|
||||
javaType = (Class) key;
|
||||
}
|
||||
else {
|
||||
javaType = ClassUtils.resolveClassName((String) key, this.beanClassLoader);
|
||||
}
|
||||
String wsdlTypeName = (String) entry.getValue();
|
||||
registerBeanMapping(mapping, javaType, wsdlTypeName);
|
||||
for (Map.Entry<Object, String> entry : this.beanMappings.entrySet()) {
|
||||
Class javaType = (entry.getKey() instanceof Class ? (Class) entry.getKey() :
|
||||
ClassUtils.resolveClassName(entry.getKey().toString(), this.beanClassLoader));
|
||||
registerBeanMapping(mapping, javaType, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,6 +94,15 @@
|
|||
<option name="LABEL_INDENT_SIZE" value="0" />
|
||||
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
|
||||
</ADDITIONAL_INDENT_OPTIONS>
|
||||
<ADDITIONAL_INDENT_OPTIONS fileType="groovy">
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="8" />
|
||||
<option name="TAB_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="false" />
|
||||
<option name="SMART_TABS" value="false" />
|
||||
<option name="LABEL_INDENT_SIZE" value="0" />
|
||||
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
|
||||
</ADDITIONAL_INDENT_OPTIONS>
|
||||
<ADDITIONAL_INDENT_OPTIONS fileType="gsp">
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="8" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue