Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Re: Runtime weaving of Java API classes - newbie question!



You have reached the right conclusion. A weaving class loader can only
weave the classes it defines. A better approach would be to put your own
proxy object, that implements java.io.OutputStream, between the
ObjectOutputStream and the FileOutputStream and advise that instead.

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/


aspectj-users-request@xxxxxxxxxxx@eclipse.org on 26/06/2004 17:00:03

Please respond to aspectj-users@xxxxxxxxxxx

Sent by:    aspectj-users-admin@xxxxxxxxxxx


To:    aspectj-users@xxxxxxxxxxx
cc:
Subject:    aspectj-users digest, Vol 1 #624 - 1 msg


Send aspectj-users mailing list submissions to
             aspectj-users@xxxxxxxxxxx

To subscribe or unsubscribe via the World Wide Web, visit
             http://dev.eclipse.org/mailman/listinfo/aspectj-users
or, via email, send a message with subject or body 'help' to
             aspectj-users-request@xxxxxxxxxxx

You can reach the person managing the list at
             aspectj-users-admin@xxxxxxxxxxx

When replying, please edit your Subject line so it is more specific
than "Re: Contents of aspectj-users digest..."


Today's Topics:

   1. Runtime weaving of Java API classes - newbie question! (Adedayo
Adetoye)

--__--__--

Message: 1
Date: Sat, 26 Jun 2004 01:42:05 +0100
From: Adedayo Adetoye <A.O.Adetoye@xxxxxxxxxxxxx>
Organization: University of Birmingham
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Runtime weaving of Java API classes - newbie
question!
Reply-To: aspectj-users@xxxxxxxxxxx

Hello All,

  I am trying to weave some precompiled aspects into classes loaded into
the JVM using the org.aspectj.weaver.WeavingURLClassLoader as
demonstrated in the aj script. However, the weaving seemed to exclude
Java API classes, although my own classes are correctly woven.

For example given the following pointcut:

             pointcut write(Object data) : call (*
java.io.*File*+.write(..)) &&
args(data,..);

and given the following code snippet

//----------------------
              import java.io.*;
              // other class codes

              FileOutputStream file = new FileOutputStream("Test");
              ObjectOutputStream file2 = new ObjectOutputStream(file);

              file.write(1);
              file2.write(2);

//----------------------


Observation:

file.write(1); gets "caught" by the pointcut but not file2.write(2);
even though the ObjectOutpuStream.write(int) method calls the
FileOutputStream.write(int) method - according to the API specs. The
behaviour I wanted was to have a trigger on the FileOutputStream.write()
method, for example, regardless of whether my code called it or one of
the Java API codes.

My assumption is that because the Java boot ClassLoader loads the Java
APIs classes, org.aspectj.weaver.WeavingURLClassLoader does not get an
opportunity to weave them. If this is correct, then how do I get to
instrument rt.jar classes at runtime/loadtime? Or is there another way
to let these classes "pass" through WeavingURLClassLoader for
instrumentation? Maybe there is a much better approach.

I am a newbie, please pardon my ignorance if I have completely lost the
plot!

Thanks,

Dayo



--__--__--

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


End of aspectj-users Digest





Back to the top