1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 1999-2002,2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.dom; 22 23 24 /** 25 * Entity nodes hold the reference data for an XML Entity -- either 26 * parsed or unparsed. The nodeName (inherited from Node) will contain 27 * the name (if any) of the Entity. Its data will be contained in the 28 * Entity's children, in exactly the structure which an 29 * EntityReference to this name will present within the document's 30 * body. 31 * <P> 32 * Note that this object models the actual entity, _not_ the entity 33 * declaration or the entity reference. 34 * <P> 35 * An XML processor may choose to completely expand entities before 36 * the structure model is passed to the DOM; in this case, there will 37 * be no EntityReferences in the DOM tree. 38 * <P> 39 * Quoting the 10/01 DOM Proposal, 40 * <BLOCKQUOTE> 41 * "The DOM Level 1 does not support editing Entity nodes; if a user 42 * wants to make changes to the contents of an Entity, every related 43 * EntityReference node has to be replaced in the structure model by 44 * a clone of the Entity's contents, and then the desired changes 45 * must be made to each of those clones instead. All the 46 * descendants of an Entity node are readonly." 47 * </BLOCKQUOTE> 48 * I'm interpreting this as: It is the parser's responsibilty to call 49 * the non-DOM operation setReadOnly(true,true) after it constructs 50 * the Entity. Since the DOM explicitly decided not to deal with this, 51 * _any_ answer will involve a non-DOM operation, and this is the 52 * simplest solution. 53 * 54 * @xerces.internal 55 * 56 * @since PR-DOM-Level-1-19980818. 57 */ 58 public class DeferredEntityImpl 59 extends EntityImpl 60 implements DeferredNode { 61 62 // 63 // Constants 64 // 65 66 /** Serialization version. */ 67 static final long serialVersionUID = 4760180431078941638L; 68 69 // 70 // Data 71 // 72 73 /** Node index. */ 74 protected transient int fNodeIndex; 75 76 // 77 // Constructors 78 // 79 80 /** 81 * This is the deferred constructor. Only the fNodeIndex is given here. 82 * All other data, can be requested from the ownerDocument via the index. 83 */ 84 DeferredEntityImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) { 85 super(ownerDocument, null); 86 87 fNodeIndex = nodeIndex; 88 needsSyncData(true); 89 needsSyncChildren(true); 90 91 } // <init>(DeferredDocumentImpl,int) 92 93 // 94 // DeferredNode methods 95 // 96 97 /** Returns the node index. */ 98 public int getNodeIndex() { 99 return fNodeIndex; 100 } 101 102 // 103 // Protected methods 104 // 105 106 /** 107 * Synchronize the entity data. This is special because of the way 108 * that the "fast" version stores the information. 109 */ 110 protected void synchronizeData() { 111 112 // no need to sychronize again 113 needsSyncData(false); 114 115 // get the node data 116 DeferredDocumentImpl ownerDocument = 117 (DeferredDocumentImpl)this.ownerDocument; 118 name = ownerDocument.getNodeName(fNodeIndex); 119 120 // get the entity data 121 publicId = ownerDocument.getNodeValue(fNodeIndex); 122 systemId = ownerDocument.getNodeURI(fNodeIndex); 123 int extraDataIndex = ownerDocument.getNodeExtra(fNodeIndex); 124 ownerDocument.getNodeType(extraDataIndex); 125 126 notationName = ownerDocument.getNodeName(extraDataIndex); 127 128 // encoding and version DOM L3 129 version = ownerDocument.getNodeValue(extraDataIndex); 130 encoding = ownerDocument.getNodeURI(extraDataIndex); 131 132 // baseURI, actualEncoding DOM L3 133 int extraIndex2 = ownerDocument.getNodeExtra(extraDataIndex); 134 baseURI = ownerDocument.getNodeName(extraIndex2); 135 inputEncoding = ownerDocument.getNodeValue(extraIndex2); 136 137 } // synchronizeData() 138 139 /** Synchronize the children. */ 140 protected void synchronizeChildren() { 141 142 // no need to synchronize again 143 needsSyncChildren(false); 144 145 isReadOnly(false); 146 DeferredDocumentImpl ownerDocument = 147 (DeferredDocumentImpl) ownerDocument(); 148 ownerDocument.synchronizeChildren(this, fNodeIndex); 149 setReadOnly(true, true); 150 151 } // synchronizeChildren() 152 153 } // class DeferredEntityImpl