Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 163   Methods: 8
NCLOC: 89   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
ServiceMapImpl.java 100% 100% 100% 100%
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.Map;
 21   
 
 22   
 import org.apache.hivemind.ApplicationRuntimeException;
 23   
 import org.apache.hivemind.ErrorLog;
 24   
 import org.apache.tapestry.engine.IEngineService;
 25   
 import org.apache.tapestry.services.ServiceMap;
 26   
 
 27   
 /**
 28   
  * Implementation of {@link org.apache.tapestry.services.ServiceMap}
 29   
  * 
 30   
  * @author Howard Lewis Ship
 31   
  * @since 4.0
 32   
  */
 33   
 public class ServiceMapImpl implements ServiceMap, EngineServiceSource
 34   
 {
 35   
     /**
 36   
      * List of {@link EngineServiceContribution}.
 37   
      */
 38   
     private List _applicationServices;
 39   
 
 40   
     /**
 41   
      * List of {@link EngineServiceContribution}.
 42   
      */
 43   
     private List _factoryServices;
 44   
 
 45   
     private ErrorLog _errorLog;
 46   
 
 47   
     /**
 48   
      * Map of {@link EngineServiceContribution} keyed on String name.
 49   
      */
 50   
     private Map _services;
 51   
 
 52   
     /**
 53   
      * Map of {@link org.apache.tapestry.services.impl.EngineServiceOuterProxy}, keyed on String
 54   
      * name.
 55   
      */
 56   
 
 57   
     private Map _proxies = new HashMap();
 58   
 
 59  51
     public void initializeService()
 60   
     {
 61  51
         Map factoryMap = buildServiceMap(_factoryServices);
 62  51
         Map applicationMap = buildServiceMap(_applicationServices);
 63   
 
 64   
         // Add services from the applicationMap to factoryMap, overwriting
 65   
         // factoryMap entries with the same name.
 66   
 
 67  51
         factoryMap.putAll(applicationMap);
 68   
 
 69  51
         _services = factoryMap;
 70   
     }
 71   
 
 72  102
     private Map buildServiceMap(List services)
 73   
     {
 74  102
         Map result = new HashMap();
 75   
 
 76  102
         Iterator i = services.iterator();
 77  102
         while (i.hasNext())
 78   
         {
 79  368
             EngineServiceContribution contribution = (EngineServiceContribution) i.next();
 80  368
             String name = contribution.getName();
 81   
 
 82  368
             EngineServiceContribution existing = (EngineServiceContribution) result.get(name);
 83   
 
 84  368
             if (existing != null)
 85   
             {
 86  1
                 _errorLog.error(
 87   
                         ImplMessages.dupeService(name, existing),
 88   
                         existing.getLocation(),
 89   
                         null);
 90  1
                 continue;
 91   
             }
 92   
 
 93  367
             result.put(name, contribution);
 94   
         }
 95   
 
 96  102
         return result;
 97   
     }
 98   
 
 99  369
     public synchronized IEngineService getService(String name)
 100   
     {
 101  369
         IEngineService result = (IEngineService) _proxies.get(name);
 102   
 
 103  369
         if (result == null)
 104   
         {
 105  167
             result = buildProxy(name);
 106  166
             _proxies.put(name, result);
 107   
         }
 108   
 
 109  368
         return result;
 110   
     }
 111   
 
 112   
     /**
 113   
      * This returns the actual service, not the outer proxy.
 114   
      */
 115   
 
 116  141
     public IEngineService resolveEngineService(String name)
 117   
     {
 118  141
         EngineServiceContribution contribution = (EngineServiceContribution) _services.get(name);
 119   
 
 120  141
         if (contribution == null)
 121  1
             throw new ApplicationRuntimeException(ImplMessages.noSuchService(name));
 122   
 
 123  140
         IEngineService service = contribution.getService();
 124  140
         String serviceName = service.getName();
 125   
 
 126  140
         if (!serviceName.equals(name))
 127  1
             throw new ApplicationRuntimeException(ImplMessages.serviceNameMismatch(
 128   
                     service,
 129   
                     name,
 130   
                     serviceName), contribution.getLocation(), null);
 131   
 
 132  139
         return service;
 133   
     }
 134   
 
 135  167
     private IEngineService buildProxy(String name)
 136   
     {
 137  167
         if (!_services.containsKey(name))
 138  1
             throw new ApplicationRuntimeException(ImplMessages.noSuchService(name));
 139   
 
 140  166
         EngineServiceOuterProxy outer = new EngineServiceOuterProxy(name);
 141   
 
 142  166
         EngineServiceInnerProxy inner = new EngineServiceInnerProxy(name, outer, this);
 143   
 
 144  166
         outer.installDelegate(inner);
 145   
 
 146  166
         return outer;
 147   
     }
 148   
 
 149  51
     public void setApplicationServices(List applicationServices)
 150   
     {
 151  51
         _applicationServices = applicationServices;
 152   
     }
 153   
 
 154  51
     public void setFactoryServices(List factoryServices)
 155   
     {
 156  51
         _factoryServices = factoryServices;
 157   
     }
 158   
 
 159  46
     public void setErrorLog(ErrorLog errorLog)
 160   
     {
 161  46
         _errorLog = errorLog;
 162   
     }
 163   
 }