Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 186   Methods: 13
NCLOC: 123   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ComponentPropertySourceImpl.java 100% 90.7% 92.3% 92.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.services.impl;
 16   
 17    import java.util.ArrayList;
 18    import java.util.HashMap;
 19    import java.util.List;
 20    import java.util.Locale;
 21    import java.util.Map;
 22   
 23    import org.apache.hivemind.Resource;
 24    import org.apache.hivemind.lib.chain.ChainBuilder;
 25    import org.apache.tapestry.IComponent;
 26    import org.apache.tapestry.INamespace;
 27    import org.apache.tapestry.engine.IPropertySource;
 28    import org.apache.tapestry.event.ResetEventListener;
 29    import org.apache.tapestry.services.ComponentPropertySource;
 30    import org.apache.tapestry.spec.IComponentSpecification;
 31    import org.apache.tapestry.util.PropertyHolderPropertySource;
 32   
 33    /**
 34    * Implementation of tapestry.props.ComponentPropertySource.
 35    * <p>
 36    * TODO: Figure out a testing strategy for this beast!
 37    *
 38    * @author Howard M. Lewis Ship
 39    * @since 4.0
 40    */
 41    public class ComponentPropertySourceImpl implements ComponentPropertySource, ResetEventListener
 42    {
 43    private IPropertySource _globalProperties;
 44   
 45    private ChainBuilder _chainBuilder;
 46   
 47    private Map _componentSources = new HashMap();
 48   
 49    private Map _localizedComponentSources = new HashMap();
 50   
 51    private Map _namespaceSources = new HashMap();
 52   
 53    private Map _localizedNamespaceSources = new HashMap();
 54   
 55  0 public synchronized void resetEventDidOccur()
 56    {
 57  0 _componentSources.clear();
 58  0 _localizedComponentSources.clear();
 59  0 _namespaceSources.clear();
 60  0 _localizedNamespaceSources.clear();
 61    }
 62   
 63  874 private synchronized IPropertySource getSourceForNamespace(INamespace namespace)
 64    {
 65  874 Resource key = namespace.getSpecificationLocation();
 66   
 67  874 IPropertySource result = (IPropertySource) _namespaceSources.get(key);
 68   
 69  874 if (result == null)
 70    {
 71  144 result = createSourceForNamespace(namespace);
 72  144 _namespaceSources.put(key, result);
 73    }
 74   
 75  874 return result;
 76    }
 77   
 78  2908 private synchronized IPropertySource getSourceForComponent(IComponent component)
 79    {
 80  2908 Resource key = component.getSpecification().getSpecificationLocation();
 81   
 82  2908 IPropertySource result = (IPropertySource) _componentSources.get(key);
 83   
 84  2908 if (result == null)
 85    {
 86  776 result = createSourceForComponent(component);
 87  776 _componentSources.put(key, result);
 88    }
 89   
 90  2908 return result;
 91    }
 92   
 93  398 private synchronized LocalizedPropertySource getLocalizedSourceForComponent(IComponent component)
 94    {
 95  398 Resource key = component.getSpecification().getSpecificationLocation();
 96   
 97  398 LocalizedPropertySource result = (LocalizedPropertySource) _localizedComponentSources
 98    .get(key);
 99   
 100  398 if (result == null)
 101    {
 102  282 result = new LocalizedPropertySource(getSourceForComponent(component));
 103   
 104  282 _localizedComponentSources.put(key, result);
 105    }
 106   
 107  398 return result;
 108    }
 109   
 110  40 private synchronized LocalizedPropertySource getLocalizedSourceForNamespace(INamespace namespace)
 111    {
 112  40 Resource key = namespace.getSpecificationLocation();
 113   
 114  40 LocalizedPropertySource result = (LocalizedPropertySource) _localizedNamespaceSources
 115    .get(key);
 116   
 117  40 if (result == null)
 118    {
 119  14 result = new LocalizedPropertySource(getSourceForNamespace(namespace));
 120   
 121  14 _localizedNamespaceSources.put(key, result);
 122    }
 123   
 124  40 return result;
 125    }
 126   
 127  776 private IPropertySource createSourceForComponent(IComponent component)
 128    {
 129  776 IComponentSpecification specification = component.getSpecification();
 130   
 131  776 List sources = new ArrayList();
 132   
 133  776 sources.add(new PropertyHolderPropertySource(specification));
 134  776 sources.add(getSourceForNamespace(component.getNamespace()));
 135   
 136  776 return (IPropertySource) _chainBuilder.buildImplementation(
 137    IPropertySource.class,
 138    sources,
 139    ImplMessages.componentPropertySourceDescription(specification));
 140    }
 141   
 142  144 private IPropertySource createSourceForNamespace(INamespace namespace)
 143    {
 144  144 List sources = new ArrayList();
 145   
 146  144 sources.add(new PropertyHolderPropertySource(namespace.getSpecification()));
 147  144 sources.add(_globalProperties);
 148   
 149  144 return (IPropertySource) _chainBuilder.buildImplementation(
 150    IPropertySource.class,
 151    sources,
 152    ImplMessages.namespacePropertySourceDescription(namespace));
 153    }
 154   
 155  2626 public String getComponentProperty(IComponent component, String propertyName)
 156    {
 157  2626 return getSourceForComponent(component).getPropertyValue(propertyName);
 158    }
 159   
 160  398 public String getLocalizedComponentProperty(IComponent component, Locale locale,
 161    String propertyName)
 162    {
 163  398 return getLocalizedSourceForComponent(component).getPropertyValue(propertyName, locale);
 164    }
 165   
 166  84 public String getNamespaceProperty(INamespace namespace, String propertyName)
 167    {
 168  84 return getSourceForNamespace(namespace).getPropertyValue(propertyName);
 169    }
 170   
 171  40 public String getLocalizedNamespaceProperty(INamespace namespace, Locale locale,
 172    String propertyName)
 173    {
 174  40 return getLocalizedSourceForNamespace(namespace).getPropertyValue(propertyName, locale);
 175    }
 176   
 177  78 public void setChainBuilder(ChainBuilder chainBuilder)
 178    {
 179  78 _chainBuilder = chainBuilder;
 180    }
 181   
 182  78 public void setGlobalProperties(IPropertySource globalProperties)
 183    {
 184  78 _globalProperties = globalProperties;
 185    }
 186    }