EL container integration; support for contextual objects; removal of deprecated Spring 2.0 functionality; Java 5 code style
This commit is contained in:
@@ -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,6 @@ import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
|
||||
import org.springframework.aop.support.ComposablePointcut;
|
||||
import org.springframework.aop.support.MethodMatchers;
|
||||
import org.springframework.aop.support.StaticMethodMatcher;
|
||||
import org.springframework.core.JdkVersion;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.PrioritizedParameterNameDiscoverer;
|
||||
@@ -136,7 +135,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
*/
|
||||
private int joinPointStaticPartArgumentIndex = -1;
|
||||
|
||||
private Map argumentBindings = null;
|
||||
private Map<String, Integer> argumentBindings = null;
|
||||
|
||||
private boolean argumentsIntrospected = false;
|
||||
|
||||
@@ -454,7 +453,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
}
|
||||
|
||||
private void bindExplicitArguments(int numArgumentsLeftToBind) {
|
||||
this.argumentBindings = new HashMap();
|
||||
this.argumentBindings = new HashMap<String, Integer>();
|
||||
|
||||
int numExpectedArgumentNames = this.aspectJAdviceMethod.getParameterTypes().length;
|
||||
if (this.argumentNames.length != numExpectedArgumentNames) {
|
||||
@@ -466,7 +465,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
// So we match in number...
|
||||
int argumentIndexOffset = this.adviceInvocationArgumentCount - numArgumentsLeftToBind;
|
||||
for (int i = argumentIndexOffset; i < this.argumentNames.length; i++) {
|
||||
this.argumentBindings.put(this.argumentNames[i],new Integer(i));
|
||||
this.argumentBindings.put(this.argumentNames[i], i);
|
||||
}
|
||||
|
||||
// Check that returning and throwing were in the argument names list if
|
||||
@@ -477,12 +476,9 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
+ this.returningName + "' was not bound in advice arguments");
|
||||
}
|
||||
else {
|
||||
Integer index = (Integer) this.argumentBindings.get(this.returningName);
|
||||
this.discoveredReturningType = this.aspectJAdviceMethod.getParameterTypes()[index.intValue()];
|
||||
if (JdkVersion.isAtLeastJava15()) {
|
||||
this.discoveredReturningGenericType =
|
||||
this.aspectJAdviceMethod.getGenericParameterTypes()[index.intValue()];
|
||||
}
|
||||
Integer index = this.argumentBindings.get(this.returningName);
|
||||
this.discoveredReturningType = this.aspectJAdviceMethod.getParameterTypes()[index];
|
||||
this.discoveredReturningGenericType = this.aspectJAdviceMethod.getGenericParameterTypes()[index];
|
||||
}
|
||||
}
|
||||
if (this.throwingName != null) {
|
||||
@@ -491,8 +487,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
+ this.throwingName + "' was not bound in advice arguments");
|
||||
}
|
||||
else {
|
||||
Integer index = (Integer) this.argumentBindings.get(this.throwingName);
|
||||
this.discoveredThrowingType = this.aspectJAdviceMethod.getParameterTypes()[index.intValue()];
|
||||
Integer index = this.argumentBindings.get(this.throwingName);
|
||||
this.discoveredThrowingType = this.aspectJAdviceMethod.getParameterTypes()[index];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -564,24 +560,23 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
// binding from pointcut match
|
||||
if (jpMatch != null) {
|
||||
PointcutParameter[] parameterBindings = jpMatch.getParameterBindings();
|
||||
for (int i = 0; i < parameterBindings.length; i++) {
|
||||
PointcutParameter parameter = parameterBindings[i];
|
||||
for (PointcutParameter parameter : parameterBindings) {
|
||||
String name = parameter.getName();
|
||||
Integer index = (Integer) this.argumentBindings.get(name);
|
||||
adviceInvocationArgs[index.intValue()] = parameter.getBinding();
|
||||
Integer index = this.argumentBindings.get(name);
|
||||
adviceInvocationArgs[index] = parameter.getBinding();
|
||||
numBound++;
|
||||
}
|
||||
}
|
||||
// binding from returning clause
|
||||
if (this.returningName != null) {
|
||||
Integer index = (Integer) this.argumentBindings.get(this.returningName);
|
||||
adviceInvocationArgs[index.intValue()] = returnValue;
|
||||
Integer index = this.argumentBindings.get(this.returningName);
|
||||
adviceInvocationArgs[index] = returnValue;
|
||||
numBound++;
|
||||
}
|
||||
// binding from thrown exception
|
||||
if (this.throwingName != null) {
|
||||
Integer index = (Integer) this.argumentBindings.get(this.throwingName);
|
||||
adviceInvocationArgs[index.intValue()] = ex;
|
||||
Integer index = this.argumentBindings.get(this.throwingName);
|
||||
adviceInvocationArgs[index] = ex;
|
||||
numBound++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -655,7 +655,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
return new PointcutBody(0, currentToken.substring(bodyStart + 1, currentToken.length() - 1));
|
||||
}
|
||||
else {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (bodyStart >= 0 && bodyStart != (currentToken.length() - 1)) {
|
||||
sb.append(currentToken.substring(bodyStart + 1));
|
||||
sb.append(" ");
|
||||
|
||||
@@ -411,7 +411,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("AspectJExpressionPointcut: ");
|
||||
if (this.pointcutParameterNames != null && this.pointcutParameterTypes != null) {
|
||||
sb.append("(");
|
||||
|
||||
@@ -146,7 +146,7 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Advice advice = this.advisor.getAdvice();
|
||||
sb.append(ClassUtils.getShortName(advice.getClass()));
|
||||
sb.append(": ");
|
||||
|
||||
@@ -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.
|
||||
@@ -78,14 +78,14 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
|
||||
}
|
||||
|
||||
private String buildDescription(BeanReference adviceReference, BeanDefinition pointcutDefinition) {
|
||||
return new StringBuffer("Advisor <advice(ref)='").
|
||||
return new StringBuilder("Advisor <advice(ref)='").
|
||||
append(adviceReference.getBeanName()).append("', pointcut(expression)=[").
|
||||
append(pointcutDefinition.getPropertyValues().getPropertyValue("expression").getValue()).
|
||||
append("]>").toString();
|
||||
}
|
||||
|
||||
private String buildDescription(BeanReference adviceReference, BeanReference pointcutReference) {
|
||||
return new StringBuffer("Advisor <advice(ref)='").
|
||||
return new StringBuilder("Advisor <advice(ref)='").
|
||||
append(adviceReference.getBeanName()).append("', pointcut(ref)='").
|
||||
append(pointcutReference.getBeanName()).append("'>").toString();
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.aopalliance.aop.Advice;
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.aop.support.DefaultIntroductionAdvisor;
|
||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.aop.target.EmptyTargetSource;
|
||||
import org.springframework.aop.target.SingletonTargetSource;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -80,19 +79,19 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
AdvisorChainFactory advisorChainFactory = new DefaultAdvisorChainFactory();
|
||||
|
||||
/** Cache with Method as key and advisor chain List as value */
|
||||
private transient Map methodCache;
|
||||
private transient Map<MethodCacheKey, List<Object>> methodCache;
|
||||
|
||||
/**
|
||||
* Interfaces to be implemented by the proxy. Held in List to keep the order
|
||||
* of registration, to create JDK proxy with specified order of interfaces.
|
||||
*/
|
||||
private List interfaces = new ArrayList();
|
||||
private List<Class> interfaces = new ArrayList<Class>();
|
||||
|
||||
/**
|
||||
* List of Advisors. If an Advice is added, it will be wrapped
|
||||
* in an Advisor before being added to this List.
|
||||
*/
|
||||
private List advisors = new LinkedList();
|
||||
private List<Advisor> advisors = new LinkedList<Advisor>();
|
||||
|
||||
/**
|
||||
* Array updated on changes to the advisors list, which is easier
|
||||
@@ -121,7 +120,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* Initialize the method cache.
|
||||
*/
|
||||
private void initMethodCache() {
|
||||
this.methodCache = CollectionFactory.createConcurrentMapIfPossible(32);
|
||||
this.methodCache = new ConcurrentHashMap<MethodCacheKey, List<Object>>(32);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,8 +194,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
public void setInterfaces(Class[] interfaces) {
|
||||
Assert.notNull(interfaces, "Interfaces must not be null");
|
||||
this.interfaces.clear();
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
addInterface(interfaces[i]);
|
||||
for (Class ifc : interfaces) {
|
||||
addInterface(ifc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,12 +226,11 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
}
|
||||
|
||||
public Class[] getProxiedInterfaces() {
|
||||
return (Class[]) this.interfaces.toArray(new Class[this.interfaces.size()]);
|
||||
return this.interfaces.toArray(new Class[this.interfaces.size()]);
|
||||
}
|
||||
|
||||
public boolean isInterfaceProxied(Class intf) {
|
||||
for (Iterator it = this.interfaces.iterator(); it.hasNext();) {
|
||||
Class proxyIntf = (Class) it.next();
|
||||
for (Class proxyIntf : this.interfaces) {
|
||||
if (intf.isAssignableFrom(proxyIntf)) {
|
||||
return true;
|
||||
}
|
||||
@@ -277,7 +275,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
"This configuration only has " + this.advisors.size() + " advisors.");
|
||||
}
|
||||
|
||||
Advisor advisor = (Advisor) this.advisors.get(index);
|
||||
Advisor advisor = this.advisors.get(index);
|
||||
if (advisor instanceof IntroductionAdvisor) {
|
||||
IntroductionAdvisor ia = (IntroductionAdvisor) advisor;
|
||||
// We need to remove introduction interfaces.
|
||||
@@ -317,8 +315,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
throw new AopConfigException("Cannot add advisor: Configuration is frozen.");
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(advisors)) {
|
||||
for (int i = 0; i < advisors.length; i++) {
|
||||
Advisor advisor = advisors[i];
|
||||
for (Advisor advisor : advisors) {
|
||||
if (advisor instanceof IntroductionAdvisor) {
|
||||
validateIntroductionAdvisor((IntroductionAdvisor) advisor);
|
||||
}
|
||||
@@ -334,8 +331,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
advisor.validateInterfaces();
|
||||
// If the advisor passed validation, we can make the change.
|
||||
Class[] ifcs = advisor.getInterfaces();
|
||||
for (int i = 0; i < ifcs.length; i++) {
|
||||
addInterface(ifcs[i]);
|
||||
for (Class ifc : ifcs) {
|
||||
addInterface(ifc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,7 +354,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* Bring the array up to date with the list.
|
||||
*/
|
||||
protected final void updateAdvisorArray() {
|
||||
this.advisorArray = (Advisor[]) this.advisors.toArray(new Advisor[this.advisors.size()]);
|
||||
this.advisorArray = this.advisors.toArray(new Advisor[this.advisors.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -408,7 +405,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
public int indexOf(Advice advice) {
|
||||
Assert.notNull(advice, "Advice must not be null");
|
||||
for (int i = 0; i < this.advisors.size(); i++) {
|
||||
Advisor advisor = (Advisor) this.advisors.get(i);
|
||||
Advisor advisor = this.advisors.get(i);
|
||||
if (advisor.getAdvice() == advice) {
|
||||
return i;
|
||||
}
|
||||
@@ -422,11 +419,11 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* @return whether this advice instance is included
|
||||
*/
|
||||
public boolean adviceIncluded(Advice advice) {
|
||||
Assert.notNull(advice, "Advice must not be null");
|
||||
for (int i = 0; i < this.advisors.size(); i++) {
|
||||
Advisor advisor = (Advisor) this.advisors.get(i);
|
||||
if (advisor.getAdvice() == advice) {
|
||||
return true;
|
||||
if (advice != null) {
|
||||
for (Advisor advisor : this.advisors) {
|
||||
if (advisor.getAdvice() == advice) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -438,13 +435,12 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* @return the count of the interceptors of this class or subclasses
|
||||
*/
|
||||
public int countAdvicesOfType(Class adviceClass) {
|
||||
Assert.notNull(adviceClass, "Advice class must not be null");
|
||||
int count = 0;
|
||||
for (int i = 0; i < this.advisors.size(); i++) {
|
||||
Advisor advisor = (Advisor) this.advisors.get(i);
|
||||
if (advisor.getAdvice() != null &&
|
||||
adviceClass.isAssignableFrom(advisor.getAdvice().getClass())) {
|
||||
count++;
|
||||
if (adviceClass != null) {
|
||||
for (Advisor advisor : this.advisors) {
|
||||
if (adviceClass.isInstance(advisor.getAdvice())) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
@@ -460,7 +456,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
*/
|
||||
public List getInterceptorsAndDynamicInterceptionAdvice(Method method, Class targetClass) {
|
||||
MethodCacheKey cacheKey = new MethodCacheKey(method);
|
||||
List cached = (List) this.methodCache.get(cacheKey);
|
||||
List<Object> cached = this.methodCache.get(cacheKey);
|
||||
if (cached == null) {
|
||||
cached = this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(
|
||||
this, method, targetClass);
|
||||
@@ -484,7 +480,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* @param other the AdvisedSupport object to copy configuration from
|
||||
*/
|
||||
protected void copyConfigurationFrom(AdvisedSupport other) {
|
||||
copyConfigurationFrom(other, other.targetSource, new ArrayList(other.advisors));
|
||||
copyConfigurationFrom(other, other.targetSource, new ArrayList<Advisor>(other.advisors));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -494,13 +490,12 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* @param targetSource the new TargetSource
|
||||
* @param advisors the Advisors for the chain
|
||||
*/
|
||||
protected void copyConfigurationFrom(AdvisedSupport other, TargetSource targetSource, List advisors) {
|
||||
protected void copyConfigurationFrom(AdvisedSupport other, TargetSource targetSource, List<Advisor> advisors) {
|
||||
copyFrom(other);
|
||||
this.targetSource = targetSource;
|
||||
this.advisorChainFactory = other.advisorChainFactory;
|
||||
this.interfaces = new ArrayList(other.interfaces);
|
||||
for (Iterator it = advisors.iterator(); it.hasNext();) {
|
||||
Advisor advisor = (Advisor) it.next();
|
||||
this.interfaces = new ArrayList<Class>(other.interfaces);
|
||||
for (Advisor advisor : advisors) {
|
||||
if (advisor instanceof IntroductionAdvisor) {
|
||||
validateIntroductionAdvisor((IntroductionAdvisor) advisor);
|
||||
}
|
||||
@@ -549,8 +544,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(getClass().getName() + ": ");
|
||||
sb.append(this.interfaces.size()).append(" interfaces ");
|
||||
StringBuilder sb = new StringBuilder(getClass().getName());
|
||||
sb.append(": ").append(this.interfaces.size()).append(" interfaces ");
|
||||
sb.append(ClassUtils.classNamesToString(this.interfaces)).append("; ");
|
||||
sb.append(this.advisors.size()).append(" advisors ");
|
||||
sb.append(this.advisors).append("; ");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,6 +35,7 @@ public interface AdvisorChainFactory {
|
||||
* @param targetClass the target class
|
||||
* @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
|
||||
*/
|
||||
List getInterceptorsAndDynamicInterceptionAdvice(Advised config, Method method, Class targetClass);
|
||||
List<Object> getInterceptorsAndDynamicInterceptionAdvice(
|
||||
Advised config, Method method, Class targetClass);
|
||||
|
||||
}
|
||||
|
||||
@@ -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,7 +19,6 @@ package org.springframework.aop.framework;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.aop.SpringProxy;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -35,27 +34,6 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public abstract class AopProxyUtils {
|
||||
|
||||
/**
|
||||
* Determine the target class of the given bean instance,
|
||||
* which might be an AOP proxy.
|
||||
* <p>Returns the target class for an AOP proxy and the plain class else.
|
||||
* @param candidate the instance to check (might be an AOP proxy)
|
||||
* @return the target class (or the plain class of the given object as fallback)
|
||||
* @deprecated as of Spring 2.0.3, in favor of <code>AopUtils.getTargetClass</code>
|
||||
* @see org.springframework.aop.support.AopUtils#getTargetClass(Object)
|
||||
*/
|
||||
@Deprecated
|
||||
public static Class getTargetClass(Object candidate) {
|
||||
Assert.notNull(candidate, "Candidate object must not be null");
|
||||
if (AopUtils.isCglibProxy(candidate)) {
|
||||
return candidate.getClass().getSuperclass();
|
||||
}
|
||||
if (candidate instanceof Advised) {
|
||||
return ((Advised) candidate).getTargetSource().getTargetClass();
|
||||
}
|
||||
return candidate.getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the complete set of interfaces to proxy for the given AOP configuration.
|
||||
* <p>This will always add the {@link Advised} interface unless the AdvisedSupport's
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -45,15 +45,15 @@ import org.springframework.aop.support.MethodMatchers;
|
||||
*/
|
||||
public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializable {
|
||||
|
||||
public List getInterceptorsAndDynamicInterceptionAdvice(Advised config, Method method, Class targetClass) {
|
||||
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(
|
||||
Advised config, Method method, Class targetClass) {
|
||||
|
||||
// This is somewhat tricky... we have to process introductions first,
|
||||
// but we need to preserve order in the ultimate list.
|
||||
List interceptorList = new ArrayList(config.getAdvisors().length);
|
||||
List<Object> interceptorList = new ArrayList<Object>(config.getAdvisors().length);
|
||||
boolean hasIntroductions = hasMatchingIntroductions(config, targetClass);
|
||||
AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry.getInstance();
|
||||
Advisor[] advisors = config.getAdvisors();
|
||||
for (int i = 0; i < advisors.length; i++) {
|
||||
Advisor advisor = advisors[i];
|
||||
for (Advisor advisor : config.getAdvisors()) {
|
||||
if (advisor instanceof PointcutAdvisor) {
|
||||
// Add it conditionally.
|
||||
PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor;
|
||||
@@ -64,8 +64,8 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ
|
||||
if (mm.isRuntime()) {
|
||||
// Creating a new object instance in the getInterceptors() method
|
||||
// isn't a problem as we normally cache created chains.
|
||||
for (int j = 0; j < interceptors.length; j++) {
|
||||
interceptorList.add(new InterceptorAndDynamicMethodMatcher(interceptors[j], mm));
|
||||
for (MethodInterceptor interceptor : interceptors) {
|
||||
interceptorList.add(new InterceptorAndDynamicMethodMatcher(interceptor, mm));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -160,7 +160,7 @@ public class ProxyConfig implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("proxyTargetClass=").append(this.proxyTargetClass).append("; ");
|
||||
sb.append("optimize=").append(this.optimize).append("; ");
|
||||
sb.append("opaque=").append(this.opaque).append("; ");
|
||||
|
||||
@@ -265,7 +265,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||
@Override
|
||||
public String toString() {
|
||||
// Don't do toString on target, it may be proxied.
|
||||
StringBuffer sb = new StringBuffer("ReflectiveMethodInvocation: ");
|
||||
StringBuilder sb = new StringBuilder("ReflectiveMethodInvocation: ");
|
||||
sb.append(this.method).append("; ");
|
||||
if (this.target == null) {
|
||||
sb.append("target is null");
|
||||
|
||||
@@ -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,6 +19,7 @@ package org.springframework.aop.framework.autoproxy;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -82,9 +83,9 @@ public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyC
|
||||
* @see #sortAdvisors
|
||||
* @see #extendAdvisors
|
||||
*/
|
||||
protected List findEligibleAdvisors(Class beanClass, String beanName) {
|
||||
List candidateAdvisors = findCandidateAdvisors();
|
||||
List eligibleAdvisors = findAdvisorsThatCanApply(candidateAdvisors, beanClass, beanName);
|
||||
protected List<Advisor> findEligibleAdvisors(Class beanClass, String beanName) {
|
||||
List<Advisor> candidateAdvisors = findCandidateAdvisors();
|
||||
List<Advisor> eligibleAdvisors = findAdvisorsThatCanApply(candidateAdvisors, beanClass, beanName);
|
||||
if (!eligibleAdvisors.isEmpty()) {
|
||||
eligibleAdvisors = sortAdvisors(eligibleAdvisors);
|
||||
}
|
||||
@@ -96,7 +97,7 @@ public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyC
|
||||
* Find all candidate Advisors to use in auto-proxying.
|
||||
* @return the List of candidate Advisors
|
||||
*/
|
||||
protected List findCandidateAdvisors() {
|
||||
protected List<Advisor> findCandidateAdvisors() {
|
||||
return this.advisorRetrievalHelper.findAdvisorBeans();
|
||||
}
|
||||
|
||||
@@ -109,7 +110,9 @@ public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyC
|
||||
* @return the List of applicable Advisors
|
||||
* @see ProxyCreationContext#getCurrentProxiedBeanName()
|
||||
*/
|
||||
protected List findAdvisorsThatCanApply(List candidateAdvisors, Class beanClass, String beanName) {
|
||||
protected List<Advisor> findAdvisorsThatCanApply(
|
||||
List<Advisor> candidateAdvisors, Class beanClass, String beanName) {
|
||||
|
||||
ProxyCreationContext.setCurrentProxiedBeanName(beanName);
|
||||
try {
|
||||
return AopUtils.findAdvisorsThatCanApply(candidateAdvisors, beanClass);
|
||||
@@ -137,7 +140,7 @@ public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyC
|
||||
* @see org.springframework.core.Ordered
|
||||
* @see org.springframework.core.OrderComparator
|
||||
*/
|
||||
protected List sortAdvisors(List advisors) {
|
||||
protected List<Advisor> sortAdvisors(List<Advisor> advisors) {
|
||||
Collections.sort(advisors, new OrderComparator());
|
||||
return advisors;
|
||||
}
|
||||
@@ -151,7 +154,7 @@ public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyC
|
||||
* @param candidateAdvisors Advisors that have already been identified as
|
||||
* applying to a given bean
|
||||
*/
|
||||
protected void extendAdvisors(List candidateAdvisors) {
|
||||
protected void extendAdvisors(List<Advisor> candidateAdvisors) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.aopalliance.aop.Advice;
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -46,7 +47,6 @@ import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -136,20 +136,15 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
/**
|
||||
* Set of bean name Strings, referring to all beans that this auto-proxy creator
|
||||
* created a custom TargetSource for. Used to detect own pre-built proxies (from
|
||||
* "postProcessBeforeInstantiation") in the "postProcessAfterInitialization" method.
|
||||
*/
|
||||
private final Set targetSourcedBeans = Collections.synchronizedSet(new HashSet());
|
||||
private final Set<Object> targetSourcedBeans = Collections.synchronizedSet(new HashSet<Object>());
|
||||
|
||||
private final Set earlyProxyReferences = Collections.synchronizedSet(new HashSet());
|
||||
private final Set<Object> earlyProxyReferences = Collections.synchronizedSet(new HashSet<Object>());
|
||||
|
||||
private final Set advisedBeans = Collections.synchronizedSet(new HashSet());
|
||||
private final Set<Object> advisedBeans = Collections.synchronizedSet(new HashSet<Object>());
|
||||
|
||||
private final Set nonAdvisedBeans = Collections.synchronizedSet(new HashSet());
|
||||
private final Set<Object> nonAdvisedBeans = Collections.synchronizedSet(new HashSet<Object>());
|
||||
|
||||
private final Map proxyTypes = CollectionFactory.createConcurrentMapIfPossible(16);
|
||||
private final Map<Object, Class> proxyTypes = new ConcurrentHashMap<Object, Class>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -260,7 +255,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
|
||||
|
||||
public Class predictBeanType(Class beanClass, String beanName) {
|
||||
Object cacheKey = getCacheKey(beanClass, beanName);
|
||||
return (Class) this.proxyTypes.get(cacheKey);
|
||||
return this.proxyTypes.get(cacheKey);
|
||||
}
|
||||
|
||||
public Constructor[] determineCandidateConstructors(Class beanClass, String beanName) throws BeansException {
|
||||
@@ -280,7 +275,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
|
||||
if (this.advisedBeans.contains(cacheKey) || this.nonAdvisedBeans.contains(cacheKey)) {
|
||||
return null;
|
||||
}
|
||||
if (isInfrastructureClass(beanClass, beanName) || shouldSkip(beanClass, beanName)) {
|
||||
if (isInfrastructureClass(beanClass) || shouldSkip(beanClass, beanName)) {
|
||||
this.nonAdvisedBeans.add(cacheKey);
|
||||
return null;
|
||||
}
|
||||
@@ -355,7 +350,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
|
||||
if (this.nonAdvisedBeans.contains(cacheKey)) {
|
||||
return bean;
|
||||
}
|
||||
if (isInfrastructureClass(bean.getClass(), beanName) || shouldSkip(bean.getClass(), beanName)) {
|
||||
if (isInfrastructureClass(bean.getClass()) || shouldSkip(bean.getClass(), beanName)) {
|
||||
this.nonAdvisedBeans.add(cacheKey);
|
||||
return bean;
|
||||
}
|
||||
@@ -373,17 +368,6 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the given bean class and bean name represents an
|
||||
* infrastructure class that should never be proxied.
|
||||
* @deprecated in favor of <code>isInfrastructureClass(beanClass)</code>
|
||||
* @see #isInfrastructureClass(Class)
|
||||
*/
|
||||
@Deprecated
|
||||
protected boolean isInfrastructureClass(Class beanClass, String beanName) {
|
||||
return isInfrastructureClass(beanClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the given bean class represents an infrastructure class
|
||||
* that should never be proxied.
|
||||
@@ -432,8 +416,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
|
||||
// We can't create fancy target sources for directly registered singletons.
|
||||
if (this.customTargetSourceCreators != null &&
|
||||
this.beanFactory != null && this.beanFactory.containsBean(beanName)) {
|
||||
for (int i = 0; i < this.customTargetSourceCreators.length; i++) {
|
||||
TargetSourceCreator tsc = this.customTargetSourceCreators[i];
|
||||
for (TargetSourceCreator tsc : this.customTargetSourceCreators) {
|
||||
TargetSource ts = tsc.getTargetSource(beanClass, beanName);
|
||||
if (ts != null) {
|
||||
// Found a matching TargetSource.
|
||||
@@ -472,14 +455,14 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
|
||||
// Must allow for introductions; can't just set interfaces to
|
||||
// the target's interfaces only.
|
||||
Class[] targetInterfaces = ClassUtils.getAllInterfacesForClass(beanClass, this.proxyClassLoader);
|
||||
for (int i = 0; i < targetInterfaces.length; i++) {
|
||||
proxyFactory.addInterface(targetInterfaces[i]);
|
||||
for (Class targetInterface : targetInterfaces) {
|
||||
proxyFactory.addInterface(targetInterface);
|
||||
}
|
||||
}
|
||||
|
||||
Advisor[] advisors = buildAdvisors(beanName, specificInterceptors);
|
||||
for (int i = 0; i < advisors.length; i++) {
|
||||
proxyFactory.addAdvisor(advisors[i]);
|
||||
for (Advisor advisor : advisors) {
|
||||
proxyFactory.addAdvisor(advisor);
|
||||
}
|
||||
|
||||
proxyFactory.setTargetSource(targetSource);
|
||||
@@ -536,7 +519,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
|
||||
// Handle prototypes correctly...
|
||||
Advisor[] commonInterceptors = resolveInterceptorNames();
|
||||
|
||||
List allInterceptors = new ArrayList();
|
||||
List<Object> allInterceptors = new ArrayList<Object>();
|
||||
if (specificInterceptors != null) {
|
||||
allInterceptors.addAll(Arrays.asList(specificInterceptors));
|
||||
if (commonInterceptors != null) {
|
||||
@@ -567,17 +550,16 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
|
||||
* @see #setInterceptorNames
|
||||
*/
|
||||
private Advisor[] resolveInterceptorNames() {
|
||||
ConfigurableBeanFactory cbf =
|
||||
(this.beanFactory instanceof ConfigurableBeanFactory ? (ConfigurableBeanFactory) this.beanFactory : null);
|
||||
List advisors = new ArrayList();
|
||||
for (int i = 0; i < this.interceptorNames.length; i++) {
|
||||
String beanName = this.interceptorNames[i];
|
||||
ConfigurableBeanFactory cbf = (this.beanFactory instanceof ConfigurableBeanFactory) ?
|
||||
(ConfigurableBeanFactory) this.beanFactory : null;
|
||||
List<Advisor> advisors = new ArrayList<Advisor>();
|
||||
for (String beanName : this.interceptorNames) {
|
||||
if (cbf == null || !cbf.isCurrentlyInCreation(beanName)) {
|
||||
Object next = this.beanFactory.getBean(beanName);
|
||||
advisors.add(this.advisorAdapterRegistry.wrap(next));
|
||||
}
|
||||
}
|
||||
return (Advisor[]) advisors.toArray(new Advisor[advisors.size()]);
|
||||
return advisors.toArray(new Advisor[advisors.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
@@ -79,12 +79,11 @@ public class BeanFactoryAdvisorRetrievalHelper {
|
||||
return new LinkedList();
|
||||
}
|
||||
|
||||
List advisors = new LinkedList();
|
||||
for (int i = 0; i < advisorNames.length; i++) {
|
||||
String name = advisorNames[i];
|
||||
List<Advisor> advisors = new LinkedList<Advisor>();
|
||||
for (String name : advisorNames) {
|
||||
if (isEligibleBean(name) && !this.beanFactory.isCurrentlyInCreation(name)) {
|
||||
try {
|
||||
advisors.add(this.beanFactory.getBean(name));
|
||||
advisors.add(this.beanFactory.getBean(name, Advisor.class));
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
Throwable rootCause = ex.getMostSpecificCause();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.aop.framework.autoproxy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aop.TargetSource;
|
||||
@@ -45,7 +44,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class BeanNameAutoProxyCreator extends AbstractAutoProxyCreator {
|
||||
|
||||
private List beanNames;
|
||||
private List<String> beanNames;
|
||||
|
||||
|
||||
/**
|
||||
@@ -62,9 +61,9 @@ public class BeanNameAutoProxyCreator extends AbstractAutoProxyCreator {
|
||||
*/
|
||||
public void setBeanNames(String[] beanNames) {
|
||||
Assert.notEmpty(beanNames, "'beanNames' must not be empty");
|
||||
this.beanNames = new ArrayList(beanNames.length);
|
||||
for (int i = 0; i < beanNames.length; i++) {
|
||||
this.beanNames.add(StringUtils.trimWhitespace(beanNames[i]));
|
||||
this.beanNames = new ArrayList<String>(beanNames.length);
|
||||
for (String mappedName : beanNames) {
|
||||
this.beanNames.add(StringUtils.trimWhitespace(mappedName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +74,7 @@ public class BeanNameAutoProxyCreator extends AbstractAutoProxyCreator {
|
||||
@Override
|
||||
protected Object[] getAdvicesAndAdvisorsForBean(Class beanClass, String beanName, TargetSource targetSource) {
|
||||
if (this.beanNames != null) {
|
||||
for (Iterator it = this.beanNames.iterator(); it.hasNext();) {
|
||||
String mappedName = (String) it.next();
|
||||
for (String mappedName : this.beanNames) {
|
||||
if (FactoryBean.class.isAssignableFrom(beanClass)) {
|
||||
if (!mappedName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX)) {
|
||||
continue;
|
||||
|
||||
@@ -95,7 +95,7 @@ public abstract class AbstractMonitoringInterceptor extends AbstractTraceInterce
|
||||
* @see #setSuffix
|
||||
*/
|
||||
protected String createInvocationTraceName(MethodInvocation invocation) {
|
||||
StringBuffer sb = new StringBuffer(getPrefix());
|
||||
StringBuilder sb = new StringBuilder(getPrefix());
|
||||
Method method = invocation.getMethod();
|
||||
Class clazz = method.getDeclaringClass();
|
||||
if (this.logTargetClassInvocation && clazz.isInstance(invocation.getThis())) {
|
||||
|
||||
@@ -423,7 +423,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
|
||||
* here for JDK 1.4 compliance reasons only.
|
||||
*/
|
||||
private String escape(String input) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
if (c == '\\') {
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -35,7 +34,6 @@ import org.springframework.aop.PointcutAdvisor;
|
||||
import org.springframework.aop.SpringProxy;
|
||||
import org.springframework.aop.TargetClassAware;
|
||||
import org.springframework.core.BridgeMethodResolver;
|
||||
import org.springframework.core.JdkVersion;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -88,7 +86,7 @@ public abstract class AopUtils {
|
||||
* @param clazz the class to check
|
||||
*/
|
||||
public static boolean isCglibProxyClass(Class clazz) {
|
||||
return (clazz != null && clazz.getName().indexOf(ClassUtils.CGLIB_CLASS_SEPARATOR) != -1);
|
||||
return (clazz != null && clazz.getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,10 +160,7 @@ public abstract class AopUtils {
|
||||
public static Method getMostSpecificMethod(Method method, Class targetClass) {
|
||||
Method resolvedMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
|
||||
// If we are dealing with method with generic parameters, find the original method.
|
||||
if (JdkVersion.isAtLeastJava15()) {
|
||||
resolvedMethod = BridgeMethodResolver.findBridgedMethod(resolvedMethod);
|
||||
}
|
||||
return resolvedMethod;
|
||||
return BridgeMethodResolver.findBridgedMethod(resolvedMethod);
|
||||
}
|
||||
|
||||
|
||||
@@ -202,15 +197,14 @@ public abstract class AopUtils {
|
||||
introductionAwareMethodMatcher = (IntroductionAwareMethodMatcher) methodMatcher;
|
||||
}
|
||||
|
||||
Set classes = new HashSet(ClassUtils.getAllInterfacesForClassAsSet(targetClass));
|
||||
Set<Class> classes = new HashSet<Class>(ClassUtils.getAllInterfacesForClassAsSet(targetClass));
|
||||
classes.add(targetClass);
|
||||
for (Iterator it = classes.iterator(); it.hasNext();) {
|
||||
Class clazz = (Class) it.next();
|
||||
for (Class clazz : classes) {
|
||||
Method[] methods = clazz.getMethods();
|
||||
for (int j = 0; j < methods.length; j++) {
|
||||
for (Method method : methods) {
|
||||
if ((introductionAwareMethodMatcher != null &&
|
||||
introductionAwareMethodMatcher.matches(methods[j], targetClass, hasIntroductions)) ||
|
||||
methodMatcher.matches(methods[j], targetClass)) {
|
||||
introductionAwareMethodMatcher.matches(method, targetClass, hasIntroductions)) ||
|
||||
methodMatcher.matches(method, targetClass)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -263,20 +257,18 @@ public abstract class AopUtils {
|
||||
* @return sublist of Advisors that can apply to an object of the given class
|
||||
* (may be the incoming List as-is)
|
||||
*/
|
||||
public static List findAdvisorsThatCanApply(List candidateAdvisors, Class clazz) {
|
||||
public static List<Advisor> findAdvisorsThatCanApply(List<Advisor> candidateAdvisors, Class clazz) {
|
||||
if (candidateAdvisors.isEmpty()) {
|
||||
return candidateAdvisors;
|
||||
}
|
||||
List eligibleAdvisors = new LinkedList();
|
||||
for (Iterator it = candidateAdvisors.iterator(); it.hasNext();) {
|
||||
Advisor candidate = (Advisor) it.next();
|
||||
List<Advisor> eligibleAdvisors = new LinkedList<Advisor>();
|
||||
for (Advisor candidate : candidateAdvisors) {
|
||||
if (candidate instanceof IntroductionAdvisor && canApply(candidate, clazz)) {
|
||||
eligibleAdvisors.add(candidate);
|
||||
}
|
||||
}
|
||||
boolean hasIntroductions = !eligibleAdvisors.isEmpty();
|
||||
for (Iterator it = candidateAdvisors.iterator(); it.hasNext();) {
|
||||
Advisor candidate = (Advisor) it.next();
|
||||
for (Advisor candidate : candidateAdvisors) {
|
||||
if (candidate instanceof IntroductionAdvisor) {
|
||||
// already processed
|
||||
continue;
|
||||
|
||||
@@ -204,7 +204,7 @@ public abstract class AbstractBeanFactoryBasedTargetSource
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(ClassUtils.getShortName(getClass()));
|
||||
sb.append(" for target bean '").append(this.targetBeanName).append("'");
|
||||
if (this.targetClass != null) {
|
||||
|
||||
Reference in New Issue
Block a user