Java Reference
In-Depth Information
create an interceptor binding type, declare the interceptor bindings, and bind this in-
terceptor to the desired component.
Creation of interceptor binding types
The interceptor binding type is created exactly like a simple annotation, except that
it adds at least the
@InterceptorBinding
among the annotations used to define
the characteristic of the interceptor binding. The following code shows the declara-
tion of an interceptor binding type to log some information:
@InterceptorBinding
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Log {
}
Declaring interceptor binding
We can declare interceptor binding by annotating an interceptor with the interceptor
binding type and the
@javax.interceptor.Interceptor
annotation. The fol-
lowing code demonstrates how to declare an interceptor binding:
@Log
@Interceptor
public class LoggerInterceptor {
// Interceptors methods
}
Binding an interceptor by using interceptor binding type
After all these operations, it is up to you to decorate a non interceptor component
with the interceptor binding types to bind the interceptor to a component. The fol-
lowing code demonstrates how to bind the
LoggerInterceptor
interceptor to our
EJB:
@Stateless
@Log
public class