Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 123   Methods: 8
NCLOC: 66   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RestartService.java 75% 94.1% 100% 93.1%
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.LinkFactory;
 29   
 30    /**
 31    * Restarts the Tapestry application. This is normally reserved for dealing with catastrophic
 32    * failures of the application. Discards the {@link javax.servlet.http.HttpSession}, if any, and
 33    * redirects to the Tapestry application servlet URL (invoking the {@link HomeService}).
 34    *
 35    * @author Howard Lewis Ship
 36    * @since 1.0.9
 37    */
 38   
 39    public class RestartService implements IEngineService
 40    {
 41    /** @since 4.0 */
 42    private Log _log;
 43   
 44    /** @since 4.0 */
 45    private HttpServletRequest _request;
 46   
 47    /** @since 4.0 */
 48    private HttpServletResponse _response;
 49   
 50    /** @since 4.0 */
 51    private LinkFactory _linkFactory;
 52   
 53    /** @since 4.0 */
 54    private String _servletPath;
 55   
 56  23 public ILink getLink(boolean post, Object parameter)
 57    {
 58  23 if (parameter != null)
 59  0 throw new IllegalArgumentException(EngineMessages.serviceNoParameter(this));
 60   
 61  23 Map parameters = new HashMap();
 62   
 63  23 return _linkFactory.constructLink(this, post, parameters, true);
 64    }
 65   
 66  3 public void service(IRequestCycle cycle) throws IOException
 67    {
 68  3 HttpSession session = _request.getSession(false);
 69   
 70  3 if (session != null)
 71    {
 72  2 try
 73    {
 74  2 session.invalidate();
 75    }
 76    catch (IllegalStateException ex)
 77    {
 78  1 _log.warn("Exception thrown invalidating HttpSession.", ex);
 79   
 80    // Otherwise, ignore it.
 81    }
 82    }
 83   
 84  3 String url = cycle.getAbsoluteURL(_servletPath);
 85   
 86  3 _response.sendRedirect(url);
 87    }
 88   
 89  39 public String getName()
 90    {
 91  39 return Tapestry.RESTART_SERVICE;
 92    }
 93   
 94    /** @since 4.0 */
 95  17 public void setLog(Log log)
 96    {
 97  17 _log = log;
 98    }
 99   
 100    /** @since 4.0 */
 101  19 public void setRequest(HttpServletRequest request)
 102    {
 103  19 _request = request;
 104    }
 105   
 106    /** @since 4.0 */
 107  19 public void setResponse(HttpServletResponse response)
 108    {
 109  19 _response = response;
 110    }
 111   
 112    /** @since 4.0 */
 113  16 public void setLinkFactory(LinkFactory linkFactory)
 114    {
 115  16 _linkFactory = linkFactory;
 116    }
 117   
 118    /** @since 4.0 */
 119  19 public void setServletPath(String servletPath)
 120    {
 121  19 _servletPath = servletPath;
 122    }
 123    }