jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/MultiDOM.java
author aefimov
Fri, 08 May 2015 11:07:35 +0300
changeset 30521 42e1babcddcc
parent 25868 686eef1e7a79
child 32328 a09e22b759a7
permissions -rw-r--r--
8062518: AIOBE occurs when accessing to document function in extended function in JAXP Reviewed-by: joehw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 2001-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: MultiDOM.java,v 1.5 2005/09/28 13:48:36 pvedula Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
package com.sun.org.apache.xalan.internal.xsltc.dom;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xalan.internal.xsltc.DOM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xalan.internal.xsltc.StripFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xalan.internal.xsltc.TransletException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.dtm.DTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xml.internal.dtm.Axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.dtm.DTMManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xml.internal.utils.SuballocatedIntVector;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import org.w3c.dom.NodeList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * @author Erwin Bolwidt <ejb@klomp.org>
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
public final class MultiDOM implements DOM {
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
    private static final int NO_TYPE = DOM.FIRST_TYPE - 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
    private static final int INITIAL_SIZE = 4;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
    private DOM[] _adapters;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
    private DOMAdapter _main;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    private DTMManager _dtmManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    private int _free;
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
    private int _size;
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
    private Hashtable _documents = new Hashtable();
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    private final class AxisIterator extends DTMAxisIteratorBase {
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
        // constitutive data
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
        private final int _axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
        private final int _type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
        // implementation mechanism
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
        private DTMAxisIterator _source;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
        private int _dtmId = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
        public AxisIterator(final int axis, final int type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
            _axis = axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
            _type = type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
        public int next() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
            if (_source == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
                return(END);
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
            return _source.next();
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
        public void setRestartable(boolean flag) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
            if (_source != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
                _source.setRestartable(flag);
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        public DTMAxisIterator setStartNode(final int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
            if (node == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
                return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
            int dom = node >>> DTMManager.IDENT_DTM_NODE_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
            // Get a new source first time and when mask changes
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
            if (_source == null || _dtmId != dom) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
                if (_type == NO_TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
                    _source = _adapters[dom].getAxisIterator(_axis);
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
                } else if (_axis == Axis.CHILD) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
                    _source = _adapters[dom].getTypedChildren(_type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
                } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
                    _source = _adapters[dom].getTypedAxisIterator(_axis, _type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
            _dtmId = dom;
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
            _source.setStartNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
            return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        public DTMAxisIterator reset() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
            if (_source != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
                _source.reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
            return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        public int getLast() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
            if (_source != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
                return _source.getLast();
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
                return END;
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
        public int getPosition() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
            if (_source != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
                return _source.getPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
                return END;
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
        public boolean isReverse() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
            return Axis.isReverse(_axis);
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
        public void setMark() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
            if (_source != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
                _source.setMark();
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
        public void gotoMark() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
            if (_source != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
                _source.gotoMark();
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
        public DTMAxisIterator cloneIterator() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
            final AxisIterator clone = new AxisIterator(_axis, _type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
            if (_source != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
                clone._source = _source.cloneIterator();
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
            clone._dtmId = _dtmId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
            return clone;
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    } // end of AxisIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    /**************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     * This is a specialised iterator for predicates comparing node or
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
     * attribute values to variable or parameter values.
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
    private final class NodeValueIterator extends DTMAxisIteratorBase {
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
        private DTMAxisIterator _source;
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
        private String _value;
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
        private boolean _op;
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
        private final boolean _isReverse;
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
        private int _returnType = RETURN_PARENT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
        public NodeValueIterator(DTMAxisIterator source, int returnType,
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
                                 String value, boolean op) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
            _source = source;
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
            _returnType = returnType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
            _value = value;
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
            _op = op;
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
            _isReverse = source.isReverse();
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
        public boolean isReverse() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
            return _isReverse;
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
        public DTMAxisIterator cloneIterator() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
                NodeValueIterator clone = (NodeValueIterator)super.clone();
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
                clone._source = _source.cloneIterator();
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
                clone.setRestartable(false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
                return clone.reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
            catch (CloneNotSupportedException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
                BasisLibrary.runTimeError(BasisLibrary.ITERATOR_CLONE_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
                                          e.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
                return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
        public void setRestartable(boolean isRestartable) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
            _isRestartable = isRestartable;
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
            _source.setRestartable(isRestartable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
        public DTMAxisIterator reset() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
            _source.reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
            return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
        public int next() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
            int node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
            while ((node = _source.next()) != END) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
                String val = getStringValueX(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
                if (_value.equals(val) == _op) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
                    if (_returnType == RETURN_CURRENT)
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
                        return returnNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
                        return returnNode(getParent(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
            return END;
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
        public DTMAxisIterator setStartNode(int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
            if (_isRestartable) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
                _source.setStartNode(_startNode = node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
                return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
            return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
        public void setMark() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
            _source.setMark();
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
        public void gotoMark() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
            _source.gotoMark();
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
    public MultiDOM(DOM main) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
        _size = INITIAL_SIZE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
        _free = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
        _adapters = new DOM[INITIAL_SIZE];
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
        DOMAdapter adapter = (DOMAdapter)main;
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
        _adapters[0] = adapter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
        _main = adapter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        DOM dom = adapter.getDOMImpl();
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        if (dom instanceof DTMDefaultBase) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
            _dtmManager = ((DTMDefaultBase)dom).getManager();
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
        // %HZ% %REVISIT% Is this the right thing to do here?  In the old
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
        // %HZ% %REVISIT% version, the main document did not get added through
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
        // %HZ% %REVISIT% a call to addDOMAdapter, which meant it couldn't be
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
        // %HZ% %REVISIT% found by a call to getDocumentMask.  The problem is
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
        // %HZ% %REVISIT% TransformerHandler is typically constructed with a
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
        // %HZ% %REVISIT% system ID equal to the stylesheet's URI; with SAX
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
        // %HZ% %REVISIT% input, it ends up giving that URI to the document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
        // %HZ% %REVISIT% Then, any references to document('') are resolved
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
        // %HZ% %REVISIT% using the stylesheet's URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
        // %HZ% %REVISIT% MultiDOM.getDocumentMask is called to verify that
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
        // %HZ% %REVISIT% a document associated with that URI has not been
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        // %HZ% %REVISIT% encountered, and that method ends up returning the
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
        // %HZ% %REVISIT% mask of the main document, when what we really what
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
        // %HZ% %REVISIT% is to read the stylesheet itself!
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        addDOMAdapter(adapter, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    public int nextMask() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
        return _free;
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
    public void setupMapping(String[] names, String[] uris, int[] types, String[] namespaces) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        // This method only has a function in DOM adapters
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
    public int addDOMAdapter(DOMAdapter adapter) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
        return addDOMAdapter(adapter, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
    private int addDOMAdapter(DOMAdapter adapter, boolean indexByURI) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
        // Add the DOM adapter to the array of DOMs
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
        DOM dom = adapter.getDOMImpl();
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
        int domNo = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
        int dtmSize = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
        SuballocatedIntVector dtmIds = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
        if (dom instanceof DTMDefaultBase) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
            DTMDefaultBase dtmdb = (DTMDefaultBase)dom;
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
            dtmIds = dtmdb.getDTMIDs();
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
            dtmSize = dtmIds.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
            domNo = dtmIds.elementAt(dtmSize-1) >>> DTMManager.IDENT_DTM_NODE_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        else if (dom instanceof SimpleResultTreeImpl) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
            SimpleResultTreeImpl simpleRTF = (SimpleResultTreeImpl)dom;
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
            domNo = simpleRTF.getDocument() >>> DTMManager.IDENT_DTM_NODE_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
        if (domNo >= _size) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
            int oldSize = _size;
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
            do {
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
                _size *= 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
            } while (_size <= domNo);
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
            final DOMAdapter[] newArray = new DOMAdapter[_size];
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
            System.arraycopy(_adapters, 0, newArray, 0, oldSize);
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
            _adapters = newArray;
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
        _free = domNo + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
        if (dtmSize == 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
            _adapters[domNo] = adapter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
        else if (dtmIds != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
            int domPos = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
            for (int i = dtmSize - 1; i >= 0; i--) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
                domPos = dtmIds.elementAt(i) >>> DTMManager.IDENT_DTM_NODE_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
                _adapters[domPos] = adapter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
            domNo = domPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
        // Store reference to document (URI) in hashtable
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
        if (indexByURI) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
            String uri = adapter.getDocumentURI(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
            _documents.put(uri, new Integer(domNo));
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
        // If the dom is an AdaptiveResultTreeImpl, we need to create a
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
        // DOMAdapter around its nested dom object (if it is non-null) and
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
        // add the DOMAdapter to the list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
        if (dom instanceof AdaptiveResultTreeImpl) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
            AdaptiveResultTreeImpl adaptiveRTF = (AdaptiveResultTreeImpl)dom;
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
            DOM nestedDom = adaptiveRTF.getNestedDOM();
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
            if (nestedDom != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
                DOMAdapter newAdapter = new DOMAdapter(nestedDom,
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
                                                       adapter.getNamesArray(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
                                                       adapter.getUrisArray(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
                                                       adapter.getTypesArray(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
                                                       adapter.getNamespaceArray());
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
                addDOMAdapter(newAdapter);
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
        return domNo;
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
    public int getDocumentMask(String uri) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
        Integer domIdx = (Integer)_documents.get(uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
        if (domIdx == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
            return(-1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
            return domIdx.intValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
    public DOM getDOMAdapter(String uri) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
        Integer domIdx = (Integer)_documents.get(uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
        if (domIdx == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
            return(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
            return(_adapters[domIdx.intValue()]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
    public int getDocument()
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        return _main.getDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
    public DTMManager getDTMManager() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
        return _dtmManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
      * Returns singleton iterator containing the document root
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
      */
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
    public DTMAxisIterator getIterator() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
        // main source document @ 0
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
        return _main.getIterator();
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
    public String getStringValue() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
        return _main.getStringValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
    public DTMAxisIterator getChildren(final int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
        return _adapters[getDTMId(node)].getChildren(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
    public DTMAxisIterator getTypedChildren(final int type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
        return new AxisIterator(Axis.CHILD, type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
    public DTMAxisIterator getAxisIterator(final int axis) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
        return new AxisIterator(axis, NO_TYPE);
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
    public DTMAxisIterator getTypedAxisIterator(final int axis, final int type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
        return new AxisIterator(axis, type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
    public DTMAxisIterator getNthDescendant(int node, int n,
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
                                            boolean includeself)
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
        return _adapters[getDTMId(node)].getNthDescendant(node, n, includeself);
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
    public DTMAxisIterator getNodeValueIterator(DTMAxisIterator iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
                                                int type, String value,
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
                                                boolean op)
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
        return(new NodeValueIterator(iterator, type, value, op));
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
    public DTMAxisIterator getNamespaceAxisIterator(final int axis,
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
                                                    final int ns)
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
        DTMAxisIterator iterator = _main.getNamespaceAxisIterator(axis, ns);
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
        return(iterator);
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
    public DTMAxisIterator orderNodes(DTMAxisIterator source, int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
        return _adapters[getDTMId(node)].orderNodes(source, node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
    public int getExpandedTypeID(final int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
        if (node != DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
            return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getExpandedTypeID(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
            return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
    public int getNamespaceType(final int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
        return _adapters[getDTMId(node)].getNamespaceType(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
    public int getNSType(int node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
   {
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
        return _adapters[getDTMId(node)].getNSType(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
   }
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
    public int getParent(final int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
        if (node == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
            return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getParent(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
    public int getAttributeNode(final int type, final int el) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
        if (el == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
            return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
        return _adapters[el >>> DTMManager.IDENT_DTM_NODE_BITS].getAttributeNode(type, el);
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
    public String getNodeName(final int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
        if (node == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
            return "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getNodeName(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
    public String getNodeNameX(final int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
        if (node == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
            return "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getNodeNameX(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
    public String getNamespaceName(final int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
        if (node == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
            return "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getNamespaceName(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
    public String getStringValueX(final int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
        if (node == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
            return "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getStringValueX(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
    public void copy(final int node, SerializationHandler handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
        throws TransletException
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
        if (node != DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
            _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].copy(node, handler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
    public void copy(DTMAxisIterator nodes, SerializationHandler handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
            throws TransletException
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
        int node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
        while ((node = nodes.next()) != DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
            _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].copy(node, handler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
    public String shallowCopy(final int node, SerializationHandler handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
            throws TransletException
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
        if (node == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
            return "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].shallowCopy(node, handler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
    public boolean lessThan(final int node1, final int node2) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
        if (node1 == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
            return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
        if (node2 == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
        final int dom1 = getDTMId(node1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
        final int dom2 = getDTMId(node2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
        return dom1 == dom2 ? _adapters[dom1].lessThan(node1, node2)
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
                            : dom1 < dom2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
    public void characters(final int textNode, SerializationHandler handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
                 throws TransletException
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
        if (textNode != DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
            _adapters[textNode >>> DTMManager.IDENT_DTM_NODE_BITS].characters(textNode, handler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
    public void setFilter(StripFilter filter) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
        for (int dom=0; dom<_free; dom++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
            if (_adapters[dom] != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
                _adapters[dom].setFilter(filter);
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
    public Node makeNode(int index) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
        if (index == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
            return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
        return _adapters[getDTMId(index)].makeNode(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
    public Node makeNode(DTMAxisIterator iter) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
        // TODO: gather nodes from all DOMs ?
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
        return _main.makeNode(iter);
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
    public NodeList makeNodeList(int index) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
        if (index == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
            return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
        return _adapters[getDTMId(index)].makeNodeList(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
    public NodeList makeNodeList(DTMAxisIterator iter) {
30521
42e1babcddcc 8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents: 25868
diff changeset
   570
        int index = iter.next();
42e1babcddcc 8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents: 25868
diff changeset
   571
        if (index == DTM.NULL) {
42e1babcddcc 8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents: 25868
diff changeset
   572
            return null;
42e1babcddcc 8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents: 25868
diff changeset
   573
        }
42e1babcddcc 8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents: 25868
diff changeset
   574
        iter.reset();
42e1babcddcc 8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents: 25868
diff changeset
   575
        return _adapters[getDTMId(index)].makeNodeList(iter);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
    public String getLanguage(int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
        return _adapters[getDTMId(node)].getLanguage(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
    public int getSize() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
        int size = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
        for (int i=0; i<_size; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
            size += _adapters[i].getSize();
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
        return(size);
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
    public String getDocumentURI(int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
        if (node == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
            node = DOM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getDocumentURI(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
    public boolean isElement(final int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
        if (node == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
        return(_adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].isElement(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
    public boolean isAttribute(final int node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
        if (node == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
        return(_adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].isAttribute(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
    public int getDTMId(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
        if (nodeHandle == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
            return 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
        int id = nodeHandle >>> DTMManager.IDENT_DTM_NODE_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
        while (id >= 2 && _adapters[id] == _adapters[id-1]) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
            id--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
        return id;
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
    public DOM getDTM(int nodeHandle) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
        return _adapters[getDTMId(nodeHandle)];
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
    public int getNodeIdent(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
        return _adapters[nodeHandle >>> DTMManager.IDENT_DTM_NODE_BITS].getNodeIdent(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
    public int getNodeHandle(int nodeId)
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
        return _main.getNodeHandle(nodeId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
    public DOM getResultTreeFrag(int initSize, int rtfType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
        return _main.getResultTreeFrag(initSize, rtfType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
    public DOM getResultTreeFrag(int initSize, int rtfType, boolean addToManager)
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
        return _main.getResultTreeFrag(initSize, rtfType, addToManager);
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
    public DOM getMain()
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
        return _main;
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
     * Returns a DOMBuilder class wrapped in a SAX adapter.
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
    public SerializationHandler getOutputDomBuilder()
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
        return _main.getOutputDomBuilder();
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
    public String lookupNamespace(int node, String prefix)
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
        throws TransletException
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
        return _main.lookupNamespace(node, prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
    // %HZ% Does this method make any sense here???
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
    public String getUnparsedEntityURI(String entity) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
        return _main.getUnparsedEntityURI(entity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
    // %HZ% Does this method make any sense here???
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
    public Hashtable getElementsWithIDs() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
        return _main.getElementsWithIDs();
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
}