Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 82   Methods: 4
NCLOC: 64   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
TypeKeyConstraint.java 33,3% 42,3% 75% 41,7%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.schema.constraint;
 11   
 
 12   
 import java.util.Iterator;
 13   
 import java.util.Map;
 14   
 
 15   
 import org.jbind.xml.core.base.IKey;
 16   
 import org.jbind.xml.core.bridge.IDataImpl;
 17   
 import org.jbind.xml.core.cmp.ISourceInfo;
 18   
 import org.jbind.xml.core.constraint.ConstraintType;
 19   
 import org.jbind.xml.core.constraint.ITypeKeyConstraint;
 20   
 import org.jbind.xml.core.data.IAnyTypeData;
 21   
 import org.jbind.xml.core.data.IDataContext;
 22   
 import org.jbind.xml.msg.IConstraintViolations;
 23   
 import org.jbind.xml.msg.XmlException;
 24   
 import org.jbind.xml.msg.XmlMessages;
 25   
 
 26   
 public class TypeKeyConstraint extends TypeInstanceConstraint implements ITypeKeyConstraint {
 27   
 
 28  4
   public TypeKeyConstraint(ISourceInfo aSourceInfo, String aNamespace, String aName, IScope aScope) {
 29  4
     super(aSourceInfo, aNamespace, aName, aScope);
 30   
   }
 31   
 
 32  3
   public void globalCheck(IDataContext aContext, IAnyTypeData aData, IAnyTypeData anEnclosingData, IConstraintViolations aViolations) {
 33  3
     if (LOCAL.equals(getScope())) {
 34  0
       return;
 35   
     }
 36  3
     try {
 37  3
       for (Iterator i = select(aData); i.hasNext(); ) {
 38  18
         IDataImpl d = (IDataImpl)i.next();
 39  18
         IKey key = createKey(d, false, aViolations);
 40  18
         if (null != key) {
 41  18
           IAnyTypeData v = d.getData();
 42  18
           if (null != v) {
 43  18
             if (null != aContext.setIndexedData(getGlobalRef(), key, v)) {
 44  0
               aViolations.add(XmlMessages.keyNotUniqueInIndex(getGlobalRef(), key, d));
 45   
             }
 46   
           } else {
 47  0
             aViolations.add(XmlMessages.indexedElementHasNoData(getGlobalRef(), key, d));
 48   
           }
 49   
         }
 50   
       }
 51   
     } catch (XmlException e) {
 52  0
       aViolations.add(e.getXmlMessage());
 53   
     }
 54   
   }
 55   
 
 56  0
   public void collectLocalTypeInstances(IAnyTypeData aData, Map aMap, IConstraintViolations aViolations) {
 57  0
     try {
 58  0
       for (Iterator i = select(aData); i.hasNext(); ) {
 59  0
         IDataImpl d = (IDataImpl)i.next();
 60  0
         IKey key = createKey(d, false, aViolations);
 61  0
         if (null != key) {
 62  0
           IAnyTypeData v = d.getData();
 63  0
           if (null != v) {
 64  0
             if (null != aMap.put(key, v)) {
 65  0
               aViolations.add(XmlMessages.keyNotUniqueInIndex(getGlobalRef(), key, d));
 66   
             }
 67   
           } else {
 68  0
             aViolations.add(XmlMessages.indexedElementHasNoData(getGlobalRef(), key, d));
 69   
           }
 70   
         }
 71   
       }
 72   
     } catch (XmlException e) {
 73  0
       aViolations.add(e.getXmlMessage());
 74   
     }
 75   
   }
 76   
 
 77  8
   public ConstraintType getConstraintType() {
 78  8
     return ConstraintType.TYPE_KEY;
 79   
   }
 80   
 
 81   
 }
 82