In the AOP examples I used in my previous posts I always captured exactly one join point with my pointcut. If you would always do it that way you had to define one pointcut for every join point. That is as you can probably imagine not effective. The real benefit comes then when you capture join points due to specific characteristics. For example you wanna capture every method in a specific class that throws an Exception. To do this you need wildcards.
AspectJ offers three wildcard notations:
- “+” indicates all subclasses or subinterfaces of a given type
- “..” indicates any number of charecters including all periods
- “*” indicates any number of characters excluding the period
You also have the negation operator “!” and the two operators “||” and “&&”.
Example:
public pointcut myPointcut() : execution(public * javax..*Model+.set*(*));
This would capture the execution of all public methods starting with set, taking one argument of any type, regardless of the return type that are defined in a class whose name ends with Model or any of its subclasses that reside in the javax package or any direct and indirect subpackages.
Funny … isn’t it?
