Coverage Report - org.apache.tapestry.error.ExceptionPresenterImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ExceptionPresenterImpl
82% 
100% 
1.5
 
 1  
 // Copyright 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.error;
 16  
 
 17  
 import org.apache.hivemind.ApplicationRuntimeException;
 18  
 import org.apache.hivemind.util.PropertyUtils;
 19  
 import org.apache.tapestry.IPage;
 20  
 import org.apache.tapestry.IRequestCycle;
 21  
 import org.apache.tapestry.services.ResponseRenderer;
 22  
 
 23  
 /**
 24  
  * @author Howard M. Lewis Ship
 25  
  * @since 4.0
 26  
  */
 27  2
 public class ExceptionPresenterImpl implements ExceptionPresenter
 28  
 {
 29  
 
 30  
     private RequestExceptionReporter _requestExceptionReporter;
 31  
 
 32  
     private ResponseRenderer _responseRenderer;
 33  
 
 34  
     private String _exceptionPageName;
 35  
 
 36  
     private boolean _verbose;
 37  
 
 38  
     public void presentException(IRequestCycle cycle, Throwable cause)
 39  
     {
 40  
         try
 41  
         {
 42  2
             IPage exceptionPage = cycle.getPage(_exceptionPageName);
 43  
             
 44  2
             PropertyUtils.write(exceptionPage, "exception", cause);
 45  
             
 46  2
             cycle.activate(exceptionPage);
 47  
 
 48  2
             _responseRenderer.renderResponse(cycle);
 49  
         }
 50  1
         catch (Throwable ex)
 51  
         {
 52  
             // Worst case scenario. The exception page itself is broken, leaving
 53  
             // us with no option but to write the cause to the output.
 54  
 
 55  1
             _requestExceptionReporter.reportRequestException(ErrorMessages
 56  
                     .unableToProcessClientRequest(cause), cause);
 57  
 
 58  
             // Also, write the exception thrown when redendering the exception
 59  
             // page, so that can get fixed as well.
 60  
 
 61  1
             _requestExceptionReporter.reportRequestException(ErrorMessages
 62  
                     .unableToPresentExceptionPage(ex), ex);
 63  
 
 64  
             // And throw the exception.
 65  
 
 66  1
             throw new ApplicationRuntimeException(ex.getMessage(), ex);
 67  1
         }
 68  
 
 69  1
         if (_verbose)
 70  0
             _requestExceptionReporter.reportRequestException(ErrorMessages
 71  
                     .unableToProcessClientRequest(cause), cause);
 72  1
     }
 73  
 
 74  
     public void setExceptionPageName(String exceptionPageName)
 75  
     {
 76  2
         _exceptionPageName = exceptionPageName;
 77  2
     }
 78  
 
 79  
     public void setRequestExceptionReporter(
 80  
             RequestExceptionReporter requestExceptionReporter)
 81  
     {
 82  1
         _requestExceptionReporter = requestExceptionReporter;
 83  1
     }
 84  
 
 85  
     public void setResponseRenderer(ResponseRenderer responseRenderer)
 86  
     {
 87  2
         _responseRenderer = responseRenderer;
 88  2
     }
 89  
 
 90  
     public boolean isVerbose()
 91  
     {
 92  0
         return _verbose;
 93  
     }
 94  
 
 95  
     public void setVerbose(boolean verbose)
 96  
     {
 97  0
         _verbose = verbose;
 98  0
     }
 99  
 }