Class AbstractRegexpMethodPointcut

All Implemented Interfaces:
Serializable, MethodMatcher, Pointcut
Direct Known Subclasses:
JdkRegexpMethodPointcut

public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPointcut implements Serializable
Abstract base regular expression pointcut bean. JavaBean properties are:
  • pattern: regular expression for the fully-qualified method names to match. The exact regexp syntax will depend on the subclass (e.g. Perl5 regular expressions)
  • patterns: alternative property taking a String array of patterns. The result will be the union of these patterns.

Note: the regular expressions must be a match. For example, .*get.* will match com.mycom.Foo.getBar(). get.* will not.

This base class is serializable. Subclasses should declare all fields transient; the initPatternRepresentation(java.lang.String[]) method will be invoked again on deserialization.

Since:
1.1
Author:
Rod Johnson, Juergen Hoeller, Rob Harrop
See Also:
  • Constructor Details

    • AbstractRegexpMethodPointcut

      public AbstractRegexpMethodPointcut()
  • Method Details

    • setPattern

      public void setPattern(String pattern)
      Convenience method when we have only a single pattern. Use either this method or setPatterns(java.lang.String...), not both.
      See Also:
    • setPatterns

      public void setPatterns(String... patterns)
      Set the regular expressions defining methods to match. Matching will be the union of all these; if any match, the pointcut matches.
      See Also:
    • getPatterns

      public String[] getPatterns()
      Return the regular expressions for method matching.
    • setExcludedPattern

      public void setExcludedPattern(String excludedPattern)
      Convenience method when we have only a single exclusion pattern. Use either this method or setExcludedPatterns(java.lang.String...), not both.
      See Also:
    • setExcludedPatterns

      public void setExcludedPatterns(String... excludedPatterns)
      Set the regular expressions defining methods to match for exclusion. Matching will be the union of all these; if any match, the pointcut matches.
      See Also:
    • getExcludedPatterns

      public String[] getExcludedPatterns()
      Returns the regular expressions for exclusion matching.
    • matches

      public boolean matches(Method method, Class<?> targetClass)
      Try to match the regular expression against the fully qualified name of the target class as well as against the method's declaring class, plus the name of the method.
      Specified by:
      matches in interface MethodMatcher
      Parameters:
      method - the candidate method
      targetClass - the target class
      Returns:
      whether this method matches statically
    • matchesPattern

      protected boolean matchesPattern(String signatureString)
      Match the specified candidate against the configured patterns.
      Parameters:
      signatureString - "java.lang.Object.hashCode" style signature
      Returns:
      whether the candidate matches at least one of the specified patterns
    • initPatternRepresentation

      protected abstract void initPatternRepresentation(String[] patterns) throws IllegalArgumentException
      Subclasses must implement this to initialize regexp pointcuts. Can be invoked multiple times.

      This method will be invoked from the setPatterns(java.lang.String...) method, and also on deserialization.

      Parameters:
      patterns - the patterns to initialize
      Throws:
      IllegalArgumentException - in case of an invalid pattern
    • initExcludedPatternRepresentation

      protected abstract void initExcludedPatternRepresentation(String[] patterns) throws IllegalArgumentException
      Subclasses must implement this to initialize regexp pointcuts. Can be invoked multiple times.

      This method will be invoked from the setExcludedPatterns(java.lang.String...) method, and also on deserialization.

      Parameters:
      patterns - the patterns to initialize
      Throws:
      IllegalArgumentException - in case of an invalid pattern
    • matches

      protected abstract boolean matches(String pattern, int patternIndex)
      Does the pattern at the given index match the given String?
      Parameters:
      pattern - the String pattern to match
      patternIndex - index of pattern (starting from 0)
      Returns:
      true if there is a match, false otherwise
    • matchesExclusion

      protected abstract boolean matchesExclusion(String pattern, int patternIndex)
      Does the exclusion pattern at the given index match the given String?
      Parameters:
      pattern - the String pattern to match
      patternIndex - index of pattern (starting from 0)
      Returns:
      true if there is a match, false otherwise
    • 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