POJO Seam Interceptor

6 05 2010

Aahhooyy!!

seam_icon.png
POJO Seam Annotation

Code First.

Read the code comments after the code.The Interceptor:

 @Interceptor(around = {
        BijectionInterceptor.class,
        MethodContextInterceptor.class,
        ConversationInterceptor.class,
        SynchronizationInterceptor.class,
        ConversationalInterceptor.class,
        RemoveInterceptor.class,
        SeamInterceptor.class,
        SecurityInterceptor.class,
        TransactionInterceptor.class,
        EventInterceptor.class,
        HibernateSessionProxyInterceptor.class,
        ManagedEntityInterceptor.class
        })
 @Name("businessConfigurator")
 public class BusinessConfigurator  {
     @AroundInvoke
     public Object configure(InvocationContext invocation) throws Exception {
         // Do all the configuration needed to execute the business layer
     }
 }

The Annotation:

 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.RUNTIME)
 @Interceptors(BusinessConfigurator.class)
 public @interface BusinessInterceptor {}

The Class:

 @Name("businessToBeIntercepted")
 @BusinessInterceptor
 public class BusinessToBeIntercepted {
     // Do the business
 }
Implementation Comments:

First of all: the Environment
For this test I’m using:
  • Linux Ubuntu 10.04
  • JBoss 5.1
  • JBoss Seam 2.2.0. GA
  • JDK 1.6.0_20

Said that, the considerations on the Interceptor implementation.

The BusinessConfigurator class make use of two main Seam Annotation:
 @Interceptor
 @AroundInvoke
The @Interceptor identifies the class as an Interceptor.

You can declare other Interceptors by your need that will work before your Interceptor.

The order of the Interceptors is relevant.

Pretty much the declaration of this interceptors sets up the Seams components to use onwards.

On my actual code I didn’t need any of the other Interceptors.

This is not required but you can create an Annotation for organization and looks purpose.

On the BusinessInterceptor Annotation I declare that whoever makes use of this annotation on a class is going to be intercepted by the BusinessConfigurator Interceptor at runtime.

Finally my Seam POJO BusinessToBeIntercepted.

This POJO is going to be intercepted by the BusinessConfigurator stated by the Annotation BusinessInterceptor.

Not too hard, huh?!?

Abraaaaaaço