001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.dom;
019:
020: import org.w3c.dom.Node;
021:
022: /**
023: * This class represents a Document Type <em>declaraction</em> in
024: * the document itself, <em>not</em> a Document Type Definition (DTD).
025: * An XML document may (or may not) have such a reference.
026: * <P>
027: * DocumentType is an Extended DOM feature, used in XML documents but
028: * not in HTML.
029: * <P>
030: * Note that Entities and Notations are no longer children of the
031: * DocumentType, but are parentless nodes hung only in their
032: * appropriate NamedNodeMaps.
033: * <P>
034: * This area is UNDERSPECIFIED IN REC-DOM-Level-1-19981001
035: * Most notably, absolutely no provision was made for storing
036: * and using Element and Attribute information. Nor was the linkage
037: * between Entities and Entity References nailed down solidly.
038: *
039: * @xerces.internal
040: *
041: * @version $Id: DeferredDocumentTypeImpl.java 447266 2006-09-18 05:57:49Z mrglavas $
042: * @since PR-DOM-Level-1-19980818.
043: */
044: public class DeferredDocumentTypeImpl extends DocumentTypeImpl
045: implements DeferredNode {
046:
047: //
048: // Constants
049: //
050:
051: /** Serialization version. */
052: static final long serialVersionUID = -2172579663227313509L;
053:
054: //
055: // Data
056: //
057:
058: /** Node index. */
059: protected transient int fNodeIndex;
060:
061: //
062: // Constructors
063: //
064:
065: /**
066: * This is the deferred constructor. Only the fNodeIndex is given here.
067: * All other data, can be requested from the ownerDocument via the index.
068: */
069: DeferredDocumentTypeImpl(DeferredDocumentImpl ownerDocument,
070: int nodeIndex) {
071: super (ownerDocument, null);
072:
073: fNodeIndex = nodeIndex;
074: needsSyncData(true);
075: needsSyncChildren(true);
076:
077: } // <init>(DeferredDocumentImpl,int)
078:
079: //
080: // DeferredNode methods
081: //
082:
083: /** Returns the node index. */
084: public int getNodeIndex() {
085: return fNodeIndex;
086: }
087:
088: //
089: // Protected methods
090: //
091:
092: /** Synchronizes the data (name and value) for fast nodes. */
093: protected void synchronizeData() {
094:
095: // no need to sync in the future
096: needsSyncData(false);
097:
098: // fluff data
099: DeferredDocumentImpl ownerDocument = (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 = (DeferredDocumentImpl) this .ownerDocument;
121:
122: entities = new NamedNodeMapImpl(this );
123: notations = new NamedNodeMapImpl(this );
124: elements = new NamedNodeMapImpl(this );
125:
126: // fill node maps
127: DeferredNode last = null;
128: for (int index = ownerDocument.getLastChild(fNodeIndex); index != -1; index = ownerDocument
129: .getPrevSibling(index)) {
130:
131: DeferredNode node = ownerDocument.getNodeObject(index);
132: int type = node.getNodeType();
133: switch (type) {
134:
135: // internal, external, and unparsed entities
136: case Node.ENTITY_NODE: {
137: entities.setNamedItem(node);
138: break;
139: }
140:
141: // notations
142: case Node.NOTATION_NODE: {
143: notations.setNamedItem(node);
144: break;
145: }
146:
147: // element definitions
148: case NodeImpl.ELEMENT_DEFINITION_NODE: {
149: elements.setNamedItem(node);
150: break;
151: }
152:
153: // elements
154: case Node.ELEMENT_NODE: {
155: if (((DocumentImpl) getOwnerDocument()).allowGrammarAccess) {
156: insertBefore(node, last);
157: last = node;
158: break;
159: }
160: }
161:
162: // NOTE: Should never get here! -Ac
163: default: {
164: System.out.println("DeferredDocumentTypeImpl"
165: + "#synchronizeInfo: "
166: + "node.getNodeType() = " + node.getNodeType()
167: + ", class = " + node.getClass().getName());
168: }
169: }
170: }
171:
172: // set mutation events flag back to its original value
173: ownerDocument().setMutationEvents(orig);
174:
175: // set entities and notations read_only per DOM spec
176: setReadOnly(true, false);
177:
178: } // synchronizeChildren()
179:
180: } // class DeferredDocumentTypeImpl
|