KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xpath > datamodel > xerces > utils > QName


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2000 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.xquark.xpath.datamodel.xerces.utils;
59
60 /**
61  * QName structure useful for gathering the parts of a qualified name.
62  *
63  * @author Andy Clark
64  * @version $Id: QName.java,v 1.1 2003/10/01 16:48:50 lars Exp $
65  */

66 public class QName {
67
68     //
69
// Constants
70
//
71

72     /**
73      * Compile to true to help find places where a URI is being set
74      * to the value -1 when it should be StringPool.EMPTY_STRING (0).
75      */

76     private static final boolean FIND_URI_IS_MINUS_ONE = false;
77
78     //
79
// Data
80
//
81

82     /** Prefix. */
83     public int prefix;
84
85     /** Local part of qname. */
86     public int localpart;
87
88     /** Fully concatenated name. */
89     public int rawname;
90
91     /** URI bound to prefix. */
92     public int uri;
93
94     //
95
// Constructors
96
//
97

98     /** Default constructor. */
99     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 JavaDoc("uri value is -1 instead of StringPool.EMPTY_STRING (0)");
128                 }
129                 catch (Exception JavaDoc 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, int uri) {
147         if (FIND_URI_IS_MINUS_ONE) {
148             if (uri == -1) {
149                 try {
150                     throw new Exception JavaDoc("uri value is -1 instead of StringPool.EMPTY_STRING (0)");
151                 }
152                 catch (Exception JavaDoc e) {
153                     e.printStackTrace(System.err);
154                 }
155             }
156         }
157         this.prefix = prefix;
158         this.localpart = localpart;
159         this.rawname = rawname;
160         this.uri = uri;
161     }
162
163     /** Clears all of the values. */
164     public void clear() {
165         prefix = -1;
166         localpart = -1;
167         rawname = -1;
168         uri = StringPool.EMPTY_STRING;
169     }
170
171     //
172
// Object methods
173
//
174

175     /** Returns true if the two objects are equal. */
176     public boolean equals(Object JavaDoc object) {
177         if (object != null && object instanceof QName) {
178             QName qname = (QName)object;
179             if (uri == StringPool.EMPTY_STRING) {
180                 return rawname == qname.rawname;
181             }
182             return localpart == qname.localpart &&
183                    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 JavaDoc toString() {
195         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
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 JavaDoc toString(StringPool stringPool) {
212         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
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
228
Popular Tags