Coverage Report - org.trails.exception.ApplicationExceptionPresenterImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ApplicationExceptionPresenterImpl
0% 
0% 
3.5
 
 1  
 package org.trails.exception;
 2  
 
 3  
 import java.io.IOException;
 4  
 
 5  
 import org.apache.commons.logging.Log;
 6  
 import org.apache.commons.logging.LogFactory;
 7  
 import org.apache.tapestry.IPage;
 8  
 import org.apache.tapestry.IRequestCycle;
 9  
 import org.apache.tapestry.error.ExceptionPresenterImpl;
 10  
 import org.trails.exception.TrailsRuntimeException;
 11  
 import org.trails.page.PageResolver;
 12  
 import org.trails.page.PageType;
 13  
 
 14  
 /* kaosko 2007-06-18:
 15  
  * I would have really liked to implement the exception presenter only as a handler in pipeline
 16  
  * (as described at http://mail-archives.apache.org/mod_mbox/tapestry-dev/200606.mbox/%3C000a01c6906b$6ba3b8b0$6601a8c0@CARMANI9300%3E)
 17  
  * It required some changed in Hivemind core that were already implemented in Hivemind 1.1.2 which was never
 18  
  * released even though it apparently came very close. I've inquired about the status of 1.1.2 on Hivemind list
 19  
  */
 20  0
 public class ApplicationExceptionPresenterImpl extends ExceptionPresenterImpl {
 21  0
         private static final Log log = LogFactory.getLog(ApplicationExceptionPresenterImpl.class);
 22  
         private PageResolver pageResolver;
 23  
         
 24  
         public void presentException(IRequestCycle cycle, Throwable throwable) {
 25  0
                 if (throwable.getCause() == null || !(throwable.getCause() instanceof TrailsRuntimeException)) {
 26  0
                         super.presentException(cycle, throwable);
 27  0
                         return;
 28  
                 }
 29  0
                 TrailsRuntimeException trailsRuntimeException = (TrailsRuntimeException)throwable.getCause();
 30  
 
 31  0
                 if (log.isWarnEnabled())
 32  
                 {
 33  0
                         if (trailsRuntimeException.getEntityType() == null)
 34  
                         {
 35  0
                                 log.warn("Trails specific exception happened while handling unknown entity, caused by: " + throwable.getCause().getMessage());
 36  
                         } else
 37  
                         {
 38  0
                                 log.warn("Trails specific exception happened while handling entity type " + trailsRuntimeException.getEntityType().getName() + ", caused by: " + throwable.getCause().getMessage());
 39  
                         }
 40  
                 }
 41  0
                 log.debug("The problem was caused by: ", throwable.getCause());
 42  0
                 IPage page = pageResolver.resolvePage(cycle, trailsRuntimeException.getEntityType(), PageType.EXCEPTION);
 43  0
                 cycle.activate(page);
 44  
                 try {
 45  0
                         cycle.getResponseBuilder().renderResponse(cycle);
 46  0
                 } catch (IOException e) {
 47  0
                         log.error("Couldn't render a Trails specific error page because of : ", e);
 48  0
                         super.presentException(cycle, throwable);
 49  
                 }
 50  0
         }
 51  
 
 52  
         public void setPageResolver(PageResolver pageResolver) {
 53  0
                 this.pageResolver = pageResolver;
 54  0
         }
 55  
 }