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