ReversibleNamedMethodPointcutAdvisor

UPDATE: Turns out ColdSpring already has this functionality via the 'includeMappedNames' property in recent versions.  The ColdSpring the app I was working on uses an older ColdSpring.  So if you have a recent version of ColdSpring, this CFC is irrelevant; use the built-in one.

If you use ColdSpring, chances are you've used it's AOP functionality, and if you've done that, NamedMethodPointcutAdvisor is probably your friend.  Today I needed the ability to proxy a CFC for all methods except one, which would have required listing out all the other methods.  Not very maintainable.  So wrote a simple subclass that accepts a 'reverseMatch' property (defaulting to false, of course) that you can use to accomplish this:

<cfcomponent extends="coldspring.aop.support.NamedMethodPointcutAdvisor" output="false">

  <cffunction name="init" access="public" output="false" returntype="ReversibleNamedMethodPointcutAdvisor">
    <cfset super.init() />
    <cfset setReverseMatch(false) />
    <cfreturn this />
  </cffunction>

  <cffunction name="setReverseMatch" access="public" output="false" returntype="void">
    <cfargument name="reverseMatch" type="boolean" required="true" />
    <cfset variables.reverseMatch = reverseMatch />
  </cffunction>

  <cffunction name="matches" access="public" output="true" returntype="boolean">
    <cfargument name="methodName" type="string" required="true" />
    <cfif variables.reverseMatch>
      <cfreturn NOT super.matches(methodName) />
    <cfelse>
      <cfreturn super.matches(methodName) />
    </cfif>
  </cffunction>

</cfcomponent>

4 responses to “ReversibleNamedMethodPointcutAdvisor”

  1. Tony

    Just curious, but is there much harm by using mappedNames * and proxying all the methods with the NamedMethodPointcutAdvisor?

  2. John Allen

    LOVE IT! Great Idea. Now I have to do some refactoring.