[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[aspectj-users] Newbie question about paramter exposure.
|
- From: Neo Anderson <javadeveloper999@xxxxxxxxxxx>
- Date: Tue, 27 Oct 2009 06:20:25 -0700 (PDT)
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s1024; t=1256649625; bh=56yLLNxQ1YdoCllUpKCLf5TbJFVKrOhwHs5BzAoPMMs=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=Tak3to8SpLSoxp29wyRmTPSFWYHKWqcp9pTMZOUTU9vrX7q75sF/u/R+v7NkgW84b++IzDABmexCGlgTfPvRslLI2yoF1gHIvMcFWTJxQlzwj9wsDHeD8UmzaPJ2EKa643A3/K7UH1xkbdXLgp5p2FYHKZIblXsEQAVMXPpRdyQ=
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.co.uk; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=Theh8igQhL9IcOGVZX7ZEU2UcOviFaRfvz4/yfsRwMq1W4EFQK9uMq1RZyV7OYSX4PXpEuUYp3ASsSgS5dtbIexQkXkcFUEA2PTdpAtCGxBFa3QUYcjuoLDIYATAzhvOngvfwOSBM3X0GMdFN8+xwyfVPQy6tDnru3vKdpR/qm0=;
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