Peter,

You will probably have to write one pointcut and piece of around advice 
for every method where you want to process the String arguments. Using the 
interface approach you will only have to define at most one interface per 
advised class (with one interface method declaration per advised method). 
These seems like less code and less effort plus each interface becomes a 
easy-to-read specification, especially for non-AspectJ experts, for the 
methods you are advising. I suggest you pick one class, perhaps the one 
with the smallest number of methods to advise, and try both approaches to 
see how they compare for simplicity, performance and maintainability.

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, [EMAIL PROTECTED]
http://w3.hursley.ibm.com/~websterm/



"Peter Koch" <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED]
01/12/2006 15:58
Please respond to
[email protected]


To
<[email protected]>
cc

Subject
Re: Re: [aspectj-users] around advice and modifying arguments






Hi Matthew !

Thanks very much for your idea / solution.
It sounds really good.

I see one little general problem.

Working with dynamic proxies, I need for all objects I'd like to 
encapsulate
with a proxy object an appropriate interface (e.g. IULCButton for 
ULCButton)
to instanciate the proxy.
This leads to your first point "1. Define an interface...".

Now, this is huge task. Because these are dozens of classes (with dozens 
of methods),
unfortunately with no appropriate interface defined, means a lot of 
manually written code
for me.

Probably I could generate the interface using java-Reflection within a 
little java program
which examines all the classes we extend from the ulc libraries (e.g. 
ULCButton) and our own classes
(e.g. RButton), but I'm sure the little java program is not that little 
;-).


I think it's the easier approach to simply define some dozens of pointcuts 
and
around-advices by hand in which I can use the regular proceed() then.
This is also a lot of code to write, but it's a simple task and the
result is faster in the meaning of performance (dynamic proxies are not 
that cheap).

What do you think ?

Thanks, best regards & have a nice weekend,
Peter

----------------------------

Peter,

To modify method arguments you need to use around advice with proceed (as
you have tried). Unfortunately thisJoinPoint is read-only so you can only
modify arguments if you access the directly with an args() pointcut. This
means enumerating all the join points because using reflection instead of
proceed won't work.

You will need to use a dynamic proxy. Some AOP frameworks support this
directly (I can't find an AspectJ enhancement) but you should be able to
do it with AspectJ too. I haven't tried this myself (anyone else?) but
this is what you need to do:
1. Define an interface that contains all the methods you want to intercept
2. Use declare parents ... : implements ... to add it to ULCProxy
3. Intercept the creation of instances of ULCProxy and return a Java
dynamic proxy instead
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Proxy.html.
4. Modify the String arguments in the invoke() method of the associated
InvocationHandler (which is a bit like around advice)

Cheers

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, [EMAIL PROTECTED]
http://w3.hursley.ibm.com/~websterm/ 
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to