1 16 17 package org.apache.xerces.impl.dv.xs; 18 19 import org.apache.xerces.impl.dv.InvalidDatatypeValueException; 20 import org.apache.xerces.impl.dv.ValidationContext; 21 import org.apache.xerces.impl.dv.util.ByteListImpl; 22 import org.apache.xerces.impl.dv.util.HexBin; 23 24 34 public class HexBinaryDV extends TypeValidator { 35 36 public short getAllowedFacets(){ 37 return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE ); 38 } 39 40 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { 41 byte[] decoded = HexBin.decode(content); 42 if (decoded == null) 43 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "hexBinary"}); 44 45 return new XHex(decoded); 46 } 47 48 public int getDataLength(Object value) { 50 return ((XHex)value).getLength(); 51 } 52 53 private static final class XHex extends ByteListImpl { 54 55 public XHex(byte[] data) { 56 super(data); 57 } 58 public synchronized String toString() { 59 if (canonical == null) { 60 canonical = HexBin.encode(data); 61 } 62 return canonical; 63 } 64 65 public boolean equals(Object obj) { 66 if (!(obj instanceof XHex)) 67 return false; 68 byte[] odata = ((XHex)obj).data; 69 int len = data.length; 70 if (len != odata.length) 71 return false; 72 for (int i = 0; i < len; i++) { 73 if (data[i] != odata[i]) 74 return false; 75 } 76 return true; 77 } 78 79 } 80 } 81 | Popular Tags |