Clover coverage report - Code Coverage for hivemind release 1.0
Coverage timestamp: Wed Sep 22 2004 08:05:25 EDT
file stats: LOC: 136   Methods: 10
NCLOC: 84   Classes: 2
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
RegistryAssemblyImpl.java 100% 100% 100% 100%
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.util.ArrayList;
 18   
 import java.util.HashMap;
 19   
 import java.util.List;
 20   
 import java.util.Map;
 21   
 
 22   
 import org.apache.commons.logging.Log;
 23   
 import org.apache.commons.logging.LogFactory;
 24   
 import org.apache.hivemind.ClassResolver;
 25   
 import org.apache.hivemind.ErrorHandler;
 26   
 import org.apache.hivemind.Resource;
 27   
 import org.apache.hivemind.parse.DescriptorParser;
 28   
 import org.apache.hivemind.parse.ModuleDescriptor;
 29   
 import org.apache.hivemind.schema.Schema;
 30   
 
 31   
 /**
 32   
  * Implementation of {@link org.apache.hivemind.impl.RegistryAssembly}.
 33   
  *
 34   
  * @author Howard Lewis Ship
 35   
  */
 36   
 public class RegistryAssemblyImpl implements RegistryAssembly
 37   
 {
 38   
     private static final Log LOG = LogFactory.getLog(RegistryAssemblyImpl.class);
 39   
 
 40   
     private List _runnables = new ArrayList();
 41   
     private Map _schemas = new HashMap();
 42   
     private List _queuedModules = new ArrayList();
 43   
     private ErrorHandler _errorHandler;
 44   
 
 45  121
     public RegistryAssemblyImpl(ErrorHandler errorHandler)
 46   
     {
 47  121
         _errorHandler = errorHandler;
 48   
     }
 49   
 
 50   
     private static class QueuedModule
 51   
     {
 52   
         private Resource _resource;
 53   
         private ClassResolver _resolver;
 54   
 
 55  1
         QueuedModule(Resource resource, ClassResolver resolver)
 56   
         {
 57  1
             _resource = resource;
 58  1
             _resolver = resolver;
 59   
         }
 60   
 
 61  1
         ModuleDescriptor parse(DescriptorParser parser)
 62   
         {
 63  1
             return parser.parse(_resource, _resolver);
 64   
         }
 65   
     }
 66   
 
 67  264
     public void addSchema(String schemaId, Schema schema)
 68   
     {
 69  264
         Schema existing = getSchema(schemaId);
 70   
 
 71  264
         if (existing != null)
 72   
         {
 73  1
             _errorHandler.error(
 74   
                 LOG,
 75   
                 ImplMessages.duplicateSchema(schemaId, existing),
 76   
                 schema.getLocation(),
 77   
                 null);
 78  1
             return;
 79   
         }
 80   
 
 81  263
         _schemas.put(schemaId, schema);
 82   
     }
 83   
 
 84  679
     public Schema getSchema(String schemaId)
 85   
     {
 86  679
         return (Schema) _schemas.get(schemaId);
 87   
     }
 88   
 
 89  59
     public void addPostProcessor(Runnable postProcessor)
 90   
     {
 91  59
         _runnables.add(postProcessor);
 92   
     }
 93   
 
 94   
     /**
 95   
      * Invokes {@link Runnable#run()} on each Runnable
 96   
      * object previously stored using
 97   
      * {@link #addPostProcessor(Runnable)}.
 98   
      */
 99  116
     public void performPostProcessing()
 100   
     {
 101  116
         int count = _runnables.size();
 102   
 
 103  116
         for (int i = 0; i < count; i++)
 104   
         {
 105  56
             Runnable r = (Runnable) _runnables.get(i);
 106   
 
 107  56
             r.run();
 108   
         }
 109   
     }
 110   
 
 111  1
     public void enqueueModuleParse(Resource resource, ClassResolver resolver)
 112   
     {
 113  1
         QueuedModule qm = new QueuedModule(resource, resolver);
 114  1
         _queuedModules.add(qm);
 115   
     }
 116   
 
 117   
     /**
 118   
      * Returns true if there are yet more queued models to be parsed.
 119   
      * 
 120   
      */
 121  194
     public boolean moreQueuedModules()
 122   
     {
 123  194
         return !_queuedModules.isEmpty();
 124   
     }
 125   
 
 126   
     /**
 127   
      * Parses the next enqueued module descripotor and returns it.
 128   
      */
 129  1
     public ModuleDescriptor parseNextQueued(DescriptorParser parser)
 130   
     {
 131  1
         QueuedModule qm = (QueuedModule) _queuedModules.remove(0);
 132   
 
 133  1
         return qm.parse(parser);
 134   
     }
 135   
 }
 136