Recipe 12.4. Capturing All Join Points NOT Specified by a Pointcut DeclarationProblemYou want to capture all the join points not caught by a particular pointcut. SolutionUse 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> DiscussionExample 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) pointcutpublic 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 AlsoTechniques 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. |