01: package javax.xml.namespace;
02:
03: /**
04: *
05: *
06: * @author
07: * Kohsuke Kawaguchi (kk@kohsuke.org)
08: * @see
09: * http://java.sun.com/webservices/docs/1.3/api/javax/xml/namespace/QName.html
10: */
11: public class QName {
12: private final String uri;
13: private final String localName;
14: private final String prefix;
15:
16: public QName(String localName) {
17: this ("", localName, "");
18: }
19:
20: public QName(String uri, String localName) {
21: this (uri, localName, "");
22: }
23:
24: public QName(String uri, String localName, String prefix) {
25: if (uri == null)
26: uri = "";
27: if (localName == null || localName.length() == 0)
28: throw new IllegalArgumentException();
29: if (prefix == null)
30: throw new IllegalArgumentException();
31:
32: this .uri = uri;
33: this .localName = localName;
34: this .prefix = prefix;
35: }
36:
37: public String getLocalPart() {
38: return localName;
39: }
40:
41: public String getNamespaceURI() {
42: return uri;
43: }
44:
45: public String getPrefix() {
46: return prefix;
47: }
48:
49: public int hashCode() {
50: return localName.hashCode() ^ uri.hashCode();
51: }
52:
53: public String toString() {
54: if (uri.length() == 0)
55: return localName;
56: return '{' + uri + '}' + localName;
57: }
58:
59: public boolean equals(Object _rhs) {
60: if (!(_rhs instanceof QName))
61: return false;
62:
63: QName rhs = (QName) _rhs;
64: return this .localName.equals(rhs.localName)
65: && this .uri.equals(rhs.uri);
66: }
67:
68: public static QName valueOf(String qNameAsString) {
69: if (qNameAsString == null || qNameAsString.length() == 0)
70: throw new IllegalArgumentException();
71:
72: if (qNameAsString.charAt(0) == '{') {
73: int idx = qNameAsString.lastIndexOf('}');
74: if (idx == -1)
75: throw new IllegalArgumentException();
76: return new QName(qNameAsString.substring(1, idx),
77: qNameAsString.substring(idx + 1));
78: } else {
79: return new QName(qNameAsString);
80: }
81: }
82: }
|