Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: Re: [aspectj-users] around advice and modifying arguments

Title: 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, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/


Back to the top