1 57 58 package com.sun.org.apache.xerces.internal.impl.dv.xs; 59 60 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; 61 import com.sun.org.apache.xerces.internal.impl.dv.ValidationContext; 62 import com.sun.org.apache.xerces.internal.impl.dv.util.HexBin; 63 64 72 public class HexBinaryDV extends TypeValidator { 73 74 public short getAllowedFacets(){ 75 return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE ); 76 } 77 78 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { 79 byte[] decoded = HexBin.decode(content); 80 if (decoded == null) 81 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "hexBinary"}); 82 83 return new XHex(decoded); 84 } 85 86 public int getDataLength(Object value) { 88 return ((XHex)value).length(); 89 } 90 91 private static final class XHex { 92 final byte[] data; 94 private String canonical; 96 public XHex(byte[] data) { 97 this.data = data; 98 } 99 public synchronized String toString() { 100 if (canonical == null) { 101 canonical = HexBin.encode(data); 102 } 103 return canonical; 104 } 105 public int length() { 106 return data.length; 107 } 108 public boolean equals(Object obj) { 109 if (!(obj instanceof XHex)) 110 return false; 111 byte[] odata = ((XHex)obj).data; 112 int len = data.length; 113 if (len != odata.length) 114 return false; 115 for (int i = 0; i < len; i++) { 116 if (data[i] != odata[i]) 117 return false; 118 } 119 return true; 120 } 121 } 122 } 123 | Popular Tags |