1 package com.thaiopensource.datatype.xsd; 2 3 import org.relaxng.datatype.ValidationContext; 4 import com.thaiopensource.xml.util.Naming; 5 6 class QNameDatatype extends DatatypeBase { 7 public boolean lexicallyAllows(String str) { 8 return Naming.isQname(str); 9 } 10 11 static class QName { 12 private final String namespaceURI; 13 private final String localName; 14 QName(String namespaceURI, String localName) { 15 this.namespaceURI = namespaceURI; 16 this.localName = localName; 17 } 18 public boolean equals(Object obj) { 19 if (obj == null || !(obj instanceof QName)) 20 return false; 21 QName other = (QName)obj; 22 return namespaceURI.equals(other.namespaceURI) && localName.equals(other.localName); 23 } 24 public int hashCode() { 25 return localName.hashCode() ^ namespaceURI.hashCode(); 26 } 27 } 28 29 Object getValue(String str, ValidationContext vc) { 30 int i = str.indexOf(':'); 31 if (i < 0) { 32 String ns = vc.resolveNamespacePrefix(""); 33 if (ns == null) 34 ns = ""; 35 return new QName(ns, str); 36 } 37 else { 38 String prefix = str.substring(0, i); 39 String ns = vc.resolveNamespacePrefix(prefix); 40 if (ns == null) 41 return null; 42 return new QName(ns, str.substring(i + 1)); 43 } 44 } 45 46 boolean allowsValue(String str, ValidationContext vc) { 47 int i = str.indexOf(':'); 48 return i < 0 || vc.resolveNamespacePrefix(str.substring(0, i)) != null; 49 } 50 51 public boolean isContextDependent() { 52 return true; 53 } 54 } 55 | Popular Tags |