Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 135   Methods: 18
NCLOC: 97   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
IdentityConstraintComponent.java 100% 90,3% 83,3% 89,8%
 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.ArrayList;
 13   
 import java.util.Iterator;
 14   
 import java.util.List;
 15   
 
 16   
 import org.jbind.xml.base.ISymbolspace;
 17   
 import org.jbind.xml.base.ISymbolspaces;
 18   
 import org.jbind.xml.core.base.IKey;
 19   
 import org.jbind.xml.core.bridge.IDataImpl;
 20   
 import org.jbind.xml.core.bridge.IXPath;
 21   
 import org.jbind.xml.core.cmp.IComponentVisitor;
 22   
 import org.jbind.xml.core.cmp.ISourceInfo;
 23   
 import org.jbind.xml.core.constraint.ICheckContext;
 24   
 import org.jbind.xml.core.constraint.IConstraint;
 25   
 import org.jbind.xml.core.constraint.IIdentityConstraintComponent;
 26   
 import org.jbind.xml.core.data.IAnyTypeData;
 27   
 import org.jbind.xml.core.type.IAnyType;
 28   
 import org.jbind.xml.msg.IConstraintViolations;
 29   
 import org.jbind.xml.msg.XmlException;
 30   
 import org.jbind.xml.msg.XmlMessages;
 31   
 import org.jbind.xml.schema.cmp.Component;
 32   
 import org.jbind.xml.schema.cmp.W3CTypes;
 33   
 
 34   
 public abstract class IdentityConstraintComponent extends Component implements IIdentityConstraintComponent {
 35   
 
 36   
   private IAnyType myDataType = null;
 37   
 
 38   
   private IXPath mySelector = null;
 39   
 
 40   
   /**
 41   
    * List of {@link IXPath IXPath}s.
 42   
    */
 43   
   private List myFields = new ArrayList();
 44   
 
 45  63
   public IdentityConstraintComponent(ISourceInfo aSourceInfo, String aNamespace, String aName) {
 46  63
     super(aSourceInfo, aNamespace, aName);
 47   
   }
 48   
 
 49  88
   public IAnyType getDataType() {
 50  88
     return myDataType;
 51   
   }
 52   
 
 53  60
   public void setDataType(IAnyType aType) {
 54  60
     myDataType = aType;
 55   
   }
 56   
 
 57  456
   public ISymbolspace getSymbolspace() {
 58  456
     return ISymbolspaces.IDENTITY_CONSTRAINT;
 59   
   }
 60   
 
 61  172
   public void accept(IComponentVisitor aVisitor) {
 62   
     // IdentityConstraintComponents are not visited
 63   
   }
 64   
 
 65  21
   public void localCheck(ICheckContext aCheckContext, IAnyTypeData aData, IConstraintViolations aViolations) {}
 66   
 
 67  0
   public boolean isRestriction(IConstraint aConstraint) {
 68  0
     return true;
 69   
   }
 70   
 
 71  0
   public boolean isFinal() {
 72  0
     return false;
 73   
   }
 74   
 
 75  88
   protected Iterator select(IAnyTypeData aData) throws XmlException {
 76  88
     return select((IDataImpl)aData.getImpl_());
 77   
   }
 78   
 
 79  88
   protected Iterator select(IDataImpl aData) throws XmlException {
 80  88
     return mySelector.select(aData);
 81   
   }
 82   
 
 83  253
   protected IKey createKey(IDataImpl aData, boolean aNullAllowed, IConstraintViolations aViolations) throws XmlException {
 84  253
     Key res = new Key();
 85  253
     for (Iterator i = iterFields(); i.hasNext(); ) {
 86  286
       IXPath field = (IXPath)i.next();
 87  286
       Iterator j = field.select(aData);
 88  286
       if (j.hasNext()) {
 89  278
         IDataImpl impl = (IDataImpl)j.next();
 90  278
         IAnyTypeData keyData = impl.getData();
 91  278
         if (null == keyData) {
 92  4
           keyData = W3CTypes.anySimpleType.createData(impl);
 93   
         }
 94  278
         res.add(keyData);
 95  278
         if (j.hasNext()) {
 96  1
           aViolations.add(XmlMessages.fieldXPathReturnedMoreThanOneNode(field, getGlobalRef(), aData.getLocation()));
 97   
         }
 98   
       } else {
 99  8
         if (!aNullAllowed) {
 100  3
           aViolations.add(XmlMessages.fieldXPathReturnedNoNode(field, getGlobalRef(), aData.getLocation()));
 101   
         }
 102  8
         res = null;
 103  8
         break;
 104   
       }
 105   
     }
 106  253
     return res;
 107   
   }
 108   
 
 109  253
   private Iterator iterFields() {
 110  253
     return myFields.iterator();
 111   
   }
 112   
 
 113  60
   public void setFields(List aFields) {
 114  60
     myFields = aFields;
 115   
   }
 116   
 
 117  16
   public IXPath getSelector() {
 118  16
     return mySelector;
 119   
   }
 120   
 
 121  60
   public void setSelector(IXPath anXPath) {
 122  60
     mySelector = anXPath;
 123   
   }
 124   
 
 125  40
   public int getNbFields() {
 126  40
     return myFields.size();
 127   
   }
 128   
 
 129  0
   public boolean isReference() {
 130  0
     return false;
 131   
   }
 132   
 
 133  59
   public void validate(IConstraintViolations aViolations) {}
 134   
 }
 135