1 19 20 package org.netbeans.modules.xml.text.completion; 21 22 import org.w3c.dom.*; 23 24 import org.netbeans.modules.xml.api.model.*; 25 import org.netbeans.modules.xml.spi.dom.*; 26 27 34 class DefaultContext implements HintContext, Attr, Element { 35 36 private Node peer; 37 private String text; 38 39 private Node parent, previous, next; 41 private boolean virtual; 42 private short type; 43 44 48 public DefaultContext() { 49 } 50 51 59 public void initVirtualElement(Node parent, Node previous, Node next) { 60 this.parent = parent; 61 this.previous = previous; 62 this.next = next; 63 this.type = Node.ELEMENT_NODE; 64 virtual = true; 65 this.peer = parent; } 67 68 75 public void initVirtualAttr(Element parent, String text) { 76 this.parent = parent; 77 this.next = null; 78 this.previous = null; 79 this.text = text; 80 this.type = Node.ATTRIBUTE_NODE; 81 virtual = true; 82 this.peer = parent; } 84 85 90 public void init(Node node, String preText) { 91 peer = node; 92 text = preText; 93 virtual = false; 94 } 96 97 public boolean isInitialized() { 98 return peer != null; 99 } 100 101 String dump() { 102 Node parent = getParentNode(); 103 if (parent != null) { 104 105 String name = parent.getNodeName(); 106 107 109 int index = 0; 110 111 Node sibling = null; 112 113 115 sibling = this; 116 do { 117 sibling = sibling.getPreviousSibling(); 118 if (sibling == null) break; 119 if (sibling.getNodeType() == Node.ELEMENT_NODE) break; 120 } while (true); 121 122 while (sibling != null) { 123 124 index++; 125 126 128 do { 129 sibling = sibling.getPreviousSibling(); 130 if (sibling == null) break; 131 if (sibling.getNodeType() == Node.ELEMENT_NODE) break; 132 } while (true); 133 134 } 135 136 138 String names = ""; 139 NodeList kids = parent.getChildNodes(); 140 141 if (kids == null) { 142 return "X missing kids"; 143 } 144 for (int i = 0; i < kids.getLength(); i++) { 145 Node next = kids.item(i); 146 if (next.getNodeType() == Node.ELEMENT_NODE) { 147 names += next.getNodeName() + ", "; 148 } 149 } 150 151 return "DefaultContext: parent: " + name + " p'kids: " + names + " index: " + index; 153 154 } else { 155 return "X missing parent"; 156 } 157 158 } 159 160 163 public String getNodeName() { 164 return peer.getNodeName(); 165 } 166 167 181 public boolean isSupported(String feature, String version) { 182 throw new UOException(); 183 } 184 185 public void setPrefix(String prefix) throws DOMException { 186 throw new UOException(); 187 } 188 189 220 public String getPrefix() { 221 throw new UOException(); 222 } 223 224 228 public Node getPreviousSibling() { 229 if (virtual) { 230 return previous; 231 } else { 232 return peer.getPreviousSibling(); 233 } 234 } 235 236 239 public short getNodeType() { 240 if (virtual) return type; 241 return peer.getNodeType(); 242 } 243 244 252 public Document getOwnerDocument() { 253 return peer.getOwnerDocument(); 254 } 255 256 278 public Node replaceChild(Node newChild, Node oldChild) throws DOMException { 279 return peer.replaceChild(newChild, oldChild); 280 } 281 282 285 public String getCurrentPrefix() { 286 return text; 287 } 288 289 313 public Node cloneNode(boolean deep) { 314 return peer.cloneNode(deep); 315 } 316 317 321 public Node getNextSibling() { 322 if (virtual) { 323 return next; 324 } else { 325 return peer.getNextSibling(); 326 } 327 } 328 329 352 public Node insertBefore(Node newChild, Node refChild) throws DOMException { 353 return peer.insertBefore(newChild, refChild); 354 } 355 356 371 public String getNamespaceURI() { 372 throw new UOException(); 373 } 374 375 379 public NamedNodeMap getAttributes() { 380 return peer.getAttributes(); 381 } 382 383 388 public NodeList getChildNodes() { 389 return peer.getChildNodes(); 390 } 391 392 402 public String getNodeValue() throws DOMException { 403 return peer.getNodeValue(); 404 } 405 406 422 public Node appendChild(Node newChild) throws DOMException { 423 return peer.appendChild(newChild); 424 } 425 426 434 public String getLocalName() { 435 throw new UOException(); 436 } 437 438 446 public Node getParentNode() { 447 if (virtual) { 448 return parent; 449 } else { 450 return peer.getParentNode(); 451 } 452 } 453 454 public void setNodeValue(String nodeValue) throws DOMException { 455 peer.setNodeValue(nodeValue); 456 } 457 458 462 public Node getLastChild() { 463 return peer.getLastChild(); 464 } 465 466 472 public boolean hasAttributes() { 473 throw new UOException(); 474 } 475 476 492 public void normalize() { 493 peer.normalize(); 494 } 495 496 506 public Node removeChild(Node oldChild) throws DOMException { 507 return peer.removeChild(oldChild); 508 } 509 510 515 public boolean hasChildNodes() { 516 return peer.hasChildNodes(); 517 } 518 519 523 public Node getFirstChild() { 524 return peer.getFirstChild(); 525 } 526 527 528 public String toString() { 529 return "context node(" + getNodeName() + ", prefix("+ getCurrentPrefix() + "))"; 530 } 531 532 534 public boolean getSpecified() { 535 if (peer instanceof Attr) { 536 return ((Attr)peer).getSpecified(); 537 } else { 538 throw new NOA(); 539 } 540 } 541 542 public String getName() { 543 if (virtual) return text; 544 if (peer instanceof Attr) { 545 return ((Attr)peer).getName(); 546 } else { 547 throw new NOA(); 548 } 549 } 550 551 public Element getOwnerElement() { 552 if (virtual) return (Element) parent; 553 554 if (peer instanceof Attr) { 555 return ((Attr)peer).getOwnerElement(); 556 } else { 557 throw new NOA(); 558 } 559 } 560 561 public void setValue(String value) throws DOMException { 562 if (peer instanceof Attr) { 563 ((Attr)peer).setValue(value); 564 } else { 565 throw new NOA(); 566 } 567 } 568 569 public String getValue() { 570 if (peer instanceof Attr) { 571 return ((Attr)peer).getValue(); 572 } else { 573 throw new NOA(); 574 } 575 } 576 577 public String getAttribute(String str) { 578 if (peer instanceof Element) { 579 return ((Element)peer).getAttribute(str); 580 } else { 581 throw new NOE(); 582 } 583 } 584 585 public String getAttributeNS(String str, String str1) { 586 if (peer instanceof Element) { 587 return ((Element)peer).getAttributeNS(str, str1); 588 } else { 589 throw new NOE(); 590 } 591 } 592 593 public org.w3c.dom.Attr getAttributeNode(String str) { 594 if (peer instanceof Element) { 595 return ((Element)peer).getAttributeNode(str); 596 } else { 597 throw new NOE(); 598 } 599 } 600 601 public org.w3c.dom.Attr getAttributeNodeNS(String str, String str1) { 602 if (peer instanceof Element) { 603 return ((Element)peer).getAttributeNodeNS(str, str1); 604 } else { 605 throw new NOE(); 606 } 607 } 608 609 public org.w3c.dom.NodeList getElementsByTagName(String str) { 610 if (peer instanceof Element) { 611 return ((Element)peer).getElementsByTagName(str); 612 } else { 613 throw new NOE(); 614 } 615 } 616 617 public org.w3c.dom.NodeList getElementsByTagNameNS(String str, String str1) { 618 if (peer instanceof Element) { 619 return ((Element)peer).getElementsByTagNameNS(str, str1); 620 } else { 621 throw new NOE(); 622 } 623 } 624 625 public String getTagName() { 626 if (peer instanceof Element) { 627 return ((Element)peer).getTagName(); 628 } else { 629 throw new NOE(); 630 } 631 } 632 633 public boolean hasAttribute(String str) { 634 if (peer instanceof Element) { 635 return ((Element)peer).hasAttribute(str); 636 } else { 637 throw new NOE(); 638 } 639 } 640 641 public boolean hasAttributeNS(String str, String str1) { 642 if (peer instanceof Element) { 643 return ((Element)peer).hasAttributeNS(str, str1); 644 } else { 645 throw new NOE(); 646 } 647 } 648 649 public void removeAttribute(String str) throws org.w3c.dom.DOMException { 650 if (peer instanceof Element) { 651 ((Element)peer).removeAttribute(str); 652 } else { 653 throw new NOE(); 654 } 655 } 656 657 public void removeAttributeNS(String str, String str1) throws org.w3c.dom.DOMException { 658 if (peer instanceof Element) { 659 ((Element)peer).removeAttributeNS(str, str1); 660 } else { 661 throw new NOE(); 662 } 663 } 664 665 public org.w3c.dom.Attr removeAttributeNode(org.w3c.dom.Attr attr) throws org.w3c.dom.DOMException { 666 if (peer instanceof Element) { 667 return ((Element)peer).removeAttributeNode(attr); 668 } else { 669 throw new NOE(); 670 } 671 } 672 673 public void setAttribute(String str, String str1) throws org.w3c.dom.DOMException { 674 if (peer instanceof Element) { 675 ((Element)peer).setAttribute(str, str1); 676 } else { 677 throw new NOE(); 678 } 679 } 680 681 public void setAttributeNS(String str, String str1, String str2) throws org.w3c.dom.DOMException { 682 if (peer instanceof Element) { 683 ((Element)peer).setAttributeNS(str, str1, str2); 684 } else { 685 throw new NOE(); 686 } 687 } 688 689 public org.w3c.dom.Attr setAttributeNode(org.w3c.dom.Attr attr) throws org.w3c.dom.DOMException { 690 if (peer instanceof Element) { 691 return ((Element)peer).setAttributeNode(attr); 692 } else { 693 throw new NOE(); 694 } 695 } 696 697 public org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr attr) throws org.w3c.dom.DOMException { 698 if (peer instanceof Element) { 699 return ((Element)peer).setAttributeNodeNS(attr); 700 } else { 701 throw new NOE(); 702 } 703 } 704 705 private class NOA extends DOMException { 707 708 private static final long serialVersionUID = 4600894053037825159L; 709 710 NOA() { 711 super(DOMException.NOT_SUPPORTED_ERR, "Peer " + peer + " is not instance of Attr!"); 712 } 713 } 714 715 private class NOE extends DOMException { 716 717 private static final long serialVersionUID = 4600894053037825159L; 718 719 NOE() { 720 super(DOMException.NOT_SUPPORTED_ERR, "Peer " + peer + " is not instance of Element!"); 721 } 722 } 723 724 728 public short compareDocumentPosition (Node a) { 729 throw new UOException(); 730 } 731 732 public String getBaseURI() { 733 throw new UOException(); 734 } 735 public Object getFeature(String a, String b) { 736 throw new UOException(); 737 } 738 public String getTextContent () { 739 throw new UOException(); 740 } 741 public Object getUserData(String a) { 742 throw new UOException(); 743 } 744 public boolean isDefaultNamespace (String a) { 745 throw new UOException(); 746 } 747 public boolean isEqualNode(Node a) { 748 throw new UOException(); 749 } 750 public boolean isSameNode(Node a) { 751 throw new UOException(); 752 } 753 public String lookupNamespaceURI(String a) { 754 throw new UOException(); 755 } 756 public String lookupPrefix(String a) { 757 throw new UOException(); 758 } 759 public void setTextContent(String a) { 760 throw new UOException(); 761 } 762 public Object setUserData(String a, Object b, UserDataHandler c) { 763 throw new UOException(); 764 } 765 public TypeInfo getSchemaTypeInfo() { 767 throw new UOException (); 768 } 769 public void setIdAttribute(String a, boolean b) { 770 throw new UOException (); 771 } 772 public void setIdAttributeNS(String a, String b, boolean c) { 773 throw new UOException (); 774 } 775 public void setIdAttributeNode(Attr a, boolean b) { 776 throw new UOException (); 777 } 778 780 public boolean isId () { 781 throw new UOException (); 782 } 783 public Text replaceWholeText (String a) { 785 throw new UOException (); 786 } 787 public String getWholeText() { 788 throw new UOException (); 789 } 790 public boolean isElementContentWhitespace() { 791 throw new UOException (); 792 } 793 } 794 | Popular Tags |