AspectJ Cookbook
Chapter 1. Aspect Orientation Overview
Section 1.1. A Brief History of Aspect Orientation
Section 1.2. AspectJ
Section 1.3. A Definition of Aspect Orientation
Section 1.4. Where to Go for More Information
Chapter 2. Getting Started with AspectJ
Introduction
Recipe 2.1. Installing AspectJ
Recipe 2.2. Developing a Simple Aspect
Recipe 2.3. Compiling an Aspect and Multiple Java Files
Recipe 2.4. Weaving Aspects into Jars
Recipe 2.5. Weaving Aspects at Load Time
Recipe 2.6. Generating Javadoc Documentation
Recipe 2.7. Compiling an AspectJ Project Using Eclipse
Recipe 2.8. Selecting the Aspects That Are Woven in a Build Within Eclipse
Recipe 2.9. Building an AspectJ Project Using Ant
Chapter 3. Deploying AspectJ Applications
Introduction
Recipe 3.1. Deploying a Command-Line AspectJ Application
Recipe 3.2. Deploying an AspectJ Application as a Fully Contained Executable JAR File
Recipe 3.3. Deploying a Java Servlet That Uses AspectJ
Recipe 3.4. Deploying a JSP That Uses AspectJ
Recipe 3.5. Deploying an Axis Web Service That Uses AspectJ
Chapter 4. Capturing Joing Points on Methods
Introduction
Recipe 4.1. Capturing a Method Call
Recipe 4.2. Capturing the Parameter Values Passed on a Method Call
Recipe 4.3. Capturing the Target of a Method Call
Recipe 4.4. Capturing a Method When It Is Executing
Recipe 4.5. Capturing the Value of the this Reference When a Method Is Executing
Chapter 5. Capturing Join Points on Exception Handling
Introduction
Recipe 5.1. Capturing When an Exception Is Caught
Recipe 5.2. Capturing the Thrown Exception
Recipe 5.3. Capturing the Object Handling the Exception
Chapter 6. Capturing Join Points on Advice
Introduction
Recipe 6.1. Capturing When Advice Is Executing
Recipe 6.2. Excluding Join Points That Are a Result of Advice Execution
Recipe 6.3. Exposing the Original Join Point When Advice Is Being Advised
Chapter 7. Capturing Join Points on Class Object Construction
Introduction
Recipe 7.1. Capturing a Call to a Constructor
Recipe 7.2. Capturing a Constructor When It Is Executing
Recipe 7.3. Capturing When an Object Is Initialized
Recipe 7.4. Capturing When an Object Is About to Be Initialized
Recipe 7.5. Capturing When a Class Is Initialized
Chapter 8. Capturing Join Points on Attributes
Introduction
Recipe 8.1. Capturing When an Object's Attribute Is Accessed
Recipe 8.2. Capturing the Value of the Field Being Accessed
Recipe 8.3. Capturing When an Object's Field Is Modified
Recipe 8.4. Capturing the Value of a Field When It Is Modified
Chapter 9. Capturing Join Points Within Programmatic Scope
Introduction
Recipe 9.1. Capturing All Join Points Within a Particular Class
Recipe 9.2. Capturing All Join Points Within a Particular Package
Recipe 9.3. Capturing All Join Points Within a Particular Method
Chapter 10. Capturing Join Points Based on Control Flow
Introduction
Recipe 10.1. Capturing All Join Points Within a Program's Control Flow Initiated by an Initial Join Point
Recipe 10.2. Capturing All Join Points Within a Program's Control Flow, Excluding the Initial Join Point
Chapter 11. Capturing Join Points Based on Object Type
Introduction
Recipe 11.1. Capturing When the this Reference Is a Specific Type
Recipe 11.2. Capturing When a Join Point's Target Object Is a Specific Type
Recipe 11.3. Capturing When the Arguments to a Join Point Are a Certain Number, Type, and Ordering
Chapter 12. Capturing Join Points Based on a Boolean or Combined Expression
Introduction
Recipe 12.1. Capturing When a Runtime Condition Evaluates to True on a Join Point
Recipe 12.2. Combining Pointcuts Using a Logical AND (&&)
Recipe 12.3. Combining Pointcuts Using a Logical OR (||)
Recipe 12.4. Capturing All Join Points NOT Specified by a Pointcut Declaration
Recipe 12.5. Declaring Anonymous Pointcuts
Recipe 12.6. Reusing Pointcuts
Chapter 13. Defining Advice
Introduction
Recipe 13.1. Accessing Class Members
Recipe 13.2. Accessing the Join Point Context
Recipe 13.3. Executing Advice Before a Join Point
Recipe 13.4. Executing Advice Around a Join Point
Recipe 13.5. Executing Advice Unconditionally After a Join Point
Recipe 13.6. Executing Advice Only After a Normal Return from a Join Point
Recipe 13.7. Executing Advice Only After an Exception Has Been Raised in a Join Point
Recipe 13.8. Controlling Advice Precedence
Recipe 13.9. Advising Aspects
Chapter 14. Defining Aspect Instantiation
Introduction
Recipe 14.1. Defining Singleton Aspects
Recipe 14.2. Defining an Aspect per Instance
Recipe 14.3. Defining an Aspect per Control Flow
Chapter 15. Defining Aspect Relationships
Introduction
Recipe 15.1. Inheriting Pointcut Definitions
Recipe 15.2. Implementing Abstract Pointcuts
Recipe 15.3. Inheriting Classes into Aspects
Recipe 15.4. Declaring Aspects Inside Classes
Chapter 16. Enhancing Classes and the Compiler
Introduction
Recipe 16.1. Extending an Existing Class
Recipe 16.2. Declaring Inheritance Between Classes
Recipe 16.3. Implementing Interfaces Using Aspects
Recipe 16.4. Declaring a Default Interface Implementation
Recipe 16.5. Softening Exceptions
Recipe 16.6. Extending Compilation
Chapter 17. Implementing Creational Object-Oriented Design Patterns
Introduction
Recipe 17.1. Implementing the Singleton Pattern
Recipe 17.2. Implementing the Prototype Pattern
Recipe 17.3. Implementing the Abstract Factory Pattern
Recipe 17.4. Implementing the Factory Method Pattern
Recipe 17.5. Implementing the Builder Pattern
Chapter 18. Implementing Structural Object-Oriented Design Patterns
Introduction
Recipe 18.1. Implementing the Composite Pattern
Recipe 18.2. Implementing the Flyweight Pattern
Recipe 18.3. Implementing the Adapter Pattern
Recipe 18.4. Implementing the Bridge Pattern
Recipe 18.5. Implementing the Decorator Pattern
Recipe 18.6. Implementing the Proxy Pattern
Chapter 19. Implementing Behavioral Object-Oriented Design Patterns
Introduction
Recipe 19.1. Implementing the Observer Pattern
Recipe 19.2. Implementing the Command Pattern
Recipe 19.3. Implementing the Iterator Pattern
Recipe 19.4. Implementing the Mediator Pattern
Recipe 19.5. Implementing the Chain of Responsibility Pattern
Recipe 19.6. Implementing the Memento Pattern
Recipe 19.7. Implementing the Strategy Pattern
Recipe 19.8. Implementing the Visitor Pattern
Recipe 19.9. Implementing the Template Method Pattern
Recipe 19.10. Implementing the State Pattern
Recipe 19.11. Implementing the Interpreter Pattern
Chapter 20. Applying Class and Component Scale Aspects
Introduction
Recipe 20.1. Validating Parameters Passed to a Method
Recipe 20.2. Overriding the Class Instantiated on a Call to a Constructor
Recipe 20.3. Adding Persistence to a Class
Recipe 20.4. Applying Mock Components to Support Unit Testing
Chapter 21. Applying Application Scale Aspects
Introduction
Recipe 21.1. Applying Aspect-Oriented Tracing
Recipe 21.2. Applying Aspect-Oriented Logging
Recipe 21.3. Applying Lazy Loading
Recipe 21.4. Managing Application Properties
Chapter 22. Applying Enterprise Scale Aspects
Introduction
Recipe 22.1. Applying Development Guidelines and Rules
Recipe 22.2. Applying Transactions
Recipe 22.3. Applying Resource Pooling
Recipe 22.4. Remoting a Class Transparently Using RMI
Recipe 22.5. Applying a Security Policy
Chapter 23. Applying Aspect-Oriented Design Patterns
Introduction
Recipe 23.1. Applying the Cuckoo's Egg Design Pattern
Recipe 23.2. Applying the Director Design Pattern
Recipe 23.3. Applying the Border Control Design Pattern
Recipe 23.4. Applying the Policy Design Pattern
Appendix A. The AspectJ Runtime API
Section A.1. org.aspectj.lang
Section A.2. Signature
Section A.3. org.aspectj.lang.reflect
Section A.4. The SoftException Class
Section A.5. The NoAspectBoundException Class
While this book does not get into too much detail on the theory behind aspect
orientation, a brief overview is provided to give you a useful foundation to support the code
recipes that form the rest of the book. The code recipes will walk you through how to
get your system set up for aspect oriented development, building your first small
programs, and eventually applying aspect orientation to complex real-world problems.
This book aims to be one of those useful books that sit on your desk and regularly
get called upon to "just show me how to do that." You should be able to jump
directly to the recipes you need as and when you need them in keeping with
the "no fluff, just stuff" approach that is synonymous with the O'Reilly
Cookbook series. With this in mind, the topics covered in this book include:
- A brief overview of aspect orientation and AspectJ
- Setting up, getting to grips with, and running AspectJ programs in a range
of build and target environments
- A practical examination of each of the AspectJ extensions to the Java© language
- Applying AspectJ to real-world software development problems that benefit from an aspect-oriented approach