Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 80   Methods: 7
NCLOC: 56   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
Particle.java 70% 73,9% 57,1% 70%
 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.IRange;
 14   
 import org.jbind.xml.base.Range;
 15   
 import org.jbind.xml.msg.IConstraintViolations;
 16   
 import org.jbind.xml.msg.XmlException;
 17   
 import org.jbind.xml.msg.XmlMessages;
 18   
 import org.jbind.xml.schema.instantiation.IElemValHelper;
 19   
 
 20   
 public abstract class Particle extends Annotated implements IParticle {
 21   
 
 22   
   private boolean myIsUnbounded = false;
 23   
   private int myMin = 1;
 24   
   private int myMax = 1;
 25   
 
 26   
 
 27  461
   public Particle(CreationParams aCreationParams) {
 28  461
     super(aCreationParams);
 29   
   }
 30   
 
 31  181
   protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
 32  181
     IAttribute res = null;
 33  181
     String an = NameUtil.getSchemaAttributeName(anACParams);
 34  181
     if ("minOccurs".equals(an)) {
 35  86
       res = new IntAttribute(anACParams);
 36  86
       myMin = res.getInt();
 37  95
     } else if ("maxOccurs".equals(an)) {
 38  95
       if ("unbounded".equals(anACParams.value)) {
 39  79
         res = new Attribute(anACParams);
 40  79
         myIsUnbounded = true;
 41   
       } else {
 42  16
         res = new IntAttribute(anACParams);
 43  16
         myMax = res.getInt();
 44   
       }
 45   
     } else {
 46  0
       res = super.doCreateAttribute(anACParams);
 47   
     }
 48  181
     return res;
 49   
   }
 50   
 
 51  0
   public boolean isUnbounded() {
 52  0
     return myIsUnbounded;
 53   
   }
 54   
 
 55   
 
 56  0
   public int getMaxOccurs() {
 57  0
     return myMax;
 58   
   }
 59   
 
 60   
 
 61  0
   public int getMinOccurs() {
 62  0
     return myMin;
 63   
   }
 64   
 
 65   
 
 66  461
   public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
 67  461
     super.validateElement(aHelper, aViolations);
 68  461
     if (myMin < 0) {
 69  0
       aViolations.add(XmlMessages.minOccursLessThan0(this));
 70   
     }
 71  461
     if (!myIsUnbounded && (myMin > myMax)) {
 72  0
       aViolations.add(XmlMessages.minOccursGreaterThanMax(this));
 73   
     }
 74   
   }
 75   
 
 76  444
   protected IRange getRange() {
 77  444
     return myIsUnbounded ? new Range(myMin) : new Range(myMin, myMax);
 78   
   }
 79   
 }
 80