Clover coverage report - Code Coverage for hivemind release 1.1-alpha-2
Coverage timestamp: Wed Feb 23 2005 09:59:04 EST
file stats: LOC: 175   Methods: 12
NCLOC: 96   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
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  632
     public String getId()
 62   
     {
 63  632
         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  375
     public boolean visibleToModule(String moduleId)
 76   
     {
 77  375
         if (_visibility == Visibility.PUBLIC)
 78  374
             return true;
 79   
 
 80  1
         return getModuleId().equals(moduleId);
 81   
     }
 82   
 
 83  3561
     public void addElementModel(ElementModel model)
 84   
     {
 85  3561
         if (_elementModels == null)
 86  1219
             _elementModels = new ArrayList();
 87   
 
 88  3561
         _elementModels.add(model);
 89  3561
         _shareableElementModels = null;
 90   
     }
 91   
 
 92  1433
     public List getElementModel()
 93   
     {
 94  1433
         if (_shareableElementModels == null)
 95  838
             _shareableElementModels = _elementModels == null ? Collections.EMPTY_LIST : Collections
 96   
                     .unmodifiableList(_elementModels);
 97   
 
 98  1433
         return _shareableElementModels;
 99   
     }
 100   
 
 101  1819
     public boolean canInstancesBeKeyed()
 102   
     {
 103  1819
         boolean emptyModel = _elementModels == null || _elementModels.isEmpty();
 104   
 
 105  1819
         if (emptyModel)
 106  1
             return false;
 107   
 
 108  1818
         for (Iterator i = _elementModels.iterator(); i.hasNext();)
 109   
         {
 110  1818
             ElementModel model = (ElementModel) i.next();
 111   
 
 112  1818
             if (model.getKeyAttribute() == null)
 113  1596
                 return false;
 114   
         }
 115   
 
 116  222
         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  1087
     public void validateKeyAttributes()
 124   
     {
 125  1087
         if (_elementModels == null)
 126  0
             return;
 127   
 
 128  1087
         for (Iterator i = _elementModels.iterator(); i.hasNext();)
 129   
         {
 130  1213
             ElementModel em = (ElementModel) i.next();
 131   
 
 132  1213
             String key = em.getKeyAttribute();
 133   
 
 134  1213
             if (key == null)
 135  1100
                 continue;
 136   
 
 137  113
             AttributeModel keyAm = em.getAttributeModel(key);
 138   
 
 139  113
             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  1030
     public void setModule(Module module)
 157   
     {
 158  1030
         _module = module;
 159   
     }
 160   
 
 161   
     /**
 162   
      * @since 1.1
 163   
      */
 164  306
     public void setId(String id)
 165   
     {
 166  306
         _id = id;
 167   
     }
 168   
 
 169   
     /** @since 1.1 */
 170   
 
 171  5017
     public Module getDefiningModule()
 172   
     {
 173  5017
         return _module;
 174   
     }
 175   
 }