View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2002, 2003,2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *      http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package com.sun.org.apache.xerces.internal.util;
22  
23  import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
24  
25  /**
26   * The XMLResourceIdentifierImpl class is an implementation of the
27   * XMLResourceIdentifier interface which defines the location identity
28   * of a resource.
29   *
30   * @author Andy Clark
31   *
32   */
33  public class XMLResourceIdentifierImpl
34      implements XMLResourceIdentifier {
35  
36      //
37      // Data
38      //
39  
40      /** The public identifier. */
41      protected String fPublicId;
42  
43      /** The literal system identifier. */
44      protected String fLiteralSystemId;
45  
46      /** The base system identifier. */
47      protected String fBaseSystemId;
48  
49      /** The expanded system identifier. */
50      protected String fExpandedSystemId;
51  
52      /** The namespace of the resource. */
53      protected String fNamespace;
54  
55      //
56      // Constructors
57      //
58  
59      /** Constructs an empty resource identifier. */
60      public XMLResourceIdentifierImpl() {} // <init>()
61  
62      /**
63       * Constructs a resource identifier.
64       *
65       * @param publicId The public identifier.
66       * @param literalSystemId The literal system identifier.
67       * @param baseSystemId The base system identifier.
68       * @param expandedSystemId The expanded system identifier.
69       */
70      public XMLResourceIdentifierImpl(String publicId,
71                                       String literalSystemId, String baseSystemId,
72                                       String expandedSystemId) {
73          setValues(publicId, literalSystemId, baseSystemId,
74                    expandedSystemId, null);
75      } // <init>(String,String,String,String)
76  
77      /**
78       * Constructs a resource identifier.
79       *
80       * @param publicId The public identifier.
81       * @param literalSystemId The literal system identifier.
82       * @param baseSystemId The base system identifier.
83       * @param expandedSystemId The expanded system identifier.
84       * @param namespace The namespace.
85       */
86      public XMLResourceIdentifierImpl(String publicId, String literalSystemId,
87                                       String baseSystemId, String expandedSystemId,
88                                       String namespace) {
89          setValues(publicId, literalSystemId, baseSystemId,
90                    expandedSystemId, namespace);
91      } // <init>(String,String,String,String,String)
92  
93      //
94      // Public methods
95      //
96  
97      /** Sets the values of the resource identifier. */
98      public void setValues(String publicId, String literalSystemId,
99                            String baseSystemId, String expandedSystemId) {
100         setValues(publicId, literalSystemId, baseSystemId,
101                   expandedSystemId, null);
102     } // setValues(String,String,String,String)
103 
104     /** Sets the values of the resource identifier. */
105     public void setValues(String publicId, String literalSystemId,
106                           String baseSystemId, String expandedSystemId,
107                           String namespace) {
108         fPublicId = publicId;
109         fLiteralSystemId = literalSystemId;
110         fBaseSystemId = baseSystemId;
111         fExpandedSystemId = expandedSystemId;
112         fNamespace = namespace;
113     } // setValues(String,String,String,String,String)
114 
115     /** Clears the values. */
116     public void clear() {
117         fPublicId = null;
118         fLiteralSystemId = null;
119         fBaseSystemId = null;
120         fExpandedSystemId = null;
121         fNamespace = null;
122     } // clear()
123 
124     /** Sets the public identifier. */
125     public void setPublicId(String publicId) {
126         fPublicId = publicId;
127     } // setPublicId(String)
128 
129     /** Sets the literal system identifier. */
130     public void setLiteralSystemId(String literalSystemId) {
131         fLiteralSystemId = literalSystemId;
132     } // setLiteralSystemId(String)
133 
134     /** Sets the base system identifier. */
135     public void setBaseSystemId(String baseSystemId) {
136         fBaseSystemId = baseSystemId;
137     } // setBaseSystemId(String)
138 
139     /** Sets the expanded system identifier. */
140     public void setExpandedSystemId(String expandedSystemId) {
141         fExpandedSystemId = expandedSystemId;
142     } // setExpandedSystemId(String)
143 
144     /** Sets the namespace of the resource. */
145     public void setNamespace(String namespace) {
146         fNamespace = namespace;
147     } // setNamespace(String)
148 
149     //
150     // XMLResourceIdentifier methods
151     //
152 
153     /** Returns the public identifier. */
154     public String getPublicId() {
155         return fPublicId;
156     } // getPublicId():String
157 
158     /** Returns the literal system identifier. */
159     public String getLiteralSystemId() {
160         return fLiteralSystemId;
161     } // getLiteralSystemId():String
162 
163     /**
164      * Returns the base URI against which the literal SystemId is to be resolved.
165      */
166     public String getBaseSystemId() {
167         return fBaseSystemId;
168     } // getBaseSystemId():String
169 
170     /** Returns the expanded system identifier. */
171     public String getExpandedSystemId() {
172         return fExpandedSystemId;
173     } // getExpandedSystemId():String
174 
175     /** Returns the namespace of the resource. */
176     public String getNamespace() {
177         return fNamespace;
178     } // getNamespace():String
179 
180     //
181     // Object methods
182     //
183 
184     /** Returns a hash code for this object. */
185     public int hashCode() {
186         int code = 0;
187         if (fPublicId != null) {
188             code += fPublicId.hashCode();
189         }
190         if (fLiteralSystemId != null) {
191             code += fLiteralSystemId.hashCode();
192         }
193         if (fBaseSystemId != null) {
194             code += fBaseSystemId.hashCode();
195         }
196         if (fExpandedSystemId != null) {
197             code += fExpandedSystemId.hashCode();
198         }
199         if (fNamespace != null) {
200             code += fNamespace.hashCode();
201         }
202         return code;
203     } // hashCode():int
204 
205     /** Returns a string representation of this object. */
206     public String toString() {
207         StringBuffer str = new StringBuffer();
208         if (fPublicId != null) {
209             str.append(fPublicId);
210         }
211         str.append(':');
212         if (fLiteralSystemId != null) {
213             str.append(fLiteralSystemId);
214         }
215         str.append(':');
216         if (fBaseSystemId != null) {
217             str.append(fBaseSystemId);
218         }
219         str.append(':');
220         if (fExpandedSystemId != null) {
221             str.append(fExpandedSystemId);
222         }
223         str.append(':');
224         if (fNamespace != null) {
225             str.append(fNamespace);
226         }
227         return str.toString();
228     } // toString():String
229 
230 } // class XMLResourceIdentifierImpl