CFFUNCTION ACCESS="Package" prevents it from being called by anything other
than a cfc in the same package . . . As for the being called by only a
certain CFC, I think you'd have to roll your own solution for that.

You could do it by examining the current stack trace via java, but the code
for obtaining that stack trace isn't pretty, requires some parsing, and may
have repercussions if execution fails.  For purely academic purposes, here's
the code, but I would not recommend using it unless you really know what
you're doing - I can't guarantee that the CF engine would be too happy with
you redirecting standard err.  Play with it at your own risk!

test2.cfc:
<CFFUNCTION NAME="test" ACCESS="public" RETURNTYPE="void" OUTPUT="true">

<CFSCRIPT>
        //this is the name of the required cfc
        sRequiredCFC = "test1.cfc";
        sRequiredCFC = "cf" & Replace(sRequiredCFC, ".", "2e");
        
        thread  = createObject("java", "java.lang.Thread");
        defaultErr  = createObject("java", "java.io.PrintStream");
        errStream = createObject("java", "java.io.ByteArrayOutputStream");
        newErr = createObject("java", "java.io.PrintStream");
        jSystem= createObject("java", "java.lang.System");
        
        //capture the default err
        defaultErr = jSystem.err;
        
        //redirect default err to our PrintStream
        errStream.init();
        newErr.init(errStream);
        jSystem.setErr(newErr);
        
        //get a stack trace
        thread.dumpStack();
        
        //restore default err
        jSystem.setErr(defaultErr);
        
        //store the stack trace
        sStack = errStream.toString();
</CFSCRIPT>

<CFIF Find(sRequiredCFC, sStack)>
        Called by test1.cfc
<CFELSE>
        Not called by test1.cfc
</CFIF>
</CFFUNCTION>




test1.cfc:
<CFFUNCTION NAME="test" ACCESS="public" RETURNTYPE="void" OUTPUT="true">
        <CFOBJECT COMPONENT="test2" NAME="oTest">

        <CFSET oTest.test()>
</CFFUNCTION>


test.cfm:
<CFOBJECT COMPONENT="test2" NAME="oTest">
<CFSET oTest.test()>
<BR>
<CFOBJECT COMPONENT="test1" NAME="oTest">
<CFSET oTest.test()>

Roland Collins

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Bryan F. Hogan
Sent: Thursday, January 15, 2004 3:49 PM
To: [EMAIL PROTECTED] Org
Subject: [CFCDev] Making sure is not called out of sequence

Does anyone know if it is possible to make sure that a CFC is not called
directly and that can only be called from a certain CFC when the CFC
that shouldn't be called is in a sub-directory of the CFC that should be
the only caller?


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words '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 words '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