JBoss.org Community Documentation
To define a named pointcut you annotate a field within an
@Aspect
or
@InterceptorDef
annotated class with
@PointcutDef
.
@PointcutDef
only applies to fields and is not recognised outside
@Aspect
or
@InterceptorDef
annotated classes.
The declaration of
org.jboss.aop.PointcutDef
is:
package org.jboss.aop; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface PointcutDef { String value(); }
@PointcutDef
takes only one value, a valid pointcut expression.
The name of the pointcut used internally and when yo want to reference it is:
<name of @Aspect/@InterceptorDef annotated class>.<name of @PointcutDef annotated field>
An example of an aspect class containing a named pointcut which it references from a bindng's pointcut expression:
package com.mypackage; import org.jboss.aop.PointcutDef; import org.jboss.aop.pointcut.Pointcut; @Aspect (scope = Scope.PER_VM) public class MyAspect { @PointcutDef ("(execution(* org.blah.Foo->someMethod()) OR \ execution(* org.blah.Foo->otherMethod()))") public static Pointcut fooMethods; public Object myAdvice(Invocation invocation) { return invocation.invokeNext(); } }
It is worth noting that named pointcuts can be referenced in pointcut expressions outside the class they are declared in (if the annotated fields are declared public of course!).
Using XML configuration this would be:
<aop> <aspect class="com.mypackage.MyAspect" scope="PER_VM"/> <pointcut name="com.mypackage.MyAspect.fooMethods" expr="(execution(* org.blah.Foo->someMethod()) OR \ execution(* org.blah.Foo->otherMethod()))" /> </aop>