Chapter 4. Capturing Joing Points on Methods
Introduction
A join point is a specific point at which advice can be woven into the code of an application. Pointcuts provide logical definitions for picking the join points that will invoke a piece of advice.
The next nine chapters correspond to the types of Java language constructs that contain join points that can be captured using pointcut declarations in AspectJ. This chapter focuses on pointcuts that can capture the selection of join points that are available on Java methods.
The
before( ) form of
advice is used for most of these pointcut-based recipes that make up
the next eight chapters to avoid confusing things by using different
types of advice. Where it’s unavoidable, other forms
of advice may have to be used, so it might be helpful to refer to
Chapter 9 to understand the implications that
the different forms of advice bring to the solutions provided.
Tip
Once you have grasped the different types of pointcut that AspectJ provides in Chapter 4 through Chapter 12, check out Mik Kersten’s standard pointcut idioms by going to http://www.eclipse.org/aspectj and then by clicking on Documentation → standard pointcut idioms. These reusable pointcut definitions provide some great tools with which to construct your own pointcut logic.
4.1. Capturing a Method Call
Problem
You want to capture when calls are made to methods that match a specific signature.
Solution
Use the
call(Signature)
pointcut. The syntax of the call(Signature) pointcut ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access