Distinquishing between interfaces and classes *before* loading?

Discussion in 'Java' started by Steve Wampler, May 28, 2004.

  1. I've got a simple class loader where I'd like to pass interfaces
    to another class loader. Is there a way to tell (from the byte
    codes, say) whether or not it's an interface?

    Thanks!
    -Steve
    Steve Wampler, May 28, 2004
    #1
    1. Advertising

  2. On Thu, 27 May 2004 19:53:45 -0700, Steve Wampler wrote:

    > I've got a simple class loader where I'd like to pass interfaces
    > to another class loader. Is there a way to tell (from the byte
    > codes, say) whether or not it's an interface?


    boolean interface =
    ClassLoader.findClass("fully.qualified.name").isInterface();

    IFAIU

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
    Andrew Thompson, May 28, 2004
    #2
    1. Advertising

  3. Jesper Nordenberg, May 28, 2004
    #3
  4. Steve Wampler

    Chris Uppal Guest

    Steve Wampler wrote:

    > I've got a simple class loader where I'd like to pass interfaces
    > to another class loader. Is there a way to tell (from the byte
    > codes, say) whether or not it's an interface?


    If you are willing to mess with the bytecodes then you can find out absolutely
    /anything/ you like.

    The problem is that decoding the classfile structure is non-trivial. But
    fortunately there are several freely available libraries around that will do
    the hard work for you, such as Apache BCEL, and the GNU bytecode library.

    Googling for:

    java bytecode library

    will turn up more leads.

    -- chris
    Chris Uppal, May 28, 2004
    #4
  5. On Fri, 28 May 2004 03:11:40 +0000, Andrew Thompson wrote:

    > On Thu, 27 May 2004 19:53:45 -0700, Steve Wampler wrote:
    >
    >> I've got a simple class loader where I'd like to pass interfaces
    >> to another class loader. Is there a way to tell (from the byte
    >> codes, say) whether or not it's an interface?

    >
    > boolean interface =
    > ClassLoader.findClass("fully.qualified.name").isInterface();
    >
    > IFAIU


    Thanks, but I *think* findClass calls define class, which is
    effectively loading the class. So (someone please let me
    know if I'm wrong!!) by the time you get to invoking the
    isInterface() method, you've got the class loaded.

    -Steve
    Steve Wampler, May 28, 2004
    #5
  6. On Fri, 28 May 2004 06:01:24 -0700, Steve Wampler wrote:
    > On Fri, 28 May 2004 03:11:40 +0000, Andrew Thompson wrote:
    >> On Thu, 27 May 2004 19:53:45 -0700, Steve Wampler wrote:
    >>
    >>> I've got a simple class loader where I'd like to pass interfaces
    >>> to another class loader. Is there a way to tell (from the byte
    >>> codes, say) whether or not it's an interface?

    >>
    >> boolean interface =
    >> ClassLoader.findClass("fully.qualified.name").isInterface();

    ....
    > Thanks, but I *think* findClass calls define class, which is
    > effectively loading the class.


    *

    I do not understand the subtle distinction..
    You have delivered the bytes of the class
    themselves through the class loader..
    But you want to avoid creating an actual
    Class with the bytes[].. Why?


    * Yes, yes.. I noticed that '...*before* loading?'
    bit in the subject *after* I had posted, it
    pays to ensure every key word of a subject is
    mentioned in the body as some people ignore
    the subject and others miss it.

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
    Andrew Thompson, May 28, 2004
    #6
  7. On Fri, 28 May 2004 13:21:21 +0000, Andrew Thompson wrote:

    > On Fri, 28 May 2004 06:01:24 -0700, Steve Wampler wrote:
    >> Thanks, but I *think* findClass calls define class, which is
    >> effectively loading the class.


    > I do not understand the subtle distinction..
    > You have delivered the bytes of the class
    > themselves through the class loader..
    > But you want to avoid creating an actual
    > Class with the bytes[].. Why?


    > * Yes, yes.. I noticed that '...*before* loading?'
    > bit in the subject *after* I had posted, it
    > pays to ensure every key word of a subject is
    > mentioned in the body as some people ignore
    > the subject and others miss it.


    Sorry!

    I thought the statement that I wanted to "pass
    interfaces to another class loader" covered it. The
    normal ClassLoader implementation means that a
    ClassLoader won't load a class if it's already been
    loaded (I think). I want interfaces to be shared
    between namespaces by having them loaded by a parent
    ClassLoader, while classes found by the current class
    loader are loaded immediately - effectively isolating
    them within the namespace defined by that class loader.

    Does that make sense now? I have a hack that works
    by putting all 'shared' interfaces into a known location,
    but that's really a pretty bad hack. I'm looking for
    better alternatives.
    Steve Wampler, May 28, 2004
    #7
  8. On Fri, 28 May 2004 01:26:51 -0700, Jesper Nordenberg wrote:

    > Steve Wampler <> wrote in message news:<>...
    >> I've got a simple class loader where I'd like to pass interfaces
    >> to another class loader. Is there a way to tell (from the byte
    >> codes, say) whether or not it's an interface?

    >
    > http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#74353
    >


    Most excellent! Thanks.
    Steve Wampler, May 28, 2004
    #8
  9. On Fri, 28 May 2004 09:32:05 +0100, Chris Uppal wrote:

    > Steve Wampler wrote:
    >
    >> I've got a simple class loader where I'd like to pass interfaces
    >> to another class loader. Is there a way to tell (from the byte
    >> codes, say) whether or not it's an interface?

    ....
    > The problem is that decoding the classfile structure is non-trivial. But
    > fortunately there are several freely available libraries around that will do
    > the hard work for you, such as Apache BCEL, and the GNU bytecode library.


    Thanks, Chris. BCEL does *exactly* what I need!

    My thanks to all who offered suggestions. After looking
    at the class file definitions and discovering that the
    access fields come after the constant pool info mess, I
    decided it would be easer to use someone else's (BCPL)
    parser...
    Steve Wampler, May 28, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Webster

    Classes and interfaces

    Webster, Jan 24, 2004, in forum: C++
    Replies:
    9
    Views:
    359
    Frank Puck
    Jan 26, 2004
  2. classes and interfaces

    , Jun 27, 2006, in forum: Python
    Replies:
    6
    Views:
    317
    Diez B. Roggisch
    Jul 4, 2006
  3. Replies:
    13
    Views:
    724
    Dave Rahardja
    Feb 2, 2007
  4. malli
    Replies:
    4
    Views:
    564
    Manivannan Palanichamy
    Jul 8, 2007
  5. Replies:
    7
    Views:
    306
Loading...

Share This Page