org.springframework.aop.aspectj
Class AspectJExpressionPointcut

java.lang.Object
  extended by org.springframework.aop.support.AbstractExpressionPointcut
      extended by org.springframework.aop.aspectj.AspectJExpressionPointcut
All Implemented Interfaces:
java.io.Serializable, ClassFilter, IntroductionAwareMethodMatcher, MethodMatcher, Pointcut, ExpressionPointcut, BeanFactoryAware

public class AspectJExpressionPointcut
extends AbstractExpressionPointcut
implements ClassFilter, IntroductionAwareMethodMatcher, BeanFactoryAware

Spring Pointcut implementation that uses the AspectJ weaver to evaluate a pointcut expression.

The pointcut expression value is an AspectJ expression. This can reference other pointcuts and use composition and other operations.

Naturally, as this is to be processed by Spring AOP's proxy-based model, only method execution pointcuts are supported.

Since:
2.0
Author:
Rob Harrop, Adrian Colyer, Rod Johnson, Juergen Hoeller, Ramnivas Laddad
See Also:
Serialized Form

Nested Class Summary
private  class AspectJExpressionPointcut.BeanNameContextMatcher
          Matcher class for the BeanNamePointcutDesignatorHandler.
private  class AspectJExpressionPointcut.BeanNamePointcutDesignatorHandler
          Handler for the Spring-specific bean() pointcut designator extension to AspectJ.
 
Field Summary
private  BeanFactory beanFactory
           
private static Log logger
           
private  java.lang.Class pointcutDeclarationScope
           
private  PointcutExpression pointcutExpression
           
private  java.lang.String[] pointcutParameterNames
           
private  java.lang.Class[] pointcutParameterTypes
           
private  java.util.Map<java.lang.reflect.Method,ShadowMatch> shadowMatchCache
           
private static java.util.Set<PointcutPrimitive> SUPPORTED_PRIMITIVES
           
 
Fields inherited from interface org.springframework.aop.ClassFilter
TRUE
 
Fields inherited from interface org.springframework.aop.Pointcut
TRUE
 
Constructor Summary
AspectJExpressionPointcut()
          Create a new default AspectJExpressionPointcut.
AspectJExpressionPointcut(java.lang.Class declarationScope, java.lang.String[] paramNames, java.lang.Class[] paramTypes)
          Create a new AspectJExpressionPointcut with the given settings.
 
Method Summary
private  void bindParameters(ProxyMethodInvocation invocation, JoinPointMatch jpm)
           
private  PointcutExpression buildPointcutExpression()
          Build the underlying AspectJ pointcut expression.
private  void checkReadyToMatch()
          Check whether this pointcut is ready to match, lazily building the underlying AspectJ pointcut expression.
 boolean equals(java.lang.Object other)
           
 ClassFilter getClassFilter()
          Return the ClassFilter for this pointcut.
protected  java.lang.String getCurrentProxiedBeanName()
           
 MethodMatcher getMethodMatcher()
          Return the MethodMatcher for this pointcut.
 PointcutExpression getPointcutExpression()
          Return the underlying AspectJ pointcut expression.
private  ShadowMatch getShadowMatch(java.lang.reflect.Method targetMethod, java.lang.reflect.Method originalMethod)
           
 int hashCode()
           
private  PointcutParser initializePointcutParser()
          Initialize the underlying AspectJ pointcut parser.
 boolean isRuntime()
          Is this MethodMatcher dynamic, that is, must a final call be made on the MethodMatcher.matches(java.lang.reflect.Method, Class, Object[]) method at runtime even if the 2-arg matches method returns true?
 boolean matches(java.lang.Class targetClass)
          Should the pointcut apply to the given interface or target class?
 boolean matches(java.lang.reflect.Method method, java.lang.Class targetClass)
          Perform static checking whether the given method matches.
 boolean matches(java.lang.reflect.Method method, java.lang.Class targetClass, boolean beanHasIntroductions)
          Perform static checking whether the given method matches.
 boolean matches(java.lang.reflect.Method method, java.lang.Class targetClass, java.lang.Object[] args)
          Check whether there a runtime (dynamic) match for this method, which must have matched statically.
private  boolean matchesIgnoringSubtypes(ShadowMatch shadowMatch)
          A match test returned maybe - if there are any subtype sensitive variables involved in the test (this, target, at_this, at_target, at_annotation) then we say this is not a match as in Spring there will never be a different runtime subtype.
private  boolean matchesTarget(ShadowMatch shadowMatch, java.lang.Class targetClass)
           
private  void readObject(java.io.ObjectInputStream ois)
           
private  java.lang.String replaceBooleanOperators(java.lang.String pcExpr)
          If a pointcut expression has been specified in XML, the user cannot write and as "&&" (though && will work).
 void setBeanFactory(BeanFactory beanFactory)
          Callback that supplies the owning factory to a bean instance.
 void setParameterNames(java.lang.String[] names)
          Set the parameter names for the pointcut.
 void setParameterTypes(java.lang.Class[] types)
          Set the parameter types for the pointcut.
 void setPointcutDeclarationScope(java.lang.Class pointcutDeclarationScope)
          Set the declaration scope for the pointcut.
 java.lang.String toString()
           
 
Methods inherited from class org.springframework.aop.support.AbstractExpressionPointcut
getExpression, getLocation, onSetExpression, setExpression, setLocation
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SUPPORTED_PRIMITIVES

private static final java.util.Set<PointcutPrimitive> SUPPORTED_PRIMITIVES

logger

private static final Log logger

pointcutDeclarationScope

private java.lang.Class pointcutDeclarationScope

pointcutParameterNames

private java.lang.String[] pointcutParameterNames

pointcutParameterTypes

private java.lang.Class[] pointcutParameterTypes

beanFactory

private BeanFactory beanFactory

pointcutExpression

private transient PointcutExpression pointcutExpression

shadowMatchCache

private transient java.util.Map<java.lang.reflect.Method,ShadowMatch> shadowMatchCache
Constructor Detail

AspectJExpressionPointcut

public AspectJExpressionPointcut()
Create a new default AspectJExpressionPointcut.


AspectJExpressionPointcut

public AspectJExpressionPointcut(java.lang.Class declarationScope,
                                 java.lang.String[] paramNames,
                                 java.lang.Class[] paramTypes)
Create a new AspectJExpressionPointcut with the given settings.

Parameters:
declarationScope - the declaration scope for the pointcut
paramNames - the parameter names for the pointcut
paramTypes - the parameter types for the pointcut
Method Detail

setPointcutDeclarationScope

public void setPointcutDeclarationScope(java.lang.Class pointcutDeclarationScope)
Set the declaration scope for the pointcut.


setParameterNames

public void setParameterNames(java.lang.String[] names)
Set the parameter names for the pointcut.


setParameterTypes

public void setParameterTypes(java.lang.Class[] types)
Set the parameter types for the pointcut.


setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
Description copied from interface: BeanFactoryAware
Callback that supplies the owning factory to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean.afterPropertiesSet() or a custom init-method.

Specified by:
setBeanFactory in interface BeanFactoryAware
Parameters:
beanFactory - owning BeanFactory (never null). The bean can immediately call methods on the factory.
See Also:
BeanInitializationException

getClassFilter

public ClassFilter getClassFilter()
Description copied from interface: Pointcut
Return the ClassFilter for this pointcut.

Specified by:
getClassFilter in interface Pointcut
Returns:
the ClassFilter (never null)

getMethodMatcher

public MethodMatcher getMethodMatcher()
Description copied from interface: Pointcut
Return the MethodMatcher for this pointcut.

Specified by:
getMethodMatcher in interface Pointcut
Returns:
the MethodMatcher (never null)

checkReadyToMatch

private void checkReadyToMatch()
Check whether this pointcut is ready to match, lazily building the underlying AspectJ pointcut expression.


buildPointcutExpression

private PointcutExpression buildPointcutExpression()
Build the underlying AspectJ pointcut expression.


initializePointcutParser

private PointcutParser initializePointcutParser()
Initialize the underlying AspectJ pointcut parser.


replaceBooleanOperators

private java.lang.String replaceBooleanOperators(java.lang.String pcExpr)
If a pointcut expression has been specified in XML, the user cannot write and as "&&" (though && will work). We also allow and between two pointcut sub-expressions.

This method converts back to && for the AspectJ pointcut parser.


getPointcutExpression

public PointcutExpression getPointcutExpression()
Return the underlying AspectJ pointcut expression.


matches

public boolean matches(java.lang.Class targetClass)
Description copied from interface: ClassFilter
Should the pointcut apply to the given interface or target class?

Specified by:
matches in interface ClassFilter
Parameters:
targetClass - the candidate target class
Returns:
whether the advice should apply to the given target class

matches

public boolean matches(java.lang.reflect.Method method,
                       java.lang.Class targetClass,
                       boolean beanHasIntroductions)
Description copied from interface: IntroductionAwareMethodMatcher
Perform static checking whether the given method matches. This may be invoked instead of the 2-arg MethodMatcher.matches(java.lang.reflect.Method, Class) method if the caller supports the extended IntroductionAwareMethodMatcher interface.

Specified by:
matches in interface IntroductionAwareMethodMatcher
Parameters:
method - the candidate method
targetClass - the target class (may be null, in which case the candidate class must be taken to be the method's declaring class)
beanHasIntroductions - true if the object on whose behalf we are asking is the subject on one or more introductions; false otherwise
Returns:
whether or not this method matches statically

matches

public boolean matches(java.lang.reflect.Method method,
                       java.lang.Class targetClass)
Description copied from interface: MethodMatcher
Perform static checking whether the given method matches. If this returns false or if the MethodMatcher.isRuntime() method returns false, no runtime check (i.e. no. MethodMatcher.matches(java.lang.reflect.Method, Class, Object[]) call) will be made.

Specified by:
matches in interface MethodMatcher
Parameters:
method - the candidate method
targetClass - the target class (may be null, in which case the candidate class must be taken to be the method's declaring class)
Returns:
whether or not this method matches statically

isRuntime

public boolean isRuntime()
Description copied from interface: MethodMatcher
Is this MethodMatcher dynamic, that is, must a final call be made on the MethodMatcher.matches(java.lang.reflect.Method, Class, Object[]) method at runtime even if the 2-arg matches method returns true?

Can be invoked when an AOP proxy is created, and need not be invoked again before each method invocation,

Specified by:
isRuntime in interface MethodMatcher
Returns:
whether or not a runtime match via the 3-arg MethodMatcher.matches(java.lang.reflect.Method, Class, Object[]) method is required if static matching passed

matches

public boolean matches(java.lang.reflect.Method method,
                       java.lang.Class targetClass,
                       java.lang.Object[] args)
Description copied from interface: MethodMatcher
Check whether there a runtime (dynamic) match for this method, which must have matched statically.

This method is invoked only if the 2-arg matches method returns true for the given method and target class, and if the MethodMatcher.isRuntime() method returns true. Invoked immediately before potential running of the advice, after any advice earlier in the advice chain has run.

Specified by:
matches in interface MethodMatcher
Parameters:
method - the candidate method
targetClass - the target class (may be null, in which case the candidate class must be taken to be the method's declaring class)
args - arguments to the method
Returns:
whether there's a runtime match
See Also:
MethodMatcher.matches(Method, Class)

getCurrentProxiedBeanName

protected java.lang.String getCurrentProxiedBeanName()

matchesIgnoringSubtypes

private boolean matchesIgnoringSubtypes(ShadowMatch shadowMatch)
A match test returned maybe - if there are any subtype sensitive variables involved in the test (this, target, at_this, at_target, at_annotation) then we say this is not a match as in Spring there will never be a different runtime subtype.


matchesTarget

private boolean matchesTarget(ShadowMatch shadowMatch,
                              java.lang.Class targetClass)

bindParameters

private void bindParameters(ProxyMethodInvocation invocation,
                            JoinPointMatch jpm)

getShadowMatch

private ShadowMatch getShadowMatch(java.lang.reflect.Method targetMethod,
                                   java.lang.reflect.Method originalMethod)

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

readObject

private void readObject(java.io.ObjectInputStream ois)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException