001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2000 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.xerces.utils;
059:
060: /**
061: * QName structure useful for gathering the parts of a qualified name.
062: *
063: * @author Andy Clark
064: * @version $Id: QName.java,v 1.3 2001/02/01 09:58:28 andyc Exp $
065: */
066: public class QName {
067:
068: //
069: // Constants
070: //
071:
072: /**
073: * Compile to true to help find places where a URI is being set
074: * to the value -1 when it should be StringPool.EMPTY_STRING (0).
075: */
076: private static final boolean FIND_URI_IS_MINUS_ONE = false;
077:
078: //
079: // Data
080: //
081:
082: /** Prefix. */
083: public int prefix;
084:
085: /** Local part of qname. */
086: public int localpart;
087:
088: /** Fully concatenated name. */
089: public int rawname;
090:
091: /** URI bound to prefix. */
092: public int uri;
093:
094: //
095: // Constructors
096: //
097:
098: /** Default constructor. */
099: public QName() {
100: clear();
101: }
102:
103: /** Constructs a specified qname. */
104: public QName(int prefix, int localpart, int rawname) {
105: setValues(prefix, localpart, rawname, StringPool.EMPTY_STRING);
106: }
107:
108: /** Constructs a specified qname. */
109: public QName(int prefix, int localpart, int rawname, int uri) {
110: setValues(prefix, localpart, rawname, uri);
111: }
112:
113: /** Copy constructor. */
114: public QName(QName qname) {
115: setValues(qname);
116: }
117:
118: //
119: // Public methods
120: //
121:
122: /** Sets the values of the qualified name. */
123: public void setValues(QName qname) {
124: if (FIND_URI_IS_MINUS_ONE) {
125: if (qname.uri == -1) {
126: try {
127: throw new Exception(
128: "uri value is -1 instead of StringPool.EMPTY_STRING (0)");
129: } catch (Exception e) {
130: e.printStackTrace(System.err);
131: }
132: }
133: }
134: prefix = qname.prefix;
135: localpart = qname.localpart;
136: rawname = qname.rawname;
137: uri = qname.uri;
138: }
139:
140: /** Sets the values of the qualified name. */
141: public void setValues(int prefix, int localpart, int rawname) {
142: setValues(prefix, localpart, rawname, StringPool.EMPTY_STRING);
143: }
144:
145: /** Sets the values of the qualified name. */
146: public void setValues(int prefix, int localpart, int rawname,
147: int uri) {
148: if (FIND_URI_IS_MINUS_ONE) {
149: if (uri == -1) {
150: try {
151: throw new Exception(
152: "uri value is -1 instead of StringPool.EMPTY_STRING (0)");
153: } catch (Exception e) {
154: e.printStackTrace(System.err);
155: }
156: }
157: }
158: this .prefix = prefix;
159: this .localpart = localpart;
160: this .rawname = rawname;
161: this .uri = uri;
162: }
163:
164: /** Clears all of the values. */
165: public void clear() {
166: prefix = -1;
167: localpart = -1;
168: rawname = -1;
169: uri = StringPool.EMPTY_STRING;
170: }
171:
172: //
173: // Object methods
174: //
175:
176: /** Returns true if the two objects are equal. */
177: public boolean equals(Object object) {
178: if (object != null && object instanceof QName) {
179: QName qname = (QName) object;
180: if (uri == StringPool.EMPTY_STRING) {
181: return rawname == qname.rawname;
182: }
183: return localpart == qname.localpart && uri == qname.uri;
184: }
185: return false;
186: }
187:
188: /** Returns a hash code value. */
189: public int hashCode() {
190: return (localpart << 16) | uri;
191: }
192:
193: /** Returns a string representation of this object. */
194: public String toString() {
195: StringBuffer str = new StringBuffer();
196: str.append("prefix: ");
197: str.append(prefix);
198: str.append(", ");
199: str.append("localpart: ");
200: str.append(localpart);
201: str.append(", ");
202: str.append("rawname: ");
203: str.append(rawname);
204: str.append(", ");
205: str.append("uri: ");
206: str.append(uri);
207: return str.toString();
208: }
209:
210: /** Returns a string representation of this object. */
211: public String toString(StringPool stringPool) {
212: StringBuffer str = new StringBuffer();
213: str.append("prefix: ");
214: str.append(String.valueOf(stringPool.toString(prefix)));
215: str.append(", ");
216: str.append("localpart: ");
217: str.append(String.valueOf(stringPool.toString(localpart)));
218: str.append(", ");
219: str.append("rawname: ");
220: str.append(String.valueOf(stringPool.toString(rawname)));
221: str.append(", ");
222: str.append("uri: ");
223: str.append(String.valueOf(stringPool.toString(uri)));
224: return str.toString();
225: }
226:
227: } // class QName
|