Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Newbie question about paramter exposure.

Hi 

I am newbie to aspectj and have a question regarding to the usage of parameters exposed in the pointcut, advice, etc. Following is the source code:

package aspectj;

public aspect P{
        public pointcut p(String command): execution(* example.A.execute(String)) && args(command);

        Object around(String command): p(command){
                System.out.println("around() advice : command:"+command);
                return proceed(command);
        }
}
 
package example;

public class A{
        public void execute(String c){
                System.out.println("[A.java][execute] command:"+c);
        }
}

package example;

public class Main{

        public static void main(String args[]){
                new Main().process();
        }

        void process(){
                new A().execute("ls -alh");
        }
        
}

The output :

around() advice : command:ls -alh
[A.java][execute] command:ls -alh


Thought I can get the code worked, I do not know how to explain the parameter exposed in the pointcut (e.g. p(String command)) and advice (e.g. around(String command)). 

What I understand is that 

Since the execution flow is 

new A().execute("ls -lah") [Main.java] -> public void execute(String c) [A.java]

therefore, execution of the method `new A().execute("ls -alh")' triggers the around() advice, which passes in a value `ls -lah' (as the variable command). That value `ls -alh' passes to pointcut p(), which also takes a variable named command. And that pointcut p() tries to capture the execution of a method specified as `* example.A.execute(String)' and its argument must be `command.'

Is this explanation correct?

I found out there is something not right for me, but I am not aware the part that I do not understand. 

I appreciate any advice.

Thank you very much.


Send instant messages to your online friends http://uk.messenger.yahoo.com


Back to the top