Clover coverage report - Code Coverage for tapestry release 4.0-beta-10
Coverage timestamp: Sat Oct 8 2005 19:08:05 EDT
file stats: LOC: 88   Methods: 5
NCLOC: 40   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PageService.java - 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.hivemind.util.Defense;
 22    import org.apache.tapestry.IRequestCycle;
 23    import org.apache.tapestry.Tapestry;
 24    import org.apache.tapestry.services.LinkFactory;
 25    import org.apache.tapestry.services.ResponseRenderer;
 26    import org.apache.tapestry.services.ServiceConstants;
 27   
 28    /**
 29    * Basic server for creating a link to another page in the application.
 30    *
 31    * @author Howard Lewis Ship
 32    * @since 1.0.9
 33    */
 34   
 35    public class PageService implements IEngineService
 36    {
 37    /** @since 4.0 */
 38    private ResponseRenderer _responseRenderer;
 39   
 40    /** @since 4.0 */
 41    private LinkFactory _linkFactory;
 42   
 43  7 public ILink getLink(IRequestCycle cycle, boolean post, Object parameter)
 44    {
 45  7 Defense.isAssignable(parameter, String.class, "parameter");
 46   
 47  7 Map parameters = new HashMap();
 48   
 49  7 parameters.put(ServiceConstants.SERVICE, getName());
 50  7 parameters.put(ServiceConstants.PAGE, parameter);
 51   
 52  7 return _linkFactory.constructLink(cycle, post, parameters, true);
 53   
 54    }
 55   
 56  54 public void service(IRequestCycle cycle) throws IOException
 57    {
 58  54 String pageName = cycle.getParameter(ServiceConstants.PAGE);
 59   
 60    // At one time, the page service required a session, but that is no longer necessary.
 61    // Users can now bookmark pages within a Tapestry application. Pages
 62    // can implement validate() and throw a PageRedirectException if they don't
 63    // want to be accessed this way. For example, most applications have a concept
 64    // of a "login" and have a few pages that don't require the user to be logged in,
 65    // and other pages that do. The protected pages should redirect to a login page.
 66   
 67  54 cycle.activate(pageName);
 68   
 69  44 _responseRenderer.renderResponse(cycle);
 70    }
 71   
 72  36 public String getName()
 73    {
 74  36 return Tapestry.PAGE_SERVICE;
 75    }
 76   
 77    /** @since 4.0 */
 78  30 public void setResponseRenderer(ResponseRenderer responseRenderer)
 79    {
 80  30 _responseRenderer = responseRenderer;
 81    }
 82   
 83    /** @since 4.0 */
 84  30 public void setLinkFactory(LinkFactory linkFactory)
 85    {
 86  30 _linkFactory = linkFactory;
 87    }
 88    }