Chapter 12. Capturing Join Points Based on a Boolean or Combined Expression
Introduction
This chapter examines how pointcuts can be combined and evaluated as Boolean expressions. Pointcut logic is evaluated to determine whether a particular join point is caught. The Boolean nature of pointcut logic allows for pointcut declarations to be combined using traditional Boolean expressions such as logical AND, logical OR, and logical NOT.
Conditional logic can also be expressed in
pointcut declarations using an if
statement. An
if
statement is used to compare expressions that
contain values other than Booleans. The if
statement evaluates the values passed to it at runtime to come to a
true
or false
result.
Anonymous pointcuts are the building blocks of more complexly named pointcut declarations. Anonymous pointcuts can be declared as part of compound-named pointcuts or as part of an advice declaration. Named pointcuts are then, in turn, the building blocks of pointcut logic reuse. Pointcut reuse allows efficient management of the complex logic that can be defined using the available pointcut within AspectJ. This chapter closes by examining how to declare anonymous pointcuts and combine those pointcuts into reusable named pointcuts.
12.1. Capturing When a Runtime Condition Evaluates to True on a Join Point
Problem
You want to trigger advice based on a true result when comparing some runtime values that can be evaluated at a captured join point.
Solution
Use
the
if(Expression)
statement ...
Get AspectJ Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.