Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Dynamic Method call

If you really need to do this dynamically, I think you will have to put the
logic of deciding whether to log a message inside your advice.  In other
words, you'll have to place advice on all method calls (perhaps you can
narrow this down to a particular package) and use reflection in the advice
to test whether the joinpoint that has activated your advice should be
logged.  This will add a ton of overhead to every method call, but I can't
see another way to do this dynamically in AspectJ.

One compile-time technique that might help you out in this regard is to put
pointcuts about which methods should be logged inside the classes that
contain those methods, rather than in the aspects.  In this case, the
definition of the pointcut is not inside the aspect, though I think that in
the current implementation you will have to compile the whole bunch together
anyway.

good luck,
shimon.

On Sun, Jul 06, 2003 at 02:10:14PM -0700, ravi varanasi wrote:
> Hi,
>      I know that wild card character can be used in JoinPoints to work on a set of similarly named methods. But, I want to log a message in any method of my choice, dynamically. How can I do that ? I do NOT know the name of the method while coding the aspect. I use a properties file which has the class name and method name. I will have to log messages only in that method of that class. How can I do that ? 
> 
> I tried to pass on the method name as a variable defined in the aspect. IT does not work. Any suggestions ?  
> 
> (PS: I do not want to end up with a big if-else block)
> 
> Thanks,


Back to the top