Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 75   Methods: 7
NCLOC: 51   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
AttributesConstraint.java 90% 94,1% 85,7% 91,2%
 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   
 
 14   
 import org.jbind.xml.base.AttributeOccurence;
 15   
 import org.jbind.xml.base.ILocation;
 16   
 import org.jbind.xml.core.cmp.IAttributesModel;
 17   
 import org.jbind.xml.core.constraint.ConstraintType;
 18   
 import org.jbind.xml.core.constraint.ICheckContext;
 19   
 import org.jbind.xml.core.constraint.IConstraint;
 20   
 import org.jbind.xml.core.content.IAttrRefOrDecl;
 21   
 import org.jbind.xml.core.data.IAnyTypeData;
 22   
 import org.jbind.xml.core.data.IDataContext;
 23   
 import org.jbind.xml.msg.IConstraintViolations;
 24   
 import org.jbind.xml.msg.XmlMessages;
 25   
 
 26   
 public class AttributesConstraint implements IConstraint {
 27   
 
 28   
   private IAttributesModel myAttributesModel = null;
 29   
 
 30  451
   public AttributesConstraint(IAttributesModel anAttributesModel) {
 31  451
     myAttributesModel = anAttributesModel;
 32   
   }
 33   
 
 34  451
   public ConstraintType getConstraintType() {
 35  451
     return ConstraintType.ATTRIBUTES;
 36   
   }
 37   
 
 38  0
   public ILocation getLocation() {
 39  0
     return myAttributesModel.getLocation();
 40   
   }
 41   
 
 42  1664
   public void globalCheck(IDataContext aContext, IAnyTypeData aData, IAnyTypeData anEnclosingData, IConstraintViolations aViolations) {
 43  1664
     if (!aData.isNil_()) {
 44  1664
       for (Iterator i = myAttributesModel.iterAttributes(); i.hasNext(); ) {
 45  5563
         IAttrRefOrDecl att = (IAttrRefOrDecl)i.next();
 46  5563
         AttributeOccurence occurence = att.getOccurence();
 47  5563
         if (AttributeOccurence.REQUIRED.equals(occurence) || AttributeOccurence.PROHIBITED.equals(occurence)) {
 48  1254
           String namespace = att.getNamespace();
 49  1254
           String name = att.getName();
 50  1254
           IAnyTypeData d = aData.getAttribute_(namespace, name);
 51  1254
           if ((d == null) && AttributeOccurence.REQUIRED.equals(occurence)) {
 52  3
             aViolations.add(XmlMessages.cvcRequiredAttribute(att.getGlobalRef(), aData.getImpl_().getLocation()));
 53  1251
           } else if ((d != null) && AttributeOccurence.PROHIBITED.equals(occurence)) {
 54  2
             aViolations.add(XmlMessages.cvcProhibitedAttribute(att.getGlobalRef(), aData.getImpl_().getLocation()));
 55   
           }
 56   
         }
 57   
       }
 58   
     }
 59   
   }
 60   
 
 61  1929
   public void localCheck(ICheckContext aCheckContext, IAnyTypeData aData, IConstraintViolations aViolations) {
 62   
     // Attribute constraints must not be checked locally. Otherwise the construction
 63   
     // of complex values with simple content is not possible.
 64   
   }
 65   
 
 66  171
   public boolean isFinal() {
 67  171
     return false;
 68   
   }
 69   
 
 70  171
   public boolean isRestriction(IConstraint aConstraint) {
 71  171
     return true;
 72   
   }
 73   
 
 74   
 }
 75