AspectJ in Action, Second Edition

Book description

To allow the creation of truly modular software, OOP has evolved into aspect-oriented programming. AspectJ is a mature AOP implementation for Java, now integrated with Spring.

AspectJ in Action, Second Edition is a fully updated, major revision of Ramnivas Laddad's best-selling first edition. It's a hands-on guide for Java developers. After introducing the core principles of AOP, it shows you how to create reusable solutions using AspectJ 6 and Spring 3. You'll master key features including annotation-based syntax, load-time weaver, annotation-based crosscutting, and Spring-AspectJ integration. Building on familiar technologies such as JDBC, Hibernate, JPA, Spring Security, Spring MVC, and Swing, you'll apply AOP to common problems encountered in enterprise applications.

This book requires no previous experience in AOP and AspectJ, but it assumes you're familiar with OOP, Java, and the basics of Spring.



About the Technology


About the Book

AspectJ in Action, Second Edition is a fully updated, major revision of Ramnivas Laddad's best-selling first edition. It's a hands-on guide for Java developers. After introducing the core principles of AOP, it shows you how to create reusable solutions using AspectJ 6 and Spring 3. You'll master key features including annotation-based syntax, load-time weaver, annotation-based crosscutting, and Spring-AspectJ integration. Building on familiar technologies such as JDBC, Hibernate, JPA, Spring Security, Spring MVC, and Swing, you'll apply AOP to common problems encountered in enterprise applications.



What's Inside
  • Totally revised Second Edition
  • When and how to apply AOP
  • Master patterns and best practices
  • Code you can reuse in real-world applications


About the Reader

This book requires no previous experience in AOP and AspectJ, but it assumes you're familiar with OOP, Java, and the basics of Spring.



About the Author

An expert in enterprise Java, Ramnivas Laddad is well known in the area of AOP and Spring. He is a committer on the Spring Framework project.



Quotes
Clear, concisely worded, well-organized... a pleasure to read.
- Rod Johnson, Creator of the Spring Framework

Ramnivas showcases how to get the best out of AspectJ and Spring.
- Andy Clement, AspectJ Project Lead

One of the best Java books in years.
- Andrew Rhine, eSecLending

By far the best reference for Spring AOP and AspectJ.
- Paul Benedict, Argus Health Systems

Ramnivas expertly demystifies the awesome power of aspect-oriented programming.
- Craig Walls, author of Spring in Action

Table of contents

  1. Praise for the First Edition
  2. More Praise for the First Edition
  3. Copyright
  4. Foreword
  5. Preface
  6. Preface to the first edition
  7. Acknowledgments
  8. About this book
    1. Roadmap
    2. Who should read this book
    3. Code and typographical conventions
    4. Getting the source code
    5. Author online
    6. About the author
  9. About the title
  10. About the cover illustration
  11. A real-world perspective of AOP
    1. Mapping AOP onto the hype cycle
      1. Technology trigger
      2. Peak of inflated expectations
      3. Trough of disillusionment
      4. Slope of enlightenment
        1. RESPONSE TO USER NEEDS
        2. FOCUSED CONTEXT: THE SPRING FACTOR
        3. AVAILABILITY OF A GRADUAL ADOPTION PATH
        4. NEW JVM LANGUAGES
        5. ACCEPTANCE OF ANNOTATIONS
        6. DISILLUSIONMENT FROM THE ALTERNATIVE TECHNOLOGIES
      5. Plateau of productivity
    2. Where is AOP being used?
      1. Enterprise applications
      2. Web and application servers
      3. Application frameworks
      4. Monitoring tools
      5. Compiler and IDE integration
  12. 1. Understanding AOP and AspectJ
    1. 1. Discovering AOP
      1. 1.1. Life without AOP
        1. 1.1.1. Code tangling
        2. 1.1.2. Code scattering
      2. 1.2. Modularizing with AOP
      3. 1.3. Anatomy of an AOP language
        1. 1.3.1. The AOP language specification
          1. 1.3.1.1. IMPLEMENTATION OF CONCERNS
          2. 1.3.1.2. WEAVING RULES SPECIFICATION
        2. 1.3.2. The AOP language implementation
      4. 1.4. Fundamental concepts in AOP
      5. 1.5. AOP by analogy
        1. 1.5.1. Cascading Style Sheets (CSS)
        2. 1.5.2. Database systems
          1. 1.5.2.1. SQL AND POINTCUTS
          2. 1.5.2.2. TRIGGERS AND ADVICE
        3. 1.5.3. Event-oriented programming
      6. 1.6. Implementations of AOP
        1. 1.6.1. AspectJ
        2. 1.6.2. Spring AOP
        3. 1.6.3. Other implementations of AOP
      7. 1.7. Alternatives to AOP
        1. 1.7.1. Frameworks
        2. 1.7.2. Code generation
        3. 1.7.3. Design patterns
          1. 1.7.3.1. OBSERVER PATTERN
          2. 1.7.3.2. CHAIN OF RESPONSIBILITY
          3. 1.7.3.3. DECORATOR AND PROXY
          4. 1.7.3.4. INTERCEPTOR
        4. 1.7.4. Dynamic languages
      8. 1.8. Costs and benefits of AOP
        1. 1.8.1. Costs of AOP
          1. 1.8.1.1. NEED FOR GREATER SKILLS
          2. 1.8.1.2. COMPLEX PROGRAM FLOW
        2. 1.8.2. Benefits of AOP
          1. 1.8.2.1. SIMPLIFIED DESIGN
          2. 1.8.2.2. CLEANER IMPLEMENTATION
          3. 1.8.2.3. BETTER CODE REUSE
      9. 1.9. Summary
    2. 2. Introducing AspectJ
      1. 2.1. Writing your first AspectJ program
        1. 2.1.1. Setting up the example
        2. 2.1.2. Adding an aspect
      2. 2.2. AspectJ crosscutting construct
        1. 2.2.1. Common crosscutting constructs
          1. 2.2.1.1. JOIN POINT
          2. 2.2.1.2. POINTCUT
          3. 2.2.1.3. ASPECT
        2. 2.2.2. Dynamic crosscutting construct: advice
        3. 2.2.3. Static crosscutting constructs
          1. 2.2.3.1. INTER-TYPE DECLARATION
          2. 2.2.3.2. WEAVE-TIME DECLARATION
      3. 2.3. AspectJ alternative syntax
      4. 2.4. Weaving mechanisms
        1. 2.4.1. Source weaving
        2. 2.4.2. Binary weaving
          1. 2.4.2.1. STEP 1: COMPILING THE JAVA SOURCES
          2. 2.4.2.2. STEP 2: COMPILING THE ASPECT
          3. 2.4.2.3. STEP 3: WEAVING THE ASPECT
        3. 2.4.3. Load-time weaving
      5. 2.5. AspectJ weaving: under the hood
        1. 2.5.1. The compiled aspect
        2. 2.5.2. The woven class
      6. 2.6. Spring AspectJ integration
      7. 2.7. AspectJ logistics overview
        1. 2.7.1. IDE integration
        2. 2.7.2. AspectJ documentation tool
      8. 2.8. Summary
    3. 3. Understanding the join point model
      1. 3.1. Understanding the join point model
        1. 3.1.1. Join points
        2. 3.1.2. Pointcuts
          1. 3.1.2.1. SELECTING JOIN POINTS
          2. 3.1.2.2. COLLECTING JOIN POINT CONTEXT
          3. 3.1.2.3. USING SIGNATURES
          4. 3.1.2.4. USING RUNTIME SELECTION CRITERION
          5. 3.1.2.5. DETERMINING POINTCUTS STATICALLY
      2. 3.2. Categorizing exposed join points
        1. 3.2.1. Method join points
        2. 3.2.2. Constructor join points
        3. 3.2.3. Field access join points
        4. 3.2.4. Exception-handler join points
        5. 3.2.5. Class-initialization join points
        6. 3.2.6. Object initialization join points
        7. 3.2.7. Object pre-initialization join points
        8. 3.2.8. Advice execution join points
      3. 3.3. Join point demonstration example
        1. 3.3.1. The aspect
        2. 3.3.2. The result
      4. 3.4. Understanding pointcut basics
        1. 3.4.1. Named and anonymous pointcuts
          1. 3.4.1.1. REUSABILITY: NAMED POINTCUTS
          2. 3.4.1.2. USE ONCE: ANONYMOUS POINTCUTS
        2. 3.4.2. Pointcut operators
      5. 3.5. Signature syntax
        1. 3.5.1. Type signature patterns
          1. 3.5.1.1. BASIC TYPE SIGNATURE PATTERN
          2. 3.5.1.2. ANNOTATION-BASED TYPE SIGNATURE PATTERN
          3. 3.5.1.3. GENERIC-BASED TYPE SIGNATURE PATTERNS
          4. 3.5.1.4. COMBINING TYPE SIGNATURE PATTERNS
        2. 3.5.2. Method and constructor signature patterns
          1. 3.5.2.1. BASIC METHOD SIGNATURE PATTERN
          2. 3.5.2.2. ANNOTATION-BASED METHOD SIGNATURE PATTERN
          3. 3.5.2.3. CONSTRUCTOR SIGNATURE PATTERN
        3. 3.5.3. Field signature patterns
          1. 3.5.3.1. BASIC FIELD SIGNATURE PATTERN
          2. 3.5.3.2. ANNOTATION-BASED FIELD SIGNATURE PATTERN
      6. 3.6. Implementing pointcuts
        1. 3.6.1. Kinded pointcuts
        2. 3.6.2. Non-kinded pointcuts
          1. 3.6.2.1. CONTROL-FLOW BASED POINTCUTS
          2. 3.6.2.2. LEXICAL-STRUCTURE BASED POINTCUTS
          3. 3.6.2.3. EXECUTION-OBJECT POINTCUTS
          4. 3.6.2.4. ARGUMENT POINTCUTS
          5. 3.6.2.5. ANNOTATION-BASED POINTCUTS
          6. 3.6.2.6. CONDITIONAL CHECK POINTCUTS
      7. 3.7. Summary
    4. 4. Modifying behavior with dynamic crosscutting
      1. 4.1. Advice overview
        1. 4.1.1. Advice classification
        2. 4.1.2. Advice syntax
      2. 4.2. Comparing advice to methods
        1. 4.2.1. Similarities between advice and methods
        2. 4.2.2. Differences between advice and methods
      3. 4.3. Advice in depth
        1. 4.3.1. Before advice
        2. 4.3.2. After advice
          1. 4.3.2.1. AFTER (FINALLY)
          2. 4.3.2.2. AFTER RETURNING
          3. 4.3.2.3. AFTER THROWING
        3. 4.3.3. Around advice
          1. 4.3.3.1. PROCEEDING WITH ADVISED JOIN POINT
          2. 4.3.3.2. RETURNING A VALUE FROM AROUND ADVICE
          3. 4.3.3.3. THROWING AN EXCEPTION FROM AROUND ADVICE
          4. 4.3.3.4. EXAMPLE: IMPLEMENTING FAULT TOLERANCE
      4. 4.4. Collecting join point context
        1. 4.4.1. Collecting objects at the join point
        2. 4.4.2. Implementing simple caching
      5. 4.5. Accessing join point context via reflection
        1. 4.5.1. The reflection API
          1. 4.5.1.1. THE ORG.ASPECTJ.LANG.JOINPOINT INTERFACE
          2. 4.5.1.2. THE ORG.ASPECTJ.LANG.JOINPOINT.STATICPART INTERFACE
        2. 4.5.2. Improving caching using reflection APIs
        3. 4.5.3. Comparing the reflection API to pointcuts
      6. 4.6. Summary
    5. 5. Modifying structure with static crosscutting
      1. 5.1. Introducing members
        1. 5.1.1. Scattering and tangling
        2. 5.1.2. Untangling with aspects
        3. 5.1.3. Mixing with mixins
        4. 5.1.4. Member introduction rules
        5. 5.1.5. Idiom: Providing a default interface implementation
      2. 5.2. Modifying the type hierarchy
      3. 5.3. Introducing members to multiple types
      4. 5.4. Supplying annotations
      5. 5.5. Declaring weave-time errors and warnings
      6. 5.6. Softening checked exceptions
      7. 5.7. Summary
    6. 6. Aspects: putting it all together
      1. 6.1. Working with aspects
        1. 6.1.1. Similarities between aspects and classes
          1. 6.1.1.1. ASPECTS CAN INCLUDE DATA MEMBERS AND METHODS
          2. 6.1.1.2. ASPECTS CAN HAVE ACCESS SPECIFICATIONS
          3. 6.1.1.3. ASPECTS CAN BE ABSTRACT
          4. 6.1.1.4. ASPECTS CAN EXTEND CLASSES AND ABSTRACT ASPECTS, AS WELL AS IMPLEMENT INTERFACES
          5. 6.1.1.5. ASPECTS CAN BE EMBEDDED IN CLASSES AND INTERFACES AS NESTED ASPECTS
        2. 6.1.2. Differences between aspects and classes
          1. 6.1.2.1. ASPECTS CAN'T BE DIRECTLY INSTANTIATED
          2. 6.1.2.2. ASPECTS CAN'T INHERIT FROM CONCRETE ASPECTS
          3. 6.1.2.3. CONCRETE ASPECTS MAY NOT DECLARE GENERIC PARAMETERS
          4. 6.1.2.4. ASPECTS CAN BE MARKED AS PRIVILEGED
      2. 6.2. Aspect association
        1. 6.2.1. Default singleton association
        2. 6.2.2. Per-object association
        3. 6.2.3. Per-control-flow association
        4. 6.2.4. Per-type association
        5. 6.2.5. Implicit limiting of join points with aspect associations
        6. 6.2.6. Accessing aspect instances
        7. 6.2.7. Comparing per-object association and member introduction
        8. 6.2.8. Improving the caching aspect
          1. 6.2.8.1. USING DEPENDENCY INJECTION WITH ASPECTS
          2. 6.2.8.2. UPDATING THE PROGRAM TO CHECK CACHE BEHAVIOR
          3. 6.2.8.3. WRITING AN AUTOMATED TEST FOR CACHING
      3. 6.3. Aspect precedence
        1. 6.3.1. Ordering of advice
        2. 6.3.2. Explicit aspect precedence
          1. 6.3.2.1. USING PRECEDENCE TO CONTROL ORDERING
          2. 6.3.2.2. TYPICAL PRECEDENCE CONTROL PATTERNS
        3. 6.3.3. Ordering advice in a single aspect
      4. 6.4. Privileged aspects
      5. 6.5. Summary
    7. 7. Diving into the @AspectJ syntax
      1. 7.1. Syntax overview
        1. 7.1.1. Natural mapping
        2. 7.1.2. Java compatibility
        3. 7.1.3. Early error detection
      2. 7.2. Mapping aspects
        1. 7.2.1. Specifying aspect association
        2. 7.2.2. Accessing the aspect instance
        3. 7.2.3. Declaring aspect precedence
      3. 7.3. Mapping pointcuts
        1. 7.3.1. Mapping abstract pointcuts
        2. 7.3.2. Mapping concrete pointcuts
          1. 7.3.2.1. REQUIREMENTS FOR POINTCUT EXPRESSIONS
          2. 7.3.2.2. REQUIREMENTS FOR COMPILATION
          3. 7.3.2.3. SPECIAL TREATMENT OF THE IF() POINTCUT
      4. 7.4. Mapping dynamic crosscutting constructs
        1. 7.4.1. The before advice
          1. 7.4.1.1. ADVISING WITH ANONYMOUS POINTCUTS
          2. 7.4.1.2. ADVISING WITH NAMED POINTCUTS
          3. 7.4.1.3. USING A REFLECTIVE JOIN POINT CONTEXT
          4. 7.4.1.4. USING A TYPED JOIN POINT CONTEXT
        2. 7.4.2. The after advice
          1. 7.4.2.1. EXPRESSING AFTER RETURNING AND AFTER THROWING
          2. 7.4.2.2. COLLECTING THE RETURN VALUE AND THROWN EXCEPTION
        3. 7.4.3. The around advice
          1. 7.4.3.1. PROCEEDING WITH THE ORIGINAL JOIN POINT EXECUTION
          2. 7.4.3.2. ALTERING THE JOIN POINT CONTEXT
      5. 7.5. Mapping static crosscutting
        1. 7.5.1. Mapping weave-time declarations
        2. 7.5.2. Mapping declare parents
          1. 7.5.2.1. DECLARING PARENTS FOR MARKER INTERFACES
          2. 7.5.2.2. DECLARING PARENTS FOR NON-MARKER INTERFACES
          3. 7.5.2.3. UTILIZING THE INTRODUCED TYPE
      6. 7.6. Features not implemented in @AspectJ
        1. 7.6.1. Associating annotations
        2. 7.6.2. Introducing data and methods
        3. 7.6.3. Softening exceptions
        4. 7.6.4. Privileged aspects
      7. 7.7. Comparing syntax styles
      8. 7.8. Summary
    8. 8. AspectJ weaving models
      1. 8.1. Classifying weaving models
      2. 8.2. Build-time weaving
        1. 8.2.1. Build-time source code weaving
        2. 8.2.2. Build-time binary weaving
      3. 8.3. Load-time weaving
        1. 8.3.1. Load-time weaving overview
        2. 8.3.2. Configuring the load-time weaver
          1. 8.3.2.1. SPECIFYING ASPECTS TO BE WOVEN
          2. 8.3.2.2. DEFINING CONCRETE ASPECTS
          3. 8.3.2.3. DEFINING ASPECT PRECEDENCE
          4. 8.3.2.4. SPECIFYING WEAVING OPTIONS IN AOP.XML
          5. 8.3.2.5. USING MULTIPLE AOP.XML FILES
      4. 8.4. Load-time weaver in action
      5. 8.5. Choosing syntax and weaving
      6. 8.6. Summary
    9. 9. Integration with Spring
      1. 9.1. Spring AOP fundamentals
        1. 9.1.1. Setting up the application
        2. 9.1.2. Utilizing the @AspectJ syntax
        3. 9.1.3. Spring IDE
      2. 9.2. Spring AOP under the hood
        1. 9.2.1. A quick introduction to dynamic proxies
        2. 9.2.2. Proxy-based AOP with Spring
        3. 9.2.3. Spring AOP internals
        4. 9.2.4. Proxy-based AOP in DI framework
        5. 9.2.5. Limitations of Spring AOP
          1. 9.2.5.1. METHOD EXECUTION-ONLY JOIN POINTS
          2. 9.2.5.2. BEAN-ONLY CROSSCUTTING
          3. 9.2.5.3. EXTERNAL CALL-ONLY INTERCEPTION
      3. 9.3. @AspectJ support in depth
        1. 9.3.1. Dynamic crosscutting
          1. 9.3.1.1. POINTCUTS
          2. 9.3.1.2. SELECTING SPRING BEANS
          3. 9.3.1.3. ADVICE
          4. 9.3.1.4. ASPECT ORDERING
          5. 9.3.1.5. ASPECT INSTANTIATION MODELS
        2. 9.3.2. Static crosscutting
      4. 9.4. Schema-style AOP support
        1. 9.4.1. Mapping aspects
        2. 9.4.2. Mapping pointcuts
        3. 9.4.3. Mapping advice
        4. 9.4.4. Mapping static crosscutting
      5. 9.5. Tapping into the full power of AspectJ
        1. 9.5.1. Configuring aspects using Spring DI
        2. 9.5.2. Spring-driven LTW
          1. 9.5.2.1. SPRING-DRIVEN LTW IN ACTION
          2. 9.5.2.2. SPRING-DRIVEN LTW: UNDER THE HOOD
      6. 9.6. Choosing an appropriate AOP system
        1. 9.6.1. Comparing AspectJ to Spring AOP
        2. 9.6.2. Comparing Spring AOP syntax
        3. 9.6.3. It's decision time
      7. 9.7. Summary
  13. 2. Applications of AspectJ with Spring
    1. 10. Monitoring techniques
      1. 10.1. Tracing in action
        1. 10.1.1. Tracing the aspect-oriented way
        2. 10.1.2. Tracing the conventional way
      2. 10.2. Conventional vs. AOP tracing
      3. 10.3. Selecting join points of interest
        1. 10.3.1. Selection based on static structure
          1. 10.3.1.1. LEVERAGING PACKAGE STRUCTURE
          2. 10.3.1.2. LEVERAGING TYPE STRUCTURE
          3. 10.3.1.3. LEVERAGING ANNOTATIONS
          4. 10.3.1.4. LEVERAGING METHOD SIGNATURE
        2. 10.3.2. Selection based on dynamic context
      4. 10.4. Tracing
        1. 10.4.1. Indenting trace calls
        2. 10.4.2. Sharing tracing aspect functionality
        3. 10.4.3. Tracing intra-method activities
        4. 10.4.4. Logging the method parameters
        5. 10.4.5. Choosing a type-specific logger
      5. 10.5. A detour: deployment options for monitoring aspects
        1. 10.5.1. Utilizing load-time weaving
        2. 10.5.2. Utilizing Spring AOP for tracing
      6. 10.6. Exception monitoring
      7. 10.7. Improving conventional logging
        1. 10.7.1. Modularizing NDC with conventional logging
        2. 10.7.2. Modularizing MDC with conventional logging
      8. 10.8. Performance monitoring
      9. 10.9. Runtime control of monitoring aspects
      10. 10.10. Summary
    2. 11. Policy enforcement: keeping your design intact
      1. 11.1. AOP-based policy enforcement overview
      2. 11.2. Policy origins and destinations
      3. 11.3. Enforcement using AOP
        1. 11.3.1. Compile-time enforcement
        2. 11.3.2. Runtime enforcement
      4. 11.4. Comparison with code-analysis tools
      5. 11.5. Implementing flexible access control
        1. 11.5.1. Restricting exposure
        2. 11.5.2. Limiting collaboration
        3. 11.5.3. Enforcing the factory pattern
      6. 11.6. Enforcement idiom: return-value restriction
      7. 11.7. Enforcing JPA-JDBC integration policies
      8. 11.8. Implementing EJB policies
        1. 11.8.1. Developing a core EJB enforcement aspect
        2. 11.8.2. Defining EJB pointcuts
        3. 11.8.3. Dealing with XML-based EJBs
        4. 11.8.4. Implementing a "no EJBs" policy
      9. 11.9. Detecting Swing concurrency control policy violations
        1. 11.9.1. Understanding the problem
        2. 11.9.2. Detecting the violation
      10. 11.10. Summary
    3. 12. Learning design patterns
      1. 12.1. The worker object pattern
        1. 12.1.1. The current solution
        2. 12.1.2. An overview of the worker object pattern
        3. 12.1.3. The worker object pattern template
        4. 12.1.4. Getting the return value
        5. 12.1.5. A summary of the worker object pattern
      2. 12.2. The wormhole pattern
        1. 12.2.1. The current solution
        2. 12.2.2. An overview of the wormhole pattern
        3. 12.2.3. The wormhole pattern template
        4. 12.2.4. A summary of the wormhole pattern
      3. 12.3. The participant pattern
        1. 12.3.1. Current solutions
          1. 12.3.1.1. TAKE ONE
          2. 12.3.1.2. TAKE TWO
        2. 12.3.2. An overview of the participant pattern
        3. 12.3.3. The participant pattern template
          1. 12.3.3.1. SCOPING PARTICIPATION
          2. 12.3.3.2. AUGMENTING BEHAVIORAL PARTICIPATION
        4. 12.3.4. Consequences of the participant pattern
        5. 12.3.5. A summary of the participant pattern
      4. 12.4. Annotation-driven participant pattern
        1. 12.4.1. Current solution
        2. 12.4.2. The annotation-driven participant pattern template
        3. 12.4.3. Annotation type abstraction
          1. 12.4.3.1. FUNCTIONALITY-SPECIFIC ANNOTATION
          2. 12.4.3.2. SUBJECTIVE CHARACTERISTIC-BASED ANNOTATION
          3. 12.4.3.3. OBJECTIVE CHARACTERISTIC-BASED ANNOTATION
        4. 12.4.4. Variation: bridged participation pattern
        5. 12.4.5. Role of ADPP in library aspects
      5. 12.5. Summary
    4. 13. Implementing concurrency control
      1. 13.1. Modularizing Swing's single-thread rule
        1. 13.1.1. A test problem
        2. 13.1.2. Solution: the conventional way
        3. 13.1.3. Solution: the AspectJ way
          1. 13.1.3.1. THE FIRST VERSION
          2. 13.1.3.2. THE SECOND VERSION
          3. 13.1.3.3. THE THIRD VERSION
        4. 13.1.4. Improving the solution
          1. 13.1.4.1. DEALING WITH EXCEPTIONS
          2. 13.1.4.2. AVOIDING THE OVERHEAD
      2. 13.2. Improving the responsiveness of UI applications
      3. 13.3. Modularizing the read-write lock pattern
        1. 13.3.1. Implementation: the conventional way
        2. 13.3.2. Implementation: the AspectJ way
          1. 13.3.2.1. IMPLEMENTING THE BASE ASPECT
          2. 13.3.2.2. IMPLEMENTING SUBASPECTS
      4. 13.4. Summary
    5. 14. Managing transactions
      1. 14.1. Transaction management implementations
        1. 14.1.1. Conventional implementation
        2. 14.1.2. AOP implementation
      2. 14.2. Transaction-management players
        1. 14.2.1. Transaction management in architecture
        2. 14.2.2. Transaction management: one concept, too many implementations
        3. 14.2.3. Transaction-management abstraction
      3. 14.3. Aspect implementation choices
        1. 14.3.1. Proxy-based AOP
        2. 14.3.2. Byte-code weaving
      4. 14.4. Transaction-management aspect (almost) from scratch
        1. 14.4.1. Implementing the aspect
        2. 14.4.2. Testing the aspect
        3. 14.4.3. Road test for the aspect
          1. 14.4.3.1. ASPECTJ BYTE-CODE WEAVING
          2. 14.4.3.2. SPRING'S PROXY-BASED AOP
      5. 14.5. Spring's transaction management
        1. 14.5.1. XML-driven transaction management
        2. 14.5.2. Annotation-driven transaction management
        3. 14.5.3. AspectJ weaver-based transaction management
      6. 14.6. Implementing fault tolerance for transactional operations
        1. 14.6.1. Base aspect
        2. 14.6.2. Using the annotation-driven participant pattern
        3. 14.6.3. Configuring the aspect
        4. 14.6.4. Testing the fault-tolerance aspect
        5. 14.6.5. Improving the solution
          1. 14.6.5.1. DEALING WITH NONTRANSACTIONAL RESOURCES
          2. 14.6.5.2. PORTING TO SPRING AOP
      7. 14.7. Summary
    6. 15. Securing applications
      1. 15.1. Securing applications with conventional techniques
        1. 15.1.1. The do-it-yourself approach
        2. 15.1.2. The framework-based approach
      2. 15.2. Modularizing security using AOP
      3. 15.3. A quick overview of Spring Security
        1. 15.3.1. Authentication
        2. 15.3.2. Authorization
      4. 15.4. Implementing a security solution from scratch
        1. 15.4.1. Implementing authentication aspects
          1. 15.4.1.1. BASE AUTHENTICATION ASPECT
          2. 15.4.1.2. EXAMPLE SUBASPECT
        2. 15.4.2. Implementing authorization aspects
          1. 15.4.2.1. BASE ASPECT
          2. 15.4.2.2. SUBASPECT WITHOUT ANNOTATIONS
          3. 15.4.2.3. ANNOTATION-DRIVEN SUBASPECT
      5. 15.5. Implementing field-level authorization
      6. 15.6. Spring Security prebuilt solutions
        1. 15.6.1. Web security
        2. 15.6.2. Service level security
          1. 15.6.2.1. EXTERNAL CONFIGURATION OPTION
          2. 15.6.2.2. ANNOTATION-BASED OPTION
          3. 15.6.2.3. GOING BEYOND ROLES
        3. 15.6.3. Domain-object security
      7. 15.7. Additional ideas in implementing security
        1. 15.7.1. Auditing access
        2. 15.7.2. Filtering field content
      8. 15.8. Summary
    7. 16. Improving domain logic
      1. 16.1. Empowering objects
        1. 16.1.1. Enabling rich behavior
        2. 16.1.2. Injecting dependencies with Spring and AspectJ
          1. 16.1.2.1. ANNOTATION-BASED DI
          2. 16.1.2.2. DOMAIN INTERFACES-BASED DI
        3. 16.1.3. Possibilities enabled by domain-object DI
          1. 16.1.3.1. ENRICHING DOMAIN OBJECT BEHAVIOR
          2. 16.1.3.2. DISCUSSION: RETHINKING THE SERVICE LAYER
          3. 16.1.3.3. SIMPLIFYING THE DOMAIN OBJECT API
      2. 16.2. Implementing business logic
        1. 16.2.1. Improving inventory management
        2. 16.2.2. Checking for the order-level constraint
        3. 16.2.3. Refactoring using aspects
      3. 16.3. Managing access to objects
        1. 16.3.1. Applying specific policies
        2. 16.3.2. Applying general policies
      4. 16.4. Summary
    8. 17. Taking the next step
      1. 17.1. The adoption path: technologies
        1. 17.1.1. Spring AOP
        2. 17.1.2. AspectJ
      2. 17.2. The adoption path: applications
        1. 17.2.1. Development aspects
          1. 17.2.1.1. HELPING WITH DEBUGGING
          2. 17.2.1.2. MONITORING PERFORMANCE
          3. 17.2.1.3. ENFORCING POLICIES
          4. 17.2.1.4. HELPING WITH TESTING
        2. 17.2.2. Production aspects
          1. 17.2.2.1. INFRASTRUCTURE ASPECTS
          2. 17.2.2.2. CROSSCUTTING DOMAIN LOGIC
          3. 17.2.2.3. REFACTORING ASPECTS
      3. 17.3. Applying AOP to new problems
        1. 17.3.1. Talking the talk
        2. 17.3.2. Walking the walk
      4. 17.4. Employing AOP in development phases
        1. 17.4.1. AOP in the design phase
        2. 17.4.2. AOP in the implementation phase
          1. 17.4.2.1. IMPLEMENTING CORE CONCERNS
          2. 17.4.2.2. IMPLEMENTING CROSSCUTTING CONCERNS
        3. 17.4.3. AOP in the maintenance phase
        4. 17.4.4. AOP in legacy projects
      5. 17.5. Parting thoughts
  14. A. Setting up the example
    1. A.1. Domain classes
    2. A.2. Repository layer
    3. A.3. Service layer
    4. A.4. Application configuration
    5. A.5. The web layer
    6. A.6. Logging configuration
    7. A.7. Building and running the application
  15. B. Using Ant with AspectJ
    1. B.1. Weaving sources
    2. B.2. Creating an aspect library
    3. B.3. Weaving into jar files
  16. C. Using Maven with AspectJ
    1. C.1. Weaving sources
    2. C.2. Creating an aspect library
    3. C.3. Weaving into jar files

Product information

  • Title: AspectJ in Action, Second Edition
  • Author(s): Ramnivas Laddad
  • Release date: August 2009
  • Publisher(s): Manning Publications
  • ISBN: 9781933988054