KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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

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

117     //
118
// DeferredNode methods
119
//
120

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

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

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

223 } // class DeferredDocumentTypeImpl
224
Popular Tags