JBoss.org Community Documentation
To prepare a joinpoint or a set of joinpoints for DynamicAOP annotate a field
with
@Prepare
in a class anotated with
@Aspect
or
@InterceptorDef
.
The declaration of
org.jboss.aop.Prepare
is:
package org.jboss.aop; @Target({ElementType.FIELD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface Prepare { String value() default ""; }
The single field
value
contains a pointcut expression
matching one or more joinpoints.
To use
@Prepare
follow this example:
package com.mypackage; import org.jboss.aop.Prepare; @InterceptorDef (scope = Scope.PER_VM) @Bind (pointcut="execution("* com.blah.Test->test(..)") public class MyInterceptor2 implements Interceptor { @Prepare ("all(com.blah.DynamicPOJO)") public static Pointcut dynamicPOJO; public Object invoke(Invocation invocation)throws Throwable { return invocation.invokeNext(); } }
Using XML configuration instead we would write:
<prepare expr="all(com.blah.DynamicPOJO)"/>
This simple example used an
@InterceptorDef
class for a bit of
variety in the examples, and to reiterate that
@Pointcut
,
@Introduction
,
@Mixin
,
@Prepare
,
@Typedef
,
@CFlow
,
@DynamicCFlow
and
@AnnotationIntroductionDef
can all be used both in
@InterceptorDef
annotated classes AND
@Aspect
annotated classes. Same for
@Bind
,
but that is a special case as mentioned above.
To summarise, when using @Prepare within an @Interceptor or @Aspect annotated class, you annotate a field within that class. When using @Prepare with a POJO you annotate the class itself.