Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2011, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jboss.seam.exception.control;
 
 import java.util.List;
 import java.util.Set;
 
 import  javax.enterprise.context.spi.CreationalContext;
 import  javax.enterprise.event.Event;
 import  javax.enterprise.event.Observes;
 import  javax.enterprise.inject.Any;
 import  javax.enterprise.inject.spi.BeanManager;
 
Observer of ExceptionToCatch events and handler dispatcher. All handlers are invoked from this class. This class is immutable.
 
 {
   
Observes the event, finds the correct exception handler(s) and invokes them.

Parameters:
eventException exception to be invoked
bm active bean manager
extension catch extension instance to obtain handlers
stackEvent Event for modifying the exception stack
Throws:
Throwable If a handler requests the exception to be re-thrown.
 
    @SuppressWarnings( { "unchecked""MethodWithMultipleLoops""ThrowableResultOfMethodCallIgnored" })
    public void executeHandlers(@Observes @Any ExceptionToCatch eventExceptionfinal BeanManager bm,
                                CatchExtension extension, Event<ExceptionStackstackEventthrows Throwable
    {
       final Stack<ThrowableunwrappedExceptions = new Stack<Throwable>();
       CreationalContext<Objectctx = null;
 
       Throwable throwException = null;
 
       try
       {
          ctx = bm.createCreationalContext(null);
 
          final Set<HandlerMethodprocessedHandlers = new HashSet<HandlerMethod>();
 
          final ExceptionStack stack = new ExceptionStack(eventException.getException());
 
          stackEvent.fire(stack); // Allow for modifying the exception stack
 
          // TODO: Clean this up so there's only the while and one for loop
          inbound_cause:
          while (stack.getCurrent() != null)
          {
 
             final List<HandlerMethodbreadthFirstHandlerMethods = new ArrayList<HandlerMethod>(
                   extension.getHandlersForExceptionType(stack.getCurrent().getClass(),
                         bmeventException.getQualifiers(), .));
 
             for (HandlerMethod handler : breadthFirstHandlerMethods)
             {
                if (!processedHandlers.contains(handler))
                {
                   final CaughtException breadthFirstEvent = new CaughtException(stacktrueeventException.isHandled());
                   handler.notify(breadthFirstEventbm);
 
                   if (!breadthFirstEvent.isUnmute())
                   {
                      processedHandlers.add(handler);
                   }
 
                   switch (breadthFirstEvent.getFlow())
                   {
                      case :
                         eventException.setHandled(true);
                         return;
                      case :
                         eventException.setHandled(true);
                         break;
                      case :
                         return;
                      case :
                        eventException.setHandled(true);
                        stack.advanceToNextCause();
                        continue inbound_cause;
                     case :
                        throwException = eventException.getException();
                        break;
                     case :
                        throwException = breadthFirstEvent.getThrowNewException();
                  }
               }
            }
            final List<HandlerMethoddepthFirstHandlerMethods = new ArrayList<HandlerMethod>(
                  extension.getHandlersForExceptionType(stack.getCurrent().getClass(),
                        bmeventException.getQualifiers(), .));
            // Reverse these so category handlers are last
            Collections.reverse(depthFirstHandlerMethods);
            for (HandlerMethod handler : depthFirstHandlerMethods)
            {
               if (!processedHandlers.contains(handler))
               {
                  final CaughtException depthFirstEvent = new CaughtException(stackfalseeventException.isHandled());
                  handler.notify(depthFirstEventbm);
                  if (!depthFirstEvent.isUnmute())
                  {
                     processedHandlers.add(handler);
                  }
                  switch (depthFirstEvent.getFlow())
                  {
                     case :
                        eventException.setHandled(true);
                        return;
                     case :
                        eventException.setHandled(true);
                        break;
                     case :
                        return;
                     case :
                        eventException.setHandled(true);
                        stack.advanceToNextCause();
                        continue inbound_cause;
                     case :
                        throwException = eventException.getException();
                        break;
                     case :
                        throwException = depthFirstEvent.getThrowNewException();
                  }
               }
            }
            stack.advanceToNextCause();
         }
         if (throwException != null)
         {
            throw throwException;
         }
      }
      finally
      {
         if (ctx != null)
         {
            ctx.release();
         }
      }
   }
New to GrepCode? Check out our FAQ X