Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 94   Methods: 8
NCLOC: 71   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
TypeKeyRefConstraint.java 33,3% 53,8% 87,5% 54,3%
 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.ITypeInstanceConstraint;
 20   
 import org.jbind.xml.core.constraint.ITypeKeyRefConstraint;
 21   
 import org.jbind.xml.core.data.IAnyTypeData;
 22   
 import org.jbind.xml.core.data.IDataContext;
 23   
 import org.jbind.xml.core.data.IDataReference;
 24   
 import org.jbind.xml.msg.IConstraintViolations;
 25   
 import org.jbind.xml.msg.XmlException;
 26   
 import org.jbind.xml.msg.XmlMessages;
 27   
 
 28   
 public class TypeKeyRefConstraint extends TypeIdentityConstraint implements ITypeKeyRefConstraint {
 29   
 
 30   
   private ITypeInstanceConstraint myRefer = null;
 31   
 
 32  8
   public TypeKeyRefConstraint(ISourceInfo aSourceInfo, String aNamespace, String aName) {
 33  8
     super(aSourceInfo, aNamespace, aName);
 34   
   }
 35   
 
 36  11
   public void globalCheck(IDataContext aContext, IAnyTypeData aData, IAnyTypeData anEnclosingData, IConstraintViolations aViolations) {
 37  11
     if (TypeInstanceConstraint.LOCAL.equals(myRefer.getScope())) {
 38  0
       return;
 39   
     }
 40  11
     try {
 41  11
       for (Iterator i = select(aData); i.hasNext(); ) {
 42  25
         IDataImpl d = (IDataImpl)i.next();
 43  25
         IKey key = createKey(d, true, aViolations);
 44  25
         if (null != key) {
 45  25
           IDataReference openReference = new OpenReference(getConstraintKey(), aData, myRefer.getGlobalRef(), key);
 46  25
           aContext.add(openReference);
 47   
         }
 48   
       }
 49   
     } catch (XmlException e) {
 50  0
       aViolations.add(e.getXmlMessage());
 51   
     }
 52   
   }
 53   
 
 54  0
   public void resolveLocalTypeInstances(Map aMap, IAnyTypeData aData, IConstraintViolations aViolations) {
 55  0
     try {
 56  0
       for (Iterator i = select(aData); i.hasNext(); ) {
 57  0
         IDataImpl d = (IDataImpl)i.next();
 58  0
         IKey key = createKey(d, true, aViolations);
 59  0
         if (null != key) {
 60  0
           IAnyTypeData referencedData = (IAnyTypeData)aMap.get(key);
 61  0
           if (null == referencedData) {
 62  0
             aViolations.add(XmlMessages.unresolvedReference(myRefer.getGlobalRef(), key, aData.getImpl_()));
 63   
           } else {
 64  0
             aData.addReferencedData_(getConstraintKey(), referencedData);
 65   
           }
 66   
         }
 67   
       }
 68   
     } catch (XmlException e) {
 69  0
       aViolations.add(e.getXmlMessage());
 70   
     }
 71   
   }
 72   
 
 73  16
   public ConstraintType getConstraintType() {
 74  16
     return ConstraintType.TYPE_KEY_REF;
 75   
   }
 76   
 
 77  11
   public ITypeInstanceConstraint getReferredConstraint() {
 78  11
     return myRefer;
 79   
   }
 80   
 
 81  8
   public void setReferredConstraint(ITypeInstanceConstraint aConstraint) {
 82  8
     myRefer = aConstraint;
 83   
   }
 84   
 
 85  16
   public boolean isSingleNotMultipleReference() {
 86  16
     return getSelector().selectsZeroOrOneNode();
 87   
   }
 88   
 
 89  49
   public String getConstraintKey() {
 90  49
     return getGlobalRef().asStringKey();
 91   
   }
 92   
 
 93   
 }
 94