JBoss.org Community Documentation
You can declare precedence by annotating a class with @Precedence
, and then annotate
fields where the types are the various Interfaces/Aspects you want to sort. You annotate fields where the
type is an interceptor with @PrecedenceInterceptor
. When the type is an
aspect class, you annotate the field with @PrecedenceAdvice
. The definitions
of org.jboss.aop.Precedence, org.jboss.aop.PrecedenceInterceptor and
org.jboss.aop.PrecedenceAdvice are
package org.jboss.aop; @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface Precedence { }
package org.jboss.aop; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface PrecedenceInterceptor { }
package org.jboss.aop; @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface PrecedenceAdvice { String value(); }
The value()
attribute of PrecedenceAdvice
is the name of the
advice method to use.
The example shown below declares a relative sort order where org.acme.Interceptor
must always be invoked before org.acme.Aspect.advice1()
which must be invoked before
org.acme.Aspect.advice2()
:
import org.jboss.aop.Precedence; import org.jboss.aop.PrecedenceAdvice; @Precedence public class MyPrecedence { @PrecedenceInterceptor org.acme.Interceptor intercept; @PrecedenceAdvice ("advice1") org.acme.Aspect precAdvice1; @PrecedenceAdvice ("advice2") org.acme.Aspect precAdvice2; }
The ordering of interceptors/advices defined via annotations that have no precedence defined, is arbitrary.