KickJava   Java API By Example, From Geeks To Geeks.

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


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

83 public class DeferredDocumentTypeImpl
84     extends DocumentTypeImpl
85     implements DeferredNode {
86
87     //
88
// Constants
89
//
90

91     /** Serialization version. */
92     static final long serialVersionUID = -2172579663227313509L;
93
94     //
95
// Data
96
//
97

98     /** Node index. */
99     protected transient int fNodeIndex;
100
101     //
102
// Constructors
103
//
104

105     /**
106      * This is the deferred constructor. Only the fNodeIndex is given here.
107      * All other data, can be requested from the ownerDocument via the index.
108      */

109     DeferredDocumentTypeImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
110         super(ownerDocument, null);
111
112         fNodeIndex = nodeIndex;
113         needsSyncData(true);
114         needsSyncChildren(true);
115
116     } // <init>(DeferredDocumentImpl,int)
117

118     //
119
// DeferredNode methods
120
//
121

122     /** Returns the node index. */
123     public int getNodeIndex() {
124         return fNodeIndex;
125     }
126
127     //
128
// Protected methods
129
//
130

131     /** Synchronizes the data (name and value) for fast nodes. */
132     protected void synchronizeData() {
133
134         // no need to sync in the future
135
needsSyncData(false);
136
137         // fluff data
138
DeferredDocumentImpl ownerDocument =
139             (DeferredDocumentImpl)this.ownerDocument;
140         name = ownerDocument.getNodeNameString(fNodeIndex);
141
142         // public and system ids
143
StringPool pool = ownerDocument.getStringPool();
144         int extraDataIndex = ownerDocument.getNodeValue(fNodeIndex);
145         //ownerDocument.getNodeType(extraDataIndex);
146
publicID = pool.toString(ownerDocument.getNodeName(extraDataIndex));
147         systemID = pool.toString(ownerDocument.getNodeValue(extraDataIndex));
148         internalSubset =
149             pool.toString(ownerDocument.getLastChild(extraDataIndex));
150     } // synchronizeData()
151

152     /** Synchronizes the entities, notations, and elements. */
153     protected void synchronizeChildren() {
154         
155         // we don't want to generate any event for this so turn them off
156
boolean orig = ownerDocument().getMutationEvents();
157         ownerDocument().setMutationEvents(false);
158
159         // no need to synchronize again
160
needsSyncChildren(false);
161
162         // create new node maps
163
DeferredDocumentImpl ownerDocument =
164             (DeferredDocumentImpl)this.ownerDocument;
165
166         entities = new NamedNodeMapImpl(this);
167         notations = new NamedNodeMapImpl(this);
168         elements = new NamedNodeMapImpl(this);
169
170         // fill node maps
171
DeferredNode last = null;
172         for (int index = ownerDocument.getLastChild(fNodeIndex);
173             index != -1;
174             index = ownerDocument.getPrevSibling(index)) {
175
176             DeferredNode node = ownerDocument.getNodeObject(index);
177             int type = node.getNodeType();
178             switch (type) {
179
180                 // internal, external, and unparsed entities
181
case Node.ENTITY_NODE: {
182                     entities.setNamedItem(node);
183                     break;
184                 }
185
186                 // notations
187
case Node.NOTATION_NODE: {
188                     notations.setNamedItem(node);
189                     break;
190                 }
191
192                 // element definitions
193
case NodeImpl.ELEMENT_DEFINITION_NODE: {
194                     elements.setNamedItem(node);
195                     break;
196                 }
197
198                 // elements
199
case Node.ELEMENT_NODE: {
200                     if (((DocumentImpl)getOwnerDocument()).allowGrammarAccess) {
201                         insertBefore(node, last);
202                         last = node;
203                         break;
204                     }
205                 }
206
207                 // NOTE: Should never get here! -Ac
208
default: {
209                     System.out.println("DeferredDocumentTypeImpl#synchronizeInfo: node.getNodeType() = "+node.getNodeType()+", class = "+node.getClass().getName());
210                 }
211              }
212         }
213
214         // set mutation events flag back to its original value
215
ownerDocument().setMutationEvents(orig);
216
217         // set entities and notations read_only per DOM spec
218
setReadOnly(true, false);
219
220     } // synchronizeChildren()
221

222 } // class DeferredDocumentTypeImpl
223
Popular Tags