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