Recipe 13.5. Executing Advice Unconditionally After a Join PointProblemYou want advice to execute after a specific join point regardless of how the join point returned. SolutionUse the after( ) type of advice. DiscussionExample 13-5 shows how to execute advice after the void MyClass.foo(int,String) method regardless of how the method returns. Example 13-5. Executing advice after a method callpublic aspect AfterAdviceRecipe { /* Specifies calling advice whenever a method matching the following rules gets called: Class Name: MyClass Method Name: foo Method Return Type: void Method Parameters: an int followed by a String */ pointcut callPointCut( ) : call(void MyClass.foo(int, String)); // Advice declaration after( ) : callPointCut( ) && !within(AfterAdviceRecipe +) { System.out.println( "------------------- Aspect Advice Logic --------------------"); System.out.println( "Source Location: " + thisJoinPoint.getStaticPart( ).getSourceLocation( )); System.out.println( "------------------------------------------------------------"); } } See AlsoThe call(Signature) pointcut is described in Recipe 4.1; the within(TypePattern) pointcut is described in Recipe 9.1; the thisJoinPoint variable and the context it encapsulates is examined in Recipe 13.2; discusses some common pointcut idioms, one of which being the ability to ignore exception handling join points as these do not support after( ) advice. |