John
John

Reputation: 4533

Help with pointcut - 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: This is from a past exam paper.... And i'm trying to understand when exactly does the logger generate the Entering....

Upvotes: 0

Views: 713

Answers (2)

knittl
knittl

Reputation: 265171

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).

Upvotes: 2

duffymo
duffymo

Reputation: 308743

The "Entering" message is generated before methods matching execution pointcut signature. It looks like that advised all calls to new for the Account class.

Upvotes: 0

Related Questions