Re: question rephrased
From: Jonas Kongslund (dont_at_mail.me.at.all)
Date: 11/22/03
- Next message: Québec: "Re: Dont work in a jar"
- Previous message: Tom: "Re: question rephrased"
- In reply to: Tom: "Re: question rephrased"
- Next in thread: Tom: "Re: question rephrased"
- Reply: Tom: "Re: question rephrased"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 22 Nov 2003 21:12:28 +0100
Tom wrote:
[snip]
> In the first place, I shouldn't have used the term application. What
> I am creating would be more accuratly be called a library. My intent
> is that others will write applications that create objects from my
> classes. Obviously, I won't know the names of the files that others
> create.
[snip]
Why is it that you would like to know the names of the files that make use
of your library?
Nevertheless, I have a solution to your problem. It is kind of a hack but
since you are trying to achieve something that one would normally not do, I
believe I can justify it ;-)
Assume one of your public library methods is invoked. We would like to know
which class invoked the method since this class belongs to the application
using your library (assuming that your library doesn't invoke its own
public methods). This can be done by examining the stack trace of an
exception like in the following code snippet:
String callingClassName = null;
try {
throw new RuntimeException();
} catch (RuntimeException e) {
StackTraceElement[] elements = e.getStackTrace();
if (elements.length > 0) {
callingClassName = elements[1].getClassName();
} else {
// This snippet is included in the main method - pretty useless...
}
}
When you have the class name you can use your recently achieved JWhich
knowledge to get the path of the class.
Ok?
Ps: The assumption that your library doesn't invoke its own public methods
can be removed if you modify the code snippet a bit. I leave this as an
exercise.
-- Jonas Kongslund
- Next message: Québec: "Re: Dont work in a jar"
- Previous message: Tom: "Re: question rephrased"
- In reply to: Tom: "Re: question rephrased"
- Next in thread: Tom: "Re: question rephrased"
- Reply: Tom: "Re: question rephrased"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|