1 16 19 package org.apache.xml.dtm.ref; 20 21 import org.apache.xml.dtm.DTM; 22 import org.apache.xml.dtm.DTMDOMException; 23 24 import org.w3c.dom.Attr ; 25 import org.w3c.dom.CDATASection ; 26 import org.w3c.dom.Comment ; 27 import org.w3c.dom.DOMException ; 28 import org.w3c.dom.DOMImplementation ; 29 import org.w3c.dom.Document ; 30 import org.w3c.dom.DocumentFragment ; 31 import org.w3c.dom.DocumentType ; 32 import org.w3c.dom.Element ; 33 import org.w3c.dom.EntityReference ; 34 import org.w3c.dom.NamedNodeMap ; 35 import org.w3c.dom.Node ; 36 import org.w3c.dom.NodeList ; 37 import org.w3c.dom.ProcessingInstruction ; 38 import org.w3c.dom.Text ; 39 40 54 public class DTMNodeProxy 55 implements Node , Document , Text , Element , Attr , 56 ProcessingInstruction , Comment , DocumentFragment 57 { 58 59 60 public DTM dtm; 61 62 63 int node; 64 65 66 static final DOMImplementation implementation=new DTMNodeProxyImplementation(); 67 68 74 public DTMNodeProxy(DTM dtm, int node) 75 { 76 this.dtm = dtm; 77 this.node = node; 78 } 79 80 85 public final DTM getDTM() 86 { 87 return dtm; 88 } 89 90 95 public final int getDTMNodeNumber() 96 { 97 return node; 98 } 99 100 107 public final boolean equals(Node node) 108 { 109 110 try 111 { 112 DTMNodeProxy dtmp = (DTMNodeProxy) node; 113 114 return (dtmp.node == this.node) && (dtmp.dtm == this.dtm); 117 } 118 catch (ClassCastException cce) 119 { 120 return false; 121 } 122 } 123 124 131 public final boolean equals(Object node) 132 { 133 134 try 135 { 136 137 return equals((Node ) node); 141 } 142 catch (ClassCastException cce) 143 { 144 return false; 145 } 146 } 147 148 155 public final boolean sameNodeAs(Node other) 156 { 157 158 if (!(other instanceof DTMNodeProxy)) 159 return false; 160 161 DTMNodeProxy that = (DTMNodeProxy) other; 162 163 return this.dtm == that.dtm && this.node == that.node; 164 } 165 166 171 public final String getNodeName() 172 { 173 return dtm.getNodeName(node); 174 } 175 176 189 public final String getTarget() 190 { 191 return dtm.getNodeName(node); 192 } 194 199 public final String getLocalName() 200 { 201 return dtm.getLocalName(node); 202 } 203 204 208 public final String getPrefix() 209 { 210 return dtm.getPrefix(node); 211 } 212 213 220 public final void setPrefix(String prefix) throws DOMException 221 { 222 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 223 } 224 225 230 public final String getNamespaceURI() 231 { 232 return dtm.getNamespaceURI(node); 233 } 234 235 251 public final boolean supports(String feature, String version) 252 { 253 return implementation.hasFeature(feature,version); 254 } 256 257 267 public final boolean isSupported(String feature, String version) 268 { 269 return implementation.hasFeature(feature,version); 270 } 272 273 280 public final String getNodeValue() throws DOMException 281 { 282 return dtm.getNodeValue(node); 283 } 284 285 290 public final String getStringValue() throws DOMException 291 { 292 return dtm.getStringValue(node).toString(); 293 } 294 295 302 public final void setNodeValue(String nodeValue) throws DOMException 303 { 304 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 305 } 306 307 312 public final short getNodeType() 313 { 314 return (short) dtm.getNodeType(node); 315 } 316 317 322 public final Node getParentNode() 323 { 324 325 if (getNodeType() == Node.ATTRIBUTE_NODE) 326 return null; 327 328 int newnode = dtm.getParent(node); 329 330 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 331 } 332 333 338 public final Node getOwnerNode() 339 { 340 341 int newnode = dtm.getParent(node); 342 343 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 344 } 345 346 351 public final NodeList getChildNodes() 352 { 353 354 return new DTMChildIterNodeList(dtm,node); 358 359 } 361 362 367 public final Node getFirstChild() 368 { 369 370 int newnode = dtm.getFirstChild(node); 371 372 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 373 } 374 375 380 public final Node getLastChild() 381 { 382 383 int newnode = dtm.getLastChild(node); 384 385 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 386 } 387 388 393 public final Node getPreviousSibling() 394 { 395 396 int newnode = dtm.getPreviousSibling(node); 397 398 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 399 } 400 401 406 public final Node getNextSibling() 407 { 408 409 if (dtm.getNodeType(node) == Node.ATTRIBUTE_NODE) 411 return null; 412 413 int newnode = dtm.getNextSibling(node); 414 415 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 416 } 417 418 420 425 public final NamedNodeMap getAttributes() 426 { 427 428 return new DTMNamedNodeMap(dtm, node); 429 } 430 431 439 public boolean hasAttribute(String name) 440 { 441 return DTM.NULL != dtm.getAttributeNode(node,null,name); 442 } 443 444 453 public boolean hasAttributeNS(String name, String x) 454 { 455 return DTM.NULL != dtm.getAttributeNode(node,x,name); 456 } 457 458 463 public final Document getOwnerDocument() 464 { 465 return (Document )(dtm.getNode(dtm.getOwnerDocument(node))); 467 } 468 469 479 public final Node insertBefore(Node newChild, Node refChild) 480 throws DOMException 481 { 482 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 483 } 484 485 495 public final Node replaceChild(Node newChild, Node oldChild) 496 throws DOMException 497 { 498 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 499 } 500 501 510 public final Node removeChild(Node oldChild) throws DOMException 511 { 512 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 513 } 514 515 524 public final Node appendChild(Node newChild) throws DOMException 525 { 526 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 527 } 528 529 534 public final boolean hasChildNodes() 535 { 536 return (DTM.NULL != dtm.getFirstChild(node)); 537 } 538 539 546 public final Node cloneNode(boolean deep) 547 { 548 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 549 } 550 551 556 public final DocumentType getDoctype() 557 { 558 return null; 559 } 560 561 566 public final DOMImplementation getImplementation() 567 { 568 return implementation; 569 } 570 571 578 public final Element getDocumentElement() 579 { 580 int dochandle=dtm.getDocument(); 581 int elementhandle=DTM.NULL; 582 for(int kidhandle=dtm.getFirstChild(dochandle); 583 kidhandle!=DTM.NULL; 584 kidhandle=dtm.getNextSibling(kidhandle)) 585 { 586 switch(dtm.getNodeType(kidhandle)) 587 { 588 case Node.ELEMENT_NODE: 589 if(elementhandle!=DTM.NULL) 590 { 591 elementhandle=DTM.NULL; kidhandle=dtm.getLastChild(dochandle); } 594 else 595 elementhandle=kidhandle; 596 break; 597 598 case Node.COMMENT_NODE: 600 case Node.PROCESSING_INSTRUCTION_NODE: 601 case Node.DOCUMENT_TYPE_NODE: 602 break; 603 604 default: 605 elementhandle=DTM.NULL; kidhandle=dtm.getLastChild(dochandle); break; 608 } 609 } 610 if(elementhandle==DTM.NULL) 611 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 612 else 613 return (Element )(dtm.getNode(elementhandle)); 614 } 615 616 625 public final Element createElement(String tagName) throws DOMException 626 { 627 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 628 } 629 630 635 public final DocumentFragment createDocumentFragment() 636 { 637 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 638 } 639 640 647 public final Text createTextNode(String data) 648 { 649 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 650 } 651 652 659 public final Comment createComment(String data) 660 { 661 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 662 } 663 664 673 public final CDATASection createCDATASection(String data) 674 throws DOMException 675 { 676 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 677 } 678 679 689 public final ProcessingInstruction createProcessingInstruction( 690 String target, String data) throws DOMException 691 { 692 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 693 } 694 695 704 public final Attr createAttribute(String name) throws DOMException 705 { 706 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 707 } 708 709 718 public final EntityReference createEntityReference(String name) 719 throws DOMException 720 { 721 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 722 } 723 724 731 public final NodeList getElementsByTagName(String tagname) 732 { 733 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 734 } 735 736 746 public final Node importNode(Node importedNode, boolean deep) 747 throws DOMException 748 { 749 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 750 } 751 752 762 public final Element createElementNS( 763 String namespaceURI, String qualifiedName) throws DOMException 764 { 765 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 766 } 767 768 778 public final Attr createAttributeNS( 779 String namespaceURI, String qualifiedName) throws DOMException 780 { 781 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 782 } 783 784 792 public final NodeList getElementsByTagNameNS(String namespaceURI, 793 String localName) 794 { 795 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 796 } 797 798 805 public final Element getElementById(String elementId) 806 { 807 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 808 } 809 810 819 public final Text splitText(int offset) throws DOMException 820 { 821 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 822 } 823 824 831 public final String getData() throws DOMException 832 { 833 return dtm.getNodeValue(node); 834 } 835 836 843 public final void setData(String data) throws DOMException 844 { 845 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 846 } 847 848 853 public final int getLength() 854 { 855 return dtm.getNodeValue(node).length(); 857 } 858 859 869 public final String substringData(int offset, int count) throws DOMException 870 { 871 return getData().substring(offset,offset+count); 872 } 873 874 881 public final void appendData(String arg) throws DOMException 882 { 883 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 884 } 885 886 894 public final void insertData(int offset, String arg) throws DOMException 895 { 896 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 897 } 898 899 907 public final void deleteData(int offset, int count) throws DOMException 908 { 909 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 910 } 911 912 921 public final void replaceData(int offset, int count, String arg) 922 throws DOMException 923 { 924 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 925 } 926 927 932 public final String getTagName() 933 { 934 return dtm.getNodeName(node); 935 } 936 937 944 public final String getAttribute(String name) 945 { 946 947 DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node); 948 Node node = map.getNamedItem(name); 949 return (null == node) ? null : node.getNodeValue(); 950 } 951 952 960 public final void setAttribute(String name, String value) 961 throws DOMException 962 { 963 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 964 } 965 966 973 public final void removeAttribute(String name) throws DOMException 974 { 975 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 976 } 977 978 985 public final Attr getAttributeNode(String name) 986 { 987 988 DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node); 989 return (Attr )map.getNamedItem(name); 990 } 991 992 1001 public final Attr setAttributeNode(Attr newAttr) throws DOMException 1002 { 1003 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1004 } 1005 1006 1015 public final Attr removeAttributeNode(Attr oldAttr) throws DOMException 1016 { 1017 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1018 } 1019 1020 1025 public boolean hasAttributes() 1026 { 1027 return DTM.NULL != dtm.getFirstAttribute(node); 1028 } 1029 1030 1031 public final void normalize() 1032 { 1033 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1034 } 1035 1036 1044 public final String getAttributeNS(String namespaceURI, String localName) 1045 { 1046 DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node); 1047 Node node = map.getNamedItemNS(namespaceURI,localName); 1048 return (null == node) ? null : node.getNodeValue(); 1049 } 1050 1051 1060 public final void setAttributeNS( 1061 String namespaceURI, String qualifiedName, String value) 1062 throws DOMException 1063 { 1064 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1065 } 1066 1067 1075 public final void removeAttributeNS(String namespaceURI, String localName) 1076 throws DOMException 1077 { 1078 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1079 } 1080 1081 1089 public final Attr getAttributeNodeNS(String namespaceURI, String localName) 1090 { 1091 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1092 } 1093 1094 1103 public final Attr setAttributeNodeNS(Attr newAttr) throws DOMException 1104 { 1105 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1106 } 1107 1108 1113 public final String getName() 1114 { 1115 return dtm.getNodeName(node); 1116 } 1117 1118 1123 public final boolean getSpecified() 1124 { 1125 return true; 1130 } 1131 1132 1137 public final String getValue() 1138 { 1139 return dtm.getNodeValue(node); 1140 } 1141 1142 1147 public final void setValue(String value) 1148 { 1149 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1150 } 1151 1152 1158 public final Element getOwnerElement() 1159 { 1160 if (getNodeType() != Node.ATTRIBUTE_NODE) 1161 return null; 1162 int newnode = dtm.getParent(node); 1165 return (newnode == DTM.NULL) ? null : (Element )(dtm.getNode(newnode)); 1166 } 1167 1168 1178 public Node adoptNode(Node source) throws DOMException 1179 { 1180 1181 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1182 } 1183 1184 1195 public String getEncoding() 1196 { 1197 1198 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1199 } 1200 1201 1212 public void setEncoding(String encoding) 1213 { 1214 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1215 } 1216 1217 1228 public boolean getStandalone() 1229 { 1230 1231 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1232 } 1233 1234 1245 public void setStandalone(boolean standalone) 1246 { 1247 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1248 } 1249 1250 1265 public boolean getStrictErrorChecking() 1266 { 1267 1268 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1269 } 1270 1271 1286 public void setStrictErrorChecking(boolean strictErrorChecking) 1287 { 1288 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1289 } 1290 1291 1302 public String getVersion() 1303 { 1304 1305 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1306 } 1307 1308 1319 public void setVersion(String version) 1320 { 1321 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1322 } 1323 1324 1325 1327 static class DTMNodeProxyImplementation implements DOMImplementation 1328 { 1329 public DocumentType createDocumentType(String qualifiedName,String publicId, String systemId) 1330 { 1331 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1332 } 1333 public Document createDocument(String namespaceURI,String qualfiedName,DocumentType doctype) 1334 { 1335 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1337 } 1338 1347 public boolean hasFeature(String feature,String version) 1348 { 1349 if( ("CORE".equals(feature.toUpperCase()) || "XML".equals(feature.toUpperCase())) 1350 && 1351 ("1.0".equals(version) || "2.0".equals(version)) 1352 ) 1353 return true; 1354 return false; 1355 } 1356 } 1357} 1358 | Popular Tags |