Table of Contents
dynaop uses a BeanShell script for configuration. BeanShell is scripted Java. You can do almost anything in BeanShell that you can do in Java. BeanShell also provides syntax sugar that can result in more concise code. BeanShell is interpreted and doesn't require a compilation step. See the BeanShell home page http://beanshell.org/ for more information.
Store the default BeanShell configuration script in the root of the class path in a file named "dynaop.bsh". Specify a different path using the "dynaop.bsh" system property.
dynaop imports a number of methods for defining pointcuts and aspects from Aspects and Pointcuts and enhances them with some additional shortcuts. dynaop makes these methods implicitly available to the script.
As an alternative to a BeanShell script, you can also use dynaop.Aspects directly to configure a ProxyFactory. Doing so requires more typing but enables better type checking (BeanShell is a scripting language and is therefore non-typed).
Pointcuts pick classes and methods to apply advice to. dynaop uses a query object pattern to define class and method pointcuts. Class pointcuts implement ClassPointcut, and method pointcuts implement MethodPointcut.
The Pointcuts class has constant fields as well as factory methods that create pointcut objects. dynaop makes these constants and methods implicitly available to the configuration script.
The dynaop configuration provides for some additional shortcuts (over what's already provided by the Pointcuts class). Specifically, you can:
As the following example illustrates, dynaop uses set operations to combine pointcuts. The intersection of two pointcuts is the classes or methods picked by both pointcuts. The union of two poincuts is the combination of all of the classes or methods picked by two pointcuts. The not() method inverts a pointcut, picking all classes or methods not picked by the pointcut.
Example 3.1. pointcut examples
import java.util.List; // pick all List implementations in the "com.mycompany" package. classPointcut = intersection(List.class, packageName("com.mycompany")); // pick all get methods. methodPointcut = GET_METHODS; // extends methodPointcut to include methods that return List. methodPointcut = union(methodPointcut, returnType(List.class)); // extends methodPointcut again to include the size() method. methodPointcut = union( methodPointcut, List.class.getMethod("size", null) );