Hi Raghu and Jonathan, can you elucidate on the 'interceptors' in the new EJB3 and does your book throw light on this new feature?
Also I have read that the new EJB3 has changed the way enterprise beans are called and accessed by replacing the service locator pattern that utilizes JNDI with something called 'Dependency Injection Pattern' (Courtesy: Java World). Can you explain what this means please. [ October 24, 2006: Message edited by: vishwanath nadimpally ]
Hi Vishwanath- Sure. Interceptors are an AOP (Aspect-Oriented Programming) construct that allow you to perform additional work whenever a particular method is called. To take a classic example, you might want to audit one or more business methods on your session bean to record whenever they are called. Instead of modifying the business methods themselves, you declaratively assign one or more interceptor methods to be "wrap" the call to the business method. Interceptor methods are annotated with the annotation, and they may be defined on the class to which they apply, or on an external class. In the latter case, the session or message driven bean specifies one or more interceptor classes that will handle calls to the bean methods. When more than one interceptor method is specified for a particular method context, they are nested, following well-defined rules of precedence. The first one is called, and it in turn calls the next one, and so on, until finally the business method on the bean itself is invoked. In addition, an interceptor method may at any point decide to throw an exception, or cancel the method call.
The key to interceptors is that neither the business method being called, nor the client that calls it, need to be modified in any way to know that the call is being interposed by interceptor methods. Interceptors can be specified through annotations or in XML. Interceptors can apply to multiple methods, possibly across multiple beans, you can turn interceptors on or off, and you can selectively choose which business methods on your bean to intercept.
JPA entities do not support interceptors per se, but instead support a well specified set of entity lifecycle event entrypoints, called entity listeners. These callback methods allow you to perform additional work during the following entity lifecycle events: