So, given that I have an instance of this component:
foo.cfc
<cfcomponent>
<cffunction name="locateMe">
<cfreturn "I don't know where I live!">
</cffunction>
</cfcomponent>
And, this other component, fooParent.cfc:
<cfcomponent>
<cfset this.foo = createObject("component", "foo")>
</cfcomponent>
Let's say I create instances of "foo" a few different ways:
<cfset myStruct = {}>
<cfset myStruct.foo = createObject("component", "foo")>
<cfset myFoo = createObject("component", "foo")>
<cfset myFooParent = createObject("component", "fooParent")>
<cfoutput>
#myStruct.foo.locateMe()#<br>
#myFoo.locateMe()#<br>
#myFooParent.foo.locateMe()#<br>
</cfoutput>
As expected, this outputs:
I don't know where I live!
I don't know where I live!
I don't know where I live!
What I want to know is, what can I possibly do within foo.cfc that will tell me something (anything!) about the context in which it is being invoked? Since everything ultimately lives in (at least) a scope of some sort, and all scopes are a kind of object, what I'm saying is that I would really like some way to determine the containing object, from within a given instantiated object. Ultimately, some way of building foo.cfc so that something like this could be my output, from my sample snippet above:
I live within a "class coldfusion.runtime.Struct" instance!
I live within a "class coldfusion.runtime.VariableScope" instance!
I live within a "component cfjunk.fooParent" instance!
Where each of those values might be determined by inspecting the result from passing getMetaData
the actual containing object reference.
Update As suggested by Micah in the comments, I've added the "Java" tag to this, since I suspect he could be correct in that the solution may lie in using Java for introspection.
Update
Rather than leave this as what appears to be a purely-academic discussion, let me explain why I need this.
I'm using CFWheels ORM with includes to get back references to my data like so:
var user = model("User").findOne(where="id=123", include="AuthSource", returnAs="object");
This will return to me an object that I can reference like so:
user.id // property of the "User" model
user.reset() // method on the "User" model
user.AuthSource.id // property of the "AuthSource" model
user.AuthSource.authenticate(password) // method on the "AuthSource" model
Now, within my "AuthSource.authenticate" method, I would like to know about the "User" object that I'm contained within. Otherwise, I will end up having to call the function like this, instead:
user.AuthSource.authenticate(user, password) // note the redundancy in the use of "user"
I should be able to rely on the fact that I'm calling the method on the AuthSource model through the User object and actually read from that object from within that method.