KickJava   Java API By Example, From Geeks To Geeks.

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


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.Node JavaDoc;
20
21 /**
22  * This class represents a Document Type <em>declaraction</em> in
23  * the document itself, <em>not</em> a Document Type Definition (DTD).
24  * An XML document may (or may not) have such a reference.
25  * <P>
26  * DocumentType is an Extended DOM feature, used in XML documents but
27  * not in HTML.
28  * <P>
29  * Note that Entities and Notations are no longer children of the
30  * DocumentType, but are parentless nodes hung only in their
31  * appropriate NamedNodeMaps.
32  * <P>
33  * This area is UNDERSPECIFIED IN REC-DOM-Level-1-19981001
34  * Most notably, absolutely no provision was made for storing
35  * and using Element and Attribute information. Nor was the linkage
36  * between Entities and Entity References nailed down solidly.
37  *
38  * @xerces.internal
39  *
40  * @version $Id: DeferredDocumentTypeImpl.java,v 1.18 2004/10/05 17:12:51 mrglavas Exp $
41  * @since PR-DOM-Level-1-19980818.
42  */

43 public class DeferredDocumentTypeImpl
44     extends DocumentTypeImpl
45     implements DeferredNode {
46
47     //
48
// Constants
49
//
50

51     /** Serialization version. */
52     static final long serialVersionUID = -2172579663227313509L;
53
54     //
55
// Data
56
//
57

58     /** Node index. */
59     protected transient int fNodeIndex;
60
61     //
62
// Constructors
63
//
64

65     /**
66      * This is the deferred constructor. Only the fNodeIndex is given here.
67      * All other data, can be requested from the ownerDocument via the index.
68      */

69     DeferredDocumentTypeImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
70         super(ownerDocument, null);
71
72         fNodeIndex = nodeIndex;
73         needsSyncData(true);
74         needsSyncChildren(true);
75
76     } // <init>(DeferredDocumentImpl,int)
77

78     //
79
// DeferredNode methods
80
//
81

82     /** Returns the node index. */
83     public int getNodeIndex() {
84         return fNodeIndex;
85     }
86
87     //
88
// Protected methods
89
//
90

91     /** Synchronizes the data (name and value) for fast nodes. */
92     protected void synchronizeData() {
93
94         // no need to sync in the future
95
needsSyncData(false);
96
97         // fluff data
98
DeferredDocumentImpl ownerDocument =
99             (DeferredDocumentImpl)this.ownerDocument;
100         name = ownerDocument.getNodeName(fNodeIndex);
101
102         // public and system ids
103
publicID = ownerDocument.getNodeValue(fNodeIndex);
104         systemID = ownerDocument.getNodeURI(fNodeIndex);
105         int extraDataIndex = ownerDocument.getNodeExtra(fNodeIndex);
106         internalSubset = ownerDocument.getNodeValue(extraDataIndex);
107     } // synchronizeData()
108

109     /** Synchronizes the entities, notations, and elements. */
110     protected void synchronizeChildren() {
111         
112         // we don't want to generate any event for this so turn them off
113
boolean orig = ownerDocument().getMutationEvents();
114         ownerDocument().setMutationEvents(false);
115
116         // no need to synchronize again
117
needsSyncChildren(false);
118
119         // create new node maps
120
DeferredDocumentImpl ownerDocument =
121             (DeferredDocumentImpl)this.ownerDocument;
122
123         entities = new NamedNodeMapImpl(this);
124         notations = new NamedNodeMapImpl(this);
125         elements = new NamedNodeMapImpl(this);
126
127         // fill node maps
128
DeferredNode last = null;
129         for (int index = ownerDocument.getLastChild(fNodeIndex);
130             index != -1;
131             index = ownerDocument.getPrevSibling(index)) {
132
133             DeferredNode node = ownerDocument.getNodeObject(index);
134             int type = node.getNodeType();
135             switch (type) {
136
137                 // internal, external, and unparsed entities
138
case Node.ENTITY_NODE: {
139                     entities.setNamedItem(node);
140                     break;
141                 }
142
143                 // notations
144
case Node.NOTATION_NODE: {
145                     notations.setNamedItem(node);
146                     break;
147                 }
148
149                 // element definitions
150
case NodeImpl.ELEMENT_DEFINITION_NODE: {
151                     elements.setNamedItem(node);
152                     break;
153                 }
154
155                 // elements
156
case Node.ELEMENT_NODE: {
157                     if (((DocumentImpl)getOwnerDocument()).allowGrammarAccess){
158                         insertBefore(node, last);
159                         last = node;
160                         break;
161                     }
162                 }
163
164                 // NOTE: Should never get here! -Ac
165
default: {
166                     System.out.println("DeferredDocumentTypeImpl" +
167                                        "#synchronizeInfo: " +
168                                        "node.getNodeType() = " +
169                                        node.getNodeType() +
170                                        ", class = " +
171                                        node.getClass().getName());
172                 }
173              }
174         }
175
176         // set mutation events flag back to its original value
177
ownerDocument().setMutationEvents(orig);
178
179         // set entities and notations read_only per DOM spec
180
setReadOnly(true, false);
181
182     } // synchronizeChildren()
183

184 } // class DeferredDocumentTypeImpl
185
Popular Tags