Eclipse AspectJ: Aspect-Oriented Programming with AspectJ and the Eclipse AspectJ Development Tools

Book description

Now every Java developer can leverage the immense power of AOP With AspectJ, Java developers can leverage the breakthrough power of Aspect-Oriented Programming (AOP) using a language they already know, within the comfortable, highly productive Eclipse development environment. In this book, AspectJ's lead developers help you master AOP's essential principles and techniques, as you use them to address your toughest software quality, productivity, and maintenance challenges.

AOP improves the modularity of programs, making the code much closer to the design. It can dramatically reduce the time taken to implement common features and functions, improve quality, integrate plain-old Java objects with systems and services, create simpler, more reusable components, and much more besides.

Drawing on their experience as tool developers, programmers, and mentors, the authors cover every facet of AOP development with AspectJ and Eclipse, from creating new projects through extending and

documenting full-fledged applications. You'll find an authoritative tutorial covering the entire AspectJ language, a complete API reference, and realistic guidance on adopting AspectJ in your organization.

  • No AOP or Eclipse experience necessary!

  • Install and configure both Eclipse and the AspectJ Development Tools (AJDT)

  • Discover how AOP can modularize and optimize everything from error checking to performance

  • Craft new AspectJ applications and incorporate AOP capabilities into existing systems

  • Build, debug, and document AspectJ applications

  • Understand crucial AOP concepts, such as join points, pointcuts, advice, and inter-type declarations

  • Master advanced techniques: Aspect libraries, linking with compiled .class files, visualization, aspect-oriented design, and more

  • The accompanying website, www.awprofessional.com/title/0321245873, is full of samples, examples, and source code to help you start writing Java-based AOP software today.

    © Copyright Pearson Education. All rights reserved.

    Table of contents

    1. Copyright
      1. Dedication
    2. The Eclipse Series
      1. Titles in the Eclipse Series
    3. Acknowledgments
    4. About the Authors
    5. Preface
      1. References
        1. Bibliography
    6. Introduction
      1. Intended Audience
      2. From Requirements to Code
      3. How Does AOP Work?
      4. Enriching the Programmer’s Vocabulary
      5. Summary
      6. How the Rest of This Book Is Organized
    7. 1. Introducing Eclipse, AspectJ, and AJDT
      1. 1. Getting Started
        1. 1.1. What is Eclipse?
        2. 1.2. Installing Eclipse
        3. 1.3. Eclipse Basics
          1. 1.3.1. A Simple Java Project in Eclipse
        4. 1.4. Installing AJDT
        5. 1.5. Examples for This Book
        6. 1.6. Summary
      2. 2. First Steps in AJDT
        1. 2.1. A Simple Insurance Application
        2. 2.2. Tracking Policy Updates
        3. 2.3. Creating an AspectJ Project
          1. 2.3.1. Converting an Existing Java Project
          2. 2.3.2. Configuring the Workbench for AspectJ Development
          3. 2.3.3. Creating a New AspectJ Project
        4. 2.4. Creating the PolicyChangeNotification Aspect
          1. 2.4.1. The New Aspect Wizard
        5. 2.5. Stating the Notification Policy
          1. 2.5.1. Introducing Join Points
          2. 2.5.2. Writing a Pointcut
          3. 2.5.3. Using Declare Warning
        6. 2.6. Implementing the Notification Policy
          1. 2.6.1. Introducing Advice
          2. 2.6.2. Calling the Notify Method
        7. 2.7. Showing Advice in AJDT
          1. 2.7.1. The Outline View
          2. 2.7.2. The Editor
          3. 2.7.3. Documentation and Visualization
        8. 2.8. Evaluating the Implementation
          1. 2.8.1. Updating the Pointcut Declaration
          2. 2.8.2. Removing the Old Calls to Notify
          3. 2.8.3. Comparing the Modular and Non-modular Implementations
        9. 2.9. Finishing Touches
        10. 2.10. Summary
      3. 3. Extending the Application
        1. 3.1. The Story So Far
        2. 3.2. Serialization-Based Persistence
          1. 3.2.1. Creating the SerializationBasedPersistence Aspect
          2. 3.2.2. Making the Domain Objects Serializable
          3. 3.2.3. Managing the DAOs
          4. 3.2.4. DAO Dependency Injection
          5. 3.2.5. Finishing the Aspect
          6. 3.2.6. Evaluating the Implementation
        3. 3.3. Hibernating
          1. 3.3.1. Preparing to Use Hibernate
          2. 3.3.2. Implementing Persistence with Hibernate
          3. 3.3.3. Creating the HibernateManager Aspect
          4. 3.3.4. DAO Dependency Injection
          5. 3.3.5. Meeting Hibernate’s Requirements
            1. 3.3.5.1. Introducing Inter-Type Declarations
            2. 3.3.5.2. Declaring the Address Key
            3. 3.3.5.3. Declaring No-Argument Constructors
            4. 3.3.5.4. Protecting Against Accidental Use
          6. 3.3.6. Initial Hibernate Configuration
          7. 3.3.7. Mapping Exceptions
          8. 3.3.8. Implementing the Data Access Objects
          9. 3.3.9. Evaluating the Implementation
        4. 3.4. Managing Build Configurations
        5. 3.5. Summary
      4. 4. More AJDT
        1. 4.1. Building an ASPECTJ Project
          1. 4.1.1. Controlling Project Builds
            1. 4.1.1.1. Incremental Compilation
            2. 4.1.1.2. Manual Builds
          2. 4.1.2. Setting Compiler Options
        2. 4.2. Debugging
        3. 4.3. Editor Templates and the Outline View Toolbar
          1. 4.3.1. Editor Templates
          2. 4.3.2. Outline View Toolbar
        4. 4.4. Generating Documentation (Ajdoc)
        5. 4.5. AspectJ Help, Examples, and Cheat Sheets
          1. 4.5.1. Getting Basic Help on AJDT and AspectJ
          2. 4.5.2. AspectJ Examples
          3. 4.5.3. AspectJ Cheat Sheets
        6. 4.6. Summary
    8. 2. The AspectJ Language
      1. 5. An Overview of AspectJ
        1. 5.1. What Is An Aspect?
          1. 5.1.1. Modularity, Encapsulation, and Abstraction
        2. 5.2. Join Points and Pointcuts
          1. 5.2.1. Join Points
          2. 5.2.2. Pointcuts
        3. 5.3. Advice
        4. 5.4. Inter-Type Declarations
        5. 5.5. Key Design Properties of the AspectJ Language
        6. 5.6. Summary
        7. References
      2. 6. Straight to the Point
        1. 6.1. The Calculator Program
        2. 6.2. Introduction to Pointcut Designators
        3. 6.3. The Method Call Pointcut Designator
          1. 6.3.1. Where Do Pointcuts Live?
          2. 6.3.2. Reusing Pointcuts
        4. 6.4. Pointcut Composition
        5. 6.5. Patterns and Signatures
          1. 6.5.1. Type Patterns
          2. 6.5.2. Method Signatures
            1. 6.5.2.1. Modifier Patterns
            2. 6.5.2.2. Return-Type Pattern
            3. 6.5.2.3. Declared-Type Pattern
            4. 6.5.2.4. Method Name
            5. 6.5.2.5. Parameters
            6. 6.5.2.6. Throws Clause
          3. 6.5.3. Summary
        6. 6.6. The Method Execution Pointcut Designator
        7. 6.7. The Target Pointcut Designator
          1. 6.7.1. Call and Target
          2. 6.7.2. Static Methods
          3. 6.7.3. Execution and Target
        8. 6.8. The this Pointcut Designator
          1. 6.8.1. Call and This
          2. 6.8.2. Execution and This
        9. 6.9. The get and set Pointcut Designators
          1. 6.9.1. Modifier Pattern
          2. 6.9.2. Field-Type Pattern
          3. 6.9.3. Declared-Type Pattern
          4. 6.9.4. Field-Name Pattern
          5. 6.9.5. Signature Examples
          6. 6.9.6. Using this and target with get and set
          7. 6.9.7. Array Accesses
          8. 6.9.8. Building Pointcuts with get and set
        10. 6.10. Capturing Context with the args Pointcut Designator
          1. 6.10.1. Matching Argument Types
          2. 6.10.2. Extracting Argument Values
          3. 6.10.3. Primitive Type Promotions
        11. 6.11. Extracting Values with this and target
        12. 6.12. The handler Pointcut Designator
        13. 6.13. Initialization Pointcut Designators
          1. 6.13.1. The staticinitialization Pointcut Designator
          2. 6.13.2. preinitialization and initialization Pointcut Designators
        14. 6.14. Static Scoping Pointcut Designators: within, withincode
        15. 6.15. Dynamic Scoping Pointcut Designators: cflow, cflowbelow
        16. 6.16. The adviceexecution Pointcut Designator
        17. 6.17. The if Pointcut Designator
        18. 6.18. How to Write a Good Pointcut
        19. 6.19. Common Pitfalls
          1. 6.19.1. Can’t Match Calls to super/this
          2. 6.19.2. Can’t Match Calls Made Reflectively
          3. 6.19.3. The Empty Pointcut Definition
        20. 6.20. Summary
      3. 7. Take My Advice
        1. 7.1. The Different Types of Advice
          1. 7.1.1. Before Advice
          2. 7.1.2. After Advice
            1. 7.1.2.1. After Throwing Advice
            2. 7.1.2.2. After Returning Advice
              1. 7.1.2.2.1. Join Point Return Values
            3. 7.1.2.3. After Finally Advice
          3. 7.1.3. Around Advice
        2. 7.2. Advice Parameters and Pointcuts
        3. 7.3. Writing Logic in the Body of Advice
          1. 7.3.1. The Context in Which Advice Runs
          2. 7.3.2. Exceptions in Advice
        4. 7.4. Advice Ordering
          1. 7.4.1. Precedence Within a Single Aspect
          2. 7.4.2. Precedence Between Multiple Aspects
        5. 7.5. Softening Exceptions
        6. 7.6. declare warning and declare error
        7. 7.7. Common Pitfalls
          1. 7.7.1. Only Before Advice at Handler Join Points
          2. 7.7.2. No get Join Points for Compile-Time Constants
          3. 7.7.3. No Return Value for Constructor Execution
          4. 7.7.4. No Return Value for set Join Points
          5. 7.7.5. After Throwing Advice Does Not Handle Exceptions
          6. 7.7.6. Restrictions on declare error / warning Pointcut Expressions
        8. 7.8. Summary
        9. References
      4. 8. Inter-Type Declarations
        1. 8.1. Fields, Methods, and Constructors
          1. 8.1.1. Inter-Type Field Declarations
          2. 8.1.2. Inter-Type Method Declarations
          3. 8.1.3. Inter-Type Constructor Declarations
        2. 8.2. Scope and Visibility
          1. 8.2.1. Visibility of, and from, Inter-Type Declarations
          2. 8.2.2. Inter-Type Declarations and Inheritance
          3. 8.2.3. Dealing with Conflicting Declarations
        3. 8.3. Inter-Type Declarations and Interfaces
          1. 8.3.1. Using an Interface as the Target of an Inter-Type Declaration
          2. 8.3.2. Using declare parents with Interfaces
        4. 8.4. Extending Classes
        5. 8.5. Using Pointcuts and Advice with Inter-Type Declarations
        6. 8.6. Summary
      5. 9. Aspects
        1. 9.1. Aspect Definition and Initialization
        2. 9.2. Aspect Instantiation
          1. 9.2.1. Singleton Aspects
          2. 9.2.2. Per-This Aspects
          3. 9.2.3. Per-Target Aspects
          4. 9.2.4. Per-Cflow and Per-Cflowbelow Aspects
          5. 9.2.5. Summary of Instantiation Models
        3. 9.3. Aspect Inheritance
          1. 9.3.1. Extending Aspects
          2. 9.3.2. Extending Classes
          3. 9.3.3. Implementing Interfaces
        4. 9.4. Inner Aspects
        5. 9.5. Aspect Privilege
        6. 9.6. Common Pitfalls
          1. 9.6.1. Forgetting the Implicit Conditions on Advice Execution in Per-xxx Aspects
          2. 9.6.2. Types Must Be Available for Aspect Linking
        7. 9.7. Summary
      6. 10. Using the AspectJ API
        1. 10.1. Package org.aspectj.lang
          1. 10.1.1. org.aspectj.lang.JoinPoint
            1. Purpose
            2. Methods
            3. Obtaining
            4. Using
          2. 10.1.2. org.aspectj.lang.JoinPoint.StaticPart
            1. Purpose
            2. Methods
            3. Obtaining
            4. Using
          3. 10.1.3. org.aspectj.lang.Signature
            1. Purpose
            2. Methods
            3. Obtaining
            4. Using
          4. 10.1.4. org.aspectj.lang.NoAspectBoundException
            1. Purpose
          5. 10.1.5. org.aspectj.lang.SoftException
            1. Purpose
        2. 10.2. Package org.aspectj.lang.reflect
          1. 10.2.1. org.aspectj.lang.reflect.SourceLocation
            1. Purpose
            2. Methods
            3. Obtaining
            4. Using
          2. 10.2.2. org.aspectj.lang.reflect.MemberSignature
            1. Purpose
          3. 10.2.3. org.aspectj.lang.reflect.FieldSignature
            1. Purpose
            2. Obtaining
            3. Using
          4. 10.2.4. org.aspectj.lang.reflect.CodeSignature
            1. Purpose
            2. Methods
            3. Obtaining
            4. Using
          5. 10.2.5. org.aspectj.lang.reflect.MethodSignature
            1. Methods
            2. Obtaining
            3. Using
          6. 10.2.6. org.aspectj.lang.reflect.AdviceSignature
            1. Methods
            2. Obtaining
            3. Using
          7. 10.2.7. ConstructorSignature and InitializerSignature
          8. 10.2.8. org.aspectj.lang.reflect.CatchClauseSignature
            1. Purpose
            2. Methods
            3. Obtaining
            4. Using
        3. 10.3. Summary
    9. 3. Putting It All Together
      1. 11. Adopting AspectJ
        1. 11.1. The Adoption Process
          1. 11.1.1. Enforcement Aspects
          2. 11.1.2. Infrastructure/Auxiliary Aspects
          3. 11.1.3. Business/Core Aspects
          4. 11.1.4. Aspect-Oriented Design and Architecture
        2. 11.2. Different Types of Aspects
          1. 11.2.1. General-Purpose Aspects
          2. 11.2.2. Domain-Specific Aspects
          3. 11.2.3. Application-Specific Aspects
        3. 11.3. Enforcement Aspect Examples
          1. 11.3.1. Use of System.out
          2. 11.3.2. Preserving Component Modularity
        4. 11.4. Infrastructure Aspect Examples
          1. 11.4.1. Implementing a Tracing Facility
          2. 11.4.2. Managing Exceptions
          3. 11.4.3. Management
        5. 11.5. Core Aspect Examples
          1. 11.5.1. Calling Untrusted Code
          2. 11.5.2. Configuring Aspects with Spring
        6. 11.6. Evaluating the Simple Insurance Application
        7. 11.7. Summary
        8. References
      2. 12. Advanced AJDT
        1. 12.1. Aspect Libraries
        2. 12.2. Linking Aspects with Compiled .class Files
        3. 12.3. Ant Integration
          1. 12.3.1. Building Simple Insurance As a Java Project
          2. 12.3.2. Building Simple Insurance As an AspectJ Project
          3. 12.3.3. Limitations When Building with Ant in AJDT
        4. 12.4. Aspect Visualization
          1. 12.4.1. The Visualiser Menu
          2. 12.4.2. Visualiser View
        5. 12.5. Summary
      3. 13. Aspect-Oriented Design
        1. 13.1. Finding Aspects
          1. 13.1.1. Aspects in the Design
            1. 13.1.1.1. Adverbs and Adjectives
            2. 13.1.1.2. Temporal Statements
            3. 13.1.1.3. Rules and Policy Statements
          2. 13.1.2. Aspects in the Code
        2. 13.2. What Makes a Good Aspect?
        3. 13.3. Closing Thoughts
    10. A. Command-Line AspectJ
      1. A.1. Installing AspectJ
      2. A.2. Using the Compiler
      3. A.3. Building with Ant
    11. B. AspectJ Language Quick Reference
      1. B.1. Aspect Declaration
      2. B.2. Pointcuts
      3. B.3. Wildcards
      4. B.4. Advice
      5. B.5. Inter-Type Declarations
    12. C. Next Steps
      1. C.1. Mailing Lists and FAQ
      2. C.2. Raising Bugs and Enhancement Requests
      3. C.3. Contributing to the Development of AspectJ and AJDT
    13. D. AJDT Icons Reference
      1. D.1. Objects
      2. D.2. Object Adornments
      3. D.3. Markers
      4. D.4. Build Configuration

    Product information

    • Title: Eclipse AspectJ: Aspect-Oriented Programming with AspectJ and the Eclipse AspectJ Development Tools
    • Author(s):
    • Release date: December 2004
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780321245878