Recipe12.4.Capturing All Join Points NOT Specified by a Pointcut Declaration


Recipe 12.4. Capturing All Join Points NOT Specified by a Pointcut Declaration

Problem

You want to capture all the join points not caught by a particular pointcut.

Solution

Use the unary ! operator to specify that the join points normally captured by a specific pointcut declaration are to be ignored. The syntax of the ! operator is:

pointcut <pointcut name>(<any values to be picked up>) :                          !<pointcut declaration>

Discussion

Example 12-5 shows an example of the ! operator being used to capture all join points not captured by the call(void MyClass.foo(int,String) pointcut.

Example 12-5. Using the ! operator to capture join points not caught by a call(Signature) pointcut
public aspect LogicalNotRecipe  {    /*            Specifies calling advice whenever a method             does NOT match the following rules             gets called:                        Class Name: MyClass            Method Name: foo            Method Return Type: void            Method Parameters: an int followed by a String    */    pointcut notCallPointCutFooIntString( ) : !call(void MyClass.                                              foo(int, String));    // Advice declaration    before( ) : notCallPointCutFooIntString( )       && !within(LogicalNotRecipe +)    {       System.out.println(          "------------------- Aspect Advice Logic --------------------");       System.out.println(          "In the advice picked by notCallPointCutFooIntStringAnyReturn( )");       System.out.println(          "Signature: " + thisJoinPoint.getSignature( ));       System.out.println(          "Source Line: " + thisJoinPoint.getSourceLocation( ));       System.out.println(          "------------------------------------------------------------");    } }

See Also

Techniques for combining pointcut declarations are covered in Recipes 12.2 and 12.3; the within(TypePattern) pointcut is described in Recipe 9.1; Chapter 13 describes the different types of advice available in AspectJ.



AspectJ Cookbook
Aspectj Cookbook
ISBN: 0596006543
EAN: 2147483647
Year: 2006
Pages: 203
Authors: Russ Miles

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net