1 23 24 package org.enhydra.xml.lazydom; 25 26 import org.enhydra.apache.xerces.dom.AttrNSImpl; 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 LazyAttrNS extends AttrNSImpl implements LazyAttr { 38 47 protected LazyAttrNS(LazyDocument ownerDoc, 48 LazyAttrNS template, 49 String namespaceURI, 50 String qualifiedName) { 51 super(ownerDoc, 52 (template != null) ? template.getNamespaceURI() : namespaceURI, 53 (template != null) ? template.getNodeName() : qualifiedName); 54 if (template != null) { 55 fTemplateNode = template; 56 fNodeId = template.getNodeId(); 57 } else { 58 fParentExpanded = true; 60 fChildrenExpanded = true; 61 } 62 } 63 64 68 71 private LazyAttrNS fTemplateNode = null; 72 73 77 public LazyAttrNS getTemplateAttr() { 78 return fTemplateNode; 79 } 80 81 84 public Node cloneNode(boolean deep) { 85 if (deep) { 86 if (!fChildrenExpanded) { 88 expandChildren(); 89 } 90 } 91 92 LazyAttrNS newAttr = (LazyAttrNS)super.cloneNode(deep); 94 newAttr.fNodeId = NULL_NODE_ID; 95 newAttr.fParentExpanded = true; 96 newAttr.fChildrenExpanded = true; 97 return newAttr; 98 } 99 100 103 public String getValue() { 104 if (!fChildrenExpanded) { 105 expandChildren(); 106 } 107 return super.getValue(); 108 } 109 110 113 public void setValue(String value) throws DOMException { 114 if (!fChildrenExpanded) { 115 expandChildren(); 116 } 117 super.setValue(value); 118 } 119 120 123 public String getNodeValue() throws DOMException { 124 if (!fChildrenExpanded) { 125 expandChildren(); 126 } 127 return super.getNodeValue(); 128 } 129 130 133 public void setNodeValue(String nodeValue) throws DOMException { 134 if (!fChildrenExpanded) { 135 expandChildren(); 136 } 137 super.setNodeValue(nodeValue); 138 } 139 140 144 147 private int fNodeId = NULL_NODE_ID; 148 149 152 private boolean fIsTemplateNode; 153 154 157 public void makeTemplateNode(int nodeId) { 158 fNodeId = nodeId; 159 fIsTemplateNode = true; 160 } 161 162 165 public int getNodeId() { 166 return fNodeId; 167 } 168 169 172 public boolean isTemplateNode() { 173 return fIsTemplateNode; 174 } 175 176 179 public LazyNode getTemplateNode() { 180 return fTemplateNode; 181 } 182 183 186 public LazyNode templateClone(Document ownerDocument) { 187 return new LazyAttrNS((LazyDocument)ownerDocument, this, null, null); 188 } 189 190 192 196 199 private boolean fParentExpanded = false; 200 private boolean fChildrenExpanded = false; 201 202 205 public boolean isParentExpanded() { 206 return fParentExpanded; 207 } 208 209 212 public void setParentExpanded() { 213 fParentExpanded = true; 214 } 215 216 219 public void setParentWhileExpanding(Node parent) { 220 ownerNode = (NodeImpl)parent; 221 flags |= OWNED; 222 fParentExpanded = true; 223 } 224 225 228 public boolean areChildrenExpanded() { 229 return fChildrenExpanded; 230 } 231 232 235 public void setChildrenExpanded() { 236 fChildrenExpanded = true; 237 } 238 239 242 public void appendChildWhileExpanding(Node child) { 243 super.insertBefore(child, null); 244 } 245 246 249 private void expandParent() { 250 ((LazyDocument)getOwnerDocument()).doExpandParent(this); 251 } 252 253 256 private void expandChildren() { 257 ((LazyDocument)getOwnerDocument()).doExpandChildren(this); 258 } 259 260 263 public Node getParentNode() { 264 if (!fParentExpanded) { 265 expandParent(); 266 } 267 return super.getParentNode(); 268 } 269 270 273 public NodeList getChildNodes() { 274 if (!fChildrenExpanded) { 275 expandChildren(); 276 } 277 return super.getChildNodes(); 278 } 279 280 283 public Node getFirstChild() { 284 if (!fChildrenExpanded) { 285 expandChildren(); 286 } 287 return super.getFirstChild(); 288 } 289 290 293 public Node getLastChild() { 294 if (!fChildrenExpanded) { 295 expandChildren(); 296 } 297 return super.getLastChild(); 298 } 299 300 303 public Node getPreviousSibling() { 304 if (!fParentExpanded) { 305 expandParent(); 306 } 307 return super.getPreviousSibling(); 308 } 309 310 313 public Node getNextSibling() { 314 if (!fParentExpanded) { 315 expandParent(); 316 } 317 return super.getNextSibling(); 318 } 319 320 323 public Node insertBefore(Node newChild, 324 Node refChild) 325 throws DOMException { 326 if (!fChildrenExpanded) { 327 expandChildren(); 328 } 329 return super.insertBefore(newChild, refChild); 330 } 331 332 335 public Node replaceChild(Node newChild, 336 Node oldChild) 337 throws DOMException { 338 if (!fChildrenExpanded) { 339 expandChildren(); 340 } 341 return super.replaceChild(newChild, oldChild); 342 } 343 344 347 public Node removeChild(Node oldChild) 348 throws DOMException { 349 if (!fChildrenExpanded) { 350 expandChildren(); 351 } 352 return super.removeChild(oldChild); 353 } 354 355 358 public Node appendChild(Node newChild) 359 throws DOMException { 360 if (!fChildrenExpanded) { 361 expandChildren(); 362 } 363 return super.appendChild(newChild); 364 } 365 366 369 public boolean hasChildNodes() { 370 if (!fChildrenExpanded) { 371 return fTemplateNode.hasChildNodes(); 372 } else { 373 return super.hasChildNodes(); 374 } 375 } 376 377 380 public void normalize() { 381 if (!fChildrenExpanded) { 382 expandChildren(); 383 } 384 super.normalize(); 385 } 386 387 391 public String toString() { 392 return getName(); 393 } 394 } 395 | Popular Tags |