Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 108   Methods: 9
NCLOC: 85   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
Facet.java 58,3% 75% 88,9% 73,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.element;
 11   
 
 12   
 import org.jbind.xml.base.IAttribute;
 13   
 import org.jbind.xml.base.INamespaces;
 14   
 import org.jbind.xml.core.bridge.IDataImpl;
 15   
 import org.jbind.xml.core.constraint.ConstraintType;
 16   
 import org.jbind.xml.core.constraint.IConstraints;
 17   
 import org.jbind.xml.core.data.IAnyTypeData;
 18   
 import org.jbind.xml.core.type.IAnyType;
 19   
 import org.jbind.xml.core.type.ISimpleType;
 20   
 import org.jbind.xml.instance.data.StringDataImpl;
 21   
 import org.jbind.xml.msg.IConstraintViolations;
 22   
 import org.jbind.xml.msg.XmlException;
 23   
 import org.jbind.xml.msg.XmlMessages;
 24   
 import org.jbind.xml.schema.instantiation.IElemValHelper;
 25   
 
 26   
 public abstract class Facet extends Annotated implements IFacet {
 27   
 
 28   
   private String myValue = null;
 29   
   private boolean myFixed = false;
 30   
   private ConstraintType myConstraintType = null;
 31   
 
 32  336
   public Facet(CreationParams aCreationParams, ConstraintType aConstraintType) {
 33  336
     super(aCreationParams);
 34  336
     myConstraintType = aConstraintType;
 35   
   }
 36   
 
 37  480
   protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
 38  480
     IAttribute res = null;
 39  480
     String an = NameUtil.getSchemaAttributeName(anACParams);
 40  480
     if ("value".equals(an)) {
 41  336
       res = new Attribute(anACParams);
 42  336
       myValue = res.getStringValue();
 43  144
     } else if ("fixed".equals(an)) {
 44  38
       res = new BooleanAttribute(anACParams);
 45  38
       myFixed = res.getBoolean();
 46   
     } else {
 47  106
       res = super.doCreateAttribute(anACParams);
 48   
     }
 49  480
     return res;
 50   
   }
 51   
 
 52  443
   public String getValue() {
 53  443
     return myValue;
 54   
   }
 55   
 
 56  0
   public boolean getFixed() {
 57  0
     return myFixed;
 58   
   }
 59   
 
 60  336
   public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
 61  336
     super.validateElement(aHelper, aViolations);
 62  336
     if (null == myValue) {
 63  0
       aViolations.add(XmlMessages.missingAttribute("value", this));
 64   
     }
 65   
   }
 66   
 
 67  35
   protected int getIntValue() throws XmlException {
 68  35
     int res;
 69  35
     try {
 70  35
       res = Integer.parseInt(getValue());
 71  35
       if (res < 0) {
 72  0
         throw new XmlException(XmlMessages.invalidInteger(getValue(), this));
 73   
       }
 74   
     } catch (NumberFormatException e) {
 75  0
       throw new XmlException(XmlMessages.invalidInteger(getValue(), this));
 76   
     }
 77  35
     return res;
 78   
   }
 79   
 
 80  212
   protected IAnyTypeData createValueData(IAnyType aType) throws XmlException {
 81  212
     IDataImpl impl = new StringDataImpl(getValue(), getPrefixToNamespaceMapping(), this);
 82  212
     IAnyTypeData res = (IAnyTypeData)aType.createData(impl);
 83  212
     return res;
 84   
   }
 85   
 
 86  323
   public final void apply(ISimpleType aType, IConstraints aConstraints, IConstraintViolations aViolations) {
 87  323
     try {
 88  323
       if (aType.isApplicable(myConstraintType)) {
 89  323
         doAddConstraint(aType, aConstraints, aViolations);
 90   
       } else {
 91  0
         IAnyType t = aType;
 92  0
         while (t.isAnonymous() || !INamespaces.XML_SCHEMA.equals(t.getGlobalRef().getNamespace())) {
 93  0
           t = t.getBaseType();
 94   
         }
 95  0
         aViolations.add(XmlMessages.facetNotApplicableOnType(getConstraintType(), t.getName(), this));
 96   
       }
 97   
     } catch (XmlException e) {
 98  0
       aViolations.add(e.getXmlMessage());
 99   
     }
 100   
   }
 101   
 
 102   
   protected abstract void doAddConstraint(IAnyType aType, IConstraints aConstraints, IConstraintViolations aViolations) throws XmlException;
 103   
 
 104  138
   protected ConstraintType getConstraintType() {
 105  138
     return myConstraintType;
 106   
   }
 107   
 }
 108