|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||
@Retention(value=RUNTIME)
@Target(value={TYPE,METHOD})
public @interface Interceptors
Declares a list of interceptors. The order in which the interceptors are
executed is equal to the order in which they are specified by this
annotation. Interceptors can be specified at both class-level and
method-level. Class-level interceptors are applied to all business methods
of a beanlet, except for business methods that are marked with the
ExcludeClassInterceptors annotation. Logically, method-level
interceptors are only applied to the method at which they are specified.
value() MUST therefore not specify
duplicate classes. If the class-level and method-level interceptor
declaration share classes, the duplicate class-level interceptors are
discarded. This allows the method-level annotation to override the order
specified at class-level. This situation is demonstrated at example (A).
InterceptorB) declarations. The order in which these interceptors
are executed for method sum(int[]) is:
InterceptorA, InterceptorC, InterceptorB and finally
InterceptorD.
The order for subtract(int, int) is: InterceptorB
and InterceptorA. Class-level interceptor InterceptorC is not
installed for this method, because the ExcludeClassInterceptors
annotation excludes class-level interceptors.
@Interceptors({InterceptorA.class, InterceptorB.class, InterceptorC.class})
public class ExampleBeanlet {
@Interceptors({InterceptorB.class, InterceptorD.class})
@Operation
public int add(int... values) {
int sum = 0;
for (int value : values) {
sum += value;
}
return sum;
}
@ExcludeClassInterceptors
@Interceptors({InterceptorB.class, InterceptorA.class})
@Operation
public int subtract(int arg0, int arg1) {
return arg0 - arg1;
}
}
(B) Interceptor instance scope example. Only two interceptor
instances are created for an instance of beanlet "example", namely
an instance of InterceptorA and an instance of InterceptorB.
Hence, method doIt(), doThis(String) and
doThat(String) share an instance of InterceptorA.
InterceptorB is shared by doThis(String) and
doThat(String).
@Interceptors({InterceptorA.class})
public class ExampleBeanlet {
@Run
public void doIt() {
}
@Interceptors(InterceptorB.class)
@Operation
public void doThis(String this) {
}
@Interceptors(InterceptorB.class)
@Operation
public void doThat(String that) {
}
}
<beanlets xmlns="http://beanlet.org/schema/beanlet"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://beanlet.org/schema/beanlet http://beanlet.org/schema/beanlet/beanlet_1_0.xsd">
<beanlet name="foo" type="com.acme.Foo">
<interceptors type="com.acme.InterceptorA"/>
</beanlet>
</beanlets>
Or alternatively:
<beanlets xmlns="http://beanlet.org/schema/beanlet"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://beanlet.org/schema/beanlet http://beanlet.org/schema/beanlet/beanlet_1_0.xsd">
<beanlet name="foo" type="com.acme.Foo">
<interceptors>
<class type="com.acme.InterceptorA"/>
<class type="com.acme.InterceptorB"/>
</interceptors>
</beanlet>
</beanlets>
AroundInvoke,
Interceptor,
ExcludeClassInterceptors| Required Element Summary | |
|---|---|
Class<?>[] |
value
Specifies interceptor classes. |
| Element Detail |
|---|
public abstract Class<?>[] value
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||