Recipe 8.4. Capturing the Value of a Field When It Is ModifiedProblemYou want to capture the value of the field after it has been modified so it can be used in your corresponding advice. SolutionCombine the args([Types | Identifiers]) pointcut with the set(Signature) pointcut to expose the new value of the field being set as an identifier on your pointcut that can be passed to the corresponding advice. DiscussionExample 8-5 shows how the new value, that the MyClass.name attribute is being set to, can be passed to the before( ) advice. Example 8-5. Accessing the new value of the field being setpublic aspect CaptureModifiedFieldValue { pointcut setNamePointcut(String newValue) : set(String MyClass.name) && args(newValue); // Advice declaration before(String newValue) : setNamePointcut(newValue) { System.out.println( "------------------- Aspect Advice Logic --------------------"); System.out.println( "In the advice picked by " + "setNamePointcut( )"); System.out.println( "Signature: " + thisJoinPoint.getStaticPart( ).getSignature( )); System.out.println( "Source Line: " + thisJoinPoint.getStaticPart( ).getSourceLocation( )); System.out.println("Field Value set to: " + newValue); System.out.println( "------------------------------------------------------------"); } } See AlsoRecipe 4.1 shows some of the wildcard variations that can be used in a Signature; The set(Signature) pointcut's syntax is examined in Recipe 8.4; the args([Types | Identifiers]) pointcut declaration is explained in Recipe 11.3; combining pointcut logic using a logical AND (&&) is shown in Recipe 12.2; Chapter 13 describes the different types of advice available in AspectJ. |