org.springframework.aop.support
Class RegexpMethodPointcut

java.lang.Object
  extended byorg.springframework.aop.support.StaticMethodMatcher
      extended byorg.springframework.aop.support.StaticMethodMatcherPointcut
          extended byorg.springframework.aop.support.RegexpMethodPointcut
All Implemented Interfaces:
ClassFilter, MethodMatcher, Pointcut
Direct Known Subclasses:
RegexpMethodPointcutAdvisor

public class RegexpMethodPointcut
extends StaticMethodMatcherPointcut
implements ClassFilter

Perl5 regular expression pointcut bean. JavaBean properties are:

  • pattern: Perl5 regular expression for the fully-qualified method names to match
  • patterns: alternative property taking a String array of patterns. The result will be the union of these patterns.
  • interceptor: AOP Alliance interceptor to invoke if the pointcut matches Matching is based purely on method name.

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

    Currently uses Jakarta ORO regular expression library. Does not require J2SE 1.4, although it runs under 1.4.

    Since:
    July 22, 2003
    Version:
    $Id: RegexpMethodPointcut.java,v 1.6 2004/03/18 02:46:11 trisberg Exp $
    Author:
    Rod Johnson

    Field Summary
     
    Fields inherited from interface org.springframework.aop.ClassFilter
    TRUE
     
    Fields inherited from interface org.springframework.aop.Pointcut
    TRUE
     
    Fields inherited from interface org.springframework.aop.MethodMatcher
    TRUE
     
    Constructor Summary
    RegexpMethodPointcut()
               
     
    Method Summary
     ClassFilter getClassFilter()
               
     java.lang.String[] getPatterns()
              Return the regular expressions for method matching.
     boolean matches(java.lang.Class clazz)
              Should the pointcut apply to the given interface or target class?
     boolean matches(java.lang.reflect.Method m, java.lang.Class targetClass)
              Try to match the regular expression against the fully qualified name of the method's declaring class, plus the name of the method.
     void setPattern(java.lang.String pattern)
              Convenience method when we have only a single pattern.
     void setPatterns(java.lang.String[] patterns)
              Set the regular expressions defining methods to match.
     
    Methods inherited from class org.springframework.aop.support.StaticMethodMatcherPointcut
    getMethodMatcher
     
    Methods inherited from class org.springframework.aop.support.StaticMethodMatcher
    isRuntime, matches
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    RegexpMethodPointcut

    public RegexpMethodPointcut()
    Method Detail

    setPattern

    public void setPattern(java.lang.String pattern)
                    throws org.apache.oro.text.regex.MalformedPatternException
    Convenience method when we have only a single pattern. Use either this method or setPatterns(), not both.

    Throws:
    org.apache.oro.text.regex.MalformedPatternException
    See Also:
    setPatterns(java.lang.String[])

    setPatterns

    public void setPatterns(java.lang.String[] patterns)
                     throws org.apache.oro.text.regex.MalformedPatternException
    Set the regular expressions defining methods to match. Matching will be the union of all these; if any match, the pointcut matches.

    Parameters:
    patterns - Perl5 regular expressions describing methods to match
    Throws:
    org.apache.oro.text.regex.MalformedPatternException

    getPatterns

    public java.lang.String[] getPatterns()
    Return the regular expressions for method matching.


    matches

    public boolean matches(java.lang.reflect.Method m,
                           java.lang.Class targetClass)
    Try to match the regular expression against the fully qualified name of the method's declaring class, plus the name of the method. Note that the declaring class is that class that originally declared the method, not necessarily the class that's currently exposing it.

    For example, java.lang.Object.hashCode matches any subclass of object's hashCode() method.

    Specified by:
    matches in interface MethodMatcher
    Parameters:
    m - candidate method
    targetClass - 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

    matches

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

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

    getClassFilter

    public ClassFilter getClassFilter()
    Specified by:
    getClassFilter in interface Pointcut
    Overrides:
    getClassFilter in class StaticMethodMatcherPointcut


    Copyright (C) 2003-2004 The Spring Framework Project.