KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > dom > EntityImpl


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.dom;
18
19 import org.w3c.dom.Entity JavaDoc;
20 import org.w3c.dom.Node JavaDoc;
21
22 /**
23  * Entity nodes hold the reference data for an XML Entity -- either
24  * parsed or unparsed. The nodeName (inherited from Node) will contain
25  * the name (if any) of the Entity. Its data will be contained in the
26  * Entity's children, in exactly the structure which an
27  * EntityReference to this name will present within the document's
28  * body.
29  * <P>
30  * Note that this object models the actual entity, _not_ the entity
31  * declaration or the entity reference.
32  * <P>
33  * An XML processor may choose to completely expand entities before
34  * the structure model is passed to the DOM; in this case, there will
35  * be no EntityReferences in the DOM tree.
36  * <P>
37  * Quoting the 10/01 DOM Proposal,
38  * <BLOCKQUOTE>
39  * "The DOM Level 1 does not support editing Entity nodes; if a user
40  * wants to make changes to the contents of an Entity, every related
41  * EntityReference node has to be replaced in the structure model by
42  * a clone of the Entity's contents, and then the desired changes
43  * must be made to each of those clones instead. All the
44  * descendants of an Entity node are readonly."
45  * </BLOCKQUOTE>
46  * I'm interpreting this as: It is the parser's responsibilty to call
47  * the non-DOM operation setReadOnly(true,true) after it constructs
48  * the Entity. Since the DOM explicitly decided not to deal with this,
49  * _any_ answer will involve a non-DOM operation, and this is the
50  * simplest solution.
51  *
52  * @xerces.internal
53  *
54  * @author Elena Litani, IBM
55  * @version $Id: EntityImpl.java,v 1.26 2004/10/05 17:12:51 mrglavas Exp $
56  * @since PR-DOM-Level-1-19980818.
57  */

58 public class EntityImpl
59     extends ParentNode
60     implements Entity JavaDoc {
61
62     //
63
// Constants
64
//
65

66     /** Serialization version. */
67     static final long serialVersionUID = -3575760943444303423L;
68     
69     //
70
// Data
71
//
72

73     /** Entity name. */
74     protected String JavaDoc name;
75
76     /** Public identifier. */
77     protected String JavaDoc publicId;
78
79     /** System identifier. */
80     protected String JavaDoc systemId;
81
82     /** Encoding */
83     protected String JavaDoc encoding;
84
85
86     /** Input Encoding */
87     protected String JavaDoc inputEncoding;
88     
89     /** Version */
90     protected String JavaDoc version;
91
92
93     /** Notation name. */
94     protected String JavaDoc notationName;
95
96     /** base uri*/
97     protected String JavaDoc baseURI;
98
99     //
100
// Constructors
101
//
102

103     /** Factory constructor. */
104     public EntityImpl(CoreDocumentImpl ownerDoc, String JavaDoc name) {
105         super(ownerDoc);
106         this.name = name;
107         isReadOnly(true);
108     }
109     
110     //
111
// Node methods
112
//
113

114     /**
115      * A short integer indicating what type of node this is. The named
116      * constants for this value are defined in the org.w3c.dom.Node interface.
117      */

118     public short getNodeType() {
119         return Node.ENTITY_NODE;
120     }
121
122     /**
123      * Returns the entity name
124      */

125     public String JavaDoc getNodeName() {
126         if (needsSyncData()) {
127             synchronizeData();
128         }
129         return name;
130     }
131
132     /** Clone node. */
133     public Node JavaDoc cloneNode(boolean deep) {
134         EntityImpl newentity = (EntityImpl)super.cloneNode(deep);
135         newentity.setReadOnly(true, deep);
136         return newentity;
137     }
138
139     //
140
// Entity methods
141
//
142

143     /**
144      * The public identifier associated with the entity. If not specified,
145      * this will be null.
146      */

147     public String JavaDoc getPublicId() {
148         
149         if (needsSyncData()) {
150             synchronizeData();
151         }
152         return publicId;
153
154     } // getPublicId():String
155

156     /**
157      * The system identifier associated with the entity. If not specified,
158      * this will be null.
159      */

160     public String JavaDoc getSystemId() {
161
162         if (needsSyncData()) {
163             synchronizeData();
164         }
165         return systemId;
166
167     } // getSystemId():String
168

169     /**
170       * DOM Level 3 WD - experimental
171       * the version number of this entity, when it is an external parsed entity.
172       */

173     public String JavaDoc getXmlVersion() {
174
175        if (needsSyncData()) {
176            synchronizeData();
177        }
178        return version;
179
180    } // getVersion():String
181

182
183     /**
184      * DOM Level 3 WD - experimental
185      * the encoding of this entity, when it is an external parsed entity.
186      */

187     public String JavaDoc getXmlEncoding() {
188
189        if (needsSyncData()) {
190            synchronizeData();
191        }
192
193        return encoding;
194
195    } // getVersion():String
196

197
198
199
200
201     /**
202      * Unparsed entities -- which contain non-XML data -- have a
203      * "notation name" which tells applications how to deal with them.
204      * Parsed entities, which <em>are</em> in XML format, don't need this and
205      * set it to null.
206      */

207     public String JavaDoc getNotationName() {
208
209         if (needsSyncData()) {
210             synchronizeData();
211         }
212         return notationName;
213
214     } // getNotationName():String
215

216     //
217
// Public methods
218
//
219

220     /**
221      * DOM Level 2: The public identifier associated with the entity. If not specified,
222      * this will be null. */

223     public void setPublicId(String JavaDoc id) {
224         
225         if (needsSyncData()) {
226             synchronizeData();
227         }
228         publicId = id;
229
230     } // setPublicId(String)
231

232     /**
233      * NON-DOM
234      * encoding - An attribute specifying, as part of the text declaration,
235      * the encoding of this entity, when it is an external parsed entity.
236      * This is null otherwise
237      *
238      */

239     public void setXmlEncoding(String JavaDoc value) {
240         if (needsSyncData()) {
241             synchronizeData();
242         }
243         encoding = value;
244     } // setEncoding (String)
245

246
247     /**
248      * An attribute specifying the encoding used for this entity at the tiome
249      * of parsing, when it is an external parsed entity. This is
250      * <code>null</code> if it an entity from the internal subset or if it
251      * is not known..
252      * @since DOM Level 3
253      */

254     public String JavaDoc getInputEncoding(){
255         if (needsSyncData()) {
256             synchronizeData();
257         }
258         return inputEncoding;
259     }
260     
261     /**
262      * NON-DOM, used to set the input encoding.
263      */

264     public void setInputEncoding(String JavaDoc inputEncoding){
265         if (needsSyncData()) {
266             synchronizeData();
267         }
268         this.inputEncoding = inputEncoding;
269     }
270
271     /**
272       * NON-DOM
273       * version - An attribute specifying, as part of the text declaration,
274       * the version number of this entity, when it is an external parsed entity.
275       * This is null otherwise
276       */

277     public void setXmlVersion(String JavaDoc value) {
278         if (needsSyncData()) {
279             synchronizeData();
280         }
281         version = value;
282     } // setVersion (String)
283

284
285     /**
286      * DOM Level 2: The system identifier associated with the entity. If not
287      * specified, this will be null.
288      */

289     public void setSystemId(String JavaDoc id) {
290         if (needsSyncData()) {
291             synchronizeData();
292         }
293         systemId = id;
294
295     } // setSystemId(String)
296

297     /**
298      * DOM Level 2: Unparsed entities -- which contain non-XML data -- have a
299      * "notation name" which tells applications how to deal with them.
300      * Parsed entities, which <em>are</em> in XML format, don't need this and
301      * set it to null.
302      */

303     public void setNotationName(String JavaDoc name) {
304         if (needsSyncData()) {
305             synchronizeData();
306         }
307         notationName = name;
308
309     } // setNotationName(String)
310

311
312
313     /**
314      * Returns the absolute base URI of this node or null if the implementation
315      * wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
316      * null is returned.
317      *
318      * @return The absolute base URI of this node or null.
319      * @since DOM Level 3
320      */

321     public String JavaDoc getBaseURI() {
322
323         if (needsSyncData()) {
324             synchronizeData();
325         }
326         return (baseURI!=null)?baseURI:((CoreDocumentImpl)getOwnerDocument()).getBaseURI();
327     }
328
329     /** NON-DOM: set base uri*/
330     public void setBaseURI(String JavaDoc uri){
331         if (needsSyncData()) {
332             synchronizeData();
333         }
334         baseURI = uri;
335     }
336
337
338
339 } // class EntityImpl
340
Popular Tags