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

查看:83
本文介绍了切入点帮助-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");
          }
     )
)

方面中的切入点定义了何时应生成跟踪消息.描述于 您自己的话,即在程序的什么时候出现日志消息"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:这是从过去的试卷中得出的....而我正试图了解记录器何时确切生成Entering....

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

推荐答案

每次在执行Account类的方法(execution(* Account.*(..)))之前,都会打印输入,无论返回值,名称或参数如何; execution(*.new(..)) && Iwithin(TraceAspect)匹配不在TraceAspect中的每个构造函数(应读为!within(…)而不是Iwithin —请参阅

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天全站免登陆