Clover coverage report - Code Coverage for tapestry release 4.0-alpha-2
Coverage timestamp: Thu May 5 2005 09:57:44 EDT
file stats: LOC: 356   Methods: 39
NCLOC: 253   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
InfrastructureImpl.java 100% 96.1% 92.3% 95.4%
coverage coverage
 1   
 // Copyright 2004, 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.HashMap;
 18   
 import java.util.Iterator;
 19   
 import java.util.List;
 20   
 import java.util.Locale;
 21   
 import java.util.Map;
 22   
 
 23   
 import org.apache.hivemind.ApplicationRuntimeException;
 24   
 import org.apache.hivemind.ClassResolver;
 25   
 import org.apache.hivemind.ErrorLog;
 26   
 import org.apache.hivemind.Resource;
 27   
 import org.apache.hivemind.service.ThreadLocale;
 28   
 import org.apache.hivemind.util.Defense;
 29   
 import org.apache.tapestry.describe.HTMLDescriber;
 30   
 import org.apache.tapestry.engine.IPageSource;
 31   
 import org.apache.tapestry.engine.IPropertySource;
 32   
 import org.apache.tapestry.engine.IScriptSource;
 33   
 import org.apache.tapestry.engine.ISpecificationSource;
 34   
 import org.apache.tapestry.engine.state.ApplicationStateManager;
 35   
 import org.apache.tapestry.error.ExceptionPresenter;
 36   
 import org.apache.tapestry.error.RequestExceptionReporter;
 37   
 import org.apache.tapestry.listener.ListenerMapSource;
 38   
 import org.apache.tapestry.markup.MarkupWriterSource;
 39   
 import org.apache.tapestry.services.ComponentMessagesSource;
 40   
 import org.apache.tapestry.services.ComponentPropertySource;
 41   
 import org.apache.tapestry.services.DataSqueezer;
 42   
 import org.apache.tapestry.services.Infrastructure;
 43   
 import org.apache.tapestry.services.LinkFactory;
 44   
 import org.apache.tapestry.services.ObjectPool;
 45   
 import org.apache.tapestry.services.RequestCycleFactory;
 46   
 import org.apache.tapestry.services.ResetEventCoordinator;
 47   
 import org.apache.tapestry.services.ResponseRenderer;
 48   
 import org.apache.tapestry.services.ServiceMap;
 49   
 import org.apache.tapestry.services.TemplateSource;
 50   
 import org.apache.tapestry.spec.IApplicationSpecification;
 51   
 import org.apache.tapestry.web.WebContext;
 52   
 import org.apache.tapestry.web.WebContextResource;
 53   
 import org.apache.tapestry.web.WebRequest;
 54   
 import org.apache.tapestry.web.WebResponse;
 55   
 
 56   
 /**
 57   
  * Allows access to selected HiveMind services.
 58   
  * 
 59   
  * @author Howard Lewis Ship
 60   
  * @since 4.0
 61   
  */
 62   
 public class InfrastructureImpl implements Infrastructure
 63   
 {
 64   
     /**
 65   
      * List of {@link org.apache.tapestry.services.impl.InfrastructureContribution}.
 66   
      */
 67   
     private List _normalContributions;
 68   
 
 69   
     /**
 70   
      * List of {@link org.apache.tapestry.services.impl.InfrastructureContribution}.
 71   
      */
 72   
     private List _overrideContributions;
 73   
 
 74   
     private Map _properties = new HashMap();
 75   
 
 76   
     private boolean _initialized;
 77   
 
 78   
     private String _mode;
 79   
 
 80   
     private ErrorLog _errorLog;
 81   
 
 82   
     private ClassResolver _classResolver;
 83   
 
 84   
     private ThreadLocale _threadLocale;
 85   
 
 86  12
     public void setLocale(Locale locale)
 87   
     {
 88  12
         _threadLocale.setLocale(locale);
 89   
     }
 90   
 
 91  45
     public String getApplicationId()
 92   
     {
 93  45
         return (String) getProperty("applicationId");
 94   
     }
 95   
 
 96  403
     public IPropertySource getApplicationPropertySource()
 97   
     {
 98  403
         return (IPropertySource) getProperty("applicationPropertySource");
 99   
     }
 100   
 
 101  51
     public IApplicationSpecification getApplicationSpecification()
 102   
     {
 103  51
         return (IApplicationSpecification) getProperty("applicationSpecification");
 104   
     }
 105   
 
 106  152
     public ApplicationStateManager getApplicationStateManager()
 107   
     {
 108  152
         return (ApplicationStateManager) getProperty("applicationStateManager");
 109   
     }
 110   
 
 111  64
     public ClassResolver getClassResolver()
 112   
     {
 113  64
         return _classResolver;
 114   
     }
 115   
 
 116  45
     public ComponentMessagesSource getComponentMessagesSource()
 117   
     {
 118  45
         return (ComponentMessagesSource) getProperty("componentMessagesSource");
 119   
     }
 120   
 
 121  45
     public ComponentPropertySource getComponentPropertySource()
 122   
     {
 123  45
         return (ComponentPropertySource) getProperty("componentPropertySource");
 124   
     }
 125   
 
 126  45
     public String getContextPath()
 127   
     {
 128  45
         return getRequest().getContextPath();
 129   
     }
 130   
 
 131  45
     public Resource getContextRoot()
 132   
     {
 133  45
         WebContext context = (WebContext) getProperty("context");
 134   
 
 135  45
         return new WebContextResource(context, "/");
 136   
     }
 137   
 
 138  45
     public DataSqueezer getDataSqueezer()
 139   
     {
 140  45
         return (DataSqueezer) getProperty("dataSqueezer");
 141   
     }
 142   
 
 143  0
     public IPropertySource getGlobalPropertySource()
 144   
     {
 145  0
         return (IPropertySource) getProperty("globalPropertySource");
 146   
     }
 147   
 
 148  45
     public LinkFactory getLinkFactory()
 149   
     {
 150  45
         return (LinkFactory) getProperty("linkFactory");
 151   
     }
 152   
 
 153  0
     public ObjectPool getObjectPool()
 154   
     {
 155  0
         return (ObjectPool) getProperty("objectPool");
 156   
     }
 157   
 
 158  148
     public IPageSource getPageSource()
 159   
     {
 160  148
         return (IPageSource) getProperty("pageSource");
 161   
     }
 162   
 
 163  521
     public WebRequest getRequest()
 164   
     {
 165  521
         return (WebRequest) getProperty("request");
 166   
     }
 167   
 
 168  148
     public RequestCycleFactory getRequestCycleFactory()
 169   
     {
 170  148
         return (RequestCycleFactory) getProperty("requestCycleFactory");
 171   
     }
 172   
 
 173  33
     public RequestExceptionReporter getRequestExceptionReporter()
 174   
     {
 175  33
         return (RequestExceptionReporter) getProperty("requestExceptionReporter");
 176   
     }
 177   
 
 178  0
     public ResetEventCoordinator getResetEventCoordinator()
 179   
     {
 180  0
         return (ResetEventCoordinator) getProperty("resetEventCoordinator");
 181   
     }
 182   
 
 183  200
     public WebResponse getResponse()
 184   
     {
 185  200
         return (WebResponse) getProperty("response");
 186   
     }
 187   
 
 188  51
     public ResponseRenderer getResponseRenderer()
 189   
     {
 190  51
         return (ResponseRenderer) getProperty("responseRenderer");
 191   
     }
 192   
 
 193  5
     public IScriptSource getScriptSource()
 194   
     {
 195  5
         return (IScriptSource) getProperty("scriptSource");
 196   
     }
 197   
 
 198  237
     public ServiceMap getServiceMap()
 199   
     {
 200  237
         return (ServiceMap) getProperty("serviceMap");
 201   
     }
 202   
 
 203  45
     public ISpecificationSource getSpecificationSource()
 204   
     {
 205  45
         return (ISpecificationSource) getProperty("specificationSource");
 206   
     }
 207   
 
 208  45
     public TemplateSource getTemplateSource()
 209   
     {
 210  45
         return (TemplateSource) getProperty("templateSource");
 211   
     }
 212   
 
 213  376
     public String getOutputEncoding()
 214   
     {
 215  376
         return getApplicationPropertySource().getPropertyValue(
 216   
                 "org.apache.tapestry.output-encoding");
 217   
     }
 218   
 
 219  45
     public MarkupWriterSource getMarkupWriterSource()
 220   
     {
 221  45
         return (MarkupWriterSource) getProperty("markupWriterSource");
 222   
     }
 223   
 
 224  15
     public HTMLDescriber getHTMLDescriber()
 225   
     {
 226  15
         return (HTMLDescriber) getProperty("HTMLDescriber");
 227   
     }
 228   
 
 229  25
     public ExceptionPresenter getExceptionPresenter()
 230   
     {
 231  25
         return (ExceptionPresenter) getProperty("exceptionPresenter");
 232   
     }
 233   
 
 234  29
     public ListenerMapSource getListenerMapSource()
 235   
     {
 236  29
         return (ListenerMapSource) getProperty("listenerMapSource");
 237   
     }
 238   
 
 239  2429
     public Object getProperty(String propertyName)
 240   
     {
 241  2429
         Defense.notNull(propertyName, "propertyName");
 242   
 
 243  2429
         if (!_initialized)
 244  1
             throw new IllegalStateException(ImplMessages.infrastructureNotInitialized());
 245   
 
 246  2428
         Object result = _properties.get(propertyName);
 247   
 
 248  2428
         if (result == null)
 249  1
             throw new ApplicationRuntimeException(ImplMessages
 250   
                     .missingInfrastructureProperty(propertyName));
 251   
 
 252  2427
         return result;
 253   
     }
 254   
 
 255  52
     public synchronized void initialize(String mode)
 256   
     {
 257  52
         Defense.notNull(mode, "mode");
 258   
 
 259  52
         if (_initialized)
 260  1
             throw new IllegalStateException(ImplMessages.infrastructureAlreadyInitialized(
 261   
                     mode,
 262   
                     _mode));
 263   
 
 264  51
         Map normalByMode = buildMapFromContributions(_normalContributions, mode);
 265  51
         Map normal = buildMapFromContributions(_normalContributions, null);
 266  51
         Map overrideByMode = buildMapFromContributions(_overrideContributions, mode);
 267  51
         Map override = buildMapFromContributions(_overrideContributions, null);
 268   
 
 269  51
         addToProperties(overrideByMode);
 270  51
         addToProperties(override);
 271  51
         addToProperties(normalByMode);
 272  51
         addToProperties(normal);
 273   
 
 274  51
         _mode = mode;
 275  51
         _initialized = true;
 276   
     }
 277   
 
 278  204
     private Map buildMapFromContributions(List contributions, String mode)
 279   
     {
 280  204
         Map result = new HashMap();
 281   
 
 282  204
         Iterator i = contributions.iterator();
 283  204
         while (i.hasNext())
 284   
         {
 285  2356
             InfrastructureContribution ic = (InfrastructureContribution) i.next();
 286   
 
 287  2356
             if (!ic.matchesMode(mode))
 288  1179
                 continue;
 289   
 
 290  1177
             String propertyName = ic.getProperty();
 291   
 
 292  1177
             InfrastructureContribution existing = (InfrastructureContribution) result
 293   
                     .get(propertyName);
 294   
 
 295  1177
             if (existing != null)
 296   
             {
 297  1
                 _errorLog.error(ImplMessages.duplicateInfrastructureContribution(ic, existing
 298   
                         .getLocation()), ic.getLocation(), null);
 299  1
                 continue;
 300   
             }
 301   
 
 302  1176
             result.put(propertyName, ic);
 303   
         }
 304   
 
 305  204
         return result;
 306   
     }
 307   
 
 308   
     /**
 309   
      * Adds to the master set of properties contributed objects that don't match an already existing
 310   
      * key.
 311   
      * 
 312   
      * @param map
 313   
      *            map of {@link org.apache.tapestry.services.impl.InfrastructureContribution}keyed
 314   
      *            on property name (String).
 315   
      */
 316   
 
 317  204
     private void addToProperties(Map map)
 318   
     {
 319  204
         Iterator i = map.values().iterator();
 320  204
         while (i.hasNext())
 321   
         {
 322  1176
             InfrastructureContribution ic = (InfrastructureContribution) i.next();
 323  1176
             String propertyName = ic.getProperty();
 324   
 
 325  1176
             if (_properties.containsKey(propertyName))
 326  2
                 continue;
 327   
 
 328  1174
             _properties.put(propertyName, ic.getObject());
 329   
         }
 330   
     }
 331   
 
 332  45
     public void setClassResolver(ClassResolver classResolver)
 333   
     {
 334  45
         _classResolver = classResolver;
 335   
     }
 336   
 
 337  45
     public void setThreadLocale(ThreadLocale threadLocale)
 338   
     {
 339  45
         _threadLocale = threadLocale;
 340   
     }
 341   
 
 342  51
     public void setNormalContributions(List normalContributions)
 343   
     {
 344  51
         _normalContributions = normalContributions;
 345   
     }
 346   
 
 347  51
     public void setOverrideContributions(List overrideContributions)
 348   
     {
 349  51
         _overrideContributions = overrideContributions;
 350   
     }
 351   
 
 352  46
     public void setErrorLog(ErrorLog errorLog)
 353   
     {
 354  46
         _errorLog = errorLog;
 355   
     }
 356   
 }