Clover coverage report - Code Coverage for hivemind release 1.0-beta-2
Coverage timestamp: Sun Aug 1 2004 14:03:45 EDT
file stats: LOC: 744   Methods: 24
NCLOC: 439   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
RegistryBuilder.java 83.7% 87.3% 100% 87.3%
coverage coverage
 1   
 //  Copyright 2004 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.hivemind.impl;
 16   
 
 17   
 import java.io.IOException;
 18   
 import java.net.URL;
 19   
 import java.util.ArrayList;
 20   
 import java.util.Collection;
 21   
 import java.util.Enumeration;
 22   
 import java.util.HashMap;
 23   
 import java.util.Iterator;
 24   
 import java.util.List;
 25   
 import java.util.Locale;
 26   
 import java.util.Map;
 27   
 
 28   
 import org.apache.commons.logging.Log;
 29   
 import org.apache.commons.logging.LogFactory;
 30   
 import org.apache.hivemind.ApplicationRuntimeException;
 31   
 import org.apache.hivemind.ClassResolver;
 32   
 import org.apache.hivemind.ErrorHandler;
 33   
 import org.apache.hivemind.HiveMind;
 34   
 import org.apache.hivemind.Occurances;
 35   
 import org.apache.hivemind.Registry;
 36   
 import org.apache.hivemind.Resource;
 37   
 import org.apache.hivemind.ShutdownCoordinator;
 38   
 import org.apache.hivemind.internal.Module;
 39   
 import org.apache.hivemind.parse.ConfigurationPointDescriptor;
 40   
 import org.apache.hivemind.parse.ContributionDescriptor;
 41   
 import org.apache.hivemind.parse.DescriptorParser;
 42   
 import org.apache.hivemind.parse.ImplementationDescriptor;
 43   
 import org.apache.hivemind.parse.InstanceBuilder;
 44   
 import org.apache.hivemind.parse.InterceptorDescriptor;
 45   
 import org.apache.hivemind.parse.ModuleDescriptor;
 46   
 import org.apache.hivemind.parse.ServicePointDescriptor;
 47   
 import org.apache.hivemind.util.IdUtils;
 48   
 import org.apache.hivemind.util.URLResource;
 49   
 
 50   
 /**
 51   
  * Class used to build a {@link org.apache.hivemind.Registry} from individual
 52   
  * {@link org.apache.hivemind.parse.ModuleDescriptor}.  The descriptors
 53   
  * are processed one at a time and the registry is constructed using a single call
 54   
  * to {@link #constructRegistry(Locale)} at the end.
 55   
  * 
 56   
  * <p>
 57   
  * A note about threadsafety: The assumption is that a single thread will access the RegistryBuilder
 58   
  * at one time (typically, a startup class within some form of server or application).  Code
 59   
  * here and in many of the related classes is divided into construction-time logic
 60   
  * and runtime logic.  Runtime logic is synchronized and threadsafe.  Construction-time logic
 61   
  * is not threadsafe.  Methods such as {@link org.apache.hivemind.impl.RegistryImpl#addModule(Module)},
 62   
  * {@link org.apache.hivemind.impl.ModuleImpl#addConfigurationPoint(ConfigurationPoint)},
 63   
  * {@link org.apache.hivemind.impl.ConfigurationPointImpl#addContribution(Contribution)}
 64   
  * and the like are construction-time.  Once the registry is fully constructed, it is not
 65   
  * allowed to invoke those methods (though, at this time, no checks occur).
 66   
  * 
 67   
  * <p>Runtime methods, such as {@link org.apache.hivemind.impl.ModuleImpl#getService(String, Class)}
 68   
  * are fully threadsafe. 
 69   
  *
 70   
  * @author Howard Lewis Ship
 71   
  */
 72   
 public final class RegistryBuilder
 73   
 {
 74   
     private static final Log LOG = LogFactory.getLog(RegistryBuilder.class);
 75   
 
 76   
     static {
 77  1
         if (!LOG.isErrorEnabled())
 78   
         {
 79  0
             System.err.println(
 80   
                 "********************************************************************************");
 81  0
             System.err.println(
 82   
                 "* L O G G I N G   C O N F I G U R A T I O N   E R R O R                        *");
 83  0
             System.err.println(
 84   
                 "* ---------------------------------------------------------------------------- *");
 85  0
             System.err.println(
 86   
                 "* Logging is not enabled for org.apache.hivemind.impl.RegistryBuilder.         *");
 87  0
             System.err.println(
 88   
                 "* Errors during HiveMind module descriptor parsing and validation may not be   *");
 89  0
             System.err.println(
 90   
                 "* logged. This may result in difficult-to-trace runtime exceptions, if there   *");
 91  0
             System.err.println(
 92   
                 "* are errors in any of your module descriptors. You should enable error        *");
 93  0
             System.err.println(
 94   
                 "* logging for the org.apache.hivemind and hivemind loggers.                    *");
 95  0
             System.err.println(
 96   
                 "********************************************************************************");
 97   
         }
 98   
     }
 99   
 
 100   
     /**
 101   
      * The path, within a JAR or the classpath, to the XML HiveMind module
 102   
      * deployment descriptor: <code>META-INF/hivemodule.xml</code>.
 103   
      */
 104   
     public static final String HIVE_MODULE_XML = "META-INF/hivemodule.xml";
 105   
 
 106   
     /**
 107   
      * The path, within a JAR or the classpath, to the SDL HiveMind module
 108   
      * deployment descriptor: <code>META-INF/hivemodule.sdl</code>.
 109   
      */
 110   
 
 111   
     public static final String HIVE_MODULE_SDL = "META-INF/hivemodule.sdl";
 112   
 
 113   
     /**
 114   
      * List of {@link ModuleDescriptor}.
 115   
      */
 116   
 
 117   
     private List _moduleDescriptors = new ArrayList();
 118   
 
 119   
     /**
 120   
      * Map of {@link ModuleImpl} keyed on fully qualified module id.
 121   
      */
 122   
     private Map _modules = new HashMap();
 123   
 
 124   
     /**
 125   
      * Map of {@link PrimitiveServiceModel} (or subclass) keyed on fully qualified id.
 126   
      */
 127   
 
 128   
     private Map _servicePoints = new HashMap();
 129   
 
 130   
     /**
 131   
      * Map of {@link ConfigurationPointImpl} keyed on fully qualified id.
 132   
      */
 133   
 
 134   
     private Map _configurationPoints = new HashMap();
 135   
 
 136   
     /**
 137   
      * Delegate used for handling errors.
 138   
      */
 139   
 
 140   
     private ErrorHandler _errorHandler;
 141   
 
 142   
     /**
 143   
      * Parser instance used by all parsing for this builder.
 144   
      */
 145   
     private DescriptorParser _parser;
 146   
 
 147   
     /**
 148   
      * Shutdown coordinator shared by all objects.
 149   
      */
 150   
 
 151   
     private ShutdownCoordinator _shutdownCoordinator = new ShutdownCoordinatorImpl();
 152   
 
 153   
     /**
 154   
      * RegistryAssembly used by the module descriptor parser(s).
 155   
      */
 156   
 
 157   
     private RegistryAssemblyImpl _registryAssembly;
 158   
 
 159  83
     public RegistryBuilder()
 160   
     {
 161  83
         this(new DefaultErrorHandler());
 162   
     }
 163   
 
 164  83
     public RegistryBuilder(ErrorHandler handler)
 165   
     {
 166  83
         _errorHandler = handler;
 167   
 
 168  83
         _registryAssembly = new RegistryAssemblyImpl(handler);
 169   
     }
 170   
 
 171   
     /**
 172   
      * Processes all modules that can be found using the resolver.
 173   
      */
 174  83
     public void processModules(ClassResolver resolver)
 175   
     {
 176  83
         if (LOG.isDebugEnabled())
 177  9
             LOG.debug("Processing modules visible to " + resolver);
 178   
 
 179  83
         processModulesResources(resolver, HIVE_MODULE_SDL);
 180  83
         processModulesResources(resolver, HIVE_MODULE_XML);
 181   
     }
 182   
 
 183   
     /**
 184   
      * Locates module deployment descriptors in the "standard" location (META-INF).
 185   
      * We support two formats, Simple Data Language (SDL) and XML.
 186   
      */
 187  166
     private void processModulesResources(ClassResolver resolver, String resourcePath)
 188   
     {
 189  166
         ClassLoader loader = resolver.getClassLoader();
 190  166
         Enumeration e = null;
 191   
 
 192  166
         try
 193   
         {
 194  166
             e = loader.getResources(resourcePath);
 195   
         }
 196   
         catch (IOException ex)
 197   
         {
 198  0
             throw new ApplicationRuntimeException(
 199   
                 ImplMessages.unableToFindModules(resolver, ex),
 200   
                 ex);
 201   
         }
 202   
 
 203  166
         while (e.hasMoreElements())
 204   
         {
 205  84
             URL descriptorURL = (URL) e.nextElement();
 206  84
             Resource descriptorResource = new URLResource(descriptorURL);
 207   
 
 208  84
             processModule(resolver, descriptorResource);
 209   
         }
 210   
     }
 211   
 
 212   
     /**
 213   
      * Parses a module and processes its contents.  This is often used
 214   
      * in conjunction with {@link #processModules(ClassResolver)} to
 215   
      * parse additional modules that are not in the standard location
 216   
      * (for whatever reason).
 217   
      */
 218  165
     public void processModule(ClassResolver resolver, Resource moduleDescriptorResource)
 219   
     {
 220  165
         if (_parser == null)
 221  83
             _parser = new DescriptorParser(_errorHandler, _registryAssembly);
 222   
 
 223  165
         try
 224   
         {
 225  165
             ModuleDescriptor md = _parser.parse(moduleDescriptorResource, resolver);
 226   
 
 227  165
             processModule(md);
 228   
 
 229   
             // After parsing a module, parse any additional modules identified
 230   
             // within the module (using the <sub-module> element.
 231   
 
 232  165
             while (_registryAssembly.moreQueuedModules())
 233   
             {
 234  1
                 md = _registryAssembly.parseNextQueued(_parser);
 235   
 
 236  1
                 processModule(md);
 237   
             }
 238   
         }
 239   
         catch (RuntimeException ex)
 240   
         {
 241   
             // An exception may leave the parser in an unknown state, so
 242   
             // give up on that instance and start with a fresh one.
 243   
 
 244  0
             _parser = null;
 245   
 
 246  0
             _errorHandler.error(LOG, ex.getMessage(), HiveMind.getLocation(ex), ex);
 247   
         }
 248   
     }
 249   
 
 250   
     /**
 251   
      * Processes a parsed HiveMind module descriptor.  This may be called
 252   
      * repeatedly before invoking {@link #constructRegistry(Locale)}.
 253   
      * 
 254   
      * @param md the parsed module descriptor
 255   
      */
 256  166
     public void processModule(ModuleDescriptor md)
 257   
     {
 258  166
         String id = md.getModuleId();
 259   
 
 260  166
         if (LOG.isDebugEnabled())
 261  18
             LOG.debug("Processing module " + id);
 262   
 
 263  166
         if (_modules.containsKey(id))
 264   
         {
 265  0
             Module existing = (Module) _modules.get(id);
 266   
 
 267  0
             _errorHandler.error(LOG, ImplMessages.duplicateModuleId(existing, md), null, null);
 268   
 
 269   
             // Ignore the duplicate module descriptor.
 270  0
             return;
 271   
         }
 272   
 
 273  166
         ModuleImpl module = new ModuleImpl();
 274   
 
 275  166
         module.setLocation(md.getLocation());
 276  166
         module.setModuleId(id);
 277  166
         module.setClassResolver(md.getClassResolver());
 278   
 
 279  166
         _modules.put(id, module);
 280   
 
 281  166
         _moduleDescriptors.add(md);
 282   
     }
 283   
 
 284  83
     private void addServiceAndConfigurationPoints(RegistryImpl registry)
 285   
     {
 286  83
         int count = _moduleDescriptors.size();
 287   
 
 288  83
         for (int i = 0; i < count; i++)
 289   
         {
 290  166
             ModuleDescriptor md = (ModuleDescriptor) _moduleDescriptors.get(i);
 291   
 
 292  166
             String id = md.getModuleId();
 293   
 
 294  166
             ModuleImpl module = (ModuleImpl) _modules.get(id);
 295   
 
 296  166
             addServicePoints(registry, module, md);
 297   
 
 298  166
             addConfigurationPoints(registry, module, md);
 299   
         }
 300   
     }
 301   
 
 302  166
     private void addServicePoints(RegistryImpl registry, ModuleImpl module, ModuleDescriptor md)
 303   
     {
 304  166
         String moduleId = md.getModuleId();
 305  166
         List services = md.getServicePoints();
 306  166
         int count = size(services);
 307   
 
 308  166
         for (int i = 0; i < count; i++)
 309   
         {
 310  1317
             ServicePointDescriptor sd = (ServicePointDescriptor) services.get(i);
 311   
 
 312  1317
             String pointId = moduleId + "." + sd.getId();
 313   
 
 314  1317
             if (LOG.isDebugEnabled())
 315  135
                 LOG.debug("Creating service extension point: " + pointId);
 316   
 
 317   
             // Choose which class to instantiate based on
 318   
             // whether the service is create-on-first-reference
 319   
             // or create-on-first-use (deferred).
 320   
 
 321  1317
             ServicePointImpl point = new ServicePointImpl();
 322   
 
 323  1317
             point.setExtensionPointId(pointId);
 324  1317
             point.setLocation(sd.getLocation());
 325  1317
             point.setModule(module);
 326   
 
 327  1317
             point.setServiceInterfaceName(sd.getInterfaceClassName());
 328  1317
             point.setParametersSchema(sd.getParametersSchema());
 329   
 
 330  1317
             point.setShutdownCoordinator(_shutdownCoordinator);
 331   
 
 332  1317
             registry.addServicePoint(point);
 333   
 
 334   
             // Save this for the second phase, where contributions
 335   
             // from other modules are applied.
 336   
 
 337  1317
             _servicePoints.put(pointId, point);
 338   
 
 339  1317
             addInternalImplementations(module, pointId, sd);
 340   
         }
 341   
     }
 342   
 
 343  166
     private void addConfigurationPoints(
 344   
         RegistryImpl registry,
 345   
         ModuleImpl module,
 346   
         ModuleDescriptor md)
 347   
     {
 348  166
         String moduleId = md.getModuleId();
 349  166
         List points = md.getConfigurationPoints();
 350  166
         int count = size(points);
 351   
 
 352  166
         for (int i = 0; i < count; i++)
 353   
         {
 354  700
             ConfigurationPointDescriptor cpd = (ConfigurationPointDescriptor) points.get(i);
 355   
 
 356  700
             String pointId = moduleId + "." + cpd.getId();
 357   
 
 358  700
             if (LOG.isDebugEnabled())
 359  80
                 LOG.debug("Creating extension point " + pointId);
 360   
 
 361  700
             ConfigurationPointImpl point = new ConfigurationPointImpl();
 362   
 
 363  700
             point.setExtensionPointId(pointId);
 364  700
             point.setLocation(cpd.getLocation());
 365  700
             point.setModule(module);
 366  700
             point.setExpectedCount(cpd.getCount());
 367  700
             point.setContributionsSchema(cpd.getContributionsSchema());
 368   
 
 369  700
             point.setShutdownCoordinator(_shutdownCoordinator);
 370   
 
 371  700
             registry.addConfigurationPoint(point);
 372   
 
 373   
             // Needed later when we reconcile the rest
 374   
             // of the configuration contributions.
 375   
 
 376  700
             _configurationPoints.put(pointId, point);
 377   
         }
 378   
     }
 379   
 
 380  456
     private void addContributionElements(
 381   
         Module sourceModule,
 382   
         ConfigurationPointImpl point,
 383   
         List elements)
 384   
     {
 385  456
         if (size(elements) == 0)
 386  0
             return;
 387   
 
 388  456
         if (LOG.isDebugEnabled())
 389  54
             LOG.debug("Adding extensions to configuration point " + point.getExtensionPointId());
 390   
 
 391  456
         ContributionImpl c = new ContributionImpl();
 392  456
         c.setContributingModule(sourceModule);
 393  456
         c.addElements(elements);
 394   
 
 395  456
         point.addContribution(c);
 396   
     }
 397   
 
 398   
     /**
 399   
      * Invoked after all modules have been added with 
 400   
      * {@link #processModule(ClassResolver, Resource)}.
 401   
      * This first resolves all the contributions, then constructs and returns
 402   
      * the registry.
 403   
      */
 404  83
     public Registry constructRegistry(Locale locale)
 405   
     {
 406   
 
 407   
         // Process any deferred operations
 408   
 
 409  83
         _registryAssembly.performPostProcessing();
 410   
 
 411  83
         RegistryImpl result = new RegistryImpl(_errorHandler, locale);
 412   
 
 413  83
         addServiceAndConfigurationPoints(result);
 414   
 
 415  83
         addImplementationsAndContributions();
 416   
 
 417  83
         checkForMissingServices();
 418   
 
 419  83
         checkContributionCounts();
 420   
 
 421  83
         result.setShutdownCoordinator(_shutdownCoordinator);
 422   
 
 423  83
         addModulesToRegistry(result);
 424   
 
 425  83
         result.startup();
 426   
 
 427  83
         return result;
 428   
     }
 429   
 
 430  83
     private void addModulesToRegistry(RegistryImpl registry)
 431   
     {
 432   
         // Add each module to the registry.
 433   
 
 434  83
         Iterator i = _modules.values().iterator();
 435  83
         while (i.hasNext())
 436   
         {
 437  166
             ModuleImpl module = (ModuleImpl) i.next();
 438   
 
 439  166
             if (LOG.isDebugEnabled())
 440  18
                 LOG.debug("Adding module " + module.getModuleId() + " to registry");
 441   
 
 442  166
             module.setRegistry(registry);
 443   
         }
 444   
     }
 445   
 
 446  83
     private void addImplementationsAndContributions()
 447   
     {
 448  83
         int count = _moduleDescriptors.size();
 449   
 
 450  83
         for (int i = 0; i < count; i++)
 451   
         {
 452  166
             ModuleDescriptor md = (ModuleDescriptor) _moduleDescriptors.get(i);
 453   
 
 454  166
             if (LOG.isDebugEnabled())
 455  18
                 LOG.debug("Adding contributions from module " + md.getModuleId());
 456   
 
 457  166
             addImplementations(md);
 458  166
             addContributions(md);
 459   
         }
 460   
     }
 461   
 
 462  166
     private void addImplementations(ModuleDescriptor md)
 463   
     {
 464  166
         String moduleId = md.getModuleId();
 465  166
         ModuleImpl sourceModule = (ModuleImpl) _modules.get(moduleId);
 466   
 
 467  166
         List implementations = md.getImplementations();
 468  166
         int count = size(implementations);
 469   
 
 470  166
         for (int i = 0; i < count; i++)
 471   
         {
 472  3
             ImplementationDescriptor impl = (ImplementationDescriptor) implementations.get(i);
 473   
 
 474  3
             String pointId = impl.getServiceId();
 475  3
             String qualifiedId = qualify(moduleId, pointId);
 476   
 
 477  3
             addImplementations(sourceModule, qualifiedId, impl);
 478   
         }
 479   
 
 480   
     }
 481   
 
 482  166
     private void addContributions(ModuleDescriptor md)
 483   
     {
 484  166
         String moduleId = md.getModuleId();
 485  166
         ModuleImpl sourceModule = (ModuleImpl) _modules.get(moduleId);
 486   
 
 487  166
         List contributions = md.getContributions();
 488  166
         int count = size(contributions);
 489   
 
 490  166
         for (int i = 0; i < count; i++)
 491   
         {
 492  457
             ContributionDescriptor cd = (ContributionDescriptor) contributions.get(i);
 493   
 
 494  457
             String pointId = cd.getConfigurationId();
 495  457
             String qualifiedId = qualify(moduleId, pointId);
 496   
 
 497  457
             ConfigurationPointImpl point =
 498   
                 (ConfigurationPointImpl) _configurationPoints.get(qualifiedId);
 499   
 
 500  457
             if (point == null)
 501   
             {
 502  1
                 _errorHandler.error(
 503   
                     LOG,
 504   
                     ImplMessages.unknownConfigurationPoint(moduleId, cd),
 505   
                     cd.getLocation(),
 506   
                     null);
 507   
 
 508  1
                 continue;
 509   
             }
 510   
 
 511  456
             addContributionElements(sourceModule, point, cd.getElements());
 512   
         }
 513   
     }
 514   
 
 515   
     /**
 516   
      * Qualifies the artifact id with the module id, if necessary.
 517   
      */
 518  475
     private static String qualify(String moduleId, String artifactId)
 519   
     {
 520  475
         if (artifactId.indexOf('.') >= 0)
 521  23
             return artifactId;
 522   
 
 523  452
         return moduleId + "." + artifactId;
 524   
     }
 525   
 
 526   
     /**
 527   
      * Adds internal service contributions; the contributions provided inplace
 528   
      * with the service definition.
 529   
      */
 530  1317
     private void addInternalImplementations(
 531   
         ModuleImpl sourceModule,
 532   
         String pointId,
 533   
         ServicePointDescriptor spd)
 534   
     {
 535  1317
         InstanceBuilder builder = spd.getInstanceBuilder();
 536  1317
         List interceptors = spd.getInterceptors();
 537   
 
 538  1317
         if (builder == null && interceptors == null)
 539  1
             return;
 540   
 
 541  1316
         if (builder != null)
 542  1316
             addServiceInstanceBuilder(sourceModule, pointId, builder);
 543   
 
 544  1316
         if (interceptors == null)
 545  1304
             return;
 546   
 
 547  12
         int count = size(interceptors);
 548   
 
 549  12
         for (int i = 0; i < count; i++)
 550   
         {
 551  12
             InterceptorDescriptor id = (InterceptorDescriptor) interceptors.get(i);
 552  12
             addInterceptor(sourceModule, pointId, id);
 553   
         }
 554   
     }
 555   
 
 556   
     /**
 557   
      * Adds ordinary service contributions.
 558   
      */
 559   
 
 560  3
     private void addImplementations(
 561   
         ModuleImpl sourceModule,
 562   
         String pointId,
 563   
         ImplementationDescriptor id)
 564   
     {
 565  3
         InstanceBuilder builder = id.getInstanceBuilder();
 566  3
         List interceptors = id.getInterceptors();
 567   
 
 568  3
         if (builder != null)
 569  1
             addServiceInstanceBuilder(sourceModule, pointId, builder);
 570   
 
 571  3
         int count = size(interceptors);
 572  3
         for (int i = 0; i < count; i++)
 573   
         {
 574  3
             InterceptorDescriptor ind = (InterceptorDescriptor) interceptors.get(i);
 575  3
             addInterceptor(sourceModule, pointId, ind);
 576   
         }
 577   
     }
 578   
 
 579   
     /**
 580   
      * Adds an {@link InstanceBuilder}
 581   
      * to a service extension point.
 582   
      * 
 583   
       * 
 584   
      */
 585   
 
 586  1317
     private void addServiceInstanceBuilder(
 587   
         ModuleImpl sourceModule,
 588   
         String pointId,
 589   
         InstanceBuilder builder)
 590   
     {
 591  1317
         if (LOG.isDebugEnabled())
 592  135
             LOG.debug("Adding " + builder + " to service extension point " + pointId);
 593   
 
 594  1317
         ServicePointImpl sep = (ServicePointImpl) _servicePoints.get(pointId);
 595   
 
 596  1317
         if (sep == null)
 597   
         {
 598  0
             _errorHandler.error(
 599   
                 LOG,
 600   
                 ImplMessages.unknownServicePoint(sourceModule, pointId),
 601   
                 builder.getLocation(),
 602   
                 null);
 603  0
             return;
 604   
         }
 605   
 
 606  1317
         if (sep.getServiceConstructor() != null)
 607   
         {
 608  0
             LOG.error(ImplMessages.duplicateFactory(sourceModule, pointId, sep));
 609   
 
 610  0
             return;
 611   
         }
 612   
 
 613  1317
         sep.setServiceModel(builder.getServiceModel());
 614  1317
         sep.setServiceConstructor(builder.createConstructor(sep, sourceModule));
 615   
     }
 616   
 
 617  15
     private void addInterceptor(ModuleImpl sourceModule, String pointId, InterceptorDescriptor id)
 618   
     {
 619  15
         if (LOG.isDebugEnabled())
 620  0
             LOG.debug("Adding " + id + " to service extension point " + pointId);
 621   
 
 622  15
         ServicePointImpl sep = (ServicePointImpl) _servicePoints.get(pointId);
 623   
 
 624  15
         String sourceModuleId = sourceModule.getModuleId();
 625   
 
 626  15
         if (sep == null)
 627   
         {
 628  0
             _errorHandler.error(
 629   
                 LOG,
 630   
                 ImplMessages.unknownServicePoint(sourceModule, pointId),
 631   
                 id.getLocation(),
 632   
                 null);
 633   
 
 634  0
             return;
 635   
         }
 636   
 
 637  15
         ServiceInterceptorContributionImpl sic = new ServiceInterceptorContributionImpl();
 638   
 
 639   
         // Allow the factory id to be unqualified, to refer to an interceptor factory
 640   
         // service from within the same module.
 641   
 
 642  15
         sic.setFactoryServiceId(qualify(sourceModuleId, id.getFactoryServiceId()));
 643  15
         sic.setLocation(id.getLocation());
 644   
 
 645  15
         sic.setFollowingInterceptorIds(IdUtils.qualifyList(sourceModuleId, id.getBefore()));
 646  15
         sic.setPrecedingInterceptorIds(IdUtils.qualifyList(sourceModuleId, id.getAfter()));
 647   
 
 648  15
         sic.setContributingModule(sourceModule);
 649  15
         sic.setParameters(id.getParameters());
 650   
 
 651  15
         sep.addInterceptorContribution(sic);
 652   
     }
 653   
 
 654   
     /**
 655   
      * Checks that each service has at service constructor.
 656   
      */
 657  83
     private void checkForMissingServices()
 658   
     {
 659  83
         Iterator i = _servicePoints.values().iterator();
 660  83
         while (i.hasNext())
 661   
         {
 662  1316
             ServicePointImpl point = (ServicePointImpl) i.next();
 663   
 
 664  1316
             if (point.getServiceConstructor() != null)
 665  1316
                 continue;
 666   
 
 667  0
             _errorHandler.error(LOG, ImplMessages.missingService(point), null, null);
 668   
         }
 669   
     }
 670   
 
 671   
     /**
 672   
      * Checks that each configuration extension point has the right number of contributions.
 673   
      */
 674   
 
 675  83
     private void checkContributionCounts()
 676   
     {
 677  83
         Iterator i = _configurationPoints.values().iterator();
 678   
 
 679  83
         while (i.hasNext())
 680   
         {
 681  700
             ConfigurationPointImpl point = (ConfigurationPointImpl) i.next();
 682   
 
 683  700
             Occurances expected = point.getExpectedCount();
 684   
 
 685  700
             if (expected == Occurances.UNBOUNDED)
 686  698
                 continue;
 687   
 
 688  2
             int count = point.getContributionCount();
 689   
 
 690   
             // Ok, so sometimes a case statement for Enums
 691   
             // would be nice.  Guess that's coming in JDK 1.5.
 692   
 
 693  2
             if (expected == Occurances.ONE_PLUS)
 694   
             {
 695  1
                 if (count > 0)
 696  0
                     continue;
 697   
             }
 698   
             else
 699  1
                 if (expected == Occurances.OPTIONAL)
 700   
                 {
 701   
 
 702  1
                     if (count < 2)
 703  0
                         continue;
 704   
                 }
 705   
                 else
 706   
                 {
 707  0
                     if (count == 1)
 708  0
                         continue;
 709   
                 }
 710   
 
 711  2
             _errorHandler.error(
 712   
                 LOG,
 713   
                 ImplMessages.wrongNumberOfContributions(point, count, expected),
 714   
                 point.getLocation(),
 715   
                 null);
 716   
         }
 717   
 
 718   
     }
 719   
 
 720  1135
     private static int size(Collection c)
 721   
     {
 722  1135
         return c == null ? 0 : c.size();
 723   
     }
 724   
 
 725   
     /**
 726   
      * Constructs a default registry based on just the modules
 727   
      * visible to the thread context class loader (this is sufficient
 728   
      * is the majority of cases), and using the default locale. If you have different
 729   
      * error handling needs, or wish to pick up HiveMind module deployment
 730   
      * descriptors for non-standard locations, you must create
 731   
      * a RegistryBuilder instance yourself.
 732   
      */
 733  2
     public static Registry constructDefaultRegistry()
 734   
     {
 735  2
         ClassResolver resolver = new DefaultClassResolver();
 736  2
         RegistryBuilder builder = new RegistryBuilder();
 737   
 
 738  2
         builder.processModules(resolver);
 739   
 
 740  2
         return builder.constructRegistry(Locale.getDefault());
 741   
     }
 742   
 
 743   
 }
 744