KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > datatype > xsd > QNameDatatype


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 JavaDoc str) {
8     return Naming.isQname(str);
9   }
10
11   static class QName {
12     private final String JavaDoc namespaceURI;
13     private final String JavaDoc localName;
14     QName(String JavaDoc namespaceURI, String JavaDoc localName) {
15       this.namespaceURI = namespaceURI;
16       this.localName = localName;
17     }
18     public boolean equals(Object JavaDoc 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 JavaDoc getValue(String JavaDoc str, ValidationContext vc) {
30     int i = str.indexOf(':');
31     if (i < 0) {
32       String JavaDoc ns = vc.resolveNamespacePrefix("");
33       if (ns == null)
34     ns = "";
35       return new QName(ns, str);
36     }
37     else {
38       String JavaDoc prefix = str.substring(0, i);
39       String JavaDoc 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 JavaDoc 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