package com.thaiopensource.datatype.xsd;

import org.relaxng.datatype.ValidationContext;
import com.thaiopensource.xml.util.Naming;

class QNameDatatype extends DatatypeBase {
  public boolean lexicallyAllows(String str) {
    return Naming.isQname(str);
  }

  static class QName {
    private final String namespaceURI;
    private final String localName;
    QName(String namespaceURI, String localName) {
      this.namespaceURI = namespaceURI;
      this.localName = localName;
    }
    public boolean equals(Object obj) {
      if (obj == null || !(obj instanceof QName))
	return false;
      QName other = (QName)obj;
      return namespaceURI.equals(other.namespaceURI) && localName.equals(other.localName);
    }
    public int hashCode() {
      return localName.hashCode() ^ namespaceURI.hashCode();
    }
  }

  Object getValue(String str, ValidationContext vc) {
    int i = str.indexOf(':');
    if (i < 0) {
      String ns = vc.resolveNamespacePrefix("");
      if (ns == null)
	ns = "";
      return new QName(ns, str);
    }
    else {
      String prefix = str.substring(0, i);
      String ns = vc.resolveNamespacePrefix(prefix);
      if (ns == null)
	return null;
      return new QName(ns, str.substring(i + 1));
    }
  }

  boolean allowsValue(String str, ValidationContext vc) {
    int i = str.indexOf(':');
    return i < 0 || vc.resolveNamespacePrefix(str.substring(0, i)) != null;
  }

  public boolean isContextDependent() {
    return true;
  }
}

@@ -46,46 +46,40 @@
 ort 
-org.relaxng.datatype.ValidationContext
+com.thaiopensource.xml.util.Name
 ;%0Aim
@@ -118,16 +118,63 @@
 .Naming;
+%0Aimport org.relaxng.datatype.ValidationContext;
 %0A%0Aclass 
@@ -298,571 +298,8 @@
  %7D%0A%0A
-  static class QName %7B%0A    private final String namespaceURI;%0A    private final String localName;%0A    QName(String namespaceURI, String localName) %7B%0A      this.namespaceURI = namespaceURI;%0A      this.localName = localName;%0A    %7D%0A    public boolean equals(Object obj) %7B%0A      if (obj == null %7C%7C !(obj instanceof QName))%0A%09return false;%0A      QName other = (QName)obj;%0A      return namespaceURI.equals(other.namespaceURI) && localName.equals(other.localName);%0A    %7D%0A    public int hashCode() %7B%0A      return localName.hashCode() %5E namespaceURI.hashCode();%0A    %7D%0A  %7D%0A%0A
   Ob
@@ -485,33 +485,32 @@
      return new 
-Q
 Name(ns, str);%0A 
@@ -657,16 +657,16 @@
 n null;%0A
+
       re
@@ -674,17 +674,16 @@
 urn new 
-Q
 Name(ns,

Make value of QNameDatatype be a Name.