Class ControlFlowPointcut

java.lang.Object
org.springframework.aop.support.ControlFlowPointcut
All Implemented Interfaces:
Serializable, ClassFilter, MethodMatcher, Pointcut

public class ControlFlowPointcut extends Object implements Pointcut, ClassFilter, MethodMatcher, Serializable
Pointcut and method matcher for use as a simple cflow-style pointcut.

Each configured method name pattern can be an exact method name or a pattern (see isMatch(String, String) for details on the supported pattern styles).

Note that evaluating such pointcuts is 10-15 times slower than evaluating normal pointcuts, but they are useful in some cases.

Author:
Rod Johnson, Rob Harrop, Juergen Hoeller, Sam Brannen
See Also:
  • Field Details

    • clazz

      protected final Class<?> clazz
      The class against which to match.

      Available for use in subclasses since 6.1.

    • methodNamePatterns

      protected final List<String> methodNamePatterns
      An immutable list of distinct method name patterns against which to match.
      Since:
      6.1
  • Constructor Details

    • ControlFlowPointcut

      public ControlFlowPointcut(Class<?> clazz)
      Construct a new pointcut that matches all control flows below the given class.
      Parameters:
      clazz - the class
    • ControlFlowPointcut

      public ControlFlowPointcut(Class<?> clazz, @Nullable String methodNamePattern)
      Construct a new pointcut that matches all calls below a method matching the given method name pattern in the given class.

      If no method name pattern is given, the pointcut matches all control flows below the given class.

      Parameters:
      clazz - the class
      methodNamePattern - the method name pattern (may be null)
    • ControlFlowPointcut

      public ControlFlowPointcut(Class<?> clazz, String... methodNamePatterns)
      Construct a new pointcut that matches all calls below a method matching one of the given method name patterns in the given class.

      If no method name pattern is given, the pointcut matches all control flows below the given class.

      Parameters:
      clazz - the class
      methodNamePatterns - the method name patterns (potentially empty)
      Since:
      6.1
    • ControlFlowPointcut

      public ControlFlowPointcut(Class<?> clazz, List<String> methodNamePatterns)
      Construct a new pointcut that matches all calls below a method matching one of the given method name patterns in the given class.

      If no method name pattern is given, the pointcut matches all control flows below the given class.

      Parameters:
      clazz - the class
      methodNamePatterns - the method name patterns (potentially empty)
      Since:
      6.1
  • Method Details

    • matches

      public boolean matches(Class<?> clazz)
      Subclasses can override this for greater filtering (and performance).

      The default implementation always returns true.

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

      public boolean matches(Method method, Class<?> targetClass)
      Subclasses can override this if it's possible to filter out some candidate classes.

      The default implementation always returns true.

      Specified by:
      matches in interface MethodMatcher
      Parameters:
      method - the candidate method
      targetClass - the target class
      Returns:
      whether this method matches statically
    • isRuntime

      public boolean isRuntime()
      Description copied from interface: MethodMatcher
      Is this MethodMatcher dynamic, that is, must a final check be made via the MethodMatcher.matches(Method, Class, Object[]) method at runtime even if MethodMatcher.matches(Method, Class) 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 a runtime match via MethodMatcher.matches(Method, Class, Object[]) is required if static matching passed
    • matches

      public boolean matches(Method method, Class<?> targetClass, Object... args)
      Description copied from interface: MethodMatcher
      Check whether there is a runtime (dynamic) match for this method, which must have matched statically.

      This method is invoked only if MethodMatcher.matches(Method, Class) returns true for the given method and target class, and if MethodMatcher.isRuntime() 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:
    • getEvaluations

      public int getEvaluations()
      Get the number of times matches(Method, Class, Object...) has been evaluated.

      Useful for optimization and testing purposes.

    • incrementEvaluationCount

      protected final void incrementEvaluationCount()
      Increment the evaluation count.
      Since:
      6.1
      See Also:
    • isMatch

      protected boolean isMatch(String methodName, int patternIndex)
      Determine if the given method name matches the method name pattern at the specified index.

      This method is invoked by matches(Method, Class, Object...).

      The default implementation retrieves the method name pattern from methodNamePatterns and delegates to isMatch(String, String).

      Can be overridden in subclasses — for example, to support regular expressions.

      Parameters:
      methodName - the method name to check
      patternIndex - the index of the method name pattern
      Returns:
      true if the method name matches the pattern at the specified index
      Since:
      6.1
      See Also:
    • isMatch

      protected boolean isMatch(String methodName, String methodNamePattern)
      Determine if the given method name matches the method name pattern.

      This method is invoked by isMatch(String, int).

      The default implementation checks for direct equality as well as xxx*, *xxx, *xxx*, and xxx*yyy matches.

      Can be overridden in subclasses — for example, to support a different style of simple pattern matching.

      Parameters:
      methodName - the method name to check
      methodNamePattern - the method name pattern
      Returns:
      true if the method name matches the pattern
      Since:
      6.1
      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)
    • 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