Pre-JDK 1.4, the only way I know to do this required getting and parsing the
stack trace. It can get rather ugly. You might look at the log4j
LocationInfo class as example.

JDK 1.4 added a Throwable.getStackTrace() method which returns an array of
StackTraceElement objects, providing a much cleaner, and thankfully standard
way, of accomplishing this. Unfortunately, you probably won't see wide
adoption of JDK 1.4 in application server software for awhile.

Best regards,
Jim Cakalic

> -----Original Message-----
> From: Galbreath, Mark [mailto:[EMAIL PROTECTED]]
> 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
> 


<font size="1">Confidentiality Warning:  This e-mail contains information intended 
only for the use of the individual or entity named above.  If the reader of this 
e-mail is not the intended recipient or the employee or agent responsible for 
delivering it to the intended recipient, any dissemination, publication or copying of 
this e-mail is strictly prohibited. The sender does not accept any responsibility for 
any loss, disruption or damage to your data or computer system that may occur while 
using data contained in, or transmitted with, this e-mail.   If you have received this 
e-mail in error, please immediately notify us by return e-mail.  Thank you.

Reply via email to