Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-25 01:29:54 +00:00
parent 1f9e63af49
commit 29657105da
71 changed files with 726 additions and 877 deletions

View File

@@ -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)) {

View File

@@ -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);

View File

@@ -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;

View File

@@ -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();
}
}
}

View File

@@ -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 + "] " +

View File

@@ -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);
}
}