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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@@ -30,7 +31,6 @@ import org.aspectj.weaver.tools.PointcutParser;
|
||||
import org.aspectj.weaver.tools.PointcutPrimitive;
|
||||
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -118,8 +118,6 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscoverer {
|
||||
|
||||
private static final String ANNOTATION_CLASS_NAME = "java.lang.annotation.Annotation";
|
||||
|
||||
private static final String THIS_JOIN_POINT = "thisJoinPoint";
|
||||
private static final String THIS_JOIN_POINT_STATIC_PART = "thisJoinPointStaticPart";
|
||||
|
||||
@@ -133,10 +131,8 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
private static final int STEP_REFERENCE_PCUT_BINDING = 7;
|
||||
private static final int STEP_FINISHED = 8;
|
||||
|
||||
private static final Set singleValuedAnnotationPcds = new HashSet();
|
||||
private static final Set nonReferencePointcutTokens = new HashSet();
|
||||
|
||||
private static Class annotationClass;
|
||||
private static final Set<String> singleValuedAnnotationPcds = new HashSet<String>();
|
||||
private static final Set<String> nonReferencePointcutTokens = new HashSet<String>();
|
||||
|
||||
|
||||
static {
|
||||
@@ -157,15 +153,6 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
nonReferencePointcutTokens.add("and");
|
||||
nonReferencePointcutTokens.add("or");
|
||||
nonReferencePointcutTokens.add("not");
|
||||
|
||||
try {
|
||||
annotationClass = ClassUtils.forName(ANNOTATION_CLASS_NAME,
|
||||
AspectJAdviceParameterNameDiscoverer.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// Running on < JDK 1.5, this is OK...
|
||||
annotationClass = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,8 +179,6 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
|
||||
private int numberOfRemainingUnboundArguments;
|
||||
|
||||
private int algorithmicStep = STEP_JOIN_POINT_BINDING;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new discoverer that attempts to discover parameter names
|
||||
@@ -241,7 +226,6 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
this.argumentTypes = method.getParameterTypes();
|
||||
this.numberOfRemainingUnboundArguments = this.argumentTypes.length;
|
||||
this.parameterNameBindings = new String[this.numberOfRemainingUnboundArguments];
|
||||
this.algorithmicStep = STEP_JOIN_POINT_BINDING;
|
||||
|
||||
int minimumNumberUnboundArgs = 0;
|
||||
if (this.returningName != null) {
|
||||
@@ -256,8 +240,9 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
}
|
||||
|
||||
try {
|
||||
while ((this.numberOfRemainingUnboundArguments > 0) && (this.algorithmicStep < STEP_FINISHED)) {
|
||||
switch (this.algorithmicStep++) {
|
||||
int algorithmicStep = STEP_JOIN_POINT_BINDING;
|
||||
while ((this.numberOfRemainingUnboundArguments > 0) && algorithmicStep < STEP_FINISHED) {
|
||||
switch (algorithmicStep++) {
|
||||
case STEP_JOIN_POINT_BINDING:
|
||||
if (!maybeBindThisJoinPoint()) {
|
||||
maybeBindThisJoinPointStaticPart();
|
||||
@@ -282,7 +267,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
maybeBindReferencePointcutParameter();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown algorithmic step: " + (this.algorithmicStep - 1));
|
||||
throw new IllegalStateException("Unknown algorithmic step: " + (algorithmicStep - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,7 +414,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
* <p>Some more support from AspectJ in doing this exercise would be nice... :)
|
||||
*/
|
||||
private void maybeBindAnnotationsFromPointcutExpression() {
|
||||
List varNames = new ArrayList();
|
||||
List<String> varNames = new ArrayList<String>();
|
||||
String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " ");
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
String toMatch = tokens[i];
|
||||
@@ -458,7 +443,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
/**
|
||||
* Match the given list of extracted variable names to argument slots.
|
||||
*/
|
||||
private void bindAnnotationsFromVarNames(List varNames) {
|
||||
private void bindAnnotationsFromVarNames(List<String> varNames) {
|
||||
if (!varNames.isEmpty()) {
|
||||
// we have work to do...
|
||||
int numAnnotationSlots = countNumberOfUnboundAnnotationArguments();
|
||||
@@ -470,7 +455,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
else if (numAnnotationSlots == 1) {
|
||||
if (varNames.size() == 1) {
|
||||
// it's a match
|
||||
findAndBind(annotationClass, (String) varNames.get(0));
|
||||
findAndBind(Annotation.class, varNames.get(0));
|
||||
}
|
||||
else {
|
||||
// multiple candidate vars, but only one slot
|
||||
@@ -495,8 +480,8 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
if (Character.isJavaIdentifierStart(candidateToken.charAt(0)) &&
|
||||
Character.isLowerCase(candidateToken.charAt(0))) {
|
||||
char[] tokenChars = candidateToken.toCharArray();
|
||||
for (int i = 0; i < tokenChars.length; i++) {
|
||||
if (!Character.isJavaIdentifierPart(tokenChars[i])) {
|
||||
for (char tokenChar : tokenChars) {
|
||||
if (!Character.isJavaIdentifierPart(tokenChar)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -511,11 +496,10 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
* Given an args pointcut body (could be <code>args</code> or <code>at_args</code>),
|
||||
* add any candidate variable names to the given list.
|
||||
*/
|
||||
private void maybeExtractVariableNamesFromArgs(String argsSpec, List varNames) {
|
||||
private void maybeExtractVariableNamesFromArgs(String argsSpec, List<String> varNames) {
|
||||
if (argsSpec == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] tokens = StringUtils.tokenizeToStringArray(argsSpec, ",");
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
tokens[i] = StringUtils.trimWhitespace(tokens[i]);
|
||||
@@ -536,7 +520,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
+ " unbound args at this(),target(),args() binding stage, with no way to determine between them");
|
||||
}
|
||||
|
||||
List varNames = new ArrayList();
|
||||
List<String> varNames = new ArrayList<String>();
|
||||
String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " ");
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
if (tokens[i].equals("this") ||
|
||||
@@ -553,12 +537,11 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
else if (tokens[i].equals("args") || tokens[i].startsWith("args(")) {
|
||||
PointcutBody body = getPointcutBody(tokens, i);
|
||||
i += body.numTokensConsumed;
|
||||
List candidateVarNames = new ArrayList();
|
||||
List<String> candidateVarNames = new ArrayList<String>();
|
||||
maybeExtractVariableNamesFromArgs(body.text, candidateVarNames);
|
||||
// we may have found some var names that were bound in previous primitive args binding step,
|
||||
// filter them out...
|
||||
for (Iterator iter = candidateVarNames.iterator(); iter.hasNext();) {
|
||||
String varName = (String) iter.next();
|
||||
for (String varName : candidateVarNames) {
|
||||
if (!alreadyBound(varName)) {
|
||||
varNames.add(varName);
|
||||
}
|
||||
@@ -574,7 +557,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
else if (varNames.size() == 1) {
|
||||
for (int j = 0; j < this.parameterNameBindings.length; j++) {
|
||||
if (isUnbound(j)) {
|
||||
bindParameterName(j, (String) varNames.get(0));
|
||||
bindParameterName(j, varNames.get(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -588,7 +571,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
+ " unbound args at reference pointcut binding stage, with no way to determine between them");
|
||||
}
|
||||
|
||||
List varNames = new ArrayList();
|
||||
List<String> varNames = new ArrayList<String>();
|
||||
String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " ");
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
String toMatch = tokens[i];
|
||||
@@ -634,7 +617,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
else if (varNames.size() == 1) {
|
||||
for (int j = 0; j < this.parameterNameBindings.length; j++) {
|
||||
if (isUnbound(j)) {
|
||||
bindParameterName(j, (String) varNames.get(0));
|
||||
bindParameterName(j, varNames.get(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -700,7 +683,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
}
|
||||
if (numUnboundPrimitives == 1) {
|
||||
// Look for arg variable and bind it if we find exactly one...
|
||||
List varNames = new ArrayList();
|
||||
List<String> varNames = new ArrayList<String>();
|
||||
String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " ");
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
if (tokens[i].equals("args") || tokens[i].startsWith("args(")) {
|
||||
@@ -751,14 +734,9 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
}
|
||||
|
||||
private int countNumberOfUnboundAnnotationArguments() {
|
||||
if (annotationClass == null) {
|
||||
// We're running on a JDK < 1.5
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < this.argumentTypes.length; i++) {
|
||||
if (isUnbound(i) && isSubtypeOf(annotationClass, i)) {
|
||||
if (isUnbound(i) && isSubtypeOf(Annotation.class, i)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,15 +19,14 @@ package org.springframework.aop.config;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
|
||||
import org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator;
|
||||
import org.springframework.aop.framework.autoproxy.InfrastructureAdvisorAutoProxyCreator;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.JdkVersion;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Utility class for handling registration of AOP auto-proxy creators.
|
||||
@@ -52,26 +51,18 @@ public abstract class AopConfigUtils {
|
||||
public static final String AUTO_PROXY_CREATOR_BEAN_NAME =
|
||||
"org.springframework.aop.config.internalAutoProxyCreator";
|
||||
|
||||
/**
|
||||
* The class name of the <code>AnnotationAwareAspectJAutoProxyCreator</code> class.
|
||||
* Only available with AspectJ and Java 5.
|
||||
*/
|
||||
private static final String ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME =
|
||||
"org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator";
|
||||
|
||||
|
||||
/**
|
||||
* Stores the auto proxy creator classes in escalation order.
|
||||
*/
|
||||
private static final List APC_PRIORITY_LIST = new ArrayList();
|
||||
private static final List<Class> APC_PRIORITY_LIST = new ArrayList<Class>();
|
||||
|
||||
/**
|
||||
* Setup the escalation list.
|
||||
*/
|
||||
static {
|
||||
APC_PRIORITY_LIST.add(InfrastructureAdvisorAutoProxyCreator.class.getName());
|
||||
APC_PRIORITY_LIST.add(AspectJAwareAdvisorAutoProxyCreator.class.getName());
|
||||
APC_PRIORITY_LIST.add(ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME);
|
||||
APC_PRIORITY_LIST.add(InfrastructureAdvisorAutoProxyCreator.class);
|
||||
APC_PRIORITY_LIST.add(AspectJAwareAdvisorAutoProxyCreator.class);
|
||||
APC_PRIORITY_LIST.add(AnnotationAwareAspectJAutoProxyCreator.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,8 +87,7 @@ public abstract class AopConfigUtils {
|
||||
}
|
||||
|
||||
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
|
||||
Class cls = getAspectJAnnotationAutoProxyCreatorClassIfPossible();
|
||||
return registerOrEscalateApcAsRequired(cls, registry, source);
|
||||
return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source);
|
||||
}
|
||||
|
||||
public static void forceAutoProxyCreatorToUseClassProxying(BeanDefinitionRegistry registry) {
|
||||
@@ -114,7 +104,7 @@ public abstract class AopConfigUtils {
|
||||
BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
|
||||
if (!cls.getName().equals(apcDefinition.getBeanClassName())) {
|
||||
int currentPriority = findPriorityForClass(apcDefinition.getBeanClassName());
|
||||
int requiredPriority = findPriorityForClass(cls.getName());
|
||||
int requiredPriority = findPriorityForClass(cls);
|
||||
if (currentPriority < requiredPriority) {
|
||||
apcDefinition.setBeanClassName(cls.getName());
|
||||
}
|
||||
@@ -123,32 +113,20 @@ public abstract class AopConfigUtils {
|
||||
}
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(cls);
|
||||
beanDefinition.setSource(source);
|
||||
beanDefinition.getPropertyValues().addPropertyValue("order", new Integer(Ordered.HIGHEST_PRECEDENCE));
|
||||
beanDefinition.getPropertyValues().addPropertyValue("order", Ordered.HIGHEST_PRECEDENCE);
|
||||
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
registry.registerBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME, beanDefinition);
|
||||
return beanDefinition;
|
||||
}
|
||||
|
||||
private static Class getAspectJAnnotationAutoProxyCreatorClassIfPossible() {
|
||||
if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) {
|
||||
throw new IllegalStateException(
|
||||
"AnnotationAwareAspectJAutoProxyCreator is only available on Java 1.5 and higher");
|
||||
}
|
||||
try {
|
||||
return ClassUtils.forName(
|
||||
ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME, AopConfigUtils.class.getClassLoader());
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Unable to load Java 1.5 dependent class [" +
|
||||
ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME + "]", ex);
|
||||
}
|
||||
private static int findPriorityForClass(Class clazz) {
|
||||
return APC_PRIORITY_LIST.indexOf(clazz);
|
||||
}
|
||||
|
||||
private static int findPriorityForClass(String className) {
|
||||
Assert.notNull(className, "Class name must not be null");
|
||||
for (int i = 0; i < APC_PRIORITY_LIST.size(); i++) {
|
||||
String str = (String) APC_PRIORITY_LIST.get(i);
|
||||
if (className.equals(str)) {
|
||||
Class clazz = APC_PRIORITY_LIST.get(i);
|
||||
if (clazz.getName().equals(className)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,68 +61,37 @@ import org.springframework.util.xml.DomUtils;
|
||||
class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
private static final String ASPECT = "aspect";
|
||||
|
||||
private static final String EXPRESSION = "expression";
|
||||
|
||||
private static final String ID = "id";
|
||||
|
||||
private static final String POINTCUT = "pointcut";
|
||||
|
||||
private static final String ADVICE_BEAN_NAME = "adviceBeanName";
|
||||
|
||||
private static final String ADVISOR = "advisor";
|
||||
|
||||
private static final String ADVICE_REF = "advice-ref";
|
||||
|
||||
private static final String POINTCUT_REF = "pointcut-ref";
|
||||
|
||||
private static final String REF = "ref";
|
||||
|
||||
private static final String BEFORE = "before";
|
||||
|
||||
private static final String DECLARE_PARENTS = "declare-parents";
|
||||
|
||||
private static final String TYPE_PATTERN = "types-matching";
|
||||
|
||||
private static final String DEFAULT_IMPL = "default-impl";
|
||||
|
||||
private static final String DELEGATE_REF = "delegate-ref";
|
||||
|
||||
private static final String IMPLEMENT_INTERFACE = "implement-interface";
|
||||
|
||||
private static final String AFTER = "after";
|
||||
|
||||
private static final String AFTER_RETURNING_ELEMENT = "after-returning";
|
||||
|
||||
private static final String AFTER_THROWING_ELEMENT = "after-throwing";
|
||||
|
||||
private static final String AROUND = "around";
|
||||
|
||||
private static final String RETURNING = "returning";
|
||||
|
||||
private static final String RETURNING_PROPERTY = "returningName";
|
||||
|
||||
private static final String THROWING = "throwing";
|
||||
|
||||
private static final String THROWING_PROPERTY = "throwingName";
|
||||
|
||||
private static final String ARG_NAMES = "arg-names";
|
||||
|
||||
private static final String ARG_NAMES_PROPERTY = "argumentNames";
|
||||
|
||||
private static final String ASPECT_NAME_PROPERTY = "aspectName";
|
||||
|
||||
private static final String DECLARATION_ORDER_PROPERTY = "declarationOrder";
|
||||
|
||||
private static final String ORDER_PROPERTY = "order";
|
||||
|
||||
private static final int METHOD_INDEX = 0;
|
||||
|
||||
private static final int POINTCUT_INDEX = 1;
|
||||
|
||||
private static final int ASPECT_INSTANCE_FACTORY_INDEX = 2;
|
||||
|
||||
|
||||
private ParseState parseState = new ParseState();
|
||||
|
||||
|
||||
@@ -232,12 +201,12 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
try {
|
||||
this.parseState.push(new AspectEntry(aspectId, aspectName));
|
||||
List beanDefinitions = new ArrayList();
|
||||
List beanReferences = new ArrayList();
|
||||
List<BeanDefinition> beanDefinitions = new ArrayList<BeanDefinition>();
|
||||
List<BeanReference> beanReferences = new ArrayList<BeanReference>();
|
||||
|
||||
List declareParents = DomUtils.getChildElementsByTagName(aspectElement, DECLARE_PARENTS);
|
||||
List<Element> declareParents = DomUtils.getChildElementsByTagName(aspectElement, DECLARE_PARENTS);
|
||||
for (int i = METHOD_INDEX; i < declareParents.size(); i++) {
|
||||
Element declareParentsElement = (Element) declareParents.get(i);
|
||||
Element declareParentsElement = declareParents.get(i);
|
||||
beanDefinitions.add(parseDeclareParents(declareParentsElement, parserContext));
|
||||
}
|
||||
|
||||
@@ -268,9 +237,8 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
aspectElement, aspectId, beanDefinitions, beanReferences, parserContext);
|
||||
parserContext.pushContainingComponent(aspectComponentDefinition);
|
||||
|
||||
List pointcuts = DomUtils.getChildElementsByTagName(aspectElement, POINTCUT);
|
||||
for (int i = 0; i < pointcuts.size(); i++) {
|
||||
Element pointcutElement = (Element) pointcuts.get(i);
|
||||
List<Element> pointcuts = DomUtils.getChildElementsByTagName(aspectElement, POINTCUT);
|
||||
for (Element pointcutElement : pointcuts) {
|
||||
parsePointcut(pointcutElement, parserContext);
|
||||
}
|
||||
|
||||
@@ -282,10 +250,11 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
}
|
||||
|
||||
private AspectComponentDefinition createAspectComponentDefinition(
|
||||
Element aspectElement, String aspectId, List beanDefs, List beanRefs, ParserContext parserContext) {
|
||||
Element aspectElement, String aspectId, List<BeanDefinition> beanDefs,
|
||||
List<BeanReference> beanRefs, ParserContext parserContext) {
|
||||
|
||||
BeanDefinition[] beanDefArray = (BeanDefinition[]) beanDefs.toArray(new BeanDefinition[beanDefs.size()]);
|
||||
BeanReference[] beanRefArray = (BeanReference[]) beanRefs.toArray(new BeanReference[beanRefs.size()]);
|
||||
BeanDefinition[] beanDefArray = beanDefs.toArray(new BeanDefinition[beanDefs.size()]);
|
||||
BeanReference[] beanRefArray = beanRefs.toArray(new BeanReference[beanRefs.size()]);
|
||||
Object source = parserContext.extractSource(aspectElement);
|
||||
return new AspectComponentDefinition(aspectId, beanDefArray, beanRefArray, source);
|
||||
}
|
||||
@@ -345,7 +314,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
*/
|
||||
private AbstractBeanDefinition parseAdvice(
|
||||
String aspectName, int order, Element aspectElement, Element adviceElement, ParserContext parserContext,
|
||||
List beanDefinitions, List beanReferences) {
|
||||
List<BeanDefinition> beanDefinitions, List<BeanReference> beanReferences) {
|
||||
|
||||
try {
|
||||
this.parseState.push(new AdviceEntry(adviceElement.getLocalName()));
|
||||
@@ -394,15 +363,14 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
*/
|
||||
private AbstractBeanDefinition createAdviceDefinition(
|
||||
Element adviceElement, ParserContext parserContext, String aspectName, int order,
|
||||
RootBeanDefinition methodDef, RootBeanDefinition aspectFactoryDef, List beanDefinitions, List beanReferences) {
|
||||
RootBeanDefinition methodDef, RootBeanDefinition aspectFactoryDef,
|
||||
List<BeanDefinition> beanDefinitions, List<BeanReference> beanReferences) {
|
||||
|
||||
RootBeanDefinition adviceDefinition = new RootBeanDefinition(getAdviceClass(adviceElement));
|
||||
adviceDefinition.setSource(parserContext.extractSource(adviceElement));
|
||||
|
||||
adviceDefinition.getPropertyValues().addPropertyValue(
|
||||
ASPECT_NAME_PROPERTY, aspectName);
|
||||
adviceDefinition.getPropertyValues().addPropertyValue(
|
||||
DECLARATION_ORDER_PROPERTY, new Integer(order));
|
||||
adviceDefinition.getPropertyValues().addPropertyValue(ASPECT_NAME_PROPERTY, aspectName);
|
||||
adviceDefinition.getPropertyValues().addPropertyValue(DECLARATION_ORDER_PROPERTY, order);
|
||||
|
||||
if (adviceElement.hasAttribute(RETURNING)) {
|
||||
adviceDefinition.getPropertyValues().addPropertyValue(
|
||||
@@ -423,7 +391,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
Object pointcut = parsePointcutProperty(adviceElement, parserContext);
|
||||
if (pointcut instanceof BeanDefinition) {
|
||||
cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcut);
|
||||
beanDefinitions.add(pointcut);
|
||||
beanDefinitions.add((BeanDefinition) pointcut);
|
||||
}
|
||||
else if (pointcut instanceof String) {
|
||||
RuntimeBeanReference pointcutRef = new RuntimeBeanReference((String) pointcut);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,11 +31,9 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ProxyCreatorSupport extends AdvisedSupport {
|
||||
|
||||
/** The AopProxyFactory to use */
|
||||
private AopProxyFactory aopProxyFactory;
|
||||
|
||||
/** List of AdvisedSupportListener */
|
||||
private List listeners = new LinkedList();
|
||||
private List<AdvisedSupportListener> listeners = new LinkedList<AdvisedSupportListener>();
|
||||
|
||||
/** Set to true when the first AOP proxy has been created */
|
||||
private boolean active = false;
|
||||
@@ -112,8 +110,8 @@ public class ProxyCreatorSupport extends AdvisedSupport {
|
||||
*/
|
||||
private void activate() {
|
||||
this.active = true;
|
||||
for (int i = 0; i < this.listeners.size(); i++) {
|
||||
((AdvisedSupportListener) this.listeners.get(i)).activated(this);
|
||||
for (AdvisedSupportListener listener : this.listeners) {
|
||||
listener.activated(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,8 +124,8 @@ public class ProxyCreatorSupport extends AdvisedSupport {
|
||||
super.adviceChanged();
|
||||
synchronized (this) {
|
||||
if (this.active) {
|
||||
for (int i = 0; i < this.listeners.size(); i++) {
|
||||
((AdvisedSupportListener) this.listeners.get(i)).adviceChanged(this);
|
||||
for (AdvisedSupportListener listener : this.listeners) {
|
||||
listener.adviceChanged(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,7 +39,7 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
*/
|
||||
public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Serializable {
|
||||
|
||||
private final List adapters = new ArrayList(3);
|
||||
private final List<AdvisorAdapter> adapters = new ArrayList<AdvisorAdapter>(3);
|
||||
|
||||
|
||||
/**
|
||||
@@ -64,9 +64,8 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se
|
||||
// So well-known it doesn't even need an adapter.
|
||||
return new DefaultPointcutAdvisor(advice);
|
||||
}
|
||||
for (int i = 0; i < this.adapters.size(); i++) {
|
||||
for (AdvisorAdapter adapter : this.adapters) {
|
||||
// Check that it is supported.
|
||||
AdvisorAdapter adapter = (AdvisorAdapter) this.adapters.get(i);
|
||||
if (adapter.supportsAdvice(advice)) {
|
||||
return new DefaultPointcutAdvisor(advice);
|
||||
}
|
||||
@@ -75,13 +74,12 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se
|
||||
}
|
||||
|
||||
public MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException {
|
||||
List interceptors = new ArrayList(3);
|
||||
List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>(3);
|
||||
Advice advice = advisor.getAdvice();
|
||||
if (advice instanceof MethodInterceptor) {
|
||||
interceptors.add(advice);
|
||||
interceptors.add((MethodInterceptor) advice);
|
||||
}
|
||||
for (int i = 0; i < this.adapters.size(); i++) {
|
||||
AdvisorAdapter adapter = (AdvisorAdapter) this.adapters.get(i);
|
||||
for (AdvisorAdapter adapter : this.adapters) {
|
||||
if (adapter.supportsAdvice(advice)) {
|
||||
interceptors.add(adapter.getInterceptor(advisor));
|
||||
}
|
||||
@@ -89,7 +87,7 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se
|
||||
if (interceptors.isEmpty()) {
|
||||
throw new UnknownAdviceTypeException(advisor.getAdvice());
|
||||
}
|
||||
return (MethodInterceptor[]) interceptors.toArray(new MethodInterceptor[interceptors.size()]);
|
||||
return interceptors.toArray(new MethodInterceptor[interceptors.size()]);
|
||||
}
|
||||
|
||||
public void registerAdvisorAdapter(AdvisorAdapter adapter) {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class BeanFactoryAdvisorRetrievalHelper {
|
||||
* @return the list of {@link org.springframework.aop.Advisor} beans
|
||||
* @see #isEligibleBean
|
||||
*/
|
||||
public List findAdvisorBeans() {
|
||||
public List<Advisor> findAdvisorBeans() {
|
||||
// Determine list of advisor bean names, if not cached already.
|
||||
String[] advisorNames = null;
|
||||
synchronized (this) {
|
||||
@@ -76,7 +76,7 @@ public class BeanFactoryAdvisorRetrievalHelper {
|
||||
}
|
||||
}
|
||||
if (advisorNames.length == 0) {
|
||||
return new LinkedList();
|
||||
return new LinkedList<Advisor>();
|
||||
}
|
||||
|
||||
List<Advisor> advisors = new LinkedList<Advisor>();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.PatternMatchUtils;
|
||||
@@ -36,7 +37,7 @@ import org.springframework.util.PatternMatchUtils;
|
||||
*/
|
||||
public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut implements Serializable {
|
||||
|
||||
private List mappedNames = new LinkedList();
|
||||
private List<String> mappedNames = new LinkedList<String>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -45,7 +46,7 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
|
||||
* @see #setMappedNames
|
||||
*/
|
||||
public void setMappedName(String mappedName) {
|
||||
setMappedNames(new String[] { mappedName });
|
||||
setMappedNames(new String[] {mappedName});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,11 +55,9 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
|
||||
* the pointcut matches.
|
||||
*/
|
||||
public void setMappedNames(String[] mappedNames) {
|
||||
this.mappedNames = new LinkedList();
|
||||
this.mappedNames = new LinkedList<String>();
|
||||
if (mappedNames != null) {
|
||||
for (int i = 0; i < mappedNames.length; i++) {
|
||||
this.mappedNames.add(mappedNames[i]);
|
||||
}
|
||||
this.mappedNames.addAll(Arrays.asList(mappedNames));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,16 +71,13 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
|
||||
* @return this pointcut to allow for multiple additions in one line
|
||||
*/
|
||||
public NameMatchMethodPointcut addMethodName(String name) {
|
||||
// TODO in a future release, consider a way of letting proxies
|
||||
// cause advice changed events.
|
||||
this.mappedNames.add(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public boolean matches(Method method, Class targetClass) {
|
||||
for (int i = 0; i < this.mappedNames.size(); i++) {
|
||||
String mappedName = (String) this.mappedNames.get(i);
|
||||
for (String mappedName : this.mappedNames) {
|
||||
if (mappedName.equals(method.getName()) || isMatch(method.getName(), mappedName)) {
|
||||
return true;
|
||||
}
|
||||
@@ -105,11 +101,8 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
return (other instanceof NameMatchMethodPointcut &&
|
||||
ObjectUtils.nullSafeEquals(this.mappedNames, ((NameMatchMethodPointcut) other).mappedNames));
|
||||
return (this == other || (other instanceof NameMatchMethodPointcut &&
|
||||
ObjectUtils.nullSafeEquals(this.mappedNames, ((NameMatchMethodPointcut) other).mappedNames)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user