1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.xerces.internal.dom; 23 24 import org.w3c.dom.Node; 25 26 /** 27 * This class represents a Document Type <em>declaraction</em> in 28 * the document itself, <em>not</em> a Document Type Definition (DTD). 29 * An XML document may (or may not) have such a reference. 30 * <P> 31 * DocumentType is an Extended DOM feature, used in XML documents but 32 * not in HTML. 33 * <P> 34 * Note that Entities and Notations are no longer children of the 35 * DocumentType, but are parentless nodes hung only in their 36 * appropriate NamedNodeMaps. 37 * <P> 38 * This area is UNDERSPECIFIED IN REC-DOM-Level-1-19981001 39 * Most notably, absolutely no provision was made for storing 40 * and using Element and Attribute information. Nor was the linkage 41 * between Entities and Entity References nailed down solidly. 42 * 43 * @xerces.internal 44 * 45 * @since PR-DOM-Level-1-19980818. 46 */ 47 public class DeferredDocumentTypeImpl 48 extends DocumentTypeImpl 49 implements DeferredNode { 50 51 // 52 // Constants 53 // 54 55 /** Serialization version. */ 56 static final long serialVersionUID = -2172579663227313509L; 57 58 // 59 // Data 60 // 61 62 /** Node index. */ 63 protected transient int fNodeIndex; 64 65 // 66 // Constructors 67 // 68 69 /** 70 * This is the deferred constructor. Only the fNodeIndex is given here. 71 * All other data, can be requested from the ownerDocument via the index. 72 */ 73 DeferredDocumentTypeImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) { 74 super(ownerDocument, null); 75 76 fNodeIndex = nodeIndex; 77 needsSyncData(true); 78 needsSyncChildren(true); 79 80 } // <init>(DeferredDocumentImpl,int) 81 82 // 83 // DeferredNode methods 84 // 85 86 /** Returns the node index. */ 87 public int getNodeIndex() { 88 return fNodeIndex; 89 } 90 91 // 92 // Protected methods 93 // 94 95 /** Synchronizes the data (name and value) for fast nodes. */ 96 protected void synchronizeData() { 97 98 // no need to sync in the future 99 needsSyncData(false); 100 101 // fluff data 102 DeferredDocumentImpl ownerDocument = 103 (DeferredDocumentImpl)this.ownerDocument; 104 name = ownerDocument.getNodeName(fNodeIndex); 105 106 // public and system ids 107 publicID = ownerDocument.getNodeValue(fNodeIndex); 108 systemID = ownerDocument.getNodeURI(fNodeIndex); 109 int extraDataIndex = ownerDocument.getNodeExtra(fNodeIndex); 110 internalSubset = ownerDocument.getNodeValue(extraDataIndex); 111 } // synchronizeData() 112 113 /** Synchronizes the entities, notations, and elements. */ 114 protected void synchronizeChildren() { 115 116 // we don't want to generate any event for this so turn them off 117 boolean orig = ownerDocument().getMutationEvents(); 118 ownerDocument().setMutationEvents(false); 119 120 // no need to synchronize again 121 needsSyncChildren(false); 122 123 // create new node maps 124 DeferredDocumentImpl ownerDocument = 125 (DeferredDocumentImpl)this.ownerDocument; 126 127 entities = new NamedNodeMapImpl(this); 128 notations = new NamedNodeMapImpl(this); 129 elements = new NamedNodeMapImpl(this); 130 131 // fill node maps 132 DeferredNode last = null; 133 for (int index = ownerDocument.getLastChild(fNodeIndex); 134 index != -1; 135 index = ownerDocument.getPrevSibling(index)) { 136 137 DeferredNode node = ownerDocument.getNodeObject(index); 138 int type = node.getNodeType(); 139 switch (type) { 140 141 // internal, external, and unparsed entities 142 case Node.ENTITY_NODE: { 143 entities.setNamedItem(node); 144 break; 145 } 146 147 // notations 148 case Node.NOTATION_NODE: { 149 notations.setNamedItem(node); 150 break; 151 } 152 153 // element definitions 154 case NodeImpl.ELEMENT_DEFINITION_NODE: { 155 elements.setNamedItem(node); 156 break; 157 } 158 159 // elements 160 case Node.ELEMENT_NODE: { 161 if (((DocumentImpl)getOwnerDocument()).allowGrammarAccess){ 162 insertBefore(node, last); 163 last = node; 164 break; 165 } 166 } 167 168 // NOTE: Should never get here! -Ac 169 default: { 170 System.out.println("DeferredDocumentTypeImpl" + 171 "#synchronizeInfo: " + 172 "node.getNodeType() = " + 173 node.getNodeType() + 174 ", class = " + 175 node.getClass().getName()); 176 } 177 } 178 } 179 180 // set mutation events flag back to its original value 181 ownerDocument().setMutationEvents(orig); 182 183 // set entities and notations read_only per DOM spec 184 setReadOnly(true, false); 185 186 } // synchronizeChildren() 187 188 } // class DeferredDocumentTypeImpl