2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

Coverage Report - org.apache.shale.view.faces.ViewActionListener
 
Classes in this File Line Coverage Branch Coverage Complexity
ViewActionListener
0% 
0% 
2
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to you under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.shale.view.faces;
 19  
 
 20  
 import javax.faces.context.FacesContext;
 21  
 import javax.faces.event.ActionEvent;
 22  
 import javax.faces.event.ActionListener;
 23  
 import org.apache.shale.view.Constants;
 24  
 import org.apache.shale.view.ExceptionHandler;
 25  
 
 26  
 /**
 27  
  * <p>Replacement for the default <code>ActionListener</code> implementation
 28  
  * used during the <em>Invoke Application</em> phase of the request processing
 29  
  * lifecycle.</p>
 30  
  *
 31  
  * @since 1.0.3
 32  
  *
 33  
  * $Id: ViewActionListener.java 464373 2006-10-16 04:21:54Z rahul $
 34  
  */
 35  
 public final class ViewActionListener implements ActionListener {
 36  
 
 37  
 
 38  
     // ------------------------------------------------------------- Constructor
 39  
 
 40  
 
 41  
     /**
 42  
      * <p>Create a new action listener instance.</p>
 43  
      *
 44  
      * @param original The original action listener instance we are wrapping
 45  
      */
 46  0
     public ViewActionListener(ActionListener original) {
 47  0
         this.original = original;
 48  0
     }
 49  
 
 50  
 
 51  
     // ------------------------------------------------------ Instance Variables
 52  
 
 53  
 
 54  
     /**
 55  
      * <p>The original <code>ActionListener</code> instance we are wrapping.</p>
 56  
      */
 57  0
     private ActionListener original = null;
 58  
 
 59  
 
 60  
     // -------------------------------------------------- ActionListener Methods
 61  
 
 62  
 
 63  
     /**
 64  
      * <p>Handle a default action event.</p>
 65  
      *
 66  
      * @param event The <code>ActionEvent</code> to be handled
 67  
      */
 68  
     public void processAction(ActionEvent event) {
 69  
 
 70  
         // FIXME - this is probably not the final answer, but gives
 71  
         // us a starting point to deal with application event handlers
 72  
         // throwing exceptions in a way consistent with elsewhere
 73  
         try {
 74  0
             original.processAction(event);
 75  0
         } catch (Exception e) {
 76  0
             handleException(FacesContext.getCurrentInstance(), e);
 77  0
         }
 78  
 
 79  0
     }
 80  
 
 81  
 
 82  
     // --------------------------------------------------------- Private Methods
 83  
 
 84  
 
 85  
     /**
 86  
      * <p>Handle the specified exception according to the strategy
 87  
      * defined by our current {@link ExceptionHandler}.</p>
 88  
      *
 89  
      * @param context FacesContext for the current request
 90  
      * @param exception Exception to be handled
 91  
      */
 92  
     private void handleException(FacesContext context, Exception exception) {
 93  
 
 94  0
         if (context == null) {
 95  0
             exception.printStackTrace(System.out);
 96  0
             return;
 97  
         }
 98  0
         ExceptionHandler handler = (ExceptionHandler)
 99  
           context.getApplication().getVariableResolver().resolveVariable
 100  
                 (context, Constants.EXCEPTION_HANDLER);
 101  0
         handler.handleException(exception);
 102  
 
 103  0
     }
 104  
 
 105  
 
 106  
 }