Re: question rephrased

From: Jonas Kongslund (dont_at_mail.me.at.all)
Date: 11/22/03


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


Relevant Pages

  • Re: question rephrased
    ... The assumption that your library doesn't invoke its own public methods ... > can be removed if you modify the code snippet a bit. ...
    (comp.lang.java.help)
  • Re: Simple race condition that I cant solve.
    ... Just off the top of my head, would it be better to check the closed ... Then Invoke is called, ... > thrown. ...
    (microsoft.public.dotnet.framework)
  • Re: If you were inventing CoBOL...
    ... > I wish we could invoke a method the way we call an intrinsic function ... > of another verb it becomes a gerund, which is a substantive, ...
    (comp.lang.cobol)
  • Re: Unload Me - simple question
    ... I make it a practice to never call ... >button that invoke the same function, I'll put that code in a separate ... rather than on first cut ...
    (microsoft.public.vb.general.discussion)
  • Re: [ Attn: Randy ] Ad-hoc Parsing?
    ... There is no syntax ambiguity here and it is easier to type than ... invoke is wanted or vica-versa, ... though it seems to mixup properties and ...
    (alt.lang.asm)