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>
Just curious, but is there much harm by using mappedNames * and proxying all the methods with the NamedMethodPointcutAdvisor?
Tony,
No, that's usually the way I do it to apply transactionality to all my beans. There are performance implications with proxying methods, particularly around the initial load (because of the filesystem/compiler churn), but it's snappy enough at runtime.
The particular case that drove this class was an app where every method is proxied for transactionality, but a single method on a single bean needed to be non-transactional (it manages it's transactions manually with CFTRANSACTION and a single method invocation encapsulates several distinct transactions.
LOVE IT! Great Idea. Now I have to do some refactoring.
Never mind. Modern ColdSpring already has this functionality built in. The app I was working on uses an older version (intentionally, mind you), that predates the addition into the core. See update in the post above.