Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 150   Methods: 9
NCLOC: 86   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClientPropertyPersistenceStrategy.java 91.7% 100% 100% 98.2%
coverage 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 java.util.Collection;
 18    import java.util.Collections;
 19    import java.util.HashMap;
 20    import java.util.Iterator;
 21    import java.util.List;
 22    import java.util.Map;
 23   
 24    import org.apache.hivemind.util.Defense;
 25    import org.apache.tapestry.engine.ServiceEncoding;
 26    import org.apache.tapestry.web.WebRequest;
 27   
 28    /**
 29    * Service tapestry.persist.ClientPropertyPersistenceStrategy. Encodes persistent page properties on
 30    * the client as query parameters.
 31    * <p>
 32    * Uses the threaded model.
 33    *
 34    * @author Howard M. Lewis Ship
 35    * @since 4.0
 36    * @see org.apache.tapestry.engine.ILink
 37    */
 38    public class ClientPropertyPersistenceStrategy implements PropertyPersistenceStrategy
 39    {
 40    /**
 41    * Keyed on page name (String), values are
 42    * {@link org.apache.tapestry.record.PersistentPropertyData}.
 43    */
 44    private final Map _data = new HashMap();
 45   
 46    private PersistentPropertyDataEncoder _encoder;
 47   
 48    private WebRequest _request;
 49   
 50    private ClientPropertyPersistenceScope _scope;
 51   
 52    /**
 53    * Initializer for this service, invoked every time a service instance is created. This
 54    * initializer pulls out of the request and query parameters whose prefix is "client:" and
 55    * expects them to be encoded {@link PersistentPropertyData}, which are stored internally.
 56    * Because the service model is threaded, this information is specific to a single request, and
 57    * will be discarded at the end of the request.
 58    */
 59   
 60  494 public void initializeService()
 61    {
 62  494 List names = _request.getParameterNames();
 63  494 Iterator i = names.iterator();
 64  494 while (i.hasNext())
 65    {
 66  1422 String name = (String) i.next();
 67   
 68  1422 if (!_scope.isParameterForScope(name))
 69  1414 continue;
 70   
 71  8 String pageName = _scope.extractPageName(name);
 72   
 73  8 String encoded = _request.getParameterValue(name);
 74   
 75  8 PersistentPropertyData data = new PersistentPropertyData(_encoder);
 76  8 data.storeEncoded(encoded);
 77   
 78  8 _data.put(pageName, data);
 79    }
 80    }
 81   
 82  2 public void store(String pageName, String idPath, String propertyName, Object newValue)
 83    {
 84  2 PersistentPropertyData data = (PersistentPropertyData) _data.get(pageName);
 85  2 if (data == null)
 86    {
 87  2 data = new PersistentPropertyData(_encoder);
 88  2 _data.put(pageName, data);
 89    }
 90   
 91  2 data.store(idPath, propertyName, newValue);
 92    }
 93   
 94  1058 public Collection getStoredChanges(String pageName)
 95    {
 96  1058 PersistentPropertyData data = (PersistentPropertyData) _data.get(pageName);
 97   
 98  1058 if (data == null)
 99  1054 return Collections.EMPTY_LIST;
 100   
 101  4 return data.getPageChanges();
 102    }
 103   
 104  2 public void discardStoredChanges(String pageName)
 105    {
 106  2 _data.remove(pageName);
 107    }
 108   
 109  676 public void addParametersForPersistentProperties(ServiceEncoding encoding, boolean post)
 110    {
 111  676 Defense.notNull(encoding, "encoding");
 112   
 113  676 Iterator i = _data.entrySet().iterator();
 114  676 while (i.hasNext())
 115    {
 116  6 Map.Entry e = (Map.Entry) i.next();
 117   
 118  6 String pageName = (String) e.getKey();
 119  6 PersistentPropertyData data = (PersistentPropertyData) e.getValue();
 120   
 121  6 ClientPropertyPersistenceScope scope = getScope();
 122   
 123  6 if (scope.shouldEncodeState(encoding, pageName, data))
 124    {
 125  4 String parameterName = _scope.constructParameterName(pageName);
 126  4 encoding.setParameterValue(parameterName, data.getEncoded());
 127    }
 128    }
 129    }
 130   
 131  494 public void setRequest(WebRequest request)
 132    {
 133  494 _request = request;
 134    }
 135   
 136  6 public ClientPropertyPersistenceScope getScope()
 137    {
 138  6 return _scope;
 139    }
 140   
 141  494 public void setScope(ClientPropertyPersistenceScope scope)
 142    {
 143  494 _scope = scope;
 144    }
 145   
 146  496 public void setEncoder(PersistentPropertyDataEncoder encoder)
 147    {
 148  496 _encoder = encoder;
 149    }
 150    }