切入点帮助 - AspectJ [英] Help with pointcut - AspectJ

查看:30
本文介绍了切入点帮助 - AspectJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是对切入点中的参数有点困惑,如果有人能向我解释一下,我将不胜感激...

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:这是来自过去的试卷....我试图了解记录器究竟何时生成输入....

PS: This is from a past exam paper.... And i'm trying to understand when exactly does the logger generate the Entering....

推荐答案

entering 每次在类 Account 中的方法执行前都会打印出来 (execution(* Account.*(..))), 不论返回值、名称或参数;execution(*.new(..)) &&Iwithin(TraceAspect) 匹配所有不在 TraceAspect 中的构造函数(应该读为 !within(…) 而不是 Iwithin — 参见 aspect 书籍a>,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 of Iwithin — see the aspectJ cookbook on google books, OCR recognizes the exclamation mark ! as capital letter i I).

这篇关于切入点帮助 - AspectJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆