Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 138   Methods: 6
NCLOC: 102   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
ConstantResolver.java 77,5% 86,4% 83,3% 82,9%
 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 java.util.Enumeration;
 13   
 import java.util.HashSet;
 14   
 import java.util.Set;
 15   
 import java.util.StringTokenizer;
 16   
 
 17   
 import org.jbind.xml.base.AttributeOccurence;
 18   
 import org.jbind.xml.base.BlockType;
 19   
 import org.jbind.xml.base.FinalType;
 20   
 import org.jbind.xml.base.IHasLocation;
 21   
 import org.jbind.xml.base.ProcessContentsType;
 22   
 import org.jbind.xml.msg.XmlException;
 23   
 import org.jbind.xml.msg.XmlMessages;
 24   
 
 25   
 public class ConstantResolver {
 26   
 
 27  184
   public static FormType getFormType(String aString, IHasLocation aHasLocation) throws XmlException {
 28  184
     FormType res = null;
 29  184
     if ("qualified".equals(aString)) {
 30  174
       res = FormType.QUALIFIED;
 31  10
     } else if ("unqualified".equals(aString)) {
 32  10
       res = FormType.UNQUALIFIED;
 33   
     } else {
 34  0
       throw new XmlException(XmlMessages.unknownFormType(aString, aHasLocation));
 35   
     }
 36  184
     return res;
 37   
   }
 38   
 
 39   
 
 40  7
   public static Set getBlockTypes(String aString, IHasLocation aHasLocation) throws XmlException {
 41  7
     Set res = new HashSet(11);
 42  7
     if (null != aString) {
 43  7
       if ("#all".equals(aString)) {
 44  2
         res.add(BlockType.EXTENSION);
 45  2
         res.add(BlockType.RESTRICTION);
 46  2
         res.add(BlockType.SUBSTITUTION);
 47   
       } else {
 48  5
         for (Enumeration e = new StringTokenizer(aString);
 49  10
                 e.hasMoreElements(); ) {
 50  5
           String b = (String)e.nextElement();
 51  5
           if ("extension".equals(b)) {
 52  4
             res.add(BlockType.EXTENSION);
 53  1
           } else if ("restriction".equals(b)) {
 54  1
             res.add(BlockType.RESTRICTION);
 55  0
           } else if ("substitution".equals(b)) {
 56  0
             res.add(BlockType.SUBSTITUTION);
 57   
           } else {
 58  0
             throw new XmlException(XmlMessages.unknownBlockType(b, aHasLocation));
 59   
           }
 60   
         }
 61   
       }
 62   
     }
 63  7
     return res;
 64   
   }
 65   
 
 66   
 
 67   
   /**
 68   
    * Gets the final types encoded in the specified string.
 69   
    *
 70   
    * @param aString <i>(required)</i>. Either the string &quot;#all&quot; or
 71   
    * a string containing 0 or more of &quot;extension&quot;, &quot;restriction&quot;,
 72   
    * &quot;list&quot;, or &quot;union&quot;.
 73   
    * @param aHasLocation <i>(required)</i>. Used for the vioalation message
 74   
    * in case that an invalid string is supplied.
 75   
    * @param aViolations <i>(required)</i>.
 76   
    * @return <i>(required)</i>. A set of {@link FinalType FinalType}s.
 77   
    */
 78  4
   public static Set getFinalTypes(String aString, IHasLocation aHasLocation) throws XmlException {
 79  4
     Set res = new HashSet(11);
 80  4
     if ("#all".equals(aString)) {
 81  1
       res.add(FinalType.EXTENSION);
 82  1
       res.add(FinalType.RESTRICTION);
 83  1
       res.add(FinalType.LIST);
 84  1
       res.add(FinalType.UNION);
 85   
     } else {
 86  3
       for (Enumeration e = new StringTokenizer(aString); e.hasMoreElements(); ) {
 87  3
         String b = (String)e.nextElement();
 88  3
         if ("extension".equals(b)) {
 89  1
           res.add(FinalType.EXTENSION);
 90  2
         } else if ("restriction".equals(b)) {
 91  1
           res.add(FinalType.RESTRICTION);
 92  1
         } else if ("list".equals(b)) {
 93  0
           res.add(FinalType.LIST);
 94  1
         } else if ("union".equals(b)) {
 95  0
           res.add(FinalType.UNION);
 96   
         } else {
 97  1
           throw new XmlException(XmlMessages.unknownFinalType(b, aHasLocation));
 98   
         }
 99   
       }
 100   
     }
 101  3
     return res;
 102   
   }
 103   
 
 104   
 
 105  78
   public static ProcessContentsType getProcessContents(String aString, IHasLocation aHasLocation) throws XmlException {
 106  78
     ProcessContentsType res = null;
 107  78
     if ("lax".equals(aString)) {
 108  58
       res = ProcessContentsType.LAX;
 109  20
     } else if ("skip".equals(aString)) {
 110  11
       res = ProcessContentsType.SKIP;
 111  9
     } else if ("strict".equals(aString)) {
 112  9
       res = ProcessContentsType.STRICT;
 113   
     } else {
 114  0
       throw new XmlException(XmlMessages.unknownProcessContents(aString, aHasLocation));
 115   
     }
 116  78
     return res;
 117   
   }
 118   
 
 119   
 
 120  197
   public static AttributeOccurence getOccurence(String aString, IHasLocation aHasLocation) throws XmlException {
 121  197
     AttributeOccurence res = null;
 122  197
     if ("optional".equals(aString)) {
 123  74
       res = AttributeOccurence.OPTIONAL;
 124  123
     } else if ("prohibited".equals(aString)) {
 125  63
       res = AttributeOccurence.PROHIBITED;
 126  60
     } else if ("required".equals(aString)) {
 127  60
       res = AttributeOccurence.REQUIRED;
 128   
     } else {
 129  0
       throw new XmlException(XmlMessages.unknownUseType(aString, aHasLocation));
 130   
     }
 131  197
     return res;
 132   
   }
 133   
 
 134   
 
 135  0
   private ConstantResolver() {}
 136   
 
 137   
 }
 138