001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 1999 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.xerces.dom;
059:
060: import org.w3c.dom.Node;
061: import org.apache.xerces.utils.StringPool;
062:
063: /**
064: * This class represents a Document Type <em>declaraction</em> in
065: * the document itself, <em>not</em> a Document Type Definition (DTD).
066: * An XML document may (or may not) have such a reference.
067: * <P>
068: * DocumentType is an Extended DOM feature, used in XML documents but
069: * not in HTML.
070: * <P>
071: * Note that Entities and Notations are no longer children of the
072: * DocumentType, but are parentless nodes hung only in their
073: * appropriate NamedNodeMaps.
074: * <P>
075: * This area is UNDERSPECIFIED IN REC-DOM-Level-1-19981001
076: * Most notably, absolutely no provision was made for storing
077: * and using Element and Attribute information. Nor was the linkage
078: * between Entities and Entity References nailed down solidly.
079: *
080: * @version
081: * @since PR-DOM-Level-1-19980818.
082: */
083: public class DeferredDocumentTypeImpl extends DocumentTypeImpl
084: implements DeferredNode {
085:
086: //
087: // Constants
088: //
089:
090: /** Serialization version. */
091: static final long serialVersionUID = -2172579663227313509L;
092:
093: //
094: // Data
095: //
096:
097: /** Node index. */
098: protected transient int fNodeIndex;
099:
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,
109: 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 = (DeferredDocumentImpl) this .ownerDocument;
139: name = ownerDocument.getNodeNameString(fNodeIndex);
140:
141: // public and system ids
142: StringPool pool = ownerDocument.getStringPool();
143: int extraDataIndex = ownerDocument.getNodeValue(fNodeIndex);
144: //ownerDocument.getNodeType(extraDataIndex);
145: publicID = pool.toString(ownerDocument
146: .getNodeName(extraDataIndex));
147: systemID = pool.toString(ownerDocument
148: .getNodeValue(extraDataIndex));
149: internalSubset = pool.toString(ownerDocument
150: .getLastChild(extraDataIndex));
151: } // synchronizeData()
152:
153: /** Synchronizes the entities, notations, and elements. */
154: protected void synchronizeChildren() {
155:
156: // we don't want to generate any event for this so turn them off
157: boolean orig = ownerDocument().getMutationEvents();
158: ownerDocument().setMutationEvents(false);
159:
160: // no need to synchronize again
161: needsSyncChildren(false);
162:
163: // create new node maps
164: DeferredDocumentImpl ownerDocument = (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); index != -1; index = ownerDocument
173: .getPrevSibling(index)) {
174:
175: DeferredNode node = ownerDocument.getNodeObject(index);
176: int type = node.getNodeType();
177: switch (type) {
178:
179: // internal, external, and unparsed entities
180: case Node.ENTITY_NODE: {
181: entities.setNamedItem(node);
182: break;
183: }
184:
185: // notations
186: case Node.NOTATION_NODE: {
187: notations.setNamedItem(node);
188: break;
189: }
190:
191: // element definitions
192: case NodeImpl.ELEMENT_DEFINITION_NODE: {
193: elements.setNamedItem(node);
194: break;
195: }
196:
197: // elements
198: case Node.ELEMENT_NODE: {
199: if (((DocumentImpl) getOwnerDocument()).allowGrammarAccess) {
200: insertBefore(node, last);
201: last = node;
202: break;
203: }
204: }
205:
206: // NOTE: Should never get here! -Ac
207: default: {
208: System.out
209: .println("DeferredDocumentTypeImpl#synchronizeInfo: node.getNodeType() = "
210: + node.getNodeType()
211: + ", class = "
212: + node.getClass().getName());
213: }
214: }
215: }
216:
217: // set mutation events flag back to its original value
218: ownerDocument().setMutationEvents(orig);
219:
220: // set entities and notations read_only per DOM spec
221: setReadOnly(true, false);
222:
223: } // synchronizeChildren()
224:
225: } // class DeferredDocumentTypeImpl
|