@ -116,29 +116,22 @@ final class InstantiationModelAwarePointcutAdvisorImpl
@@ -116,29 +116,22 @@ final class InstantiationModelAwarePointcutAdvisorImpl
/ * *
* The pointcut for Spring AOP to use . Actual behaviour of the pointcut will change
* depending on the state of the advice .
* The pointcut for Spring AOP to use .
* Actual behaviour of the pointcut will change depending on the state of the advice .
* /
@Override
public Pointcut getPointcut ( ) {
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
public boolean isPerInstance ( ) {
return ( getAspectMetadata ( ) . getAjType ( ) . getPerClause ( ) . getKind ( ) ! = PerClauseKind . SINGLETON ) ;
public boolean isLazy ( ) {
return this . lazy ;
}
/ * *
* Return the AspectJ AspectMetadata for this advisor .
* /
public AspectMetadata getAspectMetadata ( ) {
return this . aspectInstanceFactory . getAspectMetadata ( ) ;
@Override
public synchronized boolean isAdviceInstantiated ( ) {
return ( this . instantiatedAdvice ! = null ) ;
}
/ * *
@ -152,21 +145,27 @@ final class InstantiationModelAwarePointcutAdvisorImpl
@@ -152,21 +145,27 @@ final class InstantiationModelAwarePointcutAdvisorImpl
return this . instantiatedAdvice ;
}
@Override
public boolean isLazy ( ) {
return this . lazy ;
private Advice instantiateAdvice ( AspectJExpressionPointcut pointcut ) {
Advice advice = this . aspectJAdvisorFactory . getAdvice ( this . aspectJAdviceMethod , pointcut ,
this . aspectInstanceFactory , this . declarationOrder , this . aspectName ) ;
return ( advice ! = null ? advice : EMPTY_ADVICE ) ;
}
/ * *
* 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
public synchronized boolean isAdviceInstantiated ( ) {
return ( this . instantiatedAdvice ! = null ) ;
public boolean isPerInstance ( ) {
return ( getAspectMetadata ( ) . getAjType ( ) . getPerClause ( ) . getKind ( ) ! = PerClauseKind . SINGLETON ) ;
}
private Advice instantiateAdvice ( AspectJExpressionPointcut pointcut ) {
Advice advice = this . aspectJAdvisorFactory . getAdvice ( this . aspectJAdviceMethod , pointcut ,
this . aspectInstanceFactory , this . declarationOrder , this . aspectName ) ;
return ( advice ! = null ? advice : EMPTY_ADVICE ) ;
/ * *
* Return the AspectJ AspectMetadata for this advisor .
* /
public AspectMetadata getAspectMetadata ( ) {
return this . aspectInstanceFactory . getAspectMetadata ( ) ;
}
public MetadataAwareAspectInstanceFactory getAspectInstanceFactory ( ) {
@ -221,33 +220,26 @@ final class InstantiationModelAwarePointcutAdvisorImpl
@@ -221,33 +220,26 @@ final class InstantiationModelAwarePointcutAdvisorImpl
}
else {
switch ( aspectJAnnotation . getAnnotationType ( ) ) {
case AtAfter :
case AtAfterReturning :
case AtAfterThrowing :
this . isAfterAdvice = true ;
this . isBeforeAdvice = false ;
break ;
case AtAround :
case AtPointcut :
this . isAfterAdvice = false ;
case AtAround :
this . isBeforeAdvice = false ;
this . isAfterAdvice = false ;
break ;
case AtBefore :
this . isAfterAdvice = false ;
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 {
inputStream . defaultReadObject ( ) ;
try {
@ -258,11 +250,18 @@ final class InstantiationModelAwarePointcutAdvisorImpl
@@ -258,11 +250,18 @@ final 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 .
* Note that this is a < i > dynamic < / i > pointcut . Otherwise it might
* be optimized out if it does not at first match statically .
* Note that this is a < i > dynamic < / i > pointcut ; o therwise it might be optimized ou t
* if it does not at first match statically .
* /
private final class PerTargetInstantiationModelPointcut extends DynamicMethodMatcherPointcut {
@ -273,7 +272,7 @@ final class InstantiationModelAwarePointcutAdvisorImpl
@@ -273,7 +272,7 @@ final class InstantiationModelAwarePointcutAdvisorImpl
@Nullable
private LazySingletonAspectInstanceFactoryDecorator aspectInstanceFactory ;
private PerTargetInstantiationModelPointcut ( AspectJExpressionPointcut declaredPointcut ,
public PerTargetInstantiationModelPointcut ( AspectJExpressionPointcut declaredPointcut ,
Pointcut preInstantiationPointcut , MetadataAwareAspectInstanceFactory aspectInstanceFactory ) {
this . declaredPointcut = declaredPointcut ;
@ -285,7 +284,8 @@ final class InstantiationModelAwarePointcutAdvisorImpl
@@ -285,7 +284,8 @@ final class InstantiationModelAwarePointcutAdvisorImpl
@Override
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 ) ) | |
this . preInstantiationPointcut . getMethodMatcher ( ) . matches ( method , targetClass ) ;
}