1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *     http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 /*
  21  * $Id: AdaptiveResultTreeImpl.java,v 1.2.4.1 2005/09/06 05:52:18 pvedula Exp $
  22  */
  23 package com.sun.org.apache.xalan.internal.xsltc.dom;
  24 
  25 import com.sun.org.apache.xalan.internal.xsltc.DOM;
  26 import com.sun.org.apache.xalan.internal.xsltc.StripFilter;
  27 import com.sun.org.apache.xalan.internal.xsltc.TransletException;
  28 import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;
  29 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
  30 import com.sun.org.apache.xml.internal.dtm.DTMAxisTraverser;
  31 import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
  32 import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
  33 import com.sun.org.apache.xml.internal.utils.XMLString;
  34 import java.util.Map;
  35 import javax.xml.transform.SourceLocator;
  36 import org.w3c.dom.Node;
  37 import org.w3c.dom.NodeList;
  38 import org.xml.sax.Attributes;
  39 import org.xml.sax.SAXException;
  40 import org.xml.sax.helpers.AttributesImpl;
  41 
  42 /**
  43  * AdaptiveResultTreeImpl is a adaptive DOM model for result tree fragments (RTF). It is
  44  * used in the case where the RTF is likely to be pure text yet it can still be a DOM tree.
  45  * It is designed for RTFs which have <xsl:call-template> or <xsl:apply-templates> in
  46  * the contents. Example:
  47  * <pre>
  48  *    &lt;xsl:variable name = "x"&gt;
  49  *      &lt;xsl:call-template name = "test"&gt;
  50  *         &lt;xsl:with-param name="a" select="."/&gt;
  51  *      &lt;/xsl:call-template&gt;
  52  *    &lt;/xsl:variable>
  53  * </pre>
  54  * <p>In this example the result produced by <xsl:call-template> is likely to be a single
  55  * Text node. But it can also be a DOM tree. This kind of RTF cannot be modelled by
  56  * SimpleResultTreeImpl.
  57  * <p>
  58  * AdaptiveResultTreeImpl can be considered as a smart switcher between SimpleResultTreeImpl
  59  * and SAXImpl. It treats the RTF as simple Text and uses the SimpleResultTreeImpl model
  60  * at the beginning. However, if it receives a call which indicates that this is a DOM tree
  61  * (e.g. startElement), it will automatically transform itself into a wrapper around a
  62  * SAXImpl. In this way we can have a light-weight model when the result only contains
  63  * simple text, while at the same time it still works when the RTF is a DOM tree.
  64  * <p>
  65  * All methods in this class are overridden to delegate the action to the wrapped SAXImpl object
  66  * if it is non-null, or delegate the action to the SimpleResultTreeImpl if there is no
  67  * wrapped SAXImpl.
  68  * <p>
  69  * %REVISIT% Can we combine this class with SimpleResultTreeImpl? I think it is possible, but
  70  * it will make SimpleResultTreeImpl more expensive. I will use two separate classes at
  71  * this time.
  72  */
  73 public class AdaptiveResultTreeImpl extends SimpleResultTreeImpl
  74 {
  75 
  76     // Document URI index, which increases by 1 at each getDocumentURI() call.
  77     private static int _documentURIIndex = 0;
  78 
  79     private static final String EMPTY_STRING = "".intern();
  80 
  81     // The SAXImpl object wrapped by this class, if the RTF is a tree.
  82     private SAXImpl _dom;
  83 
  84     /** The following fields are only used for the nested SAXImpl **/
  85 
  86     // The whitespace filter
  87     private DTMWSFilter _wsfilter;
  88 
  89     // The size of the RTF
  90     private int _initSize;
  91 
  92     // True if we want to build the ID index table
  93     private boolean _buildIdIndex;
  94 
  95     // The AttributeList
  96     private final AttributesImpl _attributes = new AttributesImpl();
  97 
  98     // The element name
  99     private String _openElementName;
 100 
 101 
 102     // Create a AdaptiveResultTreeImpl
 103     public AdaptiveResultTreeImpl(XSLTCDTMManager dtmManager, int documentID,
 104                                   DTMWSFilter wsfilter, int initSize,
 105                                   boolean buildIdIndex)
 106     {
 107         super(dtmManager, documentID);
 108 
 109         _wsfilter = wsfilter;
 110         _initSize = initSize;
 111         _buildIdIndex = buildIdIndex;
 112     }
 113 
 114     // Return the DOM object wrapped in this object.
 115     public DOM getNestedDOM()
 116     {
 117         return _dom;
 118     }
 119 
 120     // Return the document ID
 121     public int getDocument()
 122     {
 123         if (_dom != null) {
 124             return _dom.getDocument();
 125         }
 126         else {
 127             return super.getDocument();
 128         }
 129     }
 130 
 131     // Return the String value of the RTF
 132     public String getStringValue()
 133     {
 134         if (_dom != null) {
 135             return _dom.getStringValue();
 136         }
 137         else {
 138             return super.getStringValue();
 139         }
 140     }
 141 
 142     public DTMAxisIterator getIterator()
 143     {
 144         if (_dom != null) {
 145             return _dom.getIterator();
 146         }
 147         else {
 148             return super.getIterator();
 149         }
 150     }
 151 
 152     public DTMAxisIterator getChildren(final int node)
 153     {
 154         if (_dom != null) {
 155             return _dom.getChildren(node);
 156         }
 157         else {
 158             return super.getChildren(node);
 159         }
 160     }
 161 
 162     public DTMAxisIterator getTypedChildren(final int type)
 163     {
 164         if (_dom != null) {
 165             return _dom.getTypedChildren(type);
 166         }
 167         else {
 168             return super.getTypedChildren(type);
 169         }
 170     }
 171 
 172     public DTMAxisIterator getAxisIterator(final int axis)
 173     {
 174         if (_dom != null) {
 175             return _dom.getAxisIterator(axis);
 176         }
 177         else {
 178             return super.getAxisIterator(axis);
 179         }
 180     }
 181 
 182     public DTMAxisIterator getTypedAxisIterator(final int axis, final int type)
 183     {
 184         if (_dom != null) {
 185             return _dom.getTypedAxisIterator(axis, type);
 186         }
 187         else {
 188             return super.getTypedAxisIterator(axis, type);
 189         }
 190     }
 191 
 192     public DTMAxisIterator getNthDescendant(int node, int n, boolean includeself)
 193     {
 194         if (_dom != null) {
 195             return _dom.getNthDescendant(node, n, includeself);
 196         }
 197         else {
 198             return super.getNthDescendant(node, n, includeself);
 199         }
 200     }
 201 
 202     public DTMAxisIterator getNamespaceAxisIterator(final int axis, final int ns)
 203     {
 204         if (_dom != null) {
 205             return _dom.getNamespaceAxisIterator(axis, ns);
 206         }
 207         else {
 208             return super.getNamespaceAxisIterator(axis, ns);
 209         }
 210     }
 211 
 212     public DTMAxisIterator getNodeValueIterator(DTMAxisIterator iter, int returnType,
 213                                              String value, boolean op)
 214     {
 215         if (_dom != null) {
 216             return _dom.getNodeValueIterator(iter, returnType, value, op);
 217         }
 218         else {
 219             return super.getNodeValueIterator(iter, returnType, value, op);
 220         }
 221     }
 222 
 223     public DTMAxisIterator orderNodes(DTMAxisIterator source, int node)
 224     {
 225         if (_dom != null) {
 226             return _dom.orderNodes(source, node);
 227         }
 228         else {
 229             return super.orderNodes(source, node);
 230         }
 231     }
 232 
 233     public String getNodeName(final int node)
 234     {
 235         if (_dom != null) {
 236             return _dom.getNodeName(node);
 237         }
 238         else {
 239             return super.getNodeName(node);
 240         }
 241     }
 242 
 243     public String getNodeNameX(final int node)
 244     {
 245         if (_dom != null) {
 246             return _dom.getNodeNameX(node);
 247         }
 248         else {
 249             return super.getNodeNameX(node);
 250         }
 251     }
 252 
 253     public String getNamespaceName(final int node)
 254     {
 255         if (_dom != null) {
 256             return _dom.getNamespaceName(node);
 257         }
 258         else {
 259             return super.getNamespaceName(node);
 260         }
 261     }
 262 
 263     // Return the expanded type id of a given node
 264     public int getExpandedTypeID(final int nodeHandle)
 265     {
 266         if (_dom != null) {
 267             return _dom.getExpandedTypeID(nodeHandle);
 268         }
 269         else {
 270             return super.getExpandedTypeID(nodeHandle);
 271         }
 272     }
 273 
 274     public int getNamespaceType(final int node)
 275     {
 276         if (_dom != null) {
 277             return _dom.getNamespaceType(node);
 278         }
 279         else {
 280             return super.getNamespaceType(node);
 281         }
 282     }
 283 
 284     public int getParent(final int nodeHandle)
 285     {
 286         if (_dom != null) {
 287             return _dom.getParent(nodeHandle);
 288         }
 289         else {
 290             return super.getParent(nodeHandle);
 291         }
 292     }
 293 
 294     public int getAttributeNode(final int gType, final int element)
 295     {
 296         if (_dom != null) {
 297             return _dom.getAttributeNode(gType, element);
 298         }
 299         else {
 300             return super.getAttributeNode(gType, element);
 301         }
 302     }
 303 
 304     public String getStringValueX(final int nodeHandle)
 305     {
 306         if (_dom != null) {
 307             return _dom.getStringValueX(nodeHandle);
 308         }
 309         else {
 310             return super.getStringValueX(nodeHandle);
 311         }
 312     }
 313 
 314     public void copy(final int node, SerializationHandler handler)
 315         throws TransletException
 316     {
 317         if (_dom != null) {
 318             _dom.copy(node, handler);
 319         }
 320         else {
 321             super.copy(node, handler);
 322         }
 323     }
 324 
 325     public void copy(DTMAxisIterator nodes, SerializationHandler handler)
 326         throws TransletException
 327     {
 328         if (_dom != null) {
 329             _dom.copy(nodes, handler);
 330         }
 331         else {
 332             super.copy(nodes, handler);
 333         }
 334     }
 335 
 336     public String shallowCopy(final int node, SerializationHandler handler)
 337         throws TransletException
 338     {
 339         if (_dom != null) {
 340             return _dom.shallowCopy(node, handler);
 341         }
 342         else {
 343             return super.shallowCopy(node, handler);
 344         }
 345     }
 346 
 347     public boolean lessThan(final int node1, final int node2)
 348     {
 349         if (_dom != null) {
 350             return _dom.lessThan(node1, node2);
 351         }
 352         else {
 353             return super.lessThan(node1, node2);
 354         }
 355     }
 356 
 357     /**
 358      * Dispatch the character content of a node to an output handler.
 359      *
 360      * The escape setting should be taken care of when outputting to
 361      * a handler.
 362      */
 363     public void characters(final int node, SerializationHandler handler)
 364         throws TransletException
 365     {
 366         if (_dom != null) {
 367             _dom.characters(node, handler);
 368         }
 369         else {
 370             super.characters(node, handler);
 371         }
 372     }
 373 
 374     public Node makeNode(int index)
 375     {
 376         if (_dom != null) {
 377             return _dom.makeNode(index);
 378         }
 379         else {
 380             return super.makeNode(index);
 381         }
 382     }
 383 
 384     public Node makeNode(DTMAxisIterator iter)
 385     {
 386         if (_dom != null) {
 387             return _dom.makeNode(iter);
 388         }
 389         else {
 390             return super.makeNode(iter);
 391         }
 392     }
 393 
 394     public NodeList makeNodeList(int index)
 395     {
 396         if (_dom != null) {
 397             return _dom.makeNodeList(index);
 398         }
 399         else {
 400             return super.makeNodeList(index);
 401         }
 402     }
 403 
 404     public NodeList makeNodeList(DTMAxisIterator iter)
 405     {
 406         if (_dom != null) {
 407             return _dom.makeNodeList(iter);
 408         }
 409         else {
 410             return super.makeNodeList(iter);
 411         }
 412     }
 413 
 414     public String getLanguage(int node)
 415     {
 416         if (_dom != null) {
 417             return _dom.getLanguage(node);
 418         }
 419         else {
 420             return super.getLanguage(node);
 421         }
 422     }
 423 
 424     public int getSize()
 425     {
 426         if (_dom != null) {
 427             return _dom.getSize();
 428         }
 429         else {
 430             return super.getSize();
 431         }
 432     }
 433 
 434     public String getDocumentURI(int node)
 435     {
 436         if (_dom != null) {
 437             return _dom.getDocumentURI(node);
 438         }
 439         else {
 440             return "adaptive_rtf" + _documentURIIndex++;
 441         }
 442     }
 443 
 444     public void setFilter(StripFilter filter)
 445     {
 446         if (_dom != null) {
 447             _dom.setFilter(filter);
 448         }
 449         else {
 450             super.setFilter(filter);
 451         }
 452     }
 453 
 454     public void setupMapping(String[] names, String[] uris, int[] types, String[] namespaces)
 455     {
 456         if (_dom != null) {
 457             _dom.setupMapping(names, uris, types, namespaces);
 458         }
 459         else {
 460             super.setupMapping(names, uris, types, namespaces);
 461         }
 462     }
 463 
 464     public boolean isElement(final int node)
 465     {
 466         if (_dom != null) {
 467             return _dom.isElement(node);
 468         }
 469         else {
 470             return super.isElement(node);
 471         }
 472     }
 473 
 474     public boolean isAttribute(final int node)
 475     {
 476         if (_dom != null) {
 477             return _dom.isAttribute(node);
 478         }
 479         else {
 480             return super.isAttribute(node);
 481         }
 482     }
 483 
 484     public String lookupNamespace(int node, String prefix)
 485         throws TransletException
 486     {
 487         if (_dom != null) {
 488             return _dom.lookupNamespace(node, prefix);
 489         }
 490         else {
 491             return super.lookupNamespace(node, prefix);
 492         }
 493     }
 494 
 495     /**
 496      * Return the node identity from a node handle.
 497      */
 498     public final int getNodeIdent(final int nodehandle)
 499     {
 500         if (_dom != null) {
 501             return _dom.getNodeIdent(nodehandle);
 502         }
 503         else {
 504             return super.getNodeIdent(nodehandle);
 505         }
 506     }
 507 
 508     /**
 509      * Return the node handle from a node identity.
 510      */
 511     public final int getNodeHandle(final int nodeId)
 512     {
 513         if (_dom != null) {
 514             return _dom.getNodeHandle(nodeId);
 515         }
 516         else {
 517             return super.getNodeHandle(nodeId);
 518         }
 519     }
 520 
 521     public DOM getResultTreeFrag(int initialSize, int rtfType)
 522     {
 523         if (_dom != null) {
 524             return _dom.getResultTreeFrag(initialSize, rtfType);
 525         }
 526         else {
 527             return super.getResultTreeFrag(initialSize, rtfType);
 528         }
 529     }
 530 
 531     public SerializationHandler getOutputDomBuilder()
 532     {
 533         return this;
 534     }
 535 
 536     public int getNSType(int node)
 537     {
 538         if (_dom != null) {
 539             return _dom.getNSType(node);
 540         }
 541         else {
 542             return super.getNSType(node);
 543         }
 544     }
 545 
 546     public String getUnparsedEntityURI(String name)
 547     {
 548         if (_dom != null) {
 549             return _dom.getUnparsedEntityURI(name);
 550         }
 551         else {
 552             return super.getUnparsedEntityURI(name);
 553         }
 554     }
 555 
 556     public Map<String, Integer> getElementsWithIDs()
 557     {
 558         if (_dom != null) {
 559             return _dom.getElementsWithIDs();
 560         }
 561         else {
 562             return super.getElementsWithIDs();
 563         }
 564     }
 565 
 566     /** Implementation of the SerializationHandler interfaces **/
 567 
 568     /** The code in some of the following interfaces are copied from SAXAdapter. **/
 569 
 570     private void maybeEmitStartElement() throws SAXException
 571     {
 572         if (_openElementName != null) {
 573 
 574            int index;
 575            if ((index =_openElementName.indexOf(":")) < 0)
 576                _dom.startElement(null, _openElementName, _openElementName, _attributes);
 577            else {
 578                 String uri =_dom.getNamespaceURI(_openElementName.substring(0,index));
 579                 _dom.startElement(uri, _openElementName.substring(index+1), _openElementName, _attributes);
 580            }
 581 
 582 
 583             _openElementName = null;
 584         }
 585 
 586     }
 587 
 588     // Create and initialize the wrapped SAXImpl object
 589     private void prepareNewDOM() throws SAXException
 590     {
 591         _dom = (SAXImpl)_dtmManager.getDTM(null, true, _wsfilter,
 592                                   true, false, false,
 593                                   _initSize, _buildIdIndex);
 594         _dom.startDocument();
 595         // Flush pending Text nodes to SAXImpl
 596         for (int i = 0; i < _size; i++) {
 597             String str = _textArray[i];
 598             _dom.characters(str.toCharArray(), 0, str.length());
 599         }
 600         _size = 0;
 601     }
 602 
 603     public void startDocument() throws SAXException
 604     {
 605     }
 606 
 607     public void endDocument() throws SAXException
 608     {
 609         if (_dom != null) {
 610             _dom.endDocument();
 611         }
 612         else {
 613             super.endDocument();
 614         }
 615     }
 616 
 617     public void characters(String str) throws SAXException
 618     {
 619         if (_dom != null) {
 620             characters(str.toCharArray(), 0, str.length());
 621         }
 622         else {
 623             super.characters(str);
 624         }
 625     }
 626 
 627     public void characters(char[] ch, int offset, int length)
 628         throws SAXException
 629     {
 630         if (_dom != null) {
 631             maybeEmitStartElement();
 632             _dom.characters(ch, offset, length);
 633         }
 634         else {
 635             super.characters(ch, offset, length);
 636         }
 637     }
 638 
 639     public boolean setEscaping(boolean escape) throws SAXException
 640     {
 641         if (_dom != null) {
 642             return _dom.setEscaping(escape);
 643         }
 644         else {
 645             return super.setEscaping(escape);
 646         }
 647     }
 648 
 649     public void startElement(String elementName) throws SAXException
 650     {
 651         if (_dom == null) {
 652             prepareNewDOM();
 653         }
 654 
 655         maybeEmitStartElement();
 656         _openElementName = elementName;
 657         _attributes.clear();
 658     }
 659 
 660     public void startElement(String uri, String localName, String qName)
 661         throws SAXException
 662     {
 663         startElement(qName);
 664     }
 665 
 666     public void startElement(String uri, String localName, String qName, Attributes attributes)
 667         throws SAXException
 668     {
 669         startElement(qName);
 670     }
 671 
 672     public void endElement(String elementName) throws SAXException
 673     {
 674         maybeEmitStartElement();
 675         _dom.endElement(null, null, elementName);
 676     }
 677 
 678     public void endElement(String uri, String localName, String qName)
 679         throws SAXException
 680     {
 681         endElement(qName);
 682     }
 683 
 684     public void addAttribute(String qName, String value)
 685     {
 686         // "prefix:localpart" or "localpart"
 687         int colonpos = qName.indexOf(":");
 688         String uri = EMPTY_STRING;
 689         String localName = qName;
 690         if (colonpos >0)
 691         {
 692             String prefix = qName.substring(0, colonpos);
 693             localName = qName.substring(colonpos+1);
 694             uri = _dom.getNamespaceURI(prefix);
 695         }
 696 
 697         addAttribute(uri, localName, qName, "CDATA", value);
 698     }
 699 
 700     public void addUniqueAttribute(String qName, String value, int flags)
 701         throws SAXException
 702     {
 703         addAttribute(qName, value);
 704     }
 705 
 706     public void addAttribute(String uri, String localName, String qname,
 707             String type, String value)
 708     {
 709         if (_openElementName != null) {
 710             _attributes.addAttribute(uri, localName, qname, type, value);
 711         }
 712         else {
 713             BasisLibrary.runTimeError(BasisLibrary.STRAY_ATTRIBUTE_ERR, qname);
 714         }
 715     }
 716 
 717     public void namespaceAfterStartElement(String prefix, String uri)
 718         throws SAXException
 719     {
 720         if (_dom == null) {
 721            prepareNewDOM();
 722         }
 723 
 724         _dom.startPrefixMapping(prefix, uri);
 725     }
 726 
 727     public void comment(String comment) throws SAXException
 728     {
 729         if (_dom == null) {
 730            prepareNewDOM();
 731         }
 732 
 733         maybeEmitStartElement();
 734         char[] chars = comment.toCharArray();
 735         _dom.comment(chars, 0, chars.length);
 736     }
 737 
 738     public void comment(char[] chars, int offset, int length)
 739         throws SAXException
 740     {
 741         if (_dom == null) {
 742            prepareNewDOM();
 743         }
 744 
 745         maybeEmitStartElement();
 746         _dom.comment(chars, offset, length);
 747     }
 748 
 749     public void processingInstruction(String target, String data)
 750         throws SAXException
 751     {
 752         if (_dom == null) {
 753            prepareNewDOM();
 754         }
 755 
 756         maybeEmitStartElement();
 757         _dom.processingInstruction(target, data);
 758     }
 759 
 760     /** Implementation of the DTM interfaces **/
 761 
 762     public void setFeature(String featureId, boolean state)
 763     {
 764         if (_dom != null) {
 765             _dom.setFeature(featureId, state);
 766         }
 767     }
 768 
 769     public void setProperty(String property, Object value)
 770     {
 771         if (_dom != null) {
 772             _dom.setProperty(property, value);
 773         }
 774     }
 775 
 776     public DTMAxisTraverser getAxisTraverser(final int axis)
 777     {
 778         if (_dom != null) {
 779             return _dom.getAxisTraverser(axis);
 780         }
 781         else {
 782             return super.getAxisTraverser(axis);
 783         }
 784     }
 785 
 786     public boolean hasChildNodes(int nodeHandle)
 787     {
 788         if (_dom != null) {
 789             return _dom.hasChildNodes(nodeHandle);
 790         }
 791         else {
 792             return super.hasChildNodes(nodeHandle);
 793         }
 794     }
 795 
 796     public int getFirstChild(int nodeHandle)
 797     {
 798         if (_dom != null) {
 799             return _dom.getFirstChild(nodeHandle);
 800         }
 801         else {
 802             return super.getFirstChild(nodeHandle);
 803         }
 804     }
 805 
 806     public int getLastChild(int nodeHandle)
 807     {
 808         if (_dom != null) {
 809             return _dom.getLastChild(nodeHandle);
 810         }
 811         else {
 812             return super.getLastChild(nodeHandle);
 813         }
 814     }
 815 
 816     public int getAttributeNode(int elementHandle, String namespaceURI, String name)
 817     {
 818         if (_dom != null) {
 819             return _dom.getAttributeNode(elementHandle, namespaceURI, name);
 820         }
 821         else {
 822             return super.getAttributeNode(elementHandle, namespaceURI, name);
 823         }
 824     }
 825 
 826     public int getFirstAttribute(int nodeHandle)
 827     {
 828         if (_dom != null) {
 829             return _dom.getFirstAttribute(nodeHandle);
 830         }
 831         else {
 832             return super.getFirstAttribute(nodeHandle);
 833         }
 834     }
 835 
 836     public int getFirstNamespaceNode(int nodeHandle, boolean inScope)
 837     {
 838         if (_dom != null) {
 839             return _dom.getFirstNamespaceNode(nodeHandle, inScope);
 840         }
 841         else {
 842             return super.getFirstNamespaceNode(nodeHandle, inScope);
 843         }
 844     }
 845 
 846     public int getNextSibling(int nodeHandle)
 847     {
 848         if (_dom != null) {
 849             return _dom.getNextSibling(nodeHandle);
 850         }
 851         else {
 852             return super.getNextSibling(nodeHandle);
 853         }
 854      }
 855 
 856     public int getPreviousSibling(int nodeHandle)
 857     {
 858         if (_dom != null) {
 859             return _dom.getPreviousSibling(nodeHandle);
 860         }
 861         else {
 862             return super.getPreviousSibling(nodeHandle);
 863         }
 864      }
 865 
 866     public int getNextAttribute(int nodeHandle)
 867     {
 868         if (_dom != null) {
 869             return _dom.getNextAttribute(nodeHandle);
 870         }
 871         else {
 872             return super.getNextAttribute(nodeHandle);
 873         }
 874     }
 875 
 876     public int getNextNamespaceNode(int baseHandle, int namespaceHandle,
 877                                   boolean inScope)
 878     {
 879         if (_dom != null) {
 880             return _dom.getNextNamespaceNode(baseHandle, namespaceHandle, inScope);
 881         }
 882         else {
 883             return super.getNextNamespaceNode(baseHandle, namespaceHandle, inScope);
 884         }
 885     }
 886 
 887     public int getOwnerDocument(int nodeHandle)
 888     {
 889         if (_dom != null) {
 890             return _dom.getOwnerDocument(nodeHandle);
 891         }
 892         else {
 893             return super.getOwnerDocument(nodeHandle);
 894         }
 895     }
 896 
 897     public int getDocumentRoot(int nodeHandle)
 898     {
 899         if (_dom != null) {
 900             return _dom.getDocumentRoot(nodeHandle);
 901         }
 902         else {
 903             return super.getDocumentRoot(nodeHandle);
 904         }
 905     }
 906 
 907     public XMLString getStringValue(int nodeHandle)
 908     {
 909         if (_dom != null) {
 910             return _dom.getStringValue(nodeHandle);
 911         }
 912         else {
 913             return super.getStringValue(nodeHandle);
 914         }
 915     }
 916 
 917     public int getStringValueChunkCount(int nodeHandle)
 918     {
 919         if (_dom != null) {
 920             return _dom.getStringValueChunkCount(nodeHandle);
 921         }
 922         else {
 923             return super.getStringValueChunkCount(nodeHandle);
 924         }
 925     }
 926 
 927     public char[] getStringValueChunk(int nodeHandle, int chunkIndex,
 928                                     int[] startAndLen)
 929     {
 930         if (_dom != null) {
 931             return _dom.getStringValueChunk(nodeHandle, chunkIndex, startAndLen);
 932         }
 933         else {
 934             return super.getStringValueChunk(nodeHandle, chunkIndex, startAndLen);
 935         }
 936     }
 937 
 938     public int getExpandedTypeID(String namespace, String localName, int type)
 939     {
 940         if (_dom != null) {
 941             return _dom.getExpandedTypeID(namespace, localName, type);
 942         }
 943         else {
 944             return super.getExpandedTypeID(namespace, localName, type);
 945         }
 946     }
 947 
 948     public String getLocalNameFromExpandedNameID(int ExpandedNameID)
 949     {
 950         if (_dom != null) {
 951             return _dom.getLocalNameFromExpandedNameID(ExpandedNameID);
 952         }
 953         else {
 954             return super.getLocalNameFromExpandedNameID(ExpandedNameID);
 955         }
 956     }
 957 
 958     public String getNamespaceFromExpandedNameID(int ExpandedNameID)
 959     {
 960         if (_dom != null) {
 961             return _dom.getNamespaceFromExpandedNameID(ExpandedNameID);
 962         }
 963         else {
 964             return super.getNamespaceFromExpandedNameID(ExpandedNameID);
 965         }
 966     }
 967 
 968     public String getLocalName(int nodeHandle)
 969     {
 970         if (_dom != null) {
 971             return _dom.getLocalName(nodeHandle);
 972         }
 973         else {
 974             return super.getLocalName(nodeHandle);
 975         }
 976     }
 977 
 978     public String getPrefix(int nodeHandle)
 979     {
 980         if (_dom != null) {
 981             return _dom.getPrefix(nodeHandle);
 982         }
 983         else {
 984             return super.getPrefix(nodeHandle);
 985         }
 986     }
 987 
 988     public String getNamespaceURI(int nodeHandle)
 989     {
 990         if (_dom != null) {
 991             return _dom.getNamespaceURI(nodeHandle);
 992         }
 993         else {
 994             return super.getNamespaceURI(nodeHandle);
 995         }
 996     }
 997 
 998     public String getNodeValue(int nodeHandle)
 999     {
1000         if (_dom != null) {
1001             return _dom.getNodeValue(nodeHandle);
1002         }
1003         else {
1004             return super.getNodeValue(nodeHandle);
1005         }
1006     }
1007 
1008     public short getNodeType(int nodeHandle)
1009     {
1010         if (_dom != null) {
1011             return _dom.getNodeType(nodeHandle);
1012         }
1013         else {
1014             return super.getNodeType(nodeHandle);
1015         }
1016     }
1017 
1018     public short getLevel(int nodeHandle)
1019     {
1020         if (_dom != null) {
1021             return _dom.getLevel(nodeHandle);
1022         }
1023         else {
1024             return super.getLevel(nodeHandle);
1025         }
1026     }
1027 
1028     public boolean isSupported(String feature, String version)
1029     {
1030         if (_dom != null) {
1031             return _dom.isSupported(feature, version);
1032         }
1033         else {
1034             return super.isSupported(feature, version);
1035         }
1036     }
1037 
1038     public String getDocumentBaseURI()
1039     {
1040         if (_dom != null) {
1041             return _dom.getDocumentBaseURI();
1042         }
1043         else {
1044             return super.getDocumentBaseURI();
1045         }
1046     }
1047 
1048     public void setDocumentBaseURI(String baseURI)
1049     {
1050         if (_dom != null) {
1051             _dom.setDocumentBaseURI(baseURI);
1052         }
1053         else {
1054             super.setDocumentBaseURI(baseURI);
1055         }
1056     }
1057 
1058     public String getDocumentSystemIdentifier(int nodeHandle)
1059     {
1060         if (_dom != null) {
1061             return _dom.getDocumentSystemIdentifier(nodeHandle);
1062         }
1063         else {
1064             return super.getDocumentSystemIdentifier(nodeHandle);
1065         }
1066     }
1067 
1068     public String getDocumentEncoding(int nodeHandle)
1069     {
1070         if (_dom != null) {
1071             return _dom.getDocumentEncoding(nodeHandle);
1072         }
1073         else {
1074             return super.getDocumentEncoding(nodeHandle);
1075         }
1076     }
1077 
1078     public String getDocumentStandalone(int nodeHandle)
1079     {
1080         if (_dom != null) {
1081             return _dom.getDocumentStandalone(nodeHandle);
1082         }
1083         else {
1084             return super.getDocumentStandalone(nodeHandle);
1085         }
1086     }
1087 
1088     public String getDocumentVersion(int documentHandle)
1089     {
1090         if (_dom != null) {
1091             return _dom.getDocumentVersion(documentHandle);
1092         }
1093         else {
1094             return super.getDocumentVersion(documentHandle);
1095         }
1096     }
1097 
1098     public boolean getDocumentAllDeclarationsProcessed()
1099     {
1100         if (_dom != null) {
1101             return _dom.getDocumentAllDeclarationsProcessed();
1102         }
1103         else {
1104             return super.getDocumentAllDeclarationsProcessed();
1105         }
1106     }
1107 
1108     public String getDocumentTypeDeclarationSystemIdentifier()
1109     {
1110         if (_dom != null) {
1111             return _dom.getDocumentTypeDeclarationSystemIdentifier();
1112         }
1113         else {
1114             return super.getDocumentTypeDeclarationSystemIdentifier();
1115         }
1116     }
1117 
1118     public String getDocumentTypeDeclarationPublicIdentifier()
1119     {
1120         if (_dom != null) {
1121             return _dom.getDocumentTypeDeclarationPublicIdentifier();
1122         }
1123         else {
1124             return super.getDocumentTypeDeclarationPublicIdentifier();
1125         }
1126     }
1127 
1128     public int getElementById(String elementId)
1129     {
1130         if (_dom != null) {
1131             return _dom.getElementById(elementId);
1132         }
1133         else {
1134             return super.getElementById(elementId);
1135         }
1136     }
1137 
1138     public boolean supportsPreStripping()
1139     {
1140         if (_dom != null) {
1141             return _dom.supportsPreStripping();
1142         }
1143         else {
1144             return super.supportsPreStripping();
1145         }
1146     }
1147 
1148     public boolean isNodeAfter(int firstNodeHandle, int secondNodeHandle)
1149     {
1150         if (_dom != null) {
1151             return _dom.isNodeAfter(firstNodeHandle, secondNodeHandle);
1152         }
1153         else {
1154             return super.isNodeAfter(firstNodeHandle, secondNodeHandle);
1155         }
1156     }
1157 
1158     public boolean isCharacterElementContentWhitespace(int nodeHandle)
1159     {
1160         if (_dom != null) {
1161             return _dom.isCharacterElementContentWhitespace(nodeHandle);
1162         }
1163         else {
1164             return super.isCharacterElementContentWhitespace(nodeHandle);
1165         }
1166     }
1167 
1168     public boolean isDocumentAllDeclarationsProcessed(int documentHandle)
1169     {
1170         if (_dom != null) {
1171             return _dom.isDocumentAllDeclarationsProcessed(documentHandle);
1172         }
1173         else {
1174             return super.isDocumentAllDeclarationsProcessed(documentHandle);
1175         }
1176     }
1177 
1178     public boolean isAttributeSpecified(int attributeHandle)
1179     {
1180         if (_dom != null) {
1181             return _dom.isAttributeSpecified(attributeHandle);
1182         }
1183         else {
1184             return super.isAttributeSpecified(attributeHandle);
1185         }
1186     }
1187 
1188     public void dispatchCharactersEvents(int nodeHandle, org.xml.sax.ContentHandler ch,
1189                                          boolean normalize)
1190           throws org.xml.sax.SAXException
1191     {
1192         if (_dom != null) {
1193             _dom.dispatchCharactersEvents(nodeHandle,  ch, normalize);
1194         }
1195         else {
1196             super.dispatchCharactersEvents(nodeHandle, ch, normalize);
1197         }
1198     }
1199 
1200     public void dispatchToEvents(int nodeHandle, org.xml.sax.ContentHandler ch)
1201       throws org.xml.sax.SAXException
1202     {
1203         if (_dom != null) {
1204             _dom.dispatchToEvents(nodeHandle,  ch);
1205         }
1206         else {
1207             super.dispatchToEvents(nodeHandle, ch);
1208         }
1209     }
1210 
1211     public org.w3c.dom.Node getNode(int nodeHandle)
1212     {
1213         if (_dom != null) {
1214             return _dom.getNode(nodeHandle);
1215         }
1216         else {
1217             return super.getNode(nodeHandle);
1218         }
1219     }
1220 
1221     public boolean needsTwoThreads()
1222     {
1223         if (_dom != null) {
1224             return _dom.needsTwoThreads();
1225         }
1226         else {
1227             return super.needsTwoThreads();
1228         }
1229     }
1230 
1231     public org.xml.sax.ContentHandler getContentHandler()
1232     {
1233         if (_dom != null) {
1234             return _dom.getContentHandler();
1235         }
1236         else {
1237             return super.getContentHandler();
1238         }
1239     }
1240 
1241     public org.xml.sax.ext.LexicalHandler getLexicalHandler()
1242     {
1243         if (_dom != null) {
1244             return _dom.getLexicalHandler();
1245         }
1246         else {
1247             return super.getLexicalHandler();
1248         }
1249     }
1250 
1251     public org.xml.sax.EntityResolver getEntityResolver()
1252     {
1253         if (_dom != null) {
1254             return _dom.getEntityResolver();
1255         }
1256         else {
1257             return super.getEntityResolver();
1258         }
1259     }
1260 
1261     public org.xml.sax.DTDHandler getDTDHandler()
1262     {
1263         if (_dom != null) {
1264             return _dom.getDTDHandler();
1265         }
1266         else {
1267             return super.getDTDHandler();
1268         }
1269     }
1270 
1271     public org.xml.sax.ErrorHandler getErrorHandler()
1272     {
1273         if (_dom != null) {
1274             return _dom.getErrorHandler();
1275         }
1276         else {
1277             return super.getErrorHandler();
1278         }
1279     }
1280 
1281     public org.xml.sax.ext.DeclHandler getDeclHandler()
1282     {
1283         if (_dom != null) {
1284             return _dom.getDeclHandler();
1285         }
1286         else {
1287             return super.getDeclHandler();
1288         }
1289     }
1290 
1291     public void appendChild(int newChild, boolean clone, boolean cloneDepth)
1292     {
1293         if (_dom != null) {
1294             _dom.appendChild(newChild, clone, cloneDepth);
1295         }
1296         else {
1297             super.appendChild(newChild, clone, cloneDepth);
1298         }
1299     }
1300 
1301     public void appendTextChild(String str)
1302     {
1303         if (_dom != null) {
1304             _dom.appendTextChild(str);
1305         }
1306         else {
1307             super.appendTextChild(str);
1308         }
1309     }
1310 
1311     public SourceLocator getSourceLocatorFor(int node)
1312     {
1313         if (_dom != null) {
1314             return _dom.getSourceLocatorFor(node);
1315         }
1316         else {
1317             return super.getSourceLocatorFor(node);
1318         }
1319     }
1320 
1321     public void documentRegistration()
1322     {
1323         if (_dom != null) {
1324             _dom.documentRegistration();
1325         }
1326         else {
1327             super.documentRegistration();
1328         }
1329     }
1330 
1331     public void documentRelease()
1332     {
1333         if (_dom != null) {
1334             _dom.documentRelease();
1335         }
1336         else {
1337             super.documentRelease();
1338         }
1339     }
1340 
1341 }