Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 136   Methods: 9
NCLOC: 74   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.http.HttpServletRequest;
 22   
 import javax.servlet.http.HttpServletResponse;
 23   
 import javax.servlet.http.HttpSession;
 24   
 
 25   
 import org.apache.commons.logging.Log;
 26   
 import org.apache.tapestry.IRequestCycle;
 27   
 import org.apache.tapestry.Tapestry;
 28   
 import org.apache.tapestry.services.AbsoluteURLBuilder;
 29   
 import org.apache.tapestry.services.LinkFactory;
 30   
 import org.apache.tapestry.services.ServiceConstants;
 31   
 
 32   
 /**
 33   
  * Restarts the Tapestry application. This is normally reserved for dealing with catastrophic
 34   
  * failures of the application. Discards the {@link javax.servlet.http.HttpSession}, if any, and
 35   
  * redirects to the Tapestry application servlet URL (invoking the {@link HomeService}).
 36   
  * 
 37   
  * @author Howard Lewis Ship
 38   
  * @since 1.0.9
 39   
  */
 40   
 
 41   
 public class RestartService implements IEngineService
 42   
 {
 43   
     /** @since 4.0 */
 44   
     private Log _log;
 45   
 
 46   
     /** @since 4.0 */
 47   
     private HttpServletRequest _request;
 48   
 
 49   
     /** @since 4.0 */
 50   
     private HttpServletResponse _response;
 51   
 
 52   
     /** @since 4.0 */
 53   
     private AbsoluteURLBuilder _builder;
 54   
 
 55   
     /** @since 4.0 */
 56   
     private LinkFactory _linkFactory;
 57   
 
 58   
     /** @since 4.0 */
 59   
     private String _servletPath;
 60   
 
 61  28
     public ILink getLink(IRequestCycle cycle, Object parameter)
 62   
     {
 63  28
         if (parameter != null)
 64  0
             throw new IllegalArgumentException(EngineMessages.serviceNoParameter(this));
 65   
 
 66  28
         Map parameters = new HashMap();
 67   
 
 68  28
         parameters.put(ServiceConstants.SERVICE, Tapestry.RESTART_SERVICE);
 69   
 
 70  28
         return _linkFactory.constructLink(cycle, parameters, true);
 71   
     }
 72   
 
 73  3
     public void service(IRequestCycle cycle) throws IOException
 74   
     {
 75  3
         HttpSession session = _request.getSession();
 76   
 
 77  3
         if (session != null)
 78   
         {
 79  2
             try
 80   
             {
 81  2
                 session.invalidate();
 82   
             }
 83   
             catch (IllegalStateException ex)
 84   
             {
 85  1
                 _log.warn("Exception thrown invalidating HttpSession.", ex);
 86   
 
 87   
                 // Otherwise, ignore it.
 88   
             }
 89   
         }
 90   
 
 91  3
         String url = _builder.constructURL(cycle.getAbsoluteURL(_servletPath));
 92   
 
 93  3
         _response.sendRedirect(url);
 94   
     }
 95   
 
 96  19
     public String getName()
 97   
     {
 98  19
         return Tapestry.RESTART_SERVICE;
 99   
     }
 100   
 
 101   
     /** @since 4.0 */
 102  20
     public void setLog(Log log)
 103   
     {
 104  20
         _log = log;
 105   
     }
 106   
 
 107   
     /** @since 4.0 */
 108  22
     public void setRequest(HttpServletRequest request)
 109   
     {
 110  22
         _request = request;
 111   
     }
 112   
 
 113   
     /** @since 4.0 */
 114  22
     public void setBuilder(AbsoluteURLBuilder builder)
 115   
     {
 116  22
         _builder = builder;
 117   
     }
 118   
 
 119   
     /** @since 4.0 */
 120  22
     public void setResponse(HttpServletResponse response)
 121   
     {
 122  22
         _response = response;
 123   
     }
 124   
 
 125   
     /** @since 4.0 */
 126  19
     public void setLinkFactory(LinkFactory linkFactory)
 127   
     {
 128  19
         _linkFactory = linkFactory;
 129   
     }
 130   
 
 131   
     /** @since 4.0 */
 132  22
     public void setServletPath(String servletPath)
 133   
     {
 134  22
         _servletPath = servletPath;
 135   
     }
 136   
 }