Clover coverage report - Code Coverage for tapestry release 3.1-alpha-1
Coverage timestamp: Mon Feb 21 2005 09:16:14 EST
file stats: LOC: 144   Methods: 9
NCLOC: 77   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
RestartService.java 75% 94.7% 100% 93.8%
coverage coverage
 1   
 // Copyright 2004, 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.engine;
 16   
 
 17   
 import java.io.IOException;
 18   
 import java.util.HashMap;
 19   
 import java.util.Map;
 20   
 
 21   
 import javax.servlet.ServletException;
 22   
 import javax.servlet.http.HttpServletRequest;
 23   
 import javax.servlet.http.HttpServletResponse;
 24   
 import javax.servlet.http.HttpSession;
 25   
 
 26   
 import org.apache.commons.logging.Log;
 27   
 import org.apache.tapestry.IRequestCycle;
 28   
 import org.apache.tapestry.Tapestry;
 29   
 import org.apache.tapestry.request.ResponseOutputStream;
 30   
 import org.apache.tapestry.services.AbsoluteURLBuilder;
 31   
 import org.apache.tapestry.services.LinkFactory;
 32   
 import org.apache.tapestry.services.ServiceConstants;
 33   
 
 34   
 /**
 35   
  * Restarts the Tapestry application. This is normally reserved for dealing with catastrophic
 36   
  * failures of the application. Discards the {@link javax.servlet.http.HttpSession}, if any, and
 37   
  * redirects to the Tapestry application servlet URL (invoking the {@link HomeService}).
 38   
  * 
 39   
  * @author Howard Lewis Ship
 40   
  * @since 1.0.9
 41   
  */
 42   
 
 43   
 public class RestartService implements IEngineService
 44   
 {
 45   
     /** @since 3.1 */
 46   
     private Log _log;
 47   
 
 48   
     /** @since 3.1 */
 49   
     private HttpServletRequest _request;
 50   
 
 51   
     /** @since 3.1 */
 52   
     private HttpServletResponse _response;
 53   
 
 54   
     /** @since 3.1 */
 55   
     private AbsoluteURLBuilder _builder;
 56   
 
 57   
     /** @since 3.1 */
 58   
     private LinkFactory _linkFactory;
 59   
     
 60   
     /** @since 3.1 */    
 61   
     private String _servletPath;
 62   
 
 63  43
     public ILink getLink(IRequestCycle cycle, Object parameter)
 64   
     {
 65  43
         if (parameter != null)
 66  0
             throw new IllegalArgumentException(EngineMessages.serviceNoParameter(this));
 67   
 
 68  43
         Map parameters = new HashMap();
 69   
 
 70  43
         parameters.put(ServiceConstants.SERVICE, Tapestry.RESTART_SERVICE);
 71   
 
 72  43
         return _linkFactory.constructLink(cycle, parameters, true);
 73   
     }
 74   
 
 75  3
     public void service(IRequestCycle cycle, ResponseOutputStream output) throws ServletException,
 76   
             IOException
 77   
     {
 78  3
         HttpSession session = _request.getSession();
 79   
 
 80  3
         if (session != null)
 81   
         {
 82  2
             try
 83   
             {
 84  2
                 session.invalidate();
 85   
             }
 86   
             catch (IllegalStateException ex)
 87   
             {
 88  1
                 _log.warn("Exception thrown invalidating HttpSession.", ex);
 89   
 
 90   
                 // Otherwise, ignore it.
 91   
             }
 92   
         }
 93   
 
 94   
         // Make isStateful() return false, so that the servlet doesn't
 95   
         // try to store the engine back into the (now invalid) session.
 96   
         // TODO: How to get the EngineManager to *not* try and
 97   
         // store the engine back in the (now invalid) session.
 98   
 
 99  3
         String url = _builder.constructURL(_servletPath);
 100   
 
 101  3
         _response.sendRedirect(url);
 102   
     }
 103   
 
 104  52
     public String getName()
 105   
     {
 106  52
         return Tapestry.RESTART_SERVICE;
 107   
     }
 108   
 
 109   
     /** @since 3.1 */
 110  53
     public void setLog(Log log)
 111   
     {
 112  53
         _log = log;
 113   
     }
 114   
 
 115   
     /** @since 3.1 */
 116  55
     public void setRequest(HttpServletRequest request)
 117   
     {
 118  55
         _request = request;
 119   
     }
 120   
 
 121   
     /** @since 3.1 */
 122  55
     public void setBuilder(AbsoluteURLBuilder builder)
 123   
     {
 124  55
         _builder = builder;
 125   
     }
 126   
 
 127   
     /** @since 3.1 */
 128  55
     public void setResponse(HttpServletResponse response)
 129   
     {
 130  55
         _response = response;
 131   
     }
 132   
 
 133   
     /** @since 3.1 */
 134  52
     public void setLinkFactory(LinkFactory linkFactory)
 135   
     {
 136  52
         _linkFactory = linkFactory;
 137   
     }
 138   
     
 139   
     /** @since 3.1 */
 140  55
     public void setServletPath(String servletPath)
 141   
     {
 142  55
         _servletPath = servletPath;
 143   
     }
 144   
 }