Java Reference
In-Depth Information
At this point,, NetBeans generates the code for our interceptor binding type:
package com.ensode.cdiintro.interceptorbinding;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.interceptor.InterceptorBinding;
@Inherited
@InterceptorBinding
@Retention(RUNTIME)
@Target({METHOD, TYPE})
public @interface LoggingInterceptorBinding {
}
The generated code is fully functional; we don't need to add anything to it. In order
to use our interceptor binding type, we need to write an interceptor and annotate it
with our interceptor binding type, as shown in the following code:
package com.ensode.cdiintro.interceptor;
import com.ensode.cdiintro.interceptorbinding.
LoggingInterceptorBinding;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
@LoggingInterceptorBinding
@Interceptor
public class LoggingInterceptor implements Serializable{
private static final Logger logger = Logger.getLogger(
LoggingInterceptor.class.getName());
@AroundInvoke
public Object logMethodCall(InvocationContext invocationContext)
throws Exception {
 
Search WWH ::




Custom Search