1 23 24 package org.enhydra.xml.lazydom; 25 26 import org.enhydra.apache.xerces.dom.AttrImpl; 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 40 public class LazyAttrNoNS extends AttrImpl implements LazyAttr { 41 48 protected LazyAttrNoNS(LazyDocument ownerDoc, 49 LazyAttrNoNS template, 50 String qualifiedName) { 51 super(ownerDoc, 52 (template != null) ? template.getNodeName() : qualifiedName); 53 if (template != null) { 54 fTemplateNode = template; 55 fNodeId = template.getNodeId(); 56 } else { 57 fParentExpanded = true; 59 fChildrenExpanded = true; 60 } 61 } 62 63 67 70 private LazyAttrNoNS fTemplateNode = null; 71 72 76 public LazyAttrNoNS getTemplateAttr() { 77 return fTemplateNode; 78 } 79 80 83 public Node cloneNode(boolean deep) { 84 if (deep) { 85 if (!fChildrenExpanded) { 87 expandChildren(); 88 } 89 } 90 91 LazyAttrNoNS newAttr = (LazyAttrNoNS)super.cloneNode(deep); 93 newAttr.fNodeId = NULL_NODE_ID; 94 newAttr.fParentExpanded = true; 95 newAttr.fChildrenExpanded = true; 96 return newAttr; 97 } 98 99 102 public String getValue() { 103 if (!fChildrenExpanded) { 104 expandChildren(); 105 } 106 return super.getValue(); 107 } 108 109 112 public void setValue(String value) throws DOMException { 113 if (!fChildrenExpanded) { 114 expandChildren(); 115 } 116 super.setValue(value); 117 } 118 119 122 public String getNodeValue() throws DOMException { 123 if (!fChildrenExpanded) { 124 expandChildren(); 125 } 126 return super.getNodeValue(); 127 } 128 129 132 public void setNodeValue(String nodeValue) throws DOMException { 133 if (!fChildrenExpanded) { 134 expandChildren(); 135 } 136 super.setNodeValue(nodeValue); 137 } 138 139 143 146 private int fNodeId = NULL_NODE_ID; 147 148 151 private boolean fIsTemplateNode; 152 153 156 public void makeTemplateNode(int nodeId) { 157 fNodeId = nodeId; 158 fIsTemplateNode = true; 159 } 160 161 164 public int getNodeId() { 165 return fNodeId; 166 } 167 168 171 public boolean isTemplateNode() { 172 return fIsTemplateNode; 173 } 174 175 178 public LazyNode getTemplateNode() { 179 return fTemplateNode; 180 } 181 182 185 public LazyNode templateClone(Document ownerDocument) { 186 return new LazyAttrNoNS((LazyDocument)ownerDocument, this, null); 187 } 188 189 191 195 198 private boolean fParentExpanded = false; 199 private boolean fChildrenExpanded = false; 200 201 204 public boolean isParentExpanded() { 205 return fParentExpanded; 206 } 207 208 211 public void setParentExpanded() { 212 fParentExpanded = true; 213 } 214 215 218 public void setParentWhileExpanding(Node parent) { 219 ownerNode = (NodeImpl)parent; 220 flags |= OWNED; 221 fParentExpanded = true; 222 } 223 224 227 public boolean areChildrenExpanded() { 228 return fChildrenExpanded; 229 } 230 231 234 public void setChildrenExpanded() { 235 fChildrenExpanded = true; 236 } 237 238 241 public void appendChildWhileExpanding(Node child) { 242 super.insertBefore(child, null); 243 } 244 245 248 private void expandParent() { 249 ((LazyDocument)getOwnerDocument()).doExpandParent(this); 250 } 251 252 255 private void expandChildren() { 256 ((LazyDocument)getOwnerDocument()).doExpandChildren(this); 257 } 258 259 262 public Node getParentNode() { 263 if (!fParentExpanded) { 264 expandParent(); 265 } 266 return super.getParentNode(); 267 } 268 269 272 public NodeList getChildNodes() { 273 if (!fChildrenExpanded) { 274 expandChildren(); 275 } 276 return super.getChildNodes(); 277 } 278 279 282 public Node getFirstChild() { 283 if (!fChildrenExpanded) { 284 expandChildren(); 285 } 286 return super.getFirstChild(); 287 } 288 289 292 public Node getLastChild() { 293 if (!fChildrenExpanded) { 294 expandChildren(); 295 } 296 return super.getLastChild(); 297 } 298 299 302 public Node getPreviousSibling() { 303 if (!fParentExpanded) { 304 expandParent(); 305 } 306 return super.getPreviousSibling(); 307 } 308 309 312 public Node getNextSibling() { 313 if (!fParentExpanded) { 314 expandParent(); 315 } 316 return super.getNextSibling(); 317 } 318 319 322 public Node insertBefore(Node newChild, 323 Node refChild) 324 throws DOMException { 325 if (!fChildrenExpanded) { 326 expandChildren(); 327 } 328 return super.insertBefore(newChild, refChild); 329 } 330 331 334 public Node replaceChild(Node newChild, 335 Node oldChild) 336 throws DOMException { 337 if (!fChildrenExpanded) { 338 expandChildren(); 339 } 340 return super.replaceChild(newChild, oldChild); 341 } 342 343 346 public Node removeChild(Node oldChild) 347 throws DOMException { 348 if (!fChildrenExpanded) { 349 expandChildren(); 350 } 351 return super.removeChild(oldChild); 352 } 353 354 357 public Node appendChild(Node newChild) 358 throws DOMException { 359 if (!fChildrenExpanded) { 360 expandChildren(); 361 } 362 return super.appendChild(newChild); 363 } 364 365 368 public boolean hasChildNodes() { 369 if (!fChildrenExpanded) { 370 return fTemplateNode.hasChildNodes(); 371 } else { 372 return super.hasChildNodes(); 373 } 374 } 375 376 379 public void normalize() { 380 if (!fChildrenExpanded) { 381 expandChildren(); 382 } 383 super.normalize(); 384 } 385 386 390 public String toString() { 391 return getName(); 392 } 393 } 394 | Popular Tags |