Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 120   Methods: 8
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ResetService.java 100% 100% 100% 100%
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 org.apache.tapestry.IRequestCycle;
 22    import org.apache.tapestry.Tapestry;
 23    import org.apache.tapestry.services.LinkFactory;
 24    import org.apache.tapestry.services.ResetEventHub;
 25    import org.apache.tapestry.services.ResponseRenderer;
 26    import org.apache.tapestry.services.ServiceConstants;
 27   
 28    /**
 29    * ServiceLink used to discard all cached data (templates, specifications, et cetera). This is
 30    * primarily used during development. It could be a weakness of a Tapestry application, making it
 31    * susceptible to denial of service attacks, which is why it is disabled by default. The link
 32    * generated by the ResetService redisplays the current page after discarding all data.
 33    *
 34    * @author Howard Lewis Ship
 35    * @since 1.0.9
 36    */
 37   
 38    public class ResetService implements IEngineService
 39    {
 40    /** @since 4.0 */
 41   
 42    private ResponseRenderer _responseRenderer;
 43   
 44    /** @since 4.0 */
 45   
 46    private ResetEventHub _resetEventHub;
 47   
 48    /** @since 4.0 */
 49    private boolean _enabled;
 50   
 51    /** @since 4.0 */
 52   
 53    private LinkFactory _linkFactory;
 54   
 55    /** @since 4.0 */
 56    private IRequestCycle _requestCycle;
 57   
 58  8 public ILink getLink(boolean post, Object parameter)
 59    {
 60  8 if (parameter != null)
 61  2 throw new IllegalArgumentException(EngineMessages.serviceNoParameter(this));
 62   
 63  6 Map parameters = new HashMap();
 64   
 65  6 parameters.put(ServiceConstants.PAGE, _requestCycle.getPage().getPageName());
 66   
 67  6 return _linkFactory.constructLink(this, post, parameters, true);
 68    }
 69   
 70  10 public String getName()
 71    {
 72  10 return Tapestry.RESET_SERVICE;
 73    }
 74   
 75  4 public void service(IRequestCycle cycle) throws IOException
 76    {
 77  4 String pageName = cycle.getParameter(ServiceConstants.PAGE);
 78   
 79  4 if (_enabled)
 80  2 _resetEventHub.fireResetEvent();
 81   
 82  4 cycle.activate(pageName);
 83   
 84    // Render the same page (that contained the reset link).
 85   
 86  4 _responseRenderer.renderResponse(cycle);
 87    }
 88   
 89    /** @since 4.0 */
 90  6 public void setResponseRenderer(ResponseRenderer responseRenderer)
 91    {
 92  6 _responseRenderer = responseRenderer;
 93    }
 94   
 95    /** @since 4.0 */
 96   
 97  6 public void setResetEventHub(ResetEventHub resetEventHub)
 98    {
 99  6 _resetEventHub = resetEventHub;
 100    }
 101   
 102    /** @since 4.0 */
 103   
 104  6 public void setEnabled(boolean enabled)
 105    {
 106  6 _enabled = enabled;
 107    }
 108   
 109    /** @since 4.0 */
 110  4 public void setLinkFactory(LinkFactory linkFactory)
 111    {
 112  4 _linkFactory = linkFactory;
 113    }
 114   
 115    /** @since 4.0 */
 116  4 public void setRequestCycle(IRequestCycle requestCycle)
 117    {
 118  4 _requestCycle = requestCycle;
 119    }
 120    }