Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 96   Methods: 10
NCLOC: 72   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
HexBinaryData.java 50% 54,1% 30% 49,2%
 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.instance.data;
 11   
 
 12   
 import org.jbind.xml.core.data.IAnyTypeData;
 13   
 import org.jbind.xml.core.data.IHexBinary;
 14   
 import org.jbind.xml.core.data.IHexBinaryData;
 15   
 import org.jbind.xml.msg.IConstraintViolations;
 16   
 import org.jbind.xml.msg.XmlException;
 17   
 import org.jbind.xml.msg.XmlMessages;
 18   
 
 19   
 public class HexBinaryData extends AbstractSimpleData implements IHexBinaryData {
 20   
 
 21   
   private IHexBinary myValue;
 22   
 
 23  44
   private static final int getInt(char aChar) {
 24  44
     int res;
 25  44
     if ((aChar >= '0') && (aChar <= '9')) {
 26  35
       res = aChar - '0';
 27  9
     } else if ((aChar >= 'A') && (aChar <= 'F')) {
 28  9
       res = aChar - 'A' + 10;
 29  0
     } else if ((aChar >= 'a') && (aChar <= 'f')) {
 30  0
       res = aChar - 'a' + 10;
 31   
     } else {
 32  0
       throw new NumberFormatException("not a hexadecimal digit: " + aChar);
 33   
     }
 34  44
     return res;
 35   
   }
 36   
 
 37  1
   protected void doAccept(String aString) throws XmlException {
 38  1
     super.doAccept(aString);
 39  1
     if (aString.length() % 2 != 0) {
 40  0
       String s = new StringBuffer(aString.substring(0, (aString.length() > 100) ? 100 : aString.length())).append((aString.length() > 100) ? "..." : "").toString();
 41  0
       throw new XmlException(XmlMessages.invalidHexBinaryLength(s, getImpl_()));
 42   
     }
 43  1
     int nbBytes = aString.length() / 2;
 44  1
     byte[] array = new byte[nbBytes];
 45  1
     int idx = 0;
 46  1
     for (int i = 0; i < nbBytes; i++) {
 47  22
       char c1 = aString.charAt(idx++);
 48  22
       char c2 = aString.charAt(idx++);
 49  22
       int n1 = getInt(c1);
 50  22
       int n2 = getInt(c2);
 51  22
       byte b = (byte)(16 * n1 + n2);
 52  22
       array[i] = b;
 53   
     }
 54  1
     myValue = new HexBinary(array);
 55   
   }
 56   
 
 57  25
   public IHexBinary getHexBinary() {
 58  25
     return myValue;
 59   
   }
 60   
 
 61  0
   public void setHexBinary(IHexBinary aNewValue) throws XmlException {
 62  0
     IHexBinary oldValue = myValue;
 63  0
     myValue = aNewValue;
 64  0
     IConstraintViolations violations = completeSimpleStorageAssignment_();
 65  0
     if (!violations.isEmpty()) {
 66  0
       myValue = oldValue;
 67  0
       throw new XmlException(violations);
 68   
     }
 69   
   }
 70   
 
 71  0
   public int getLength() {
 72  0
     return myValue.getBytes().length;
 73   
   }
 74   
 
 75  0
   public String getCanonicalForm_() {
 76  0
     return myValue.toString();
 77   
   }
 78   
 
 79  0
   public boolean simpleStorageValueEquals(IAnyTypeData aData) {
 80  0
     return (aData instanceof IHexBinaryData) && myValue.equals(((IHexBinaryData)aData).getHexBinary());
 81   
   }
 82   
 
 83  0
   public int simpleStorageValueHashCode() {
 84  0
     return myValue.hashCode();
 85   
   }
 86   
 
 87  0
   public Object getSimpleStorageObject() {
 88  0
     return myValue;
 89   
   }
 90   
 
 91  0
   public void setSimpleStorageObject(Object aValue) {
 92  0
     myValue = (IHexBinary)aValue;
 93   
   }
 94   
 
 95   
 }
 96