1 23 24 package org.enhydra.xml.lazydom; 25 26 import org.enhydra.apache.xerces.dom.EntityReferenceImpl; 27 import org.enhydra.apache.xerces.dom.NodeImpl; 28 import org.w3c.dom.DOMException ; 29 import org.w3c.dom.Document ; 30 import org.w3c.dom.Node ; 31 import org.w3c.dom.NodeList ; 32 33 36 public class LazyEntityReference extends EntityReferenceImpl implements LazyParent { 37 44 protected LazyEntityReference(LazyDocument ownerDoc, 45 LazyEntityReference template, 46 String name) { 47 super(ownerDoc, 48 (template != null) ? template.getNodeName() : name); 49 if (template != null) { 50 fTemplateNode = template; 51 fNodeId = template.getNodeId(); 52 } else { 53 fParentExpanded = true; 55 fChildrenExpanded = true; 56 } 57 } 58 59 63 66 private LazyEntityReference fTemplateNode = null; 67 68 72 public LazyEntityReference getTemplateEntityReference() { 73 return fTemplateNode; 74 } 75 76 79 public Node cloneNode(boolean deep) { 80 if (deep) { 81 if (!fChildrenExpanded) { 83 expandChildren(); 84 } 85 } 86 87 LazyEntityReference newEntityReference = (LazyEntityReference)super.cloneNode(deep); 89 newEntityReference.fNodeId = NULL_NODE_ID; 90 newEntityReference.fParentExpanded = true; 91 newEntityReference.fChildrenExpanded = true; 92 return newEntityReference; 93 } 94 95 99 102 private int fNodeId = NULL_NODE_ID; 103 104 107 private boolean fIsTemplateNode; 108 109 112 public void makeTemplateNode(int nodeId) { 113 fNodeId = nodeId; 114 fIsTemplateNode = true; 115 } 116 117 120 public int getNodeId() { 121 return fNodeId; 122 } 123 124 127 public boolean isTemplateNode() { 128 return fIsTemplateNode; 129 } 130 131 134 public LazyNode getTemplateNode() { 135 return fTemplateNode; 136 } 137 138 141 public LazyNode templateClone(Document ownerDocument) { 142 return new LazyEntityReference((LazyDocument)ownerDocument, this, null); 143 } 144 145 150 public void setNodeValue(String value) { 151 fNodeId = NULL_NODE_ID; 152 super.setNodeValue(value); 153 } 154 155 159 162 private boolean fParentExpanded = false; 163 private boolean fChildrenExpanded = false; 164 165 168 public boolean isParentExpanded() { 169 return fParentExpanded; 170 } 171 172 175 public void setParentExpanded() { 176 fParentExpanded = true; 177 } 178 179 182 public void setParentWhileExpanding(Node parent) { 183 ownerNode = (NodeImpl)parent; 184 flags |= OWNED; 185 fParentExpanded = true; 186 } 187 188 191 public boolean areChildrenExpanded() { 192 return fChildrenExpanded; 193 } 194 195 198 public void setChildrenExpanded() { 199 fChildrenExpanded = true; 200 } 201 202 205 public void appendChildWhileExpanding(Node child) { 206 super.insertBefore(child, null); 207 } 208 209 212 private void expandParent() { 213 ((LazyDocument)getOwnerDocument()).doExpandParent(this); 214 } 215 216 219 private void expandChildren() { 220 ((LazyDocument)getOwnerDocument()).doExpandChildren(this); 221 } 222 223 226 public Node getParentNode() { 227 if (!fParentExpanded) { 228 expandParent(); 229 } 230 return super.getParentNode(); 231 } 232 233 236 public NodeList getChildNodes() { 237 if (!fChildrenExpanded) { 238 expandChildren(); 239 } 240 return super.getChildNodes(); 241 } 242 243 246 public Node getFirstChild() { 247 if (!fChildrenExpanded) { 248 expandChildren(); 249 } 250 return super.getFirstChild(); 251 } 252 253 256 public Node getLastChild() { 257 if (!fChildrenExpanded) { 258 expandChildren(); 259 } 260 return super.getLastChild(); 261 } 262 263 266 public Node getPreviousSibling() { 267 if (!fParentExpanded) { 268 expandParent(); 269 } 270 return super.getPreviousSibling(); 271 } 272 273 276 public Node getNextSibling() { 277 if (!fParentExpanded) { 278 expandParent(); 279 } 280 return super.getNextSibling(); 281 } 282 283 286 public Node insertBefore(Node newChild, 287 Node refChild) 288 throws DOMException { 289 if (!fChildrenExpanded) { 290 expandChildren(); 291 } 292 return super.insertBefore(newChild, refChild); 293 } 294 295 298 public Node replaceChild(Node newChild, 299 Node oldChild) 300 throws DOMException { 301 if (!fChildrenExpanded) { 302 expandChildren(); 303 } 304 return super.replaceChild(newChild, oldChild); 305 } 306 307 310 public Node removeChild(Node oldChild) 311 throws DOMException { 312 if (!fChildrenExpanded) { 313 expandChildren(); 314 } 315 return super.removeChild(oldChild); 316 } 317 318 321 public Node appendChild(Node newChild) 322 throws DOMException { 323 if (!fChildrenExpanded) { 324 expandChildren(); 325 } 326 return super.appendChild(newChild); 327 } 328 329 332 public boolean hasChildNodes() { 333 if (!fChildrenExpanded) { 334 return fTemplateNode.hasChildNodes(); 335 } else { 336 return super.hasChildNodes(); 337 } 338 } 339 340 343 public void normalize() { 344 if (!fChildrenExpanded) { 345 expandChildren(); 346 } 347 super.normalize(); 348 } 349 350 } 351 | Popular Tags |