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.apache.xerces.utils.StringPool;
061:
062: /**
063: * Entity nodes hold the reference data for an XML Entity -- either
064: * parsed or unparsed. The nodeName (inherited from Node) will contain
065: * the name (if any) of the Entity. Its data will be contained in the
066: * Entity's children, in exactly the structure which an
067: * EntityReference to this name will present within the document's
068: * body.
069: * <P>
070: * Note that this object models the actual entity, _not_ the entity
071: * declaration or the entity reference.
072: * <P>
073: * An XML processor may choose to completely expand entities before
074: * the structure model is passed to the DOM; in this case, there will
075: * be no EntityReferences in the DOM tree.
076: * <P>
077: * Quoting the 10/01 DOM Proposal,
078: * <BLOCKQUOTE>
079: * "The DOM Level 1 does not support editing Entity nodes; if a user
080: * wants to make changes to the contents of an Entity, every related
081: * EntityReference node has to be replaced in the structure model by
082: * a clone of the Entity's contents, and then the desired changes
083: * must be made to each of those clones instead. All the
084: * descendants of an Entity node are readonly."
085: * </BLOCKQUOTE>
086: * I'm interpreting this as: It is the parser's responsibilty to call
087: * the non-DOM operation setReadOnly(true,true) after it constructs
088: * the Entity. Since the DOM explicitly decided not to deal with this,
089: * _any_ answer will involve a non-DOM operation, and this is the
090: * simplest solution.
091: *
092: *
093: * @version
094: * @since PR-DOM-Level-1-19980818.
095: */
096: public class DeferredEntityImpl extends EntityImpl implements
097: DeferredNode {
098:
099: //
100: // Constants
101: //
102:
103: /** Serialization version. */
104: static final long serialVersionUID = 4760180431078941638L;
105:
106: //
107: // Data
108: //
109:
110: /** Node index. */
111: protected transient int fNodeIndex;
112:
113: //
114: // Constructors
115: //
116:
117: /**
118: * This is the deferred constructor. Only the fNodeIndex is given here.
119: * All other data, can be requested from the ownerDocument via the index.
120: */
121: DeferredEntityImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
122: super (ownerDocument, null);
123:
124: fNodeIndex = nodeIndex;
125: needsSyncData(true);
126: needsSyncChildren(true);
127:
128: } // <init>(DeferredDocumentImpl,int)
129:
130: //
131: // DeferredNode methods
132: //
133:
134: /** Returns the node index. */
135: public int getNodeIndex() {
136: return fNodeIndex;
137: }
138:
139: //
140: // Protected methods
141: //
142:
143: /**
144: * Synchronize the entity data. This is special because of the way
145: * that the "fast" version stores the information.
146: */
147: protected void synchronizeData() {
148:
149: // no need to sychronize again
150: needsSyncData(false);
151:
152: // get the node data
153: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) this .ownerDocument;
154: name = ownerDocument.getNodeNameString(fNodeIndex);
155:
156: // get the entity data
157: StringPool pool = ownerDocument.getStringPool();
158: int extraDataIndex = ownerDocument.getNodeValue(fNodeIndex);
159: ownerDocument.getNodeType(extraDataIndex);
160: publicId = pool.toString(ownerDocument
161: .getNodeName(extraDataIndex));
162: notationName = pool.toString(ownerDocument
163: .getLastChild(extraDataIndex));
164:
165: // DOM Level 3 adding experimental features -el
166: extraDataIndex = ownerDocument.getNodeValue(extraDataIndex);
167: systemId = pool.toString(ownerDocument
168: .getNodeName(extraDataIndex));
169: version = pool.toString(ownerDocument
170: .getNodeValue(extraDataIndex));
171: encoding = pool.toString(ownerDocument
172: .getLastChild(extraDataIndex));
173:
174: } // synchronizeData()
175:
176: /** Synchronize the children. */
177: protected void synchronizeChildren() {
178:
179: // no need to synchronize again
180: needsSyncChildren(false);
181:
182: isReadOnly(false);
183: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) ownerDocument();
184: ownerDocument.synchronizeChildren(this , fNodeIndex);
185: setReadOnly(true, true);
186:
187: } // synchronizeChildren()
188:
189: } // class DeferredEntityImpl
|