1 23 24 package org.enhydra.xml.lazydom; 25 26 import org.enhydra.apache.xerces.dom.EntityImpl; 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 37 public class LazyEntity extends EntityImpl implements LazyParent { 38 51 protected LazyEntity(LazyDocument ownerDoc, 52 LazyEntity template, 53 String name, 54 String publicId, 55 String systemId, 56 String notationName) { 57 super(ownerDoc, 58 (template != null) ? template.getNodeName() : name); 59 if (template != null) { 60 fTemplateNode = template; 61 fNodeId = template.getNodeId(); 62 if (template.getPublicId() != null) { 63 setPublicId(template.getPublicId()); 64 } 65 if (template.getSystemId() != null) { 66 setSystemId(template.getSystemId()); 67 } 68 if (template.getNotationName() != null) { 69 setNotationName(template.getNotationName()); 70 } 71 } else { 72 if (publicId != null) { 73 setPublicId(publicId); 74 } 75 if (systemId != null) { 76 setSystemId(systemId); 77 } 78 if (notationName != null) { 79 setNotationName(notationName); 80 } 81 fParentExpanded = true; 83 fChildrenExpanded = true; 84 } 85 } 86 87 91 94 private LazyEntity fTemplateNode = null; 95 96 100 public LazyEntity getTemplateEntity() { 101 return fTemplateNode; 102 } 103 104 107 public Node cloneNode(boolean deep) { 108 if (deep) { 109 if (!fChildrenExpanded) { 111 expandChildren(); 112 } 113 } 114 115 LazyEntity newEntity = (LazyEntity)super.cloneNode(deep); 117 newEntity.fNodeId = NULL_NODE_ID; 118 newEntity.fParentExpanded = true; 119 newEntity.fChildrenExpanded = true; 120 return newEntity; 121 } 122 123 127 130 private int fNodeId = NULL_NODE_ID; 131 132 135 private boolean fIsTemplateNode; 136 137 140 public void makeTemplateNode(int nodeId) { 141 fNodeId = nodeId; 142 fIsTemplateNode = true; 143 } 144 145 148 public int getNodeId() { 149 return fNodeId; 150 } 151 152 155 public boolean isTemplateNode() { 156 return fIsTemplateNode; 157 } 158 159 162 public LazyNode getTemplateNode() { 163 return fTemplateNode; 164 } 165 166 169 public LazyNode templateClone(Document ownerDocument) { 170 return new LazyEntity((LazyDocument)ownerDocument, this, 171 null, null, null, null); 172 } 173 174 179 public void setNodeValue(String value) { 180 fNodeId = NULL_NODE_ID; 181 super.setNodeValue(value); 182 } 183 184 188 191 private boolean fParentExpanded = false; 192 private boolean fChildrenExpanded = false; 193 194 197 public boolean isParentExpanded() { 198 return fParentExpanded; 199 } 200 201 204 public void setParentExpanded() { 205 fParentExpanded = true; 206 } 207 208 211 public void setParentWhileExpanding(Node parent) { 212 ownerNode = (NodeImpl)parent; 213 flags |= OWNED; 214 fParentExpanded = true; 215 } 216 217 220 public boolean areChildrenExpanded() { 221 return fChildrenExpanded; 222 } 223 224 227 public void setChildrenExpanded() { 228 fChildrenExpanded = true; 229 } 230 231 234 public void appendChildWhileExpanding(Node child) { 235 super.insertBefore(child, null); 236 } 237 238 241 private void expandParent() { 242 ((LazyDocument)getOwnerDocument()).doExpandParent(this); 243 } 244 245 248 private void expandChildren() { 249 ((LazyDocument)getOwnerDocument()).doExpandChildren(this); 250 } 251 252 255 public Node getParentNode() { 256 if (!fParentExpanded) { 257 expandParent(); 258 } 259 return super.getParentNode(); 260 } 261 262 265 public NodeList getChildNodes() { 266 if (!fChildrenExpanded) { 267 expandChildren(); 268 } 269 return super.getChildNodes(); 270 } 271 272 275 public Node getFirstChild() { 276 if (!fChildrenExpanded) { 277 expandChildren(); 278 } 279 return super.getFirstChild(); 280 } 281 282 285 public Node getLastChild() { 286 if (!fChildrenExpanded) { 287 expandChildren(); 288 } 289 return super.getLastChild(); 290 } 291 292 295 public Node getPreviousSibling() { 296 if (!fParentExpanded) { 297 expandParent(); 298 } 299 return super.getPreviousSibling(); 300 } 301 302 305 public Node getNextSibling() { 306 if (!fParentExpanded) { 307 expandParent(); 308 } 309 return super.getNextSibling(); 310 } 311 312 315 public Node insertBefore(Node newChild, 316 Node refChild) 317 throws DOMException { 318 if (!fChildrenExpanded) { 319 expandChildren(); 320 } 321 return super.insertBefore(newChild, refChild); 322 } 323 324 327 public Node replaceChild(Node newChild, 328 Node oldChild) 329 throws DOMException { 330 if (!fChildrenExpanded) { 331 expandChildren(); 332 } 333 return super.replaceChild(newChild, oldChild); 334 } 335 336 339 public Node removeChild(Node oldChild) 340 throws DOMException { 341 if (!fChildrenExpanded) { 342 expandChildren(); 343 } 344 return super.removeChild(oldChild); 345 } 346 347 350 public Node appendChild(Node newChild) 351 throws DOMException { 352 if (!fChildrenExpanded) { 353 expandChildren(); 354 } 355 return super.appendChild(newChild); 356 } 357 358 361 public boolean hasChildNodes() { 362 if (!fChildrenExpanded) { 363 return fTemplateNode.hasChildNodes(); 364 } else { 365 return super.hasChildNodes(); 366 } 367 } 368 369 372 public void normalize() { 373 if (!fChildrenExpanded) { 374 expandChildren(); 375 } 376 super.normalize(); 377 } 378 } 379 | Popular Tags |