/**
 * 
 */
package org.jboss.seam.faces.context.conversation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import javax.enterprise.context.Conversation;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

import org.slf4j.Logger;

/**
 * Intercepts methods annotated as Conversational entry points.
 * 
 * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
 * 
 */
@Begin
@Interceptor
public class BeginConversationInterceptor
{
   @Inject
   Logger log;

   @Inject
   Conversation conversation;

   @AroundInvoke
   public Object before(final InvocationContext ctx) throws Exception
   {
      String cid = getConversationId(ctx.getMethod());
      if (cid != null)
      {
         conversation.begin(cid);
      }
      else
      {
         conversation.begin();
      }

      log.debug("Began conversation: (#0) on method: (#1.#2(...))", new Object[] { conversation.getId(), ctx.getMethod().getDeclaringClass().getName(), ctx.getMethod().getName() });

      try
      {
         Object result = ctx.proceed();
         return result;
      }
      catch (Exception e)
      {
         conversation.end();
         throw e;
      }

   }

   private String getConversationId(final Method m)
   {
      String result = null;
      for (Annotation a : m.getAnnotations())
      {
         if (a.annotationType().isAnnotationPresent(Begin.class))
         {
            result = a.annotationType().getAnnotation(Begin.class).id();
         }
      }

      if (result == null)
      {
         for (Annotation a : m.getDeclaringClass().getAnnotations())
         {
            if (a.annotationType().isAnnotationPresent(Begin.class))
            {
               result = a.annotationType().getAnnotation(Begin.class).id();
            }
         }
      }
      return result;
   }
}

@@ -57,16 +57,45 @@
 ation;%0A%0A
+import java.io.Serializable;%0A
 import j
@@ -599,16 +599,40 @@
 erceptor
+ implements Serializable
 %0A%7B%0A   @I

make serializable