You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Galbreath, Mark" <Ga...@tessco.com> on 2002/02/15 22:03:06 UTC

Determining the name of a calling class

Hey gang.  Here's something I've not run into before).
 
I have struts delegating database access to several (like 12) entity EJBs
through a session facade.  I have a utility class that has extracted
numerous common functions out of the entity beans like setting the context,
the appropriate SQL, and obtaining references to the home and remote
interfaces (among other things).  While debugging one of these entity beans
I found a method calling the wrong overloaded constructor in my utility
class.  To my horror :-) I found several more like cases in the same bean
and in another (I have not reviewed the other beans yet).  So I was
thinking, should not there be a way to validate these calls within my
utility class' overloaded constructors?  In other words, within the utility
class, each constructor should be able to tell if it is the correct one for
the calling method without relying on its signature (sounds pretty far
fetched, I guess).
 
Anyway, does anyone know if there is a way to determine the class name of
the calling method to another class' constructor in order to validate the
call?  In other words, can a constructor know that it should not instantiate
its class from a call from Class A, even though Class A's method signature
matches the constructor's?
 
Probably not, but I thought I'd check.
 
Cheers! (it's almost time for BEER!)
Mark

RE: Determining the name of a calling class

Posted by Robert <rm...@bull-enterprises.com>.
Yes there is, and there was a recent article in JavaDev Journal
describing this. Basically what you have to do is is create a Throwable
object, which you can then inspect the stacktrace. The stack trace
contains the calling order of objects. Yes you have to parse it, but it
works. The article presented a couple of utility classes to handle the
parsing and such. It was presented as a sort of security mechanism. 

It was in the November 2001 issue and the source is at:
www.sys-con.com/java/sourcec.cfm volume 6 issue 11.

Hope that helps

Robert


-----Original Message-----
From: Galbreath, Mark [mailto:Galbreath@tessco.com] 
Sent: Friday, February 15, 2002 3:03 PM
To: J2ee (E-mail); Struts (E-mail); Advanced Servlets (E-mail)
Subject: Determining the name of a calling class

Hey gang.  Here's something I've not run into before).
 
I have struts delegating database access to several (like 12) entity
EJBs
through a session facade.  I have a utility class that has extracted
numerous common functions out of the entity beans like setting the
context,
the appropriate SQL, and obtaining references to the home and remote
interfaces (among other things).  While debugging one of these entity
beans
I found a method calling the wrong overloaded constructor in my utility
class.  To my horror :-) I found several more like cases in the same
bean
and in another (I have not reviewed the other beans yet).  So I was
thinking, should not there be a way to validate these calls within my
utility class' overloaded constructors?  In other words, within the
utility
class, each constructor should be able to tell if it is the correct one
for
the calling method without relying on its signature (sounds pretty far
fetched, I guess).
 
Anyway, does anyone know if there is a way to determine the class name
of
the calling method to another class' constructor in order to validate
the
call?  In other words, can a constructor know that it should not
instantiate
its class from a call from Class A, even though Class A's method
signature
matches the constructor's?
 
Probably not, but I thought I'd check.
 
Cheers! (it's almost time for BEER!)
Mark


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>