12005
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* The Apache Software License, Version 1.1
|
|
7 |
*
|
|
8 |
*
|
|
9 |
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
|
|
10 |
* reserved.
|
|
11 |
*
|
|
12 |
* Redistribution and use in source and binary forms, with or without
|
|
13 |
* modification, are permitted provided that the following conditions
|
|
14 |
* are met:
|
|
15 |
*
|
|
16 |
* 1. Redistributions of source code must retain the above copyright
|
|
17 |
* notice, this list of conditions and the following disclaimer.
|
|
18 |
*
|
|
19 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
20 |
* notice, this list of conditions and the following disclaimer in
|
|
21 |
* the documentation and/or other materials provided with the
|
|
22 |
* distribution.
|
|
23 |
*
|
|
24 |
* 3. The end-user documentation included with the redistribution,
|
|
25 |
* if any, must include the following acknowledgment:
|
|
26 |
* "This product includes software developed by the
|
|
27 |
* Apache Software Foundation (http://www.apache.org/)."
|
|
28 |
* Alternately, this acknowledgment may appear in the software itself,
|
|
29 |
* if and wherever such third-party acknowledgments normally appear.
|
|
30 |
*
|
|
31 |
* 4. The names "Xerces" and "Apache Software Foundation" must
|
|
32 |
* not be used to endorse or promote products derived from this
|
|
33 |
* software without prior written permission. For written
|
|
34 |
* permission, please contact apache@apache.org.
|
|
35 |
*
|
|
36 |
* 5. Products derived from this software may not be called "Apache",
|
|
37 |
* nor may "Apache" appear in their name, without prior written
|
|
38 |
* permission of the Apache Software Foundation.
|
|
39 |
*
|
|
40 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
|
41 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
42 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
43 |
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
|
44 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
45 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
46 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
47 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
48 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
49 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
50 |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
51 |
* SUCH DAMAGE.
|
|
52 |
* ====================================================================
|
|
53 |
*
|
|
54 |
* This software consists of voluntary contributions made by many
|
|
55 |
* individuals on behalf of the Apache Software Foundation and was
|
|
56 |
* originally based on software copyright (c) 1999, International
|
|
57 |
* Business Machines, Inc., http://www.apache.org. For more
|
|
58 |
* information on the Apache Software Foundation, please see
|
|
59 |
* <http://www.apache.org/>.
|
|
60 |
*/
|
|
61 |
|
|
62 |
package com.sun.org.apache.xerces.internal.xni;
|
|
63 |
|
|
64 |
/**
|
|
65 |
* A structure that holds the components of an XML Namespaces qualified
|
|
66 |
* name.
|
|
67 |
* <p>
|
|
68 |
* To be used correctly, the strings must be identical references for
|
|
69 |
* equal strings. Within the parser, these values are considered symbols
|
|
70 |
* and should always be retrieved from the <code>SymbolTable</code>.
|
|
71 |
*
|
|
72 |
* @see <a href="../../../../../xerces2/com/sun/org/apache/xerces/internal/util/SymbolTable.html">com.sun.org.apache.xerces.internal.util.SymbolTable</a>
|
|
73 |
*
|
|
74 |
* @author Andy Clark, IBM
|
|
75 |
*
|
|
76 |
* Better performance patch for the equals method by Daniel Petersson: refer to jaxp issue 61;
|
|
77 |
* == were used to compare strings
|
|
78 |
* @author Joe Wang, Oracle
|
|
79 |
*
|
|
80 |
*/
|
|
81 |
public class QName
|
|
82 |
implements Cloneable {
|
|
83 |
|
|
84 |
|
|
85 |
/**
|
|
86 |
* The qname prefix. For example, the prefix for the qname "a:foo"
|
|
87 |
* is "a".
|
|
88 |
*/
|
|
89 |
public String prefix;
|
|
90 |
|
|
91 |
/**
|
|
92 |
* The qname localpart. For example, the localpart for the qname "a:foo"
|
|
93 |
* is "foo".
|
|
94 |
*/
|
|
95 |
public String localpart;
|
|
96 |
|
|
97 |
/**
|
|
98 |
* The qname rawname. For example, the rawname for the qname "a:foo"
|
|
99 |
* is "a:foo".
|
|
100 |
*/
|
|
101 |
public String rawname;
|
|
102 |
|
|
103 |
/**
|
|
104 |
* The URI to which the qname prefix is bound. This binding must be
|
|
105 |
* performed by a XML Namespaces aware processor.
|
|
106 |
*/
|
|
107 |
public String uri;
|
|
108 |
|
|
109 |
//
|
|
110 |
// Constructors
|
|
111 |
//
|
|
112 |
|
|
113 |
/** Default constructor. */
|
|
114 |
public QName() {
|
|
115 |
clear();
|
|
116 |
} // <init>()
|
|
117 |
|
|
118 |
/** Constructs a QName with the specified values. */
|
|
119 |
public QName(String prefix, String localpart, String rawname, String uri) {
|
|
120 |
setValues(prefix, localpart, rawname, uri);
|
|
121 |
} // <init>(String,String,String,String)
|
|
122 |
|
|
123 |
/** Constructs a copy of the specified QName. */
|
|
124 |
public QName(QName qname) {
|
|
125 |
setValues(qname);
|
|
126 |
} // <init>(QName)
|
|
127 |
|
|
128 |
//
|
|
129 |
// Public methods
|
|
130 |
//
|
|
131 |
|
|
132 |
/**
|
|
133 |
* Convenience method to set the values of the qname components.
|
|
134 |
*
|
|
135 |
* @param QName The qualified name to be copied.
|
|
136 |
*/
|
|
137 |
public void setValues(QName qname) {
|
|
138 |
prefix = qname.prefix;
|
|
139 |
localpart = qname.localpart;
|
|
140 |
rawname = qname.rawname;
|
|
141 |
uri = qname.uri;
|
|
142 |
} // setValues(QName)
|
|
143 |
|
|
144 |
/**
|
|
145 |
* Convenience method to set the values of the qname components.
|
|
146 |
*
|
|
147 |
* @param prefix The qname prefix. (e.g. "a")
|
|
148 |
* @param localpart The qname localpart. (e.g. "foo")
|
|
149 |
* @param rawname The qname rawname. (e.g. "a:foo")
|
|
150 |
* @param uri The URI binding. (e.g. "http://foo.com/mybinding")
|
|
151 |
*/
|
|
152 |
public void setValues(String prefix, String localpart, String rawname,
|
|
153 |
String uri) {
|
|
154 |
this.prefix = prefix;
|
|
155 |
this.localpart = localpart;
|
|
156 |
this.rawname = rawname;
|
|
157 |
this.uri = uri;
|
|
158 |
} // setValues(String,String,String,String)
|
|
159 |
|
|
160 |
/** Clears the values of the qname components. */
|
|
161 |
public void clear() {
|
|
162 |
prefix = null;
|
|
163 |
localpart = null;
|
|
164 |
rawname = null;
|
|
165 |
uri = null;
|
|
166 |
} // clear()
|
|
167 |
|
|
168 |
//
|
|
169 |
// Cloneable methods
|
|
170 |
//
|
|
171 |
|
|
172 |
/** Returns a clone of this object. */
|
|
173 |
public Object clone() {
|
|
174 |
return new QName(this);
|
|
175 |
} // clone():Object
|
|
176 |
|
|
177 |
//
|
|
178 |
// Object methods
|
|
179 |
//
|
|
180 |
|
|
181 |
/** Returns the hashcode for this object. */
|
|
182 |
public int hashCode() {
|
|
183 |
if (uri != null) {
|
|
184 |
return uri.hashCode() +
|
|
185 |
((localpart != null) ? localpart.hashCode() : 0);
|
|
186 |
}
|
|
187 |
return (rawname != null) ? rawname.hashCode() : 0;
|
|
188 |
} // hashCode():int
|
|
189 |
|
|
190 |
/** Returns true if the two objects are equal. */
|
|
191 |
public boolean equals(Object object) {
|
|
192 |
if (object == this) {
|
|
193 |
return true;
|
|
194 |
}
|
|
195 |
|
|
196 |
if (object != null && object instanceof QName) {
|
|
197 |
QName qname = (QName)object;
|
|
198 |
if (qname.uri != null) {
|
|
199 |
return qname.localpart.equals(localpart) && qname.uri.equals(uri);
|
|
200 |
}
|
|
201 |
else if (uri == null) {
|
|
202 |
return rawname.equals(qname.rawname);
|
|
203 |
}
|
|
204 |
// fall through and return not equal
|
|
205 |
}
|
|
206 |
return false;
|
|
207 |
} // equals(Object):boolean
|
|
208 |
|
|
209 |
/** Returns a string representation of this object. */
|
|
210 |
public String toString() {
|
|
211 |
|
|
212 |
StringBuffer str = new StringBuffer();
|
|
213 |
boolean comma = false;
|
|
214 |
if (prefix != null) {
|
|
215 |
str.append("prefix=\""+prefix+'"');
|
|
216 |
comma = true;
|
|
217 |
}
|
|
218 |
if (localpart != null) {
|
|
219 |
if (comma) {
|
|
220 |
str.append(',');
|
|
221 |
}
|
|
222 |
str.append("localpart=\""+localpart+'"');
|
|
223 |
comma = true;
|
|
224 |
}
|
|
225 |
if (rawname != null) {
|
|
226 |
if (comma) {
|
|
227 |
str.append(',');
|
|
228 |
}
|
|
229 |
str.append("rawname=\""+rawname+'"');
|
|
230 |
comma = true;
|
|
231 |
}
|
|
232 |
if (uri != null) {
|
|
233 |
if (comma) {
|
|
234 |
str.append(',');
|
|
235 |
}
|
|
236 |
str.append("uri=\""+uri+'"');
|
|
237 |
}
|
|
238 |
return str.toString();
|
|
239 |
|
|
240 |
} // toString():String
|
|
241 |
|
|
242 |
} // class QName
|