Aliasing a class name?

Discussion in 'Java' started by Wesley T Perkins, Jun 28, 2005.

  1. Hello All,

    I would like to wrap a class which is contained in a *.jar file (for which I
    don't have the source) so I can intercept calls to that class. For example,
    say that the class is named SomeClass, I would like to create my own class
    something like this:

    public class SomeClass
    extends
    AliasedNameAssignedToTheReal_SomeClass_SoThatIInheritEverythingButTheName
    {
    ... some methods of my own to profile what the original SomeClass is
    doing...
    }

    then precede the *.jar file with my own source in the classpath, together
    with an option which says "export the class SomeClass from the jar file but
    use another name as an alias. I know I used to do something similar in
    C/Unix and possibly with Windows *.dll's as well

    Thanks,
    Wesley
     
    Wesley T Perkins, Jun 28, 2005
    #1
    1. Advertising

  2. Hi Wesley,

    Wesley T Perkins wrote:
    > Hello All,
    >
    > I would like to wrap a class which is contained in a *.jar file (for which I
    > don't have the source) so I can intercept calls to that class. For example,
    > say that the class is named SomeClass, I would like to create my own class
    > something like this:
    >
    > public class SomeClass
    > extends
    > AliasedNameAssignedToTheReal_SomeClass_SoThatIInheritEverythingButTheName
    > {
    > ... some methods of my own to profile what the original SomeClass is
    > doing...
    > }
    >
    > then precede the *.jar file with my own source in the classpath, together
    > with an option which says "export the class SomeClass from the jar file but
    > use another name as an alias. I know I used to do something similar in
    > C/Unix and possibly with Windows *.dll's as well
    >
    > Thanks,
    > Wesley


    I suppose, this might be possible using an own classloader. Perhaps,
    some tool (like bcel) might be useful... (I didn't do something like
    this until now.)

    Anyhow, there is no *simple* way to do so.

    Ciao,
    Ingo
     
    Ingo R. Homann, Jun 28, 2005
    #2
    1. Advertising

  3. Wesley T Perkins

    Roedy Green Guest

    On Tue, 28 Jun 2005 01:17:05 GMT, "Wesley T Perkins"
    <> wrote or quoted :

    >I would like to wrap a class which is contained in a *.jar file (for which I
    >don't have the source) so I can intercept calls to that class. For example,
    >say that the class is named SomeClass, I would like to create my own class
    >something like this:


    I have often wanted to do this too, to introduce some instrumenting on
    somebody else's code. I don't think you can pull this off in any
    simple way in java. what you could do is decompile his class, and give
    his class a new name, then you subclass his class, and use his OLD
    name as your class name. The clients will never know what hit them.


    With a little cleverness, you might be able to hex patch his class
    file, so long as there are no checksums to deal with.

    See http://mindprod.com/jgloss/jvm.html
    http://mindprod.com/jgloss/decompiler.html

    Sounds like a fun little project. I might take it on for a fee.

    --
    Bush crime family lost/embezzled $3 trillion from Pentagon.
    Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
    http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

    Canadian Mind Products, Roedy Green.
    See http://mindprod.com/iraq.html photos of Bush's war crimes
     
    Roedy Green, Jun 28, 2005
    #3
  4. Wesley T Perkins

    Roedy Green Guest

    Roedy Green, Jun 28, 2005
    #4
  5. Wesley T Perkins

    Goran Novak Guest

    Wesley T Perkins wrote:
    > Hello All,
    >
    > I would like to wrap a class which is contained in a *.jar file (for which I
    > don't have the source) so I can intercept calls to that class. For example,
    > say that the class is named SomeClass, I would like to create my own class
    > something like this:
    >
    > public class SomeClass
    > extends
    > AliasedNameAssignedToTheReal_SomeClass_SoThatIInheritEverythingButTheName
    > {
    > ... some methods of my own to profile what the original SomeClass is
    > doing...
    > }
    >
    > then precede the *.jar file with my own source in the classpath, together
    > with an option which says "export the class SomeClass from the jar file but
    > use another name as an alias. I know I used to do something similar in
    > C/Unix and possibly with Windows *.dll's as well
    >
    > Thanks,
    > Wesley
    >
    >


    Something similar could be acomplished whith an extension of Java
    language calles AspectJ, check it out at
    http://eclipse.org/aspectj/
    http://www.eclipse.org/aspectj/doc/released/progguide/index.html

    There is an eclipse plugin for AspectJ at http://www.eclipse.org/ajdt/

    You can look at
    http://www.javaworld.com/javaworld/jw-01-2002/jw-0118-aspect.html for
    some quick explanation

    http://en.wikipedia.org/wiki/AspectJ
    http://en.wikipedia.org/wiki/Aspect_(computer_science)

    --
    Goran
     
    Goran Novak, Jun 28, 2005
    #5
  6. Hey Wesley,

    Wesley T Perkins wrote:
    > Hello All,
    >
    > I would like to wrap a class which is contained in a *.jar file (for which I
    > don't have the source) so I can intercept calls to that class. For example,
    > say that the class is named SomeClass, I would like to create my own class
    > something like this:
    >
    > public class SomeClass
    > extends
    > AliasedNameAssignedToTheReal_SomeClass_SoThatIInheritEverythingButTheName
    > {
    > ... some methods of my own to profile what the original SomeClass is
    > doing...
    > }
    >
    > then precede the *.jar file with my own source in the classpath, together
    > with an option which says "export the class SomeClass from the jar file but
    > use another name as an alias. I know I used to do something similar in
    > C/Unix and possibly with Windows *.dll's as well
    >
    > Thanks,
    > Wesley


    Perhaps this can also be done using
    java.lang.instrument.Instrumen­tation.addClassFileTransformer? (For some
    links see the Thread "use of getObjectSize").

    Ciao,
    Ingo
     
    Ingo R. Homann, Jun 28, 2005
    #6
  7. Wesley T Perkins

    John Currier Guest

    Another implementation of Aspect Oriented Programming is Spring. You
    can do some really cool things in Spring. It's relatively simple to do
    things like Wesley is trying to do.

    John
     
    John Currier, Jun 29, 2005
    #7
  8. Wesley T Perkins

    Goran Novak Guest

    John Currier wrote:
    > Another implementation of Aspect Oriented Programming is Spring. You
    > can do some really cool things in Spring. It's relatively simple to do
    > things like Wesley is trying to do.
    >
    > John
    >


    Can you please recommend some articles about spring, for beginers :)
    Thanks.

    --
    Goran
     
    Goran Novak, Jun 29, 2005
    #8
  9. Wesley T Perkins

    John Currier Guest

    John Currier, Jul 1, 2005
    #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. Mathieu Benoit
    Replies:
    5
    Views:
    420
    Benoit Mathieu
    Jan 20, 2004
  2. toton

    aliasing a class

    toton, May 14, 2007, in forum: C++
    Replies:
    9
    Views:
    355
    toton
    May 21, 2007
  3. Yuri Leikind
    Replies:
    7
    Views:
    166
    Cai Li
    Sep 12, 2004
  4. Bob Hutchison

    Class method aliasing

    Bob Hutchison, Oct 18, 2005, in forum: Ruby
    Replies:
    6
    Views:
    152
  5. Rahul Kumar

    get method name when aliasing

    Rahul Kumar, Nov 2, 2010, in forum: Ruby
    Replies:
    5
    Views:
    147
    Ryan Davis
    Nov 2, 2010
Loading...

Share This Page