Clover coverage report - Code Coverage for tapestry release 4.0-rc-2
Coverage timestamp: Sat Dec 17 2005 09:39:46 PST
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  437 private synchronized IPropertySource getSourceForNamespace(INamespace namespace)
 64    {
 65  437 Resource key = namespace.getSpecificationLocation();
 66   
 67  437 IPropertySource result = (IPropertySource) _namespaceSources.get(key);
 68   
 69  437 if (result == null)
 70    {
 71  72 result = createSourceForNamespace(namespace);
 72  72 _namespaceSources.put(key, result);
 73    }
 74   
 75  437 return result;
 76    }
 77   
 78  1454 private synchronized IPropertySource getSourceForComponent(IComponent component)
 79    {
 80  1454 Resource key = component.getSpecification().getSpecificationLocation();
 81   
 82  1454 IPropertySource result = (IPropertySource) _componentSources.get(key);
 83   
 84  1454 if (result == null)
 85    {
 86  388 result = createSourceForComponent(component);
 87  388 _componentSources.put(key, result);
 88    }
 89   
 90  1454 return result;
 91    }
 92   
 93  199 private synchronized LocalizedPropertySource getLocalizedSourceForComponent(IComponent component)
 94    {
 95  199 Resource key = component.getSpecification().getSpecificationLocation();
 96   
 97  199 LocalizedPropertySource result = (LocalizedPropertySource) _localizedComponentSources
 98    .get(key);
 99   
 100  199 if (result == null)
 101    {
 102  141 result = new LocalizedPropertySource(getSourceForComponent(component));
 103   
 104  141 _localizedComponentSources.put(key, result);
 105    }
 106   
 107  199 return result;
 108    }
 109   
 110  20 private synchronized LocalizedPropertySource getLocalizedSourceForNamespace(INamespace namespace)
 111    {
 112  20 Resource key = namespace.getSpecificationLocation();
 113   
 114  20 LocalizedPropertySource result = (LocalizedPropertySource) _localizedNamespaceSources
 115    .get(key);
 116   
 117  20 if (result == null)
 118    {
 119  7 result = new LocalizedPropertySource(getSourceForNamespace(namespace));
 120   
 121  7 _localizedNamespaceSources.put(key, result);
 122    }
 123   
 124  20 return result;
 125    }
 126   
 127  388 private IPropertySource createSourceForComponent(IComponent component)
 128    {
 129  388 IComponentSpecification specification = component.getSpecification();
 130   
 131  388 List sources = new ArrayList();
 132   
 133  388 sources.add(new PropertyHolderPropertySource(specification));
 134  388 sources.add(getSourceForNamespace(component.getNamespace()));
 135   
 136  388 return (IPropertySource) _chainBuilder.buildImplementation(
 137    IPropertySource.class,
 138    sources,
 139    ImplMessages.componentPropertySourceDescription(specification));
 140    }
 141   
 142  72 private IPropertySource createSourceForNamespace(INamespace namespace)
 143    {
 144  72 List sources = new ArrayList();
 145   
 146  72 sources.add(new PropertyHolderPropertySource(namespace.getSpecification()));
 147  72 sources.add(_globalProperties);
 148   
 149  72 return (IPropertySource) _chainBuilder.buildImplementation(
 150    IPropertySource.class,
 151    sources,
 152    ImplMessages.namespacePropertySourceDescription(namespace));
 153    }
 154   
 155  1313 public String getComponentProperty(IComponent component, String propertyName)
 156    {
 157  1313 return getSourceForComponent(component).getPropertyValue(propertyName);
 158    }
 159   
 160  199 public String getLocalizedComponentProperty(IComponent component, Locale locale,
 161    String propertyName)
 162    {
 163  199 return getLocalizedSourceForComponent(component).getPropertyValue(propertyName, locale);
 164    }
 165   
 166  42 public String getNamespaceProperty(INamespace namespace, String propertyName)
 167    {
 168  42 return getSourceForNamespace(namespace).getPropertyValue(propertyName);
 169    }
 170   
 171  20 public String getLocalizedNamespaceProperty(INamespace namespace, Locale locale,
 172    String propertyName)
 173    {
 174  20 return getLocalizedSourceForNamespace(namespace).getPropertyValue(propertyName, locale);
 175    }
 176   
 177  39 public void setChainBuilder(ChainBuilder chainBuilder)
 178    {
 179  39 _chainBuilder = chainBuilder;
 180    }
 181   
 182  39 public void setGlobalProperties(IPropertySource globalProperties)
 183    {
 184  39 _globalProperties = globalProperties;
 185    }
 186    }