001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.xni;
019:
020: /**
021: * A structure that holds the components of an XML Namespaces qualified
022: * name.
023: * <p>
024: * To be used correctly, the strings must be identical references for
025: * equal strings. Within the parser, these values are considered symbols
026: * and should always be retrieved from the <code>SymbolTable</code>.
027: *
028: * @see <a href="../../../../../xerces2/org/apache/xerces/util/SymbolTable.html">org.apache.xerces.util.SymbolTable</a>
029: *
030: * @author Andy Clark, IBM
031: *
032: * @version $Id: QName.java 447247 2006-09-18 05:23:52Z mrglavas $
033: */
034: public class QName implements Cloneable {
035:
036: //
037: // Data
038: //
039:
040: /**
041: * The qname prefix. For example, the prefix for the qname "a:foo"
042: * is "a".
043: */
044: public String prefix;
045:
046: /**
047: * The qname localpart. For example, the localpart for the qname "a:foo"
048: * is "foo".
049: */
050: public String localpart;
051:
052: /**
053: * The qname rawname. For example, the rawname for the qname "a:foo"
054: * is "a:foo".
055: */
056: public String rawname;
057:
058: /**
059: * The URI to which the qname prefix is bound. This binding must be
060: * performed by a XML Namespaces aware processor.
061: */
062: public String uri;
063:
064: //
065: // Constructors
066: //
067:
068: /** Default constructor. */
069: public QName() {
070: clear();
071: } // <init>()
072:
073: /** Constructs a QName with the specified values. */
074: public QName(String prefix, String localpart, String rawname,
075: String uri) {
076: setValues(prefix, localpart, rawname, uri);
077: } // <init>(String,String,String,String)
078:
079: /** Constructs a copy of the specified QName. */
080: public QName(QName qname) {
081: setValues(qname);
082: } // <init>(QName)
083:
084: //
085: // Public methods
086: //
087:
088: /**
089: * Convenience method to set the values of the qname components.
090: *
091: * @param qname The qualified name to be copied.
092: */
093: public void setValues(QName qname) {
094: prefix = qname.prefix;
095: localpart = qname.localpart;
096: rawname = qname.rawname;
097: uri = qname.uri;
098: } // setValues(QName)
099:
100: /**
101: * Convenience method to set the values of the qname components.
102: *
103: * @param prefix The qname prefix. (e.g. "a")
104: * @param localpart The qname localpart. (e.g. "foo")
105: * @param rawname The qname rawname. (e.g. "a:foo")
106: * @param uri The URI binding. (e.g. "http://foo.com/mybinding")
107: */
108: public void setValues(String prefix, String localpart,
109: String rawname, String uri) {
110: this .prefix = prefix;
111: this .localpart = localpart;
112: this .rawname = rawname;
113: this .uri = uri;
114: } // setValues(String,String,String,String)
115:
116: /** Clears the values of the qname components. */
117: public void clear() {
118: prefix = null;
119: localpart = null;
120: rawname = null;
121: uri = null;
122: } // clear()
123:
124: //
125: // Cloneable methods
126: //
127:
128: /** Returns a clone of this object. */
129: public Object clone() {
130: return new QName(this );
131: } // clone():Object
132:
133: //
134: // Object methods
135: //
136:
137: /** Returns the hashcode for this object. */
138: public int hashCode() {
139: if (uri != null) {
140: return uri.hashCode()
141: + ((localpart != null) ? localpart.hashCode() : 0);
142: }
143: return (rawname != null) ? rawname.hashCode() : 0;
144: } // hashCode():int
145:
146: /** Returns true if the two objects are equal. */
147: public boolean equals(Object object) {
148: if (object instanceof QName) {
149: QName qname = (QName) object;
150: if (qname.uri != null) {
151: return uri == qname.uri && localpart == qname.localpart;
152: } else if (uri == null) {
153: return rawname == qname.rawname;
154: }
155: // fall through and return not equal
156: }
157: return false;
158: } // equals(Object):boolean
159:
160: /** Returns a string representation of this object. */
161: public String toString() {
162:
163: StringBuffer str = new StringBuffer();
164: boolean comma = false;
165: if (prefix != null) {
166: str.append("prefix=\"").append(prefix).append('"');
167: comma = true;
168: }
169: if (localpart != null) {
170: if (comma) {
171: str.append(',');
172: }
173: str.append("localpart=\"").append(localpart).append('"');
174: comma = true;
175: }
176: if (rawname != null) {
177: if (comma) {
178: str.append(',');
179: }
180: str.append("rawname=\"").append(rawname).append('"');
181: comma = true;
182: }
183: if (uri != null) {
184: if (comma) {
185: str.append(',');
186: }
187: str.append("uri=\"").append(uri).append('"');
188: }
189: return str.toString();
190:
191: } // toString():String
192:
193: } // class QName
|