Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package javax.faces.webapp;
 
 

This javax.faces.context.ExceptionHandlerFactory instance produces JSF 1.2 compatible javax.faces.context.ExceptionHandler instances. The javax.faces.context.ExceptionHandler.handle() method of the ExceptionHandler produced by this factory must meet the following requirements

Since:
2.0
 
 
 
     // ------------------------------------ Methods from ExceptionHandlerFactory
 

    

Returns:
a new javax.faces.context.ExceptionHandler that behaves in a fashion compatible with specifications prior to JavaServerFaces 1.2
        return new PreJsf2ExceptionHandler();
    }
    // ---------------------------------------------------------- Nested Classes


    
JSF 1.2-style ExceptionHandler implementation.
    private static final class PreJsf2ExceptionHandler extends ExceptionHandler {
        private static final Logger LOGGER =
              Logger.getLogger("javax.faces.webapp""javax.faces.LogStrings");
        private static final String LOG_BEFORE_KEY =
              "servere.webapp.prejsf2.exception.handler.log_before";
        private static final String LOG_AFTER_KEY =
              "servere.webapp.prejsf2.exception.handler.log_after";
        private static final String LOG_KEY =
              "servere.webapp.prejsf2.exception.handler.log";
        private ExceptionQueuedEvent handled;
        // ------------------------------------------- Methods from ExceptionHandler


        

See also:
ExceptionHandler@getHandledExceptionQueuedEvent()
            return ;
        }


        

Since:
2.0
        public void handle() throws FacesException {
            for (Iterator<ExceptionQueuedEventi = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) {
                ExceptionQueuedEvent event = i.next();
                ExceptionQueuedEventContext context =
                      (ExceptionQueuedEventContextevent.getSource();
                try {
                    Throwable t = context.getException();
                    if (isRethrown(t, (context.inBeforePhase() || context.inAfterPhase()))) {
                         = event;
                        Throwable unwrapped = getRootCause(t);
                        if (unwrapped != null) {
                            throw new FacesException(unwrapped.getMessage(), unwrapped);
                        } else {
                            if (t instanceof FacesException) {
                                throw (FacesExceptiont;
                            } else {
                                throw new FacesException(t.getMessage(), t);
                            }
                        }
                    } else {
                        log(context);
                    }
                } finally {
                    if ( == null) {
                         =
                              new LinkedList<ExceptionQueuedEvent>();
                    }
                    .add(event);
                    i.remove();
                }
            }
        }


        
        public boolean isListenerForSource(Object source) {
            return (source instanceof ExceptionQueuedEventContext);
        }


        
        public void processEvent(SystemEvent event)
              throws AbortProcessingException {
            if (event != null) {
                if ( == null) {
                     = new LinkedList<ExceptionQueuedEvent>();
                }
                .add((ExceptionQueuedEventevent);
            }
        }


        
        public Throwable getRootCause(Throwable t) {
            if (t == null) {
                return null;
            }
            if (shouldUnwrap(t.getClass())) {
                Throwable root = t.getCause();
                if (root != null) {
                    Throwable tmp = getRootCause(root);
                    if (tmp == null) {
                        return root;
                    } else {
                        return tmp;
                    }
                } else {
                    return t;
                }
            }
            return t;
        }


        
            return (( != null)
                    ? 
                    : Collections.<ExceptionQueuedEvent>emptyList());
        }


        
            return (( != null)
                    ? 
                    : Collections.<ExceptionQueuedEvent>emptyList());
        }
        // --------------------------------------------------------- Private Methods


        

Parameters:
c Throwable implementation class
Returns:
true if c is FacesException.class or ELException.class
        private boolean shouldUnwrap(Class<? extends Throwablec) {
            return (FacesException.class.equals(c) || ELException.class.equals(c));
        }
        private boolean isRethrown(Throwable tboolean isBeforeOrAfterPhase) {
            return (!isBeforeOrAfterPhase &&
                    !(t instanceof AbortProcessingException) &&
                    !(t instanceof UpdateModelException));
        }
        
        private void log(ExceptionQueuedEventContext exceptionContext) {
            Throwable t = exceptionContext.getException();
            UIComponent c = exceptionContext.getComponent();
            if (t instanceof UpdateModelException) {
                FacesContext context = FacesContext.getCurrentInstance();
                FacesMessage message = ((UpdateModelException)t).getFacesMessage();
                .log(.message.getSummary(), t.getCause());
                context.addMessage(c.getClientId(context), message);
            } else {
                boolean beforePhase = exceptionContext.inBeforePhase();
                boolean afterPhase = exceptionContext.inAfterPhase();
                PhaseId phaseId = exceptionContext.getPhaseId();
                String key = getLoggingKey(beforePhaseafterPhase);
                if (.isLoggable(.)) {
                    .log(.,
                            key,
                            new Object[]{t.getClass().getName(),
                                        phaseId.toString(),
                                        ((c != null)
                                         ? c.getClientId(exceptionContext.getContext())
                                         : ""),
                                        t.getMessage()});
                    .log(.t.getMessage(), t);
                }
            }
        }
        private String getLoggingKey(boolean beforePhaseboolean afterPhase) {
            if (beforePhase) {
                return ;
            } else if (afterPhase) {
                return ;
            } else {
                return ;
            }
        }
    } // END PreJsf2ExceptionHandler
    
New to GrepCode? Check out our FAQ X