1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2002, 2003 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.util;
  58. import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
  59. /**
  60. * The XMLResourceIdentifierImpl class is an implementation of the
  61. * XMLResourceIdentifier interface which defines the location identity
  62. * of a resource.
  63. *
  64. * @author Andy Clark
  65. *
  66. * @version $Id: XMLResourceIdentifierImpl.java,v 1.2 2003/03/24 21:10:59 sandygao Exp $
  67. */
  68. public class XMLResourceIdentifierImpl
  69. implements XMLResourceIdentifier {
  70. //
  71. // Data
  72. //
  73. /** The public identifier. */
  74. protected String fPublicId;
  75. /** The literal system identifier. */
  76. protected String fLiteralSystemId;
  77. /** The base system identifier. */
  78. protected String fBaseSystemId;
  79. /** The expanded system identifier. */
  80. protected String fExpandedSystemId;
  81. /** The namespace of the resource. */
  82. protected String fNamespace;
  83. //
  84. // Constructors
  85. //
  86. /** Constructs an empty resource identifier. */
  87. public XMLResourceIdentifierImpl() {} // <init>()
  88. /**
  89. * Constructs a resource identifier.
  90. *
  91. * @param publicId The public identifier.
  92. * @param literalSystemId The literal system identifier.
  93. * @param baseSystemId The base system identifier.
  94. * @param expandedSystemId The expanded system identifier.
  95. */
  96. public XMLResourceIdentifierImpl(String publicId,
  97. String literalSystemId, String baseSystemId,
  98. String expandedSystemId) {
  99. setValues(publicId, literalSystemId, baseSystemId,
  100. expandedSystemId, null);
  101. } // <init>(String,String,String,String)
  102. /**
  103. * Constructs a resource identifier.
  104. *
  105. * @param publicId The public identifier.
  106. * @param literalSystemId The literal system identifier.
  107. * @param baseSystemId The base system identifier.
  108. * @param expandedSystemId The expanded system identifier.
  109. * @param namespace The namespace.
  110. */
  111. public XMLResourceIdentifierImpl(String publicId, String literalSystemId,
  112. String baseSystemId, String expandedSystemId,
  113. String namespace) {
  114. setValues(publicId, literalSystemId, baseSystemId,
  115. expandedSystemId, namespace);
  116. } // <init>(String,String,String,String,String)
  117. //
  118. // Public methods
  119. //
  120. /** Sets the values of the resource identifier. */
  121. public void setValues(String publicId, String literalSystemId,
  122. String baseSystemId, String expandedSystemId) {
  123. setValues(publicId, literalSystemId, baseSystemId,
  124. expandedSystemId, null);
  125. } // setValues(String,String,String,String)
  126. /** Sets the values of the resource identifier. */
  127. public void setValues(String publicId, String literalSystemId,
  128. String baseSystemId, String expandedSystemId,
  129. String namespace) {
  130. fPublicId = publicId;
  131. fLiteralSystemId = literalSystemId;
  132. fBaseSystemId = baseSystemId;
  133. fExpandedSystemId = expandedSystemId;
  134. fNamespace = namespace;
  135. } // setValues(String,String,String,String,String)
  136. /** Clears the values. */
  137. public void clear() {
  138. fPublicId = null;
  139. fLiteralSystemId = null;
  140. fBaseSystemId = null;
  141. fExpandedSystemId = null;
  142. fNamespace = null;
  143. } // clear()
  144. /** Sets the public identifier. */
  145. public void setPublicId(String publicId) {
  146. fPublicId = publicId;
  147. } // setPublicId(String)
  148. /** Sets the literal system identifier. */
  149. public void setLiteralSystemId(String literalSystemId) {
  150. fLiteralSystemId = literalSystemId;
  151. } // setLiteralSystemId(String)
  152. /** Sets the base system identifier. */
  153. public void setBaseSystemId(String baseSystemId) {
  154. fBaseSystemId = baseSystemId;
  155. } // setBaseSystemId(String)
  156. /** Sets the expanded system identifier. */
  157. public void setExpandedSystemId(String expandedSystemId) {
  158. fExpandedSystemId = expandedSystemId;
  159. } // setExpandedSystemId(String)
  160. /** Sets the namespace of the resource. */
  161. public void setNamespace(String namespace) {
  162. fNamespace = namespace;
  163. } // setNamespace(String)
  164. //
  165. // XMLResourceIdentifier methods
  166. //
  167. /** Returns the public identifier. */
  168. public String getPublicId() {
  169. return fPublicId;
  170. } // getPublicId():String
  171. /** Returns the literal system identifier. */
  172. public String getLiteralSystemId() {
  173. return fLiteralSystemId;
  174. } // getLiteralSystemId():String
  175. /**
  176. * Returns the base URI against which the literal SystemId is to be resolved.
  177. */
  178. public String getBaseSystemId() {
  179. return fBaseSystemId;
  180. } // getBaseSystemId():String
  181. /** Returns the expanded system identifier. */
  182. public String getExpandedSystemId() {
  183. return fExpandedSystemId;
  184. } // getExpandedSystemId():String
  185. /** Returns the namespace of the resource. */
  186. public String getNamespace() {
  187. return fNamespace;
  188. } // getNamespace():String
  189. //
  190. // Object methods
  191. //
  192. /** Returns a hash code for this object. */
  193. public int hashCode() {
  194. int code = 0;
  195. if (fPublicId != null) {
  196. code += fPublicId.hashCode();
  197. }
  198. if (fLiteralSystemId != null) {
  199. code += fLiteralSystemId.hashCode();
  200. }
  201. if (fBaseSystemId != null) {
  202. code += fBaseSystemId.hashCode();
  203. }
  204. if (fExpandedSystemId != null) {
  205. code += fExpandedSystemId.hashCode();
  206. }
  207. if (fNamespace != null) {
  208. code += fNamespace.hashCode();
  209. }
  210. return code;
  211. } // hashCode():int
  212. /** Returns a string representation of this object. */
  213. public String toString() {
  214. StringBuffer str = new StringBuffer();
  215. if (fPublicId != null) {
  216. str.append(fPublicId);
  217. }
  218. str.append(':');
  219. if (fLiteralSystemId != null) {
  220. str.append(fLiteralSystemId);
  221. }
  222. str.append(':');
  223. if (fBaseSystemId != null) {
  224. str.append(fBaseSystemId);
  225. }
  226. str.append(':');
  227. if (fExpandedSystemId != null) {
  228. str.append(fExpandedSystemId);
  229. }
  230. str.append(':');
  231. if (fNamespace != null) {
  232. str.append(fNamespace);
  233. }
  234. return str.toString();
  235. } // toString():String
  236. } // class XMLResourceIdentifierImpl