2009/04/15 - Apache HiveMind has been retired.

For more information, please explore the Attic.

Clover coverage report - Code Coverage for hivemind release 1.2.1
Coverage timestamp: Fri Feb 10 2006 16:33:43 PST
file stats: LOC: 251   Methods: 24
NCLOC: 152   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ModuleDescriptor.java 80% 100% 100% 95.6%
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.hivemind.parse;
 16   
 17    import java.util.ArrayList;
 18    import java.util.Collection;
 19    import java.util.Collections;
 20    import java.util.HashMap;
 21    import java.util.List;
 22    import java.util.Map;
 23   
 24    import org.apache.commons.logging.Log;
 25    import org.apache.commons.logging.LogFactory;
 26    import org.apache.hivemind.ClassResolver;
 27    import org.apache.hivemind.ErrorHandler;
 28    import org.apache.hivemind.schema.Schema;
 29    import org.apache.hivemind.schema.impl.SchemaImpl;
 30    import org.apache.hivemind.util.ToStringBuilder;
 31   
 32    /**
 33    * Representation of a HiveMind module descriptor, as parsed by
 34    * {@link org.apache.hivemind.parse.DescriptorParser}. Corresponds to the root <module>
 35    * element.
 36    *
 37    * @author Howard Lewis Ship
 38    */
 39    public final class ModuleDescriptor extends BaseAnnotationHolder
 40    {
 41    /** @since 1.1 */
 42    private static final Log LOG = LogFactory.getLog(ModuleDescriptor.class);
 43   
 44    private String _moduleId;
 45   
 46    private String _version;
 47   
 48    /** @since 1.1 */
 49   
 50    private String _packageName;
 51   
 52    private List _servicePoints;
 53   
 54    private List _implementations;
 55   
 56    private List _configurationPoints;
 57   
 58    private List _contributions;
 59   
 60    private List _subModules;
 61   
 62    private List _dependencies;
 63   
 64    /** @since 1.1 */
 65    private Map _schemas;
 66   
 67    private ClassResolver _resolver;
 68   
 69    /** @since 1.1 */
 70    private ErrorHandler _errorHandler;
 71   
 72  301 public ModuleDescriptor(ClassResolver resolver, ErrorHandler errorHandler)
 73    {
 74  301 _resolver = resolver;
 75  301 _errorHandler = errorHandler;
 76    }
 77   
 78  28 public String toString()
 79    {
 80  28 ToStringBuilder builder = new ToStringBuilder(this);
 81   
 82  28 builder.append("moduleId", _moduleId);
 83  28 builder.append("version", _version);
 84   
 85  28 return builder.toString();
 86    }
 87   
 88  2640 public void addServicePoint(ServicePointDescriptor service)
 89    {
 90  2640 if (_servicePoints == null)
 91  220 _servicePoints = new ArrayList();
 92   
 93  2640 _servicePoints.add(service);
 94    }
 95   
 96  271 public List getServicePoints()
 97    {
 98  271 return _servicePoints;
 99    }
 100   
 101  16 public void addImplementation(ImplementationDescriptor descriptor)
 102    {
 103  16 if (_implementations == null)
 104  16 _implementations = new ArrayList();
 105   
 106  16 _implementations.add(descriptor);
 107    }
 108   
 109  267 public List getImplementations()
 110    {
 111  267 return _implementations;
 112    }
 113   
 114  1087 public void addConfigurationPoint(ConfigurationPointDescriptor descriptor)
 115    {
 116  1087 if (_configurationPoints == null)
 117  202 _configurationPoints = new ArrayList();
 118   
 119  1087 _configurationPoints.add(descriptor);
 120    }
 121   
 122  274 public List getConfigurationPoints()
 123    {
 124  274 return _configurationPoints;
 125    }
 126   
 127  712 public void addContribution(ContributionDescriptor descriptor)
 128    {
 129  712 if (_contributions == null)
 130  194 _contributions = new ArrayList();
 131   
 132  712 _contributions.add(descriptor);
 133    }
 134   
 135  268 public List getContributions()
 136    {
 137  268 return _contributions;
 138    }
 139   
 140  3 public void addSubModule(SubModuleDescriptor subModule)
 141    {
 142  3 if (_subModules == null)
 143  3 _subModules = new ArrayList();
 144   
 145  3 _subModules.add(subModule);
 146    }
 147   
 148  254 public List getSubModules()
 149    {
 150  254 return _subModules;
 151    }
 152   
 153  13 public void addDependency(DependencyDescriptor dependency)
 154    {
 155  13 if (_dependencies == null)
 156  13 _dependencies = new ArrayList();
 157   
 158  13 _dependencies.add(dependency);
 159    }
 160   
 161  268 public List getDependencies()
 162    {
 163  268 return _dependencies;
 164    }
 165   
 166    /**
 167    * Adds a schema to this module descriptor. If a schema with the same id already has been added,
 168    * an error is reported and the given schema is ignored.
 169    *
 170    * @since 1.1
 171    */
 172  335 public void addSchema(SchemaImpl schema)
 173    {
 174  335 if (_schemas == null)
 175  189 _schemas = new HashMap();
 176   
 177  335 String schemaId = schema.getId();
 178   
 179  335 Schema existing = getSchema(schemaId);
 180   
 181  335 if (existing != null)
 182    {
 183  1 _errorHandler.error(LOG, ParseMessages.duplicateSchema(
 184    _moduleId + '.' + schemaId,
 185    existing), schema.getLocation(), null);
 186  1 return;
 187    }
 188   
 189  334 _schemas.put(schemaId, schema);
 190    }
 191   
 192    /** @since 1.1 */
 193  340 public Schema getSchema(String id)
 194    {
 195  340 return _schemas == null ? null : (Schema) _schemas.get(id);
 196    }
 197   
 198    /**
 199    * Returns a Collection of {@link org.apache.hivemind.schema.impl.SchemaImpl}.
 200    *
 201    * @since 1.1
 202    */
 203  264 public Collection getSchemas()
 204    {
 205  264 return _schemas != null ? _schemas.values() : Collections.EMPTY_LIST;
 206    }
 207   
 208  1857 public String getModuleId()
 209    {
 210  1857 return _moduleId;
 211    }
 212   
 213  9 public String getVersion()
 214    {
 215  9 return _version;
 216    }
 217   
 218  300 public void setModuleId(String string)
 219    {
 220  300 _moduleId = string;
 221    }
 222   
 223  291 public void setVersion(String string)
 224    {
 225  291 _version = string;
 226    }
 227   
 228  257 public ClassResolver getClassResolver()
 229    {
 230  257 return _resolver;
 231    }
 232   
 233    /**
 234    * Returns the name of the package to search for class names within. By default, the package
 235    * name will match the module id, but this can be overridden in the module descriptor.
 236    *
 237    * @since 1.1
 238    */
 239   
 240  2904 public String getPackageName()
 241    {
 242  2904 return _packageName;
 243    }
 244   
 245    /** @since 1.1 */
 246   
 247  283 public void setPackageName(String packageName)
 248    {
 249  283 _packageName = packageName;
 250    }
 251    }