Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 91   Methods: 7
NCLOC: 68   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
ElementKeyRefConstraintElement.java 58,3% 82,1% 85,7% 76,6%
 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.element;
 11   
 
 12   
 import org.jbind.xml.base.IAttribute;
 13   
 import org.jbind.xml.base.IRef;
 14   
 import org.jbind.xml.base.ISymbolspaces;
 15   
 import org.jbind.xml.core.cmp.IComponent;
 16   
 import org.jbind.xml.core.constraint.IElementInstanceConstraint;
 17   
 import org.jbind.xml.core.type.IAnyType;
 18   
 import org.jbind.xml.msg.IConstraintViolations;
 19   
 import org.jbind.xml.msg.XmlException;
 20   
 import org.jbind.xml.msg.XmlMessages;
 21   
 import org.jbind.xml.schema.constraint.ElementKeyRefConstraint;
 22   
 import org.jbind.xml.schema.instantiation.IElemValHelper;
 23   
 import org.jbind.xml.schema.instantiation.IElementHelper;
 24   
 import org.jbind.xml.schema.instantiation.IJobRefs;
 25   
 
 26   
 public class ElementKeyRefConstraintElement extends ElementIdentityConstraintElement implements IKeyRefConstraintElement {
 27   
 
 28   
   private IRef myRefer = null;
 29   
 
 30   
 
 31  15
   public ElementKeyRefConstraintElement(CreationParams aCreationParams) {
 32  15
     super(aCreationParams);
 33   
   }
 34   
 
 35   
 
 36  0
   public IRef getRefer() {
 37  0
     return myRefer;
 38   
   }
 39   
 
 40  30
   protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
 41  30
     IAttribute res = null;
 42  30
     String an = NameUtil.getSchemaAttributeName(anACParams);
 43  30
     if ("refer".equals(an)) {
 44  15
       res = new RefAttribute(anACParams, ISymbolspaces.IDENTITY_CONSTRAINT);
 45  15
       myRefer = res.getRef();
 46   
     } else {
 47  15
       res = super.doCreateAttribute(anACParams);
 48   
     }
 49  30
     return res;
 50   
   }
 51   
 
 52  15
   public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
 53  15
     super.validateElement(aHelper, aViolations);
 54  15
     if (null == myRefer) {
 55  0
       aViolations.add(XmlMessages.missingAttribute("refer", this));
 56   
     }
 57   
   }
 58   
 
 59  26
   protected void doCollectRefsForCompletion(IElementHelper anElementHelper, IJobRefs aJobRefs) {
 60  26
     aJobRefs.add(myRefer, true, this);
 61   
   }
 62   
 
 63  15
   public IComponent createComponent(IElementHelper anElementHelper, IConstraintViolations aViolations) {
 64  15
     return new ElementKeyRefConstraint(this, getTargetNamespace(), getName());
 65   
   }
 66   
 
 67  12
   public void completeComponent(IElementHelper anElementHelper, IComponent aComponent, IConstraintViolations aViolations) {
 68  12
     super.completeComponent(anElementHelper, aComponent, aViolations);
 69  12
     ElementKeyRefConstraint krc = (ElementKeyRefConstraint)aComponent;
 70  12
     IComponent referredComponent = anElementHelper.getComponent(myRefer, true);
 71  12
     if (!(referredComponent instanceof IElementInstanceConstraint)) {
 72  0
       aViolations.add(XmlMessages.referencedConstraintMustBeKeyOrUnique(this));
 73   
     } else {
 74  12
       IElementInstanceConstraint referredConstraint = (IElementInstanceConstraint)referredComponent;
 75  12
       if (krc.getNbFields() != referredConstraint.getNbFields()) {
 76  1
         aViolations.add(XmlMessages.numberOfkeyRefFieldsDoNotMatchKeyFields(this));
 77   
       }
 78  12
       krc.setRefer(referredConstraint);
 79  12
       IAnyType referredDataType = referredConstraint.getDataType();
 80  12
       if (null == krc.getDataType()) {
 81  12
         krc.setDataType(referredDataType);
 82   
       } else {
 83  0
         if (!referredDataType.isBaseType(krc.getDataType())) {
 84  0
           aViolations.add(XmlMessages.typeOfRefMustBeSubType(this));
 85   
         }
 86   
       }
 87   
     }
 88   
   }
 89   
 
 90   
 }
 91