01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.jxpath.ri;
17:
18: /**
19: * A qualified name: a combination of an optional namespace prefix
20: * and an local name.
21: *
22: * @author Dmitri Plotnikov
23: * @version $Revision: 1.10 $ $Date: 2004/02/29 14:17:45 $
24: */
25: public class QName {
26: private String prefix;
27: private String name;
28:
29: public QName(String qualifiedName) {
30: int index = qualifiedName.indexOf(':');
31: if (index == -1) {
32: prefix = null;
33: name = qualifiedName;
34: } else {
35: prefix = qualifiedName.substring(0, index);
36: name = qualifiedName.substring(index + 1);
37: }
38: }
39:
40: public QName(String prefix, String localName) {
41: this .prefix = prefix;
42: this .name = localName;
43: }
44:
45: public String getPrefix() {
46: return prefix;
47: }
48:
49: public String getName() {
50: return name;
51: }
52:
53: public String toString() {
54: if (prefix != null) {
55: return prefix + ':' + name;
56: }
57: return name;
58: }
59:
60: public int hashCode() {
61: return name.hashCode();
62: }
63:
64: public boolean equals(Object object) {
65: if (!(object instanceof QName)) {
66: return false;
67: }
68: if (this == object) {
69: return true;
70: }
71: QName that = (QName) object;
72: if (!this .name.equals(that.name)) {
73: return false;
74: }
75:
76: if ((this .prefix == null && that.prefix != null)
77: || (this .prefix != null && !this .prefix
78: .equals(that.prefix))) {
79: return false;
80: }
81:
82: return true;
83: }
84: }
|