Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 142   Methods: 14
NCLOC: 110   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
ElemRefOrDecl.java 90% 95,1% 100% 94,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.cmp;
 11   
 
 12   
 import java.util.ArrayList;
 13   
 import java.util.Collections;
 14   
 import java.util.Iterator;
 15   
 import java.util.List;
 16   
 import java.util.Map;
 17   
 
 18   
 import org.jbind.xml.base.IRange;
 19   
 import org.jbind.xml.base.IRef;
 20   
 import org.jbind.xml.base.ISymbolspace;
 21   
 import org.jbind.xml.base.ISymbolspaces;
 22   
 import org.jbind.xml.base.Range;
 23   
 import org.jbind.xml.core.base.IKeyStore;
 24   
 import org.jbind.xml.core.cmp.ISourceInfo;
 25   
 import org.jbind.xml.core.constraint.IElementIdentityConstraint;
 26   
 import org.jbind.xml.core.content.IElemGroupDesc;
 27   
 import org.jbind.xml.core.content.IElemRefOrDecl;
 28   
 import org.jbind.xml.core.content.IUseState;
 29   
 import org.jbind.xml.core.data.IAnyTypeData;
 30   
 import org.jbind.xml.core.data.ISimpleData;
 31   
 import org.jbind.xml.instance.use.ElemRefOrDeclUseState;
 32   
 import org.jbind.xml.msg.IConstraintViolations;
 33   
 import org.jbind.xml.msg.XmlMessages;
 34   
 
 35   
 public abstract class ElemRefOrDecl extends ElemDesc implements IElemRefOrDecl {
 36   
 
 37   
   protected ISimpleData myDefault = null;
 38   
   protected ISimpleData myFixed = null;
 39   
   protected String myDefaultTextContent = null;
 40   
 
 41   
   private List myIdentityConstraints = null;
 42   
 
 43  1408
   public ElemRefOrDecl(ISourceInfo aSourceInfo, String aNamespace, String aName, IRange aRange) {
 44  1408
     super(aSourceInfo, aNamespace, aName, aRange);
 45   
   }
 46   
 
 47  30594
   public ISymbolspace getSymbolspace() {
 48  30594
     return ISymbolspaces.ELEMENT;
 49   
   }
 50   
 
 51  906
   public void validate(IConstraintViolations aViolations) {}
 52   
 
 53  4241
   public IUseState createUseState(IUseState aParent) {
 54  4241
     return new ElemRefOrDeclUseState(this, aParent);
 55   
   }
 56   
 
 57  19137
   public IRange getRange(IRef aRef) {
 58  19137
     IRange res = null;
 59  19137
     if (null == aRef) {
 60  2444
       res = getRange();
 61   
     } else {
 62  16693
       IRef r = getGlobalRef();
 63  16693
       if (aRef.getNamespace().equals(r.getNamespace()) && aRef.getLocalPart().equals(r.getLocalPart())) {
 64  2695
         res = getRange();
 65   
       } else {
 66  13998
         res = Range.ZERO;
 67   
       }
 68   
     }
 69  19137
     return res;
 70   
   }
 71   
 
 72  4022
   public ISimpleData getDefault() {
 73  4022
     return myDefault;
 74   
   }
 75  4174
   public ISimpleData getFixed() {
 76  4174
     return myFixed;
 77   
   }
 78   
 
 79  2436
   public String getDefaultTextContent() {
 80  2436
     return (null != myDefaultTextContent) ? myDefaultTextContent : ((null != getDefault()) ? getDefault().getCanonicalForm_() : null);
 81   
   }
 82   
 
 83  43
   public void add(IElementIdentityConstraint aConstraint) {
 84  43
     if (null == myIdentityConstraints) {
 85  22
       myIdentityConstraints = new ArrayList();
 86   
     }
 87  43
     myIdentityConstraints.add(aConstraint);
 88   
   }
 89   
 
 90  2047
   public Iterator iterIdentityConstraints() {
 91  2047
     Iterator res = null;
 92  2047
     if (null == myIdentityConstraints) {
 93  2007
       res = Collections.EMPTY_LIST.iterator();
 94   
     } else {
 95  40
       res = myIdentityConstraints.iterator();
 96   
     }
 97  2047
     return res;
 98   
   }
 99   
 
 100  2047
   public void checkIdentityConstraints(IAnyTypeData aData, IKeyStore anElementKeys, IConstraintViolations aViolations) {
 101  2047
     for (Iterator i = iterIdentityConstraints(); i.hasNext(); ) {
 102  67
       IElementIdentityConstraint c = (IElementIdentityConstraint)i.next();
 103  67
       c.checkElementKeys(anElementKeys, aData, aViolations);
 104   
     }
 105   
   }
 106   
 
 107  1991
   public void collectElemDescs(Map anElementDecls, List anElemWildcards, IConstraintViolations aViolations) {
 108  1991
     IElemRefOrDecl old = (IElemRefOrDecl)anElementDecls.put(getGlobalRef(), this);
 109  1991
     if (null != old) {
 110  4
       if (getType() != old.getType()) {
 111  0
         aViolations.add(XmlMessages.elementsMustHaveSameType(getGlobalRef(), this));
 112   
       }
 113  4
       if (((getDefault() != null) && !getDefault().equals(old.getDefault())) || ((getDefault() == null) && (old.getDefault() != null)) || ((getFixed() != null) && !getFixed().equals(old.getFixed())) || ((getFixed() == null) && (old.getFixed() != null))) {
 114  0
         aViolations.add(XmlMessages.elementsMustHaveSameFixedOrDefault(getGlobalRef(), this));
 115   
       }
 116   
     }
 117   
   }
 118   
 
 119  318
   public void replaceSubstitutions(IElemGroupDesc aParent) {
 120  318
     Iterator i = iterSubstitutes();
 121  318
     if (!i.hasNext()) {
 122  316
       aParent.add(this);
 123   
     } else {
 124   
       // create a choice group that contains this element and all elements that
 125   
       // can be substituted for this element.
 126  2
       ChoiceDecl choice = new ChoiceDecl(this, null, null, getRange());
 127  2
       aParent.add(choice);
 128   
       // add the head of the substitution group
 129  2
       choice.add(new ElemRef(this, Range.ONE));
 130   
       // add uses for all substitutable declarations
 131  2
       while (i.hasNext()) {
 132  4
         IElemRefOrDecl c = (IElemRefOrDecl)i.next();
 133  4
         choice.add(c);
 134   
       }
 135   
     }
 136   
   }
 137   
 
 138  487
   protected void doAddToParentWithNewRange(IRange aRange, IElemGroupDesc aParent) {
 139  487
     aParent.add(new ElemRef(this, aRange));
 140   
   }
 141   
 }
 142