KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > dom > EntityImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999-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
58 package com.sun.org.apache.xerces.internal.dom;
59
60 import org.w3c.dom.Entity JavaDoc;
61 import org.w3c.dom.Node JavaDoc;
62
63 /**
64  * Entity nodes hold the reference data for an XML Entity -- either
65  * parsed or unparsed. The nodeName (inherited from Node) will contain
66  * the name (if any) of the Entity. Its data will be contained in the
67  * Entity's children, in exactly the structure which an
68  * EntityReference to this name will present within the document's
69  * body.
70  * <P>
71  * Note that this object models the actual entity, _not_ the entity
72  * declaration or the entity reference.
73  * <P>
74  * An XML processor may choose to completely expand entities before
75  * the structure model is passed to the DOM; in this case, there will
76  * be no EntityReferences in the DOM tree.
77  * <P>
78  * Quoting the 10/01 DOM Proposal,
79  * <BLOCKQUOTE>
80  * "The DOM Level 1 does not support editing Entity nodes; if a user
81  * wants to make changes to the contents of an Entity, every related
82  * EntityReference node has to be replaced in the structure model by
83  * a clone of the Entity's contents, and then the desired changes
84  * must be made to each of those clones instead. All the
85  * descendants of an Entity node are readonly."
86  * </BLOCKQUOTE>
87  * I'm interpreting this as: It is the parser's responsibilty to call
88  * the non-DOM operation setReadOnly(true,true) after it constructs
89  * the Entity. Since the DOM explicitly decided not to deal with this,
90  * _any_ answer will involve a non-DOM operation, and this is the
91  * simplest solution.
92  *
93  * @author Elena Litani, IBM
94  * @version $Id: EntityImpl.java,v 1.23 2003/11/13 22:47:15 elena Exp $
95  * @since PR-DOM-Level-1-19980818.
96  */

97 public class EntityImpl
98     extends ParentNode
99     implements Entity JavaDoc {
100
101     //
102
// Constants
103
//
104

105     /** Serialization version. */
106     static final long serialVersionUID = -3575760943444303423L;
107     
108     //
109
// Data
110
//
111

112     /** Entity name. */
113     protected String JavaDoc name;
114
115     /** Public identifier. */
116     protected String JavaDoc publicId;
117
118     /** System identifier. */
119     protected String JavaDoc systemId;
120
121     /** Encoding */
122     protected String JavaDoc encoding;
123
124
125     /** Input Encoding */
126     protected String JavaDoc inputEncoding;
127     
128     /** Version */
129     protected String JavaDoc version;
130
131
132     /** Notation name. */
133     protected String JavaDoc notationName;
134
135     /** base uri*/
136     protected String JavaDoc baseURI;
137
138     //
139
// Constructors
140
//
141

142     /** Factory constructor. */
143     public EntityImpl(CoreDocumentImpl ownerDoc, String JavaDoc name) {
144         super(ownerDoc);
145         this.name = name;
146         isReadOnly(true);
147     }
148     
149     //
150
// Node methods
151
//
152

153     /**
154      * A short integer indicating what type of node this is. The named
155      * constants for this value are defined in the org.w3c.dom.Node interface.
156      */

157     public short getNodeType() {
158         return Node.ENTITY_NODE;
159     }
160
161     /**
162      * Returns the entity name
163      */

164     public String JavaDoc getNodeName() {
165         if (needsSyncData()) {
166             synchronizeData();
167         }
168         return name;
169     }
170
171     /** Clone node. */
172     public Node JavaDoc cloneNode(boolean deep) {
173         EntityImpl newentity = (EntityImpl)super.cloneNode(deep);
174         newentity.setReadOnly(true, deep);
175         return newentity;
176     }
177
178     //
179
// Entity methods
180
//
181

182     /**
183      * The public identifier associated with the entity. If not specified,
184      * this will be null.
185      */

186     public String JavaDoc getPublicId() {
187         
188         if (needsSyncData()) {
189             synchronizeData();
190         }
191         return publicId;
192
193     } // getPublicId():String
194

195     /**
196      * The system identifier associated with the entity. If not specified,
197      * this will be null.
198      */

199     public String JavaDoc getSystemId() {
200
201         if (needsSyncData()) {
202             synchronizeData();
203         }
204         return systemId;
205
206     } // getSystemId():String
207

208     /**
209       * DOM Level 3 WD - experimental
210       * the version number of this entity, when it is an external parsed entity.
211       */

212     public String JavaDoc getXmlVersion() {
213
214        if (needsSyncData()) {
215            synchronizeData();
216        }
217        return version;
218
219    } // getVersion():String
220

221
222     /**
223      * DOM Level 3 WD - experimental
224      * the encoding of this entity, when it is an external parsed entity.
225      */

226     public String JavaDoc getXmlEncoding() {
227
228        if (needsSyncData()) {
229            synchronizeData();
230        }
231
232        return encoding;
233
234    } // getVersion():String
235

236
237
238
239
240     /**
241      * Unparsed entities -- which contain non-XML data -- have a
242      * "notation name" which tells applications how to deal with them.
243      * Parsed entities, which <em>are</em> in XML format, don't need this and
244      * set it to null.
245      */

246     public String JavaDoc getNotationName() {
247
248         if (needsSyncData()) {
249             synchronizeData();
250         }
251         return notationName;
252
253     } // getNotationName():String
254

255     //
256
// Public methods
257
//
258

259     /**
260      * DOM Level 2: The public identifier associated with the entity. If not specified,
261      * this will be null. */

262     public void setPublicId(String JavaDoc id) {
263         
264         if (needsSyncData()) {
265             synchronizeData();
266         }
267         publicId = id;
268
269     } // setPublicId(String)
270

271     /**
272      * NON-DOM
273      * encoding - An attribute specifying, as part of the text declaration,
274      * the encoding of this entity, when it is an external parsed entity.
275      * This is null otherwise
276      *
277      */

278     public void setXmlEncoding(String JavaDoc value) {
279         if (needsSyncData()) {
280             synchronizeData();
281         }
282         encoding = value;
283     } // setEncoding (String)
284

285
286     /**
287      * An attribute specifying the encoding used for this entity at the tiome
288      * of parsing, when it is an external parsed entity. This is
289      * <code>null</code> if it an entity from the internal subset or if it
290      * is not known..
291      * @since DOM Level 3
292      */

293     public String JavaDoc getInputEncoding(){
294         if (needsSyncData()) {
295             synchronizeData();
296         }
297         return inputEncoding;
298     }
299     
300     /**
301      * NON-DOM, used to set the input encoding.
302      */

303     public void setInputEncoding(String JavaDoc inputEncoding){
304         if (needsSyncData()) {
305             synchronizeData();
306         }
307         this.inputEncoding = inputEncoding;
308     }
309
310     /**
311       * NON-DOM
312       * version - An attribute specifying, as part of the text declaration,
313       * the version number of this entity, when it is an external parsed entity.
314       * This is null otherwise
315       */

316     public void setXmlVersion(String JavaDoc value) {
317         if (needsSyncData()) {
318             synchronizeData();
319         }
320         version = value;
321     } // setVersion (String)
322

323
324     /**
325      * DOM Level 2: The system identifier associated with the entity. If not
326      * specified, this will be null.
327      */

328     public void setSystemId(String JavaDoc id) {
329         if (needsSyncData()) {
330             synchronizeData();
331         }
332         systemId = id;
333
334     } // setSystemId(String)
335

336     /**
337      * DOM Level 2: Unparsed entities -- which contain non-XML data -- have a
338      * "notation name" which tells applications how to deal with them.
339      * Parsed entities, which <em>are</em> in XML format, don't need this and
340      * set it to null.
341      */

342     public void setNotationName(String JavaDoc name) {
343         if (needsSyncData()) {
344             synchronizeData();
345         }
346         notationName = name;
347
348     } // setNotationName(String)
349

350
351
352     /**
353      * DOM Level 3 WD - Experimental.
354      * Retrieve baseURI
355      */

356     public String JavaDoc getBaseURI() {
357
358         if (needsSyncData()) {
359             synchronizeData();
360         }
361         return (baseURI!=null)?baseURI:((CoreDocumentImpl)getOwnerDocument()).getBaseURI();
362     }
363
364     /** NON-DOM: set base uri*/
365     public void setBaseURI(String JavaDoc uri){
366         if (needsSyncData()) {
367             synchronizeData();
368         }
369         baseURI = uri;
370     }
371
372
373
374 } // class EntityImpl
375
Popular Tags