Awesome.

Adam Wayne Lehman
Web Systems Developer
Johns Hopkins Bloomberg School of Public Health
Distance Education Division


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Matt Liotta
Sent: Wednesday, September 17, 2003 2:53 PM
To: [EMAIL PROTECTED]
Subject: [CFCDev] Programmatically determining a method call

A while back I seem to remember someone asking how to programmatically 
determine what method of a CFC was called and by whom. At the time it 
didn't seem like there was a way to do it, but I have come up with a 
way through a new feature found in JDK 1.4. Below is an example CFC 
that has a single method, which determines who called it and what 
method it is.

<cfcomponent>
        <cffunction name="getCaller" returntype="struct"
access="public">
                <cfscript>
                        e = CreateObject("java", "java.lang.Exception");
                        sts = e.getStackTrace();
                        foundme = false;
                        theCaller = StructNew();
                        for(itr = 1; itr lte ArrayLen(sts); itr = itr +
1) {
                                className = sts[itr].getClassName();
                                if(foundme and className contains
"2ecf") {
                                        index = Find("2ecf", className);
                                        theCaller.from = Mid(className,
3, index - 3);
                                        break;
                                }
                                if(not foundme and className contains
"2ecfc") {
                                        foundme = true;
                                        methodName =
sts[itr].getClassName();
                                        index = Find("$func",
methodName);
                                        theCaller.toMethod =
Mid(methodName, index + 5, Len(methodName));
                                }
                        }
                </cfscript>
                <cfreturn theCaller>
        </cffunction>
</cfcomponent>

Again, the above only works in JDK 1.4. There is a way to make it work 
with earlier JDKs, but that would be more time consuming both from a 
development point of view and a performance one.

I also blogged this at http://devilm.com/archives/000044.html.

Matt Liotta
President & CEO
Montara Software, Inc.
http://www.MontaraSoftware.com
(888) 408-0900 x901

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to