Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Question about advising an advice

Hi Herbey,
 
You might want to just advise the different call join points that occur
within Advised. You could also use cflow to do what you are looking for,
e.g., this matches calls caused by advice execution. If you do NOT want to
match calls from helper methods, you could exclude those too, although it's
rare you'd want to do that.
 
aspect Advisor {
    before(): cflow(adviceexecution() && within(Advised)) && call (void
myFun()) { ... }
...
}

I'm not sure what you are looking to do depending on the methods being
called. In some cases you might want to use the AspectJ reflection API
(e.g., if you want to track the method name and parameters), rather than
explictly address the various cases.

A related problem that I've seen is the need to distinguish among different
advices, which of course aren't named. With Java 5 and AspectJ 5 you could
use annotations and write a pointcut to match those. For earlier JVM's, you
can use static inner aspects to give a name to a specific piece of advice,
e.g.,
 
aspect Advised {
    public pointcut firstpc() : call(* coreClass.fun(..))

    private static aspect SayHello {
        before():firstpc() {
            System.out.println("Hi");
            Advised.aspectOf().myFun();
        }
    }
    ...
}

// assumes you want to distinguish between the different adviceexecution
join points, rather than the calls made from the same advice
aspect Advisor {
    before(): adviceexecution() && within(SayHello) { ... }
...
} 


 

 
________________________________

From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Zepeda, Herbey
Sent: Wednesday, September 21, 2005 10:15 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Question about advising an advice



Hi

 

I have being trying to advice an advice in one aspect using it as the join
point, with another advice in another aspect.

 

The syntax is something like:

 

Aspect advisor

{

            before(): adviceexecution() && within(advised)

{

            Do something.

}

}

 

Aspect advised

{

            Public pointcut firstpc() :call(* coreClass.fun(..))

before():firstpc()

 {

            System.out.println("Hi");

            myFun();

}

Public void myFun()

{

            System.out.println("Hi Inner fun");

}

 

}

 

coreClass

{

Definition.

Public void fun()

{

Do something

}

 

}

 

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

 

When I run this code it works, however, I am not being able to go into more
detail, I want to specify an advice in the advisor aspect which advices a
specific function,

For example, in the advised aspect in the advice we have two function calls,
one to System.out... and the other one to myFun, I want to be able to
differentiate (create a different join point) for the System. and for myFun
so that the advisor aspect performs different activities for calls to the
different functions. Something like:

 

Aspect advisor

{

            before(): adviceexecution() && within(advised) && call (void
myFun())

{

            Do something.

}

 

before(): adviceexecution() && within(advised) && call (void System.*(..))

{

            Do something else.

}

 

}

 

I have tried to run the latter and similar approaches but have not being
successful. I know it can be done as it is mentioned in page 50 of the book
(AspectJ in action) but have not figured it out, do you have an idea of how
can I solve this problem?

 

Thank you

 

Herbey

 

 

 




Back to the top