1 21 22 package nu.xom; 23 24 53 public abstract class Node { 54 55 56 private ParentNode parent = null; 57 58 65 Node() {} 66 67 68 75 public abstract String getValue(); 76 77 78 90 public final Document getDocument() { 91 Node parent = this; 92 while (parent != null && !(parent.isDocument())) { 93 parent = parent.getParent(); 94 } 95 return (Document) parent; 96 } 97 98 99 168 public String getBaseURI() { 169 if (parent == null) return ""; 170 return parent.getBaseURI(); 171 } 172 173 174 184 public final ParentNode getParent() { 185 return this.parent; 186 } 187 188 189 final void setParent(ParentNode parent) { 190 this.parent = parent; 191 } 192 193 194 203 public void detach() { 204 205 if (parent == null) return; 206 else if (this.isAttribute()) { 207 Element element = (Element) parent; 208 element.removeAttribute((Attribute) this); 209 } 210 else { 211 parent.removeChild(this); 212 } 213 214 } 215 216 217 228 public abstract Node getChild(int position); 229 230 231 239 public abstract int getChildCount(); 240 241 242 260 public abstract Node copy(); 261 262 263 274 public abstract String toXML(); 275 276 277 290 public final boolean equals(Object o) { 291 return this == o; 292 } 293 294 295 307 public final int hashCode() { 308 return super.hashCode(); 309 } 310 311 312 boolean isElement() { 314 return false; 315 } 316 317 boolean isText() { 318 return false; 319 } 320 321 boolean isComment() { 322 return false; 323 } 324 325 boolean isProcessingInstruction() { 326 return false; 327 } 328 329 boolean isAttribute() { 330 return false; 331 } 332 333 boolean isDocument() { 334 return false; 335 } 336 337 boolean isDocType() { 338 return false; 339 } 340 341 342 } 343 | Popular Tags |