Clover coverage report - Code Coverage for hivemind release 1.1
Coverage timestamp: Tue Oct 25 2005 10:47:07 EDT
file stats: LOC: 175   Methods: 12
NCLOC: 96   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SchemaImpl.java 95.5% 97.1% 100% 97.1%
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.schema.impl;
 16   
 17    import java.util.ArrayList;
 18    import java.util.Collections;
 19    import java.util.Iterator;
 20    import java.util.List;
 21   
 22    import org.apache.hivemind.ApplicationRuntimeException;
 23    import org.apache.hivemind.internal.Module;
 24    import org.apache.hivemind.internal.Visibility;
 25    import org.apache.hivemind.parse.BaseAnnotationHolder;
 26    import org.apache.hivemind.schema.AttributeModel;
 27    import org.apache.hivemind.schema.ElementModel;
 28    import org.apache.hivemind.schema.Schema;
 29   
 30    /**
 31    * Implementation of {@link org.apache.hivemind.schema.Schema}.
 32    *
 33    * @author Howard Lewis Ship
 34    */
 35    public class SchemaImpl extends BaseAnnotationHolder implements Schema
 36    {
 37    private List _elementModels;
 38   
 39    private List _shareableElementModels;
 40   
 41    /** @since 1.1 */
 42    private Visibility _visibility = Visibility.PUBLIC;
 43   
 44    /** @since 1.1 */
 45    private Module _module;
 46   
 47    /** @since 1.1 */
 48    private String _id;
 49   
 50    /**
 51    * @since 1.1
 52    */
 53  1 public String getModuleId()
 54    {
 55  1 return _module.getModuleId();
 56    }
 57   
 58    /**
 59    * @since 1.1
 60    */
 61  690 public String getId()
 62    {
 63  690 return _id;
 64    }
 65   
 66    /**
 67    * @since 1.1
 68    */
 69  30 public Visibility getVisibility()
 70    {
 71  30 return _visibility;
 72    }
 73   
 74    /** @since 1.1 */
 75  418 public boolean visibleToModule(String moduleId)
 76    {
 77  418 if (_visibility == Visibility.PUBLIC)
 78  417 return true;
 79   
 80  1 return getModuleId().equals(moduleId);
 81    }
 82   
 83  3999 public void addElementModel(ElementModel model)
 84    {
 85  3999 if (_elementModels == null)
 86  1363 _elementModels = new ArrayList();
 87   
 88  3999 _elementModels.add(model);
 89  3999 _shareableElementModels = null;
 90    }
 91   
 92  1619 public List getElementModel()
 93    {
 94  1619 if (_shareableElementModels == null)
 95  925 _shareableElementModels = _elementModels == null ? Collections.EMPTY_LIST : Collections
 96    .unmodifiableList(_elementModels);
 97   
 98  1619 return _shareableElementModels;
 99    }
 100   
 101  2061 public boolean canInstancesBeKeyed()
 102    {
 103  2061 boolean emptyModel = _elementModels == null || _elementModels.isEmpty();
 104   
 105  2061 if (emptyModel)
 106  1 return false;
 107   
 108  2060 for (Iterator i = _elementModels.iterator(); i.hasNext();)
 109    {
 110  2060 ElementModel model = (ElementModel) i.next();
 111   
 112  2060 if (model.getKeyAttribute() == null)
 113  1810 return false;
 114    }
 115   
 116  250 return true;
 117    }
 118   
 119    /**
 120    * Called by the {@link org.apache.hivemind.parse.DescriptorParser} to make sure that key
 121    * attributes specified by the top-level elements actually are defined.
 122    */
 123  1216 public void validateKeyAttributes()
 124    {
 125  1216 if (_elementModels == null)
 126  0 return;
 127   
 128  1216 for (Iterator i = _elementModels.iterator(); i.hasNext();)
 129    {
 130  1356 ElementModel em = (ElementModel) i.next();
 131   
 132  1356 String key = em.getKeyAttribute();
 133   
 134  1356 if (key == null)
 135  1229 continue;
 136   
 137  127 AttributeModel keyAm = em.getAttributeModel(key);
 138   
 139  127 if (keyAm == null)
 140  1 throw new ApplicationRuntimeException("Key attribute \'" + key + "\' of element \'"
 141    + em.getElementName() + "\' never declared.", em.getLocation(), null);
 142    }
 143    }
 144   
 145    /**
 146    * @since 1.1
 147    */
 148  2 public void setVisibility(Visibility visibility)
 149    {
 150  2 _visibility = visibility;
 151    }
 152   
 153    /**
 154    * @since 1.1
 155    */
 156  1159 public void setModule(Module module)
 157    {
 158  1159 _module = module;
 159    }
 160   
 161    /**
 162    * @since 1.1
 163    */
 164  335 public void setId(String id)
 165    {
 166  335 _id = id;
 167    }
 168   
 169    /** @since 1.1 */
 170   
 171  5898 public Module getDefiningModule()
 172    {
 173  5898 return _module;
 174    }
 175    }