1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2000-2002 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. package com.sun.org.apache.xerces.internal.xni;
  58. /**
  59. * A structure that holds the components of an XML Namespaces qualified
  60. * name.
  61. * <p>
  62. * To be used correctly, the strings must be identical references for
  63. * equal strings. Within the parser, these values are considered symbols
  64. * and should always be retrieved from the <code>SymbolTable</code>.
  65. *
  66. * @see <a href="../../../../../xerces2/com/sun/org/apache/xerces/internal/util/SymbolTable.html">com.sun.org.apache.xerces.internal.util.SymbolTable</a>
  67. *
  68. * @author Andy Clark, IBM
  69. *
  70. * @version $Id: QName.java,v 1.5 2002/01/29 01:15:19 lehors Exp $
  71. */
  72. public class QName
  73. implements Cloneable {
  74. //
  75. // Data
  76. //
  77. /**
  78. * The qname prefix. For example, the prefix for the qname "a:foo"
  79. * is "a".
  80. */
  81. public String prefix;
  82. /**
  83. * The qname localpart. For example, the localpart for the qname "a:foo"
  84. * is "foo".
  85. */
  86. public String localpart;
  87. /**
  88. * The qname rawname. For example, the rawname for the qname "a:foo"
  89. * is "a:foo".
  90. */
  91. public String rawname;
  92. /**
  93. * The URI to which the qname prefix is bound. This binding must be
  94. * performed by a XML Namespaces aware processor.
  95. */
  96. public String uri;
  97. //
  98. // Constructors
  99. //
  100. /** Default constructor. */
  101. public QName() {
  102. clear();
  103. } // <init>()
  104. /** Constructs a QName with the specified values. */
  105. public QName(String prefix, String localpart, String rawname, String uri) {
  106. setValues(prefix, localpart, rawname, uri);
  107. } // <init>(String,String,String,String)
  108. /** Constructs a copy of the specified QName. */
  109. public QName(QName qname) {
  110. setValues(qname);
  111. } // <init>(QName)
  112. //
  113. // Public methods
  114. //
  115. /**
  116. * Convenience method to set the values of the qname components.
  117. *
  118. * @param QName The qualified name to be copied.
  119. */
  120. public void setValues(QName qname) {
  121. prefix = qname.prefix;
  122. localpart = qname.localpart;
  123. rawname = qname.rawname;
  124. uri = qname.uri;
  125. } // setValues(QName)
  126. /**
  127. * Convenience method to set the values of the qname components.
  128. *
  129. * @param prefix The qname prefix. (e.g. "a")
  130. * @param localpart The qname localpart. (e.g. "foo")
  131. * @param rawname The qname rawname. (e.g. "a:foo")
  132. * @param uri The URI binding. (e.g. "http://foo.com/mybinding")
  133. */
  134. public void setValues(String prefix, String localpart, String rawname,
  135. String uri) {
  136. this.prefix = prefix;
  137. this.localpart = localpart;
  138. this.rawname = rawname;
  139. this.uri = uri;
  140. } // setValues(String,String,String,String)
  141. /** Clears the values of the qname components. */
  142. public void clear() {
  143. prefix = null;
  144. localpart = null;
  145. rawname = null;
  146. uri = null;
  147. } // clear()
  148. //
  149. // Cloneable methods
  150. //
  151. /** Returns a clone of this object. */
  152. public Object clone() {
  153. return new QName(this);
  154. } // clone():Object
  155. //
  156. // Object methods
  157. //
  158. /** Returns the hashcode for this object. */
  159. public int hashCode() {
  160. if (uri != null) {
  161. return uri.hashCode() + localpart.hashCode();
  162. }
  163. return rawname.hashCode();
  164. } // hashCode():int
  165. /** Returns true if the two objects are equal. */
  166. public boolean equals(Object object) {
  167. if (object instanceof QName) {
  168. QName qname = (QName)object;
  169. if (qname.uri != null) {
  170. return uri == qname.uri && localpart == qname.localpart;
  171. }
  172. else if (uri == null) {
  173. return rawname == qname.rawname;
  174. }
  175. // fall through and return not equal
  176. }
  177. return false;
  178. } // equals(Object):boolean
  179. /** Returns a string representation of this object. */
  180. public String toString() {
  181. StringBuffer str = new StringBuffer();
  182. boolean comma = false;
  183. if (prefix != null) {
  184. str.append("prefix=\""+prefix+'"');
  185. comma = true;
  186. }
  187. if (localpart != null) {
  188. if (comma) {
  189. str.append(',');
  190. }
  191. str.append("localpart=\""+localpart+'"');
  192. comma = true;
  193. }
  194. if (rawname != null) {
  195. if (comma) {
  196. str.append(',');
  197. }
  198. str.append("rawname=\""+rawname+'"');
  199. comma = true;
  200. }
  201. if (uri != null) {
  202. if (comma) {
  203. str.append(',');
  204. }
  205. str.append("uri=\""+uri+'"');
  206. }
  207. return str.toString();
  208. } // toString():String
  209. } // class QName