|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -109,29 +109,22 @@ class InstantiationModelAwarePointcutAdvisorImpl |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The pointcut for Spring AOP to use. Actual behaviour of the pointcut will change |
|
|
|
* The pointcut for Spring AOP to use. |
|
|
|
* depending on the state of the advice. |
|
|
|
* Actual behaviour of the pointcut will change depending on the state of the advice. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Pointcut getPointcut() { |
|
|
|
public Pointcut getPointcut() { |
|
|
|
return this.pointcut; |
|
|
|
return this.pointcut; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* This is only of interest for Spring AOP: AspectJ instantiation semantics |
|
|
|
|
|
|
|
* are much richer. In AspectJ terminology, all a return of {@code true} |
|
|
|
|
|
|
|
* means here is that the aspect is not a SINGLETON. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean isPerInstance() { |
|
|
|
public boolean isLazy() { |
|
|
|
return (getAspectMetadata().getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON); |
|
|
|
return this.lazy; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@Override |
|
|
|
* Return the AspectJ AspectMetadata for this advisor. |
|
|
|
public synchronized boolean isAdviceInstantiated() { |
|
|
|
*/ |
|
|
|
return (this.instantiatedAdvice != null); |
|
|
|
public AspectMetadata getAspectMetadata() { |
|
|
|
|
|
|
|
return this.aspectInstanceFactory.getAspectMetadata(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -145,20 +138,26 @@ class InstantiationModelAwarePointcutAdvisorImpl |
|
|
|
return this.instantiatedAdvice; |
|
|
|
return this.instantiatedAdvice; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
private Advice instantiateAdvice(AspectJExpressionPointcut pcut) { |
|
|
|
public boolean isLazy() { |
|
|
|
return this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pcut, |
|
|
|
return this.lazy; |
|
|
|
this.aspectInstanceFactory, this.declarationOrder, this.aspectName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* This is only of interest for Spring AOP: AspectJ instantiation semantics |
|
|
|
|
|
|
|
* are much richer. In AspectJ terminology, all a return of {@code true} |
|
|
|
|
|
|
|
* means here is that the aspect is not a SINGLETON. |
|
|
|
|
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public synchronized boolean isAdviceInstantiated() { |
|
|
|
public boolean isPerInstance() { |
|
|
|
return (this.instantiatedAdvice != null); |
|
|
|
return (getAspectMetadata().getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
private Advice instantiateAdvice(AspectJExpressionPointcut pcut) { |
|
|
|
* Return the AspectJ AspectMetadata for this advisor. |
|
|
|
return this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pcut, |
|
|
|
*/ |
|
|
|
this.aspectInstanceFactory, this.declarationOrder, this.aspectName); |
|
|
|
public AspectMetadata getAspectMetadata() { |
|
|
|
|
|
|
|
return this.aspectInstanceFactory.getAspectMetadata(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public MetadataAwareAspectInstanceFactory getAspectInstanceFactory() { |
|
|
|
public MetadataAwareAspectInstanceFactory getAspectInstanceFactory() { |
|
|
|
@ -213,33 +212,26 @@ class InstantiationModelAwarePointcutAdvisorImpl |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
switch (aspectJAnnotation.getAnnotationType()) { |
|
|
|
switch (aspectJAnnotation.getAnnotationType()) { |
|
|
|
case AtAfter: |
|
|
|
|
|
|
|
case AtAfterReturning: |
|
|
|
|
|
|
|
case AtAfterThrowing: |
|
|
|
|
|
|
|
this.isAfterAdvice = true; |
|
|
|
|
|
|
|
this.isBeforeAdvice = false; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case AtAround: |
|
|
|
|
|
|
|
case AtPointcut: |
|
|
|
case AtPointcut: |
|
|
|
this.isAfterAdvice = false; |
|
|
|
case AtAround: |
|
|
|
this.isBeforeAdvice = false; |
|
|
|
this.isBeforeAdvice = false; |
|
|
|
|
|
|
|
this.isAfterAdvice = false; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case AtBefore: |
|
|
|
case AtBefore: |
|
|
|
this.isAfterAdvice = false; |
|
|
|
|
|
|
|
this.isBeforeAdvice = true; |
|
|
|
this.isBeforeAdvice = true; |
|
|
|
|
|
|
|
this.isAfterAdvice = false; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case AtAfter: |
|
|
|
|
|
|
|
case AtAfterReturning: |
|
|
|
|
|
|
|
case AtAfterThrowing: |
|
|
|
|
|
|
|
this.isBeforeAdvice = false; |
|
|
|
|
|
|
|
this.isAfterAdvice = true; |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String toString() { |
|
|
|
|
|
|
|
return "InstantiationModelAwarePointcutAdvisor: expression [" + getDeclaredPointcut().getExpression() + |
|
|
|
|
|
|
|
"]; advice method [" + this.aspectJAdviceMethod + "]; perClauseKind=" + |
|
|
|
|
|
|
|
this.aspectInstanceFactory.getAspectMetadata().getAjType().getPerClause().getKind(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException { |
|
|
|
private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException { |
|
|
|
inputStream.defaultReadObject(); |
|
|
|
inputStream.defaultReadObject(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -250,11 +242,18 @@ class InstantiationModelAwarePointcutAdvisorImpl |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String toString() { |
|
|
|
|
|
|
|
return "InstantiationModelAwarePointcutAdvisor: expression [" + getDeclaredPointcut().getExpression() + |
|
|
|
|
|
|
|
"]; advice method [" + this.aspectJAdviceMethod + "]; perClauseKind=" + |
|
|
|
|
|
|
|
this.aspectInstanceFactory.getAspectMetadata().getAjType().getPerClause().getKind(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Pointcut implementation that changes its behaviour when the advice is instantiated. |
|
|
|
* Pointcut implementation that changes its behaviour when the advice is instantiated. |
|
|
|
* Note that this is a <i>dynamic</i> pointcut. Otherwise it might |
|
|
|
* Note that this is a <i>dynamic</i> pointcut; otherwise it might be optimized out |
|
|
|
* be optimized out if it does not at first match statically. |
|
|
|
* if it does not at first match statically. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private class PerTargetInstantiationModelPointcut extends DynamicMethodMatcherPointcut { |
|
|
|
private class PerTargetInstantiationModelPointcut extends DynamicMethodMatcherPointcut { |
|
|
|
|
|
|
|
|
|
|
|
@ -264,8 +263,9 @@ class InstantiationModelAwarePointcutAdvisorImpl |
|
|
|
|
|
|
|
|
|
|
|
private LazySingletonAspectInstanceFactoryDecorator aspectInstanceFactory; |
|
|
|
private LazySingletonAspectInstanceFactoryDecorator aspectInstanceFactory; |
|
|
|
|
|
|
|
|
|
|
|
private PerTargetInstantiationModelPointcut(AspectJExpressionPointcut declaredPointcut, |
|
|
|
public PerTargetInstantiationModelPointcut(AspectJExpressionPointcut declaredPointcut, |
|
|
|
Pointcut preInstantiationPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory) { |
|
|
|
Pointcut preInstantiationPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory) { |
|
|
|
|
|
|
|
|
|
|
|
this.declaredPointcut = declaredPointcut; |
|
|
|
this.declaredPointcut = declaredPointcut; |
|
|
|
this.preInstantiationPointcut = preInstantiationPointcut; |
|
|
|
this.preInstantiationPointcut = preInstantiationPointcut; |
|
|
|
if (aspectInstanceFactory instanceof LazySingletonAspectInstanceFactoryDecorator) { |
|
|
|
if (aspectInstanceFactory instanceof LazySingletonAspectInstanceFactoryDecorator) { |
|
|
|
@ -275,7 +275,8 @@ class InstantiationModelAwarePointcutAdvisorImpl |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean matches(Method method, Class<?> targetClass) { |
|
|
|
public boolean matches(Method method, Class<?> targetClass) { |
|
|
|
// We're either instantiated and matching on declared pointcut, or uninstantiated matching on either pointcut
|
|
|
|
// We're either instantiated and matching on declared pointcut,
|
|
|
|
|
|
|
|
// or uninstantiated matching on either pointcut...
|
|
|
|
return (isAspectMaterialized() && this.declaredPointcut.matches(method, targetClass)) || |
|
|
|
return (isAspectMaterialized() && this.declaredPointcut.matches(method, targetClass)) || |
|
|
|
this.preInstantiationPointcut.getMethodMatcher().matches(method, targetClass); |
|
|
|
this.preInstantiationPointcut.getMethodMatcher().matches(method, targetClass); |
|
|
|
} |
|
|
|
} |
|
|
|
|