根据连接点的所属,Pointcut有以下几种类型:
Method execution execution(MethodSignature)
Method Call call(MethodSignature)
Method execution捕捉的连接点是在被执行的函数体,而Method call捕捉的连接点是在调用符合MethodSignature的函数的代码处。
如:
public pointcut MethodExecutor():execution(* Shape .draw(..));
before():MethodExecutor(){
Signature sig = thisJoinPointStaticPart.getSignature();
logger.logp(Level.INFO, sig.getDeclaringType().getName(),
sig.getName(), "method execution");
}
捕捉的是在Circle.draw()执行前的连接点
public class Circle implements Shape{
…
public void draw(){
logger.logp(Level.INFO,
"circle", "draw", "drawing a circle");
}
…
}
而
public pointcut MethodCall():call(* Shape .draw());
before():MethodCall(){
Signature sig = thisJoinPointStaticPart.getSignature();
logger.logp(Level.INFO, sig.getDeclaringType().getName(),
sig.getName(), "method call ");
}
捕捉的是调用Circle.draw()之前的代码
Circle clr = new Circle();
…
clr.draw();
…
两者的功能基本一致。
上面的代码运行的结果如下:
2005-7-14
22:14:36 com.aia.ch03.Circle draw
信息
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!



