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