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: /**
021: * Entity nodes hold the reference data for an XML Entity -- either
022: * parsed or unparsed. The nodeName (inherited from Node) will contain
023: * the name (if any) of the Entity. Its data will be contained in the
024: * Entity's children, in exactly the structure which an
025: * EntityReference to this name will present within the document's
026: * body.
027: * <P>
028: * Note that this object models the actual entity, _not_ the entity
029: * declaration or the entity reference.
030: * <P>
031: * An XML processor may choose to completely expand entities before
032: * the structure model is passed to the DOM; in this case, there will
033: * be no EntityReferences in the DOM tree.
034: * <P>
035: * Quoting the 10/01 DOM Proposal,
036: * <BLOCKQUOTE>
037: * "The DOM Level 1 does not support editing Entity nodes; if a user
038: * wants to make changes to the contents of an Entity, every related
039: * EntityReference node has to be replaced in the structure model by
040: * a clone of the Entity's contents, and then the desired changes
041: * must be made to each of those clones instead. All the
042: * descendants of an Entity node are readonly."
043: * </BLOCKQUOTE>
044: * I'm interpreting this as: It is the parser's responsibilty to call
045: * the non-DOM operation setReadOnly(true,true) after it constructs
046: * the Entity. Since the DOM explicitly decided not to deal with this,
047: * _any_ answer will involve a non-DOM operation, and this is the
048: * simplest solution.
049: *
050: * @xerces.internal
051: *
052: * @version $Id: DeferredEntityImpl.java 447266 2006-09-18 05:57:49Z mrglavas $
053: * @since PR-DOM-Level-1-19980818.
054: */
055: public class DeferredEntityImpl extends EntityImpl implements
056: DeferredNode {
057:
058: //
059: // Constants
060: //
061:
062: /** Serialization version. */
063: static final long serialVersionUID = 4760180431078941638L;
064:
065: //
066: // Data
067: //
068:
069: /** Node index. */
070: protected transient int fNodeIndex;
071:
072: //
073: // Constructors
074: //
075:
076: /**
077: * This is the deferred constructor. Only the fNodeIndex is given here.
078: * All other data, can be requested from the ownerDocument via the index.
079: */
080: DeferredEntityImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
081: super (ownerDocument, null);
082:
083: fNodeIndex = nodeIndex;
084: needsSyncData(true);
085: needsSyncChildren(true);
086:
087: } // <init>(DeferredDocumentImpl,int)
088:
089: //
090: // DeferredNode methods
091: //
092:
093: /** Returns the node index. */
094: public int getNodeIndex() {
095: return fNodeIndex;
096: }
097:
098: //
099: // Protected methods
100: //
101:
102: /**
103: * Synchronize the entity data. This is special because of the way
104: * that the "fast" version stores the information.
105: */
106: protected void synchronizeData() {
107:
108: // no need to sychronize again
109: needsSyncData(false);
110:
111: // get the node data
112: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) this .ownerDocument;
113: name = ownerDocument.getNodeName(fNodeIndex);
114:
115: // get the entity data
116: publicId = ownerDocument.getNodeValue(fNodeIndex);
117: systemId = ownerDocument.getNodeURI(fNodeIndex);
118: int extraDataIndex = ownerDocument.getNodeExtra(fNodeIndex);
119: ownerDocument.getNodeType(extraDataIndex);
120:
121: notationName = ownerDocument.getNodeName(extraDataIndex);
122:
123: // encoding and version DOM L3
124: version = ownerDocument.getNodeValue(extraDataIndex);
125: encoding = ownerDocument.getNodeURI(extraDataIndex);
126:
127: // baseURI, actualEncoding DOM L3
128: int extraIndex2 = ownerDocument.getNodeExtra(extraDataIndex);
129: baseURI = ownerDocument.getNodeName(extraIndex2);
130: inputEncoding = ownerDocument.getNodeValue(extraIndex2);
131:
132: } // synchronizeData()
133:
134: /** Synchronize the children. */
135: protected void synchronizeChildren() {
136:
137: // no need to synchronize again
138: needsSyncChildren(false);
139:
140: isReadOnly(false);
141: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) ownerDocument();
142: ownerDocument.synchronizeChildren(this , fNodeIndex);
143: setReadOnly(true, true);
144:
145: } // synchronizeChildren()
146:
147: } // class DeferredEntityImpl
|