Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 66   Methods: 3
NCLOC: 25   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PageClientPropertyPersistenceScope.java 100% 100% 100% 100%
coverage
 1    // Copyright 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.record;
 16   
 17    import org.apache.tapestry.IPage;
 18    import org.apache.tapestry.IRequestCycle;
 19    import org.apache.tapestry.engine.ServiceEncoding;
 20   
 21    /**
 22    * Defines the 'page' scope for persisting client properties. Persist the properties only if the
 23    * current page name is the same as that of the property.
 24    *
 25    * @author Mindbridge
 26    * @since 4.0
 27    * @see org.apache.tapestry.record.ClientPropertyPersistenceScope
 28    */
 29    public class PageClientPropertyPersistenceScope extends
 30    AbstractPrefixedClientPropertyPersistenceScope
 31    {
 32    private IRequestCycle _requestCycle;
 33   
 34  41 public PageClientPropertyPersistenceScope()
 35    {
 36  41 super("state:");
 37    }
 38   
 39    /**
 40    * Returns true if the active page name matches the page for this property. This means that
 41    * <em>after a new page has been activated</em>, the state is discarded.
 42    */
 43   
 44  5 public boolean shouldEncodeState(ServiceEncoding encoding, String pageName,
 45    PersistentPropertyData data)
 46    {
 47  5 IPage page = _requestCycle.getPage();
 48   
 49    // TAPESTRY-701: if you try to generate a link using, say, page or external service,
 50    // from inside PageValidateListener.pageValidate(), then there may not be an active
 51    // page yet. Seems like the right thing to do is hold onto any properties until
 52    // we know what the active page is. I know this one is going to cause a fight
 53    // since its not clear whether keeping or discarding is the right way to go.
 54   
 55  5 if (page == null)
 56  1 return true;
 57   
 58  4 return pageName.equals(page.getPageName());
 59    }
 60   
 61  38 public void setRequestCycle(IRequestCycle requestCycle)
 62    {
 63  38 _requestCycle = requestCycle;
 64    }
 65   
 66    }