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");
开发者_Go百科 }
)
)
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 of Iwithin
— see the aspectJ cookbook on google books, OCR recognizes the exclamation mark !
as capital letter i I
).
The "Entering" message is generated before methods matching execution pointcut signature. It looks like that advised all calls to new for the Account class.
精彩评论