Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Aliasing a class name?

Reply
Thread Tools

Aliasing a class name?

 
 
Wesley T Perkins
Guest
Posts: n/a
 
      06-28-2005
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_SoThatIInhe ritEverythingButTheName
{
... 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


 
Reply With Quote
 
 
 
 
Ingo R. Homann
Guest
Posts: n/a
 
      06-28-2005
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_SoThatIInhe ritEverythingButTheName
> {
> ... 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

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      06-28-2005
On Tue, 28 Jun 2005 01:17:05 GMT, "Wesley T Perkins"
<(E-Mail Removed)> 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/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-28-2005
On Tue, 28 Jun 2005 11:49:01 GMT, Roedy Green
<(E-Mail Removed)> wrote or quoted :

>I have often wanted to do this too,


I have a forth background where doing that is trivial.

--
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/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
Goran Novak
Guest
Posts: n/a
 
      06-28-2005
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_SoThatIInhe ritEverythingButTheName
> {
> ... 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/r...ide/index.html

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

You can look at
http://www.javaworld.com/javaworld/j...18-aspect.html for
some quick explanation

http://en.wikipedia.org/wiki/AspectJ
http://en.wikipedia.org/wiki/Aspect_...ter_science%29

--
Goran
 
Reply With Quote
 
Ingo R. Homann
Guest
Posts: n/a
 
      06-28-2005
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_SoThatIInhe ritEverythingButTheName
> {
> ... 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.addClassFile Transformer? (For some
links see the Thread "use of getObjectSize").

Ciao,
Ingo

 
Reply With Quote
 
John Currier
Guest
Posts: n/a
 
      06-29-2005
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

 
Reply With Quote
 
Goran Novak
Guest
Posts: n/a
 
      06-29-2005
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
 
Reply With Quote
 
John Currier
Guest
Posts: n/a
 
      07-01-2005
Spring in Action. Good book.

John
http://schemaspy.sourceforge.net

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
aliasing a class toton C++ 9 05-21-2007 02:12 PM
Class method aliasing Bob Hutchison Ruby 6 10-18-2005 06:33 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Aliasing a singleton method of a Class object Yuri Leikind Ruby 7 09-12-2004 09:50 AM
Array class and pointer aliasing problems Mathieu Benoit C++ 5 01-20-2004 09:51 PM



Advertisments