[jboss-cvs] jboss-seam/src/main/org/jboss/seam/interceptors ...

Gavin King gavin.king at jboss.com
Wed Nov 29 07:43:22 EST 2006


  User: gavin   
  Date: 06/11/29 07:43:22

  Modified:    src/main/org/jboss/seam/interceptors 
                        ExceptionInterceptor.java
  Log:
  fix a bug and use event context instead of threadlocal
  
  Revision  Changes    Path
  1.14      +41 -21    jboss-seam/src/main/org/jboss/seam/interceptors/ExceptionInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ExceptionInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/ExceptionInterceptor.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -b -r1.13 -r1.14
  --- ExceptionInterceptor.java	29 Nov 2006 01:30:12 -0000	1.13
  +++ ExceptionInterceptor.java	29 Nov 2006 12:43:22 -0000	1.14
  @@ -1,6 +1,9 @@
  -//$Id: ExceptionInterceptor.java,v 1.13 2006/11/29 01:30:12 nrichards Exp $
  +// $Id: ExceptionInterceptor.java,v 1.14 2006/11/29 12:43:22 gavin Exp $
   package org.jboss.seam.interceptors;
   
  +import static org.jboss.seam.contexts.Contexts.getEventContext;
  +import static org.jboss.seam.contexts.Contexts.isEventContextActive;
  +
   import javax.faces.context.FacesContext;
   
   import org.jboss.seam.InterceptorType;
  @@ -10,30 +13,47 @@
   import org.jboss.seam.intercept.InvocationContext;
   
   /**
  - * Handles exceptions annotation @Redirect, @HttpError or @Render.
  + * Handles exceptions annotated @Redirect, @HttpError or
  + * @Render.
    * 
    * @author Gavin King
    */
  - at Interceptor(stateless=true, type=InterceptorType.CLIENT)
  + at Interceptor(stateless = true, type = InterceptorType.CLIENT)
   public class ExceptionInterceptor extends AbstractInterceptor
   {
  -    static ThreadLocal marker = new ThreadLocal();
  +
  +   private static final String OUTERMOST_EXCEPTION_INTERCEPTOR = "org.jboss.seam.outermostExceptionInterceptor";
   
       @AroundInvoke
       public Object handleExceptions(InvocationContext invocation) throws Exception
       {
  -        boolean outermost = marker.get() == null;
  -        marker.set(this);
  -        try  {
  +      boolean outermost = isEventContextActive() && 
  +                        getEventContext().get(OUTERMOST_EXCEPTION_INTERCEPTOR) == null;
  +      if (outermost)
  +      {
  +         getEventContext().set(OUTERMOST_EXCEPTION_INTERCEPTOR, true);
  +      }
  +      try
  +      {
               return invocation.proceed();
  -        } catch (Exception e) {
  -            if (outermost && FacesContext.getCurrentInstance()!=null) {
  +      }
  +      catch (Exception e)
  +      {
  +         if ( outermost && FacesContext.getCurrentInstance()!=null )
  +         {
                   return Exceptions.instance().handle(e);
  -            } else {
  +         }
  +         else
  +         {
                   throw e;
               }
  -        } finally {
  -            marker.remove();
  +      }
  +      finally
  +      {
  +         if (outermost) 
  +         {
  +            getEventContext().remove(OUTERMOST_EXCEPTION_INTERCEPTOR);
  +         }
           }
       }
   }
  
  
  



More information about the jboss-cvs-commits mailing list