Each advice has a type: before, after or around. A before (or after) advice indicates that the code within the advice should be executed before (or after) the joinpoint matching the pointcut. An around advice allows changing the parameters of the original joinpoint, and even making the original call zero or more than once.
Some first (simple) examples are:
1)
before(): call(void *.m(..)){
System.out.println("before calling m");
}
2)
after(): call(void *.m(..)){
System.out.println("after calling m");
}
3)
void after(): call(void *.m(..)){
System.out.println("before calling m");
proceed();
System.out.println("after calling m");
}
In the first example, before calling to any void method m (belonging to any class, with any set of arguments), the message "before calling m" is printed.
The second example is similar, but only prints the message after m has been called (and returned either successfully or because of an exception)
The third example surrounds the call with the two messages.
System.out.println("before calling m");
proceed();
System.out.println("after calling m");
}
In the first example, before calling to any void method m (belonging to any class, with any set of arguments), the message "before calling m" is printed.
The second example is similar, but only prints the message after m has been called (and returned either successfully or because of an exception)
The third example surrounds the call with the two messages.
No comments:
Post a Comment