Aliasing a class name?

W

Wesley T Perkins

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

Ingo R. Homann

Hi Wesley,
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
 
R

Roedy Green

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
 
G

Goran Novak

Wesley said:
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)
 
I

Ingo R. Homann

Hey Wesley,
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
 
J

John Currier

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
 
G

Goran Novak

John said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Variable class name in python 0
aliasing 0
C11, const, and aliasing 13
Aliasing classes 1
aliasing a class 9
char and strict aliasing 4
EJB Bindings - Class Cast Exception 0
Really "BIG" class name wanted 23

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top