切入点帮助 - AspectJ
我只是对切入点中的参数有点困惑,如果有人可以向我解释一下,我将不胜感激...
import Java.util.logging.*;
import org.aspect j.lang.*;
public aspect TraceAspect {
private Logger _logger = Logger.getLogger("trace");
TraceAspectV2() {
_logger.setLevel(Level.ALL);
}
pointcut traceMethods()
(execution(* Account.*(..)) || execution(*.new(..))) && !within(TraceAspect);
before () : traceMethods() {
if (_logger.isLoggable(Level.INFO)) {
Signature sig = thisJoinPointStaticPart.getSignature();
_logger.logp(Level.INFO, sig.getOeclaringType().getName(),sig.getNameO , "Entering");
}
)
)
方面中的切入点定义了何时应生成跟踪消息。描述于 你自己的话,何时,即程序的哪些点,日志消息“Entering” 将被生成。
PS:这是来自过去的考试试卷......我试图了解记录器何时生成输入......
I'm just a bit confused with the parameters in a pointcut would appreciate if anyone could explain it to me...
import Java.util.logging.*;
import org.aspect j.lang.*;
public aspect TraceAspect {
private Logger _logger = Logger.getLogger("trace");
TraceAspectV2() {
_logger.setLevel(Level.ALL);
}
pointcut traceMethods()
(execution(* Account.*(..)) || execution(*.new(..))) && !within(TraceAspect);
before () : traceMethods() {
if (_logger.isLoggable(Level.INFO)) {
Signature sig = thisJoinPointStaticPart.getSignature();
_logger.logp(Level.INFO, sig.getOeclaringType().getName(),sig.getNameO , "Entering");
}
)
)
The pointcut in the aspect defines when trace messages should be generated. Describe in
your own words when, that is, at what points of the program, the log message "Entering"
will be generated.
PS: This is from a past exam paper.... And i'm trying to understand when exactly does the logger generate the Entering....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每次执行类 Account 中的方法 (
execution(* Account.*(..))
) 之前都会打印 Entering,无论返回值、名称或参数如何;执行(*.new(..)) && Iwithin(TraceAspect)
匹配不在 TraceAspect 中的每个构造函数(应读取!within(…)
而不是Iwithin
— 请参阅 google books 上的aspectJ Cookbook,OCR 将感叹号!
识别为大写字母iI
)。entering is printed every time before a method from class Account is executed (
execution(* Account.*(..))
), regardless of return value, name or parameters;execution(*.new(..)) && Iwithin(TraceAspect)
matches every constructor not in TraceAspect (should read!within(…)
instead ofIwithin
— see the aspectJ cookbook on google books, OCR recognizes the exclamation mark!
as capital letter iI
).“Entering”消息在与执行切入点签名匹配的方法之前生成。看起来这建议所有对 Account 类的 new 调用。
The "Entering" message is generated before methods matching execution pointcut signature. It looks like that advised all calls to new for the Account class.