KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xpath > datamodel > 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.xquark.xpath.datamodel.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(DocumentImpl 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>(DocumentImpl,String)
142

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

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

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

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

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

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

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

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

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

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

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

245     void setOwnerDocument(DocumentImpl doc) {
246         super.setOwnerDocument(doc);
247         entities.setOwnerDocument(doc);
248         notations.setOwnerDocument(doc);
249         elements.setOwnerDocument(doc);
250     }
251
252     //
253
// DocumentType methods
254
//
255

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

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

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

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

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

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

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

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

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