Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
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  247 public void initializeService()
 61    {
 62  247 List names = _request.getParameterNames();
 63  247 Iterator i = names.iterator();
 64  247 while (i.hasNext())
 65    {
 66  711 String name = (String) i.next();
 67   
 68  711 if (!_scope.isParameterForScope(name))
 69  707 continue;
 70   
 71  4 String pageName = _scope.extractPageName(name);
 72   
 73  4 String encoded = _request.getParameterValue(name);
 74   
 75  4 PersistentPropertyData data = new PersistentPropertyData(_encoder);
 76  4 data.storeEncoded(encoded);
 77   
 78  4 _data.put(pageName, data);
 79    }
 80    }
 81   
 82  1 public void store(String pageName, String idPath, String propertyName, Object newValue)
 83    {
 84  1 PersistentPropertyData data = (PersistentPropertyData) _data.get(pageName);
 85  1 if (data == null)
 86    {
 87  1 data = new PersistentPropertyData(_encoder);
 88  1 _data.put(pageName, data);
 89    }
 90   
 91  1 data.store(idPath, propertyName, newValue);
 92    }
 93   
 94  529 public Collection getStoredChanges(String pageName)
 95    {
 96  529 PersistentPropertyData data = (PersistentPropertyData) _data.get(pageName);
 97   
 98  529 if (data == null)
 99  527 return Collections.EMPTY_LIST;
 100   
 101  2 return data.getPageChanges();
 102    }
 103   
 104  1 public void discardStoredChanges(String pageName)
 105    {
 106  1 _data.remove(pageName);
 107    }
 108   
 109  338 public void addParametersForPersistentProperties(ServiceEncoding encoding, boolean post)
 110    {
 111  338 Defense.notNull(encoding, "encoding");
 112   
 113  338 Iterator i = _data.entrySet().iterator();
 114  338 while (i.hasNext())
 115    {
 116  3 Map.Entry e = (Map.Entry) i.next();
 117   
 118  3 String pageName = (String) e.getKey();
 119  3 PersistentPropertyData data = (PersistentPropertyData) e.getValue();
 120   
 121  3 ClientPropertyPersistenceScope scope = getScope();
 122   
 123  3 if (scope.shouldEncodeState(encoding, pageName, data))
 124    {
 125  2 String parameterName = _scope.constructParameterName(pageName);
 126  2 encoding.setParameterValue(parameterName, data.getEncoded());
 127    }
 128    }
 129    }
 130   
 131  247 public void setRequest(WebRequest request)
 132    {
 133  247 _request = request;
 134    }
 135   
 136  3 public ClientPropertyPersistenceScope getScope()
 137    {
 138  3 return _scope;
 139    }
 140   
 141  247 public void setScope(ClientPropertyPersistenceScope scope)
 142    {
 143  247 _scope = scope;
 144    }
 145   
 146  248 public void setEncoder(PersistentPropertyDataEncoder encoder)
 147    {
 148  248 _encoder = encoder;
 149    }
 150    }