Recipe 13.3. Executing Advice Before a Join PointProblemYou want advice to execute before the join points that trigger it. SolutionUse the before( ) type of advice. DiscussionExample 13-3 shows how to execute advice before a call to the void MyClass.foo(int,String) method. Example 13-3. Executing advice before a method callpublic aspect BeforeAdviceRecipe { /* 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 before( ) : callPointCut( ) && !within(BeforeAdviceRecipe +) { 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 is examined in Recipe 13.2. |