KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xerces > dom > DocumentTypeImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999 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 org.enhydra.apache.xerces.dom;
59
60 import org.w3c.dom.DocumentType JavaDoc;
61 import org.w3c.dom.NamedNodeMap JavaDoc;
62 import org.w3c.dom.Node JavaDoc;
63
64 /**
65  * This class represents a Document Type <em>declaraction</em> in
66  * the document itself, <em>not</em> a Document Type Definition (DTD).
67  * An XML document may (or may not) have such a reference.
68  * <P>
69  * DocumentType is an Extended DOM feature, used in XML documents but
70  * not in HTML.
71  * <P>
72  * Note that Entities and Notations are no longer children of the
73  * DocumentType, but are parentless nodes hung only in their
74  * appropriate NamedNodeMaps.
75  * <P>
76  * This area is UNDERSPECIFIED IN REC-DOM-Level-1-19981001
77  * Most notably, absolutely no provision was made for storing
78  * and using Element and Attribute information. Nor was the linkage
79  * between Entities and Entity References nailed down solidly.
80  *
81  * @author Arnaud Le Hors, IBM
82  * @author Joe Kesselman, IBM
83  * @author Andy Clark, IBM
84  * @version
85  * @since PR-DOM-Level-1-19980818.
86  */

87 public class DocumentTypeImpl
88     extends ParentNode
89     implements DocumentType JavaDoc {
90
91     //
92
// Constants
93
//
94

95     /** Serialization version. */
96     static final long serialVersionUID = 7751299192316526485L;
97     
98     //
99
// Data
100
//
101

102     /** Document type name. */
103     protected String JavaDoc name;
104
105     /** Entities. */
106     protected NamedNodeMapImpl entities;
107     
108     /** Notations. */
109     protected NamedNodeMapImpl notations;
110
111     // NON-DOM
112

113     /** Elements. */
114     protected NamedNodeMapImpl elements;
115     
116     // DOM2: support public ID.
117
protected String JavaDoc publicID;
118     
119     // DOM2: support system ID.
120
protected String JavaDoc systemID;
121     
122     // DOM2: support internal subset.
123
protected String JavaDoc internalSubset;
124
125     //
126
// Constructors
127
//
128

129     /** Factory method for creating a document type node. */
130     public DocumentTypeImpl(CoreDocumentImpl ownerDocument, String JavaDoc name) {
131         super(ownerDocument);
132
133         this.name = name;
134         // DOM
135
entities = new NamedNodeMapImpl(this);
136         notations = new NamedNodeMapImpl(this);
137
138         // NON-DOM
139
elements = new NamedNodeMapImpl(this);
140
141     } // <init>(CoreDocumentImpl,String)
142

143     /** Factory method for creating a document type node. */
144     public DocumentTypeImpl(CoreDocumentImpl ownerDocument,
145                             String JavaDoc qualifiedName,
146                             String JavaDoc publicID, String JavaDoc systemID) {
147         this(ownerDocument, qualifiedName);
148         this.publicID = publicID;
149         this.systemID = systemID;
150
151     } // <init>(CoreDocumentImpl,String)
152

153     //
154
// DOM2: methods.
155
//
156

157     /**
158      * Introduced in DOM Level 2. <p>
159      *
160      * Return the public identifier of this Document type.
161      * @since WD-DOM-Level-2-19990923
162      */

163     public String JavaDoc getPublicId() {
164         if (needsSyncData()) {
165             synchronizeData();
166         }
167         return publicID;
168     }
169     /**
170      * Introduced in DOM Level 2. <p>
171      *
172      * Return the system identifier of this Document type.
173      * @since WD-DOM-Level-2-19990923
174      */

175     public String JavaDoc getSystemId() {
176         if (needsSyncData()) {
177             synchronizeData();
178         }
179         return systemID;
180     }
181     
182     /**
183      * NON-DOM. <p>
184      *
185      * Set the internalSubset given as a string.
186      */

187     public void setInternalSubset(String JavaDoc internalSubset) {
188         if (needsSyncData()) {
189             synchronizeData();
190         }
191         this.internalSubset = internalSubset;
192     }
193
194     /**
195      * Introduced in DOM Level 2. <p>
196      *
197      * Return the internalSubset given as a string.
198      * @since WD-DOM-Level-2-19990923
199      */

200     public String JavaDoc getInternalSubset() {
201         if (needsSyncData()) {
202             synchronizeData();
203         }
204         return internalSubset;
205     }
206     
207     //
208
// Node methods
209
//
210

211     /**
212      * A short integer indicating what type of node this is. The named
213      * constants for this value are defined in the org.w3c.dom.Node interface.
214      */

215     public short getNodeType() {
216         return Node.DOCUMENT_TYPE_NODE;
217     }
218     
219     /**
220      * Returns the document type name
221      */

222     public String JavaDoc getNodeName() {
223         if (needsSyncData()) {
224             synchronizeData();
225         }
226         return name;
227     }
228
229     /** Clones the node. */
230     public Node JavaDoc cloneNode(boolean deep) {
231
232         DocumentTypeImpl newnode = (DocumentTypeImpl)super.cloneNode(deep);
233         // NamedNodeMaps must be cloned explicitly, to avoid sharing them.
234
newnode.entities = entities.cloneMap(newnode);
235         newnode.notations = notations.cloneMap(newnode);
236         newnode.elements = elements.cloneMap(newnode);
237         newnode.internalSubset = internalSubset;
238
239         return newnode;
240
241     } // cloneNode(boolean):Node
242

243     /**
244      * NON-DOM
245      * set the ownerDocument of this node and its children
246      */

247     protected void setOwnerDocument(CoreDocumentImpl doc) {
248         super.setOwnerDocument(doc);
249         entities.setOwnerDocument(doc);
250         notations.setOwnerDocument(doc);
251         elements.setOwnerDocument(doc);
252     }
253
254     //
255
// DocumentType methods
256
//
257

258     /**
259      * Name of this document type. If we loaded from a DTD, this should
260      * be the name immediately following the DOCTYPE keyword.
261      */

262     public String JavaDoc getName() {
263
264         if (needsSyncData()) {
265             synchronizeData();
266         }
267         return name;
268
269     } // getName():String
270

271     /**
272      * Access the collection of general Entities, both external and
273      * internal, defined in the DTD. For example, in:
274      * <p>
275      * <pre>
276      * &lt;!doctype example SYSTEM "ex.dtd" [
277      * &lt;!ENTITY foo "foo"&gt;
278      * &lt;!ENTITY bar "bar"&gt;
279      * &lt;!ENTITY % baz "baz"&gt;
280      * ]&gt;
281      * </pre>
282      * <p>
283      * The Entities map includes foo and bar, but not baz. It is promised that
284      * only Nodes which are Entities will exist in this NamedNodeMap.
285      * <p>
286      * For HTML, this will always be null.
287      * <p>
288      * Note that "built in" entities such as &amp; and &lt; should be
289      * converted to their actual characters before being placed in the DOM's
290      * contained text, and should be converted back when the DOM is rendered
291      * as XML or HTML, and hence DO NOT appear here.
292      */

293     public NamedNodeMap JavaDoc getEntities() {
294         if (needsSyncChildren()) {
295             synchronizeChildren();
296             }
297         return entities;
298     }
299
300     /**
301      * Access the collection of Notations defined in the DTD. A
302      * notation declares, by name, the format of an XML unparsed entity
303      * or is used to formally declare a Processing Instruction target.
304      */

305     public NamedNodeMap JavaDoc getNotations() {
306         if (needsSyncChildren()) {
307             synchronizeChildren();
308             }
309         return notations;
310     }
311
312     //
313
// Public methods
314
//
315

316     /**
317      * NON-DOM: Subclassed to flip the entities' and notations' readonly switch
318      * as well.
319      * @see NodeImpl#setReadOnly
320      */

321     public void setReadOnly(boolean readOnly, boolean deep) {
322         
323         if (needsSyncChildren()) {
324             synchronizeChildren();
325         }
326         super.setReadOnly(readOnly, deep);
327
328         // set read-only property
329
elements.setReadOnly(readOnly, true);
330         entities.setReadOnly(readOnly, true);
331         notations.setReadOnly(readOnly, true);
332
333     } // setReadOnly(boolean,boolean)
334

335     /**
336      * NON-DOM: Access the collection of ElementDefinitions.
337      * @see ElementDefinitionImpl
338      */

339     public NamedNodeMap JavaDoc getElements() {
340         if (needsSyncChildren()) {
341             synchronizeChildren();
342         }
343         return elements;
344     }
345
346 } // class DocumentTypeImpl
347
Popular Tags