Class AspectJExpressionPointcut

java.lang.Object
org.springframework.aop.support.AbstractExpressionPointcut
org.springframework.aop.aspectj.AspectJExpressionPointcut
All Implemented Interfaces:
Serializable, ClassFilter, IntroductionAwareMethodMatcher, MethodMatcher, Pointcut, ExpressionPointcut, Aware, 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, Dave Syer
See Also:
  • Constructor Details

    • AspectJExpressionPointcut

      public AspectJExpressionPointcut()
      Create a new default AspectJExpressionPointcut.
    • AspectJExpressionPointcut

      public AspectJExpressionPointcut(Class<?> declarationScope, String[] paramNames, 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 Details

    • setPointcutDeclarationScope

      public void setPointcutDeclarationScope(Class<?> pointcutDeclarationScope)
      Set the declaration scope for the pointcut.
    • setParameterNames

      public void setParameterNames(String... names)
      Set the parameter names for the pointcut.
    • setParameterTypes

      public void setParameterTypes(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:
    • 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)
    • getPointcutExpression

      public org.aspectj.weaver.tools.PointcutExpression getPointcutExpression()
      Return the underlying AspectJ pointcut expression.
    • matches

      public boolean matches(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(Method method, Class<?> targetClass, boolean hasIntroductions)
      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
      hasIntroductions - 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(Method method, 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
      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(Method method, Class<?> targetClass, 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
      args - arguments to the method
      Returns:
      whether there's a runtime match
      See Also:
    • getCurrentProxiedBeanName

      @Nullable protected String getCurrentProxiedBeanName()
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object