Coverage Report - org.apache.tapestry.error.ExceptionPresenterImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ExceptionPresenterImpl
0%
0/22
0%
0/2
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  0
 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  0
             IPage exceptionPage = cycle.getPage(_exceptionPageName);
 43  
             
 44  0
             PropertyUtils.write(exceptionPage, "exception", cause);
 45  
             
 46  0
             cycle.activate(exceptionPage);
 47  
 
 48  0
             _responseRenderer.renderResponse(cycle);
 49  
         }
 50  0
         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  0
             _requestExceptionReporter.reportRequestException(ErrorMessages.unableToProcessClientRequest(cause), cause);
 56  
 
 57  
             // Also, write the exception thrown when redendering the exception
 58  
             // page, so that can get fixed as well.
 59  
 
 60  0
             _requestExceptionReporter.reportRequestException(ErrorMessages.unableToPresentExceptionPage(ex), ex);
 61  
 
 62  
             // And throw the exception.
 63  
 
 64  0
             throw new ApplicationRuntimeException(ex.getMessage(), ex);
 65  0
         }
 66  
 
 67  0
         if (_verbose)
 68  0
             _requestExceptionReporter.reportRequestException(ErrorMessages.unableToProcessClientRequest(cause), cause);
 69  0
     }
 70  
 
 71  
     public void setExceptionPageName(String exceptionPageName)
 72  
     {
 73  0
         _exceptionPageName = exceptionPageName;
 74  0
     }
 75  
 
 76  
     public void setRequestExceptionReporter(
 77  
             RequestExceptionReporter requestExceptionReporter)
 78  
     {
 79  0
         _requestExceptionReporter = requestExceptionReporter;
 80  0
     }
 81  
 
 82  
     public void setResponseRenderer(ResponseRenderer responseRenderer)
 83  
     {
 84  0
         _responseRenderer = responseRenderer;
 85  0
     }
 86  
 
 87  
     public boolean isVerbose()
 88  
     {
 89  0
         return _verbose;
 90  
     }
 91  
 
 92  
     public void setVerbose(boolean verbose)
 93  
     {
 94  0
         _verbose = verbose;
 95  0
     }
 96  
 }