1 23 24 package org.enhydra.xml.lazydom; 25 26 import org.enhydra.apache.xerces.dom.DocumentTypeImpl; 27 import org.w3c.dom.Document ; 28 import org.w3c.dom.NamedNodeMap ; 29 import org.w3c.dom.Node ; 30 31 35 public class LazyDocumentType extends DocumentTypeImpl implements LazyNode { 36 49 public LazyDocumentType(LazyDocument ownerDoc, 50 LazyDocumentType template, 51 String name, 52 String publicId, 53 String systemId, 54 String internalSubset) { 55 super(ownerDoc, 56 (template != null) ? template.getNodeName() : name, 57 (template != null) ? template.getPublicId() : publicId, 58 (template != null) ? template.getSystemId() : systemId); 59 if (template != null) { 60 fTemplateNode = template; 61 fNodeId = template.getNodeId(); 62 setInternalSubset(template.getInternalSubset()); 63 } else { 64 fContentsExpanded = true; 66 setInternalSubset(internalSubset); 67 } 68 } 69 70 74 protected void setOwnerDocument(LazyDocument doc) { 75 super.setOwnerDocument(doc); 76 } 77 78 82 85 private LazyDocumentType fTemplateNode = null; 86 87 90 private boolean fContentsExpanded = false; 91 92 96 public LazyDocumentType getTemplateDocumentType() { 97 return fTemplateNode; 98 } 99 100 103 public Node cloneNode(boolean deep) { 104 if (deep) { 105 if (!fContentsExpanded) { 107 expandContents(); 108 } 109 } 110 111 LazyDocumentType newDocumentType = (LazyDocumentType)super.cloneNode(deep); 113 newDocumentType.fNodeId = NULL_NODE_ID; 114 newDocumentType.fContentsExpanded = true; 115 return newDocumentType; 116 } 117 118 121 public boolean isContentsExpanded() { 122 return fContentsExpanded; 123 } 124 125 129 private void doExpandContents(LazyDocument doc) { 130 NamedNodeMap templateEntities = fTemplateNode.getEntities(); 131 int numEntities = templateEntities.getLength(); 132 NamedNodeMap entities = super.getEntities(); 133 for (int idx = 0; idx < numEntities; idx++) { 134 entities.setNamedItem(((LazyNode)templateEntities.item(idx)).templateClone(doc)); 135 } 136 137 NamedNodeMap templateNotations = fTemplateNode.getNotations(); 138 int numNotations = templateNotations.getLength(); 139 NamedNodeMap notations = super.getNotations(); 140 for (int idx = 0; idx < numNotations; idx++) { 141 notations.setNamedItem(((LazyNode)templateNotations.item(idx)).templateClone(doc)); 142 } 143 144 fContentsExpanded = true; 145 } 146 147 150 private void expandContents() { 151 LazyDocument doc = (LazyDocument)getOwnerDocument(); 152 synchronized (doc) { 153 if (fContentsExpanded) { 154 doExpandContents(doc); 155 } 156 } 157 } 158 159 162 public NamedNodeMap getEntities() { 163 if (!fContentsExpanded) { 164 expandContents(); 165 } 166 return super.getEntities(); 167 } 168 169 172 public NamedNodeMap getNotations() { 173 if (!fContentsExpanded) { 174 expandContents(); 175 } 176 return super.getNotations(); 177 } 178 179 183 186 private int fNodeId = NULL_NODE_ID; 187 188 191 private boolean fIsTemplateNode; 192 193 196 public void makeTemplateNode(int nodeId) { 197 fNodeId = nodeId; 198 fIsTemplateNode = true; 199 } 200 201 204 public int getNodeId() { 205 return fNodeId; 206 } 207 208 211 public boolean isTemplateNode() { 212 return fIsTemplateNode; 213 } 214 215 218 public LazyNode getTemplateNode() { 219 return fTemplateNode; 220 } 221 222 225 public LazyNode templateClone(Document ownerDocument) { 226 return new LazyDocumentType((LazyDocument)ownerDocument, this, 227 null, null, null, null); 228 } 229 230 235 public void setNodeValue(String value) { 236 fNodeId = NULL_NODE_ID; 237 super.setNodeValue(value); 238 } 239 240 } 241 | Popular Tags |