org.beanlet
Annotation Type Interceptors


@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.

Interceptor Execution Order

Class-level interceptors are placed in front of method-level interceptors. The interceptor chain does not allow the same interceptor class more than once. The classes specified by 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).

Interceptor Instance Scope

New interceptor instances are created for every beanlet instance that is constructed. These instances are always associated with this particular beanlet instance. A new interceptor chain is assembled for every single interceptor-enabled method of this beanlet instance. This interceptor chain is composed of the previously created interceptor instances. The applicability of an interceptor to more than one business method of a beanlet does not affect the relationship between the interceptor instance and the beanlet instance. Only a single instance of the interceptor class is created per beanlet instance.

Examples

(A) Example of a beanlet with duplicate interceptor (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) {
     }
 }
 

XML Representation

The following xml-fragment shows how to express this annotation in xml.
<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>

See Also:
AroundInvoke, Interceptor, ExcludeClassInterceptors

Required Element Summary
 Class<?>[] value
          Specifies interceptor classes.
 

Element Detail

value

public abstract Class<?>[] value
Specifies interceptor classes. These classes are executed in the order they are specified.



Copyright © 2006-2012. All Rights Reserved.