Recipe 13.9. Advising AspectsProblemYou want to apply advice to other aspects. SolutionUse the pointcuts available within AspectJ to specify the aspects to be advised. DiscussionAspectJ includes aspects within the scope of advisable things, so the various pointcuts available in AspectJ can be used to specify advising other aspects in addition to the classes within the application. Example 13-10 shows how to declare advice to be applied to advice within another aspect. Example 13-10. Applying advice to other advicepublic aspect AdviseAspectRecipe { /* 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(AdvisedAspect +) { System.out.println( "------------------- Aspect Advice Logic --------------------"); System.out.println( "In the advice attached to the call point cut"); System.out.println( "Signature: " + thisJoinPoint.getStaticPart( ).getSignature( )); System.out.println( "Source Line: " + 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. |