src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/sax2dtm/SAX2DTM2.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
     8
 * this work for additional information regarding copyright ownership.
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    21
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xml.internal.dtm.ref.sax2dtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    24
import com.sun.org.apache.xml.internal.dtm.DTM;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    25
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    26
import com.sun.org.apache.xml.internal.dtm.DTMException;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    27
import com.sun.org.apache.xml.internal.dtm.DTMManager;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    28
import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    29
import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    30
import com.sun.org.apache.xml.internal.dtm.ref.ExpandedNameTable;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    31
import com.sun.org.apache.xml.internal.dtm.ref.ExtendedType;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    32
import com.sun.org.apache.xml.internal.res.XMLErrorResources;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    33
import com.sun.org.apache.xml.internal.res.XMLMessages;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    34
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.utils.FastStringBuffer;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    36
import com.sun.org.apache.xml.internal.utils.SuballocatedIntVector;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xml.internal.utils.XMLString;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xml.internal.utils.XMLStringDefault;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xml.internal.utils.XMLStringFactory;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    40
import java.util.ArrayList;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    41
import java.util.List;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import javax.xml.transform.Source;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    43
import org.xml.sax.Attributes;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    44
import org.xml.sax.ContentHandler;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    45
import org.xml.sax.SAXException;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * SAX2DTM2 is an optimized version of SAX2DTM which is used in non-incremental situation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * It is used as the super class of the XSLTC SAXImpl. Many of the interfaces in SAX2DTM
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * and DTMDefaultBase are overridden in SAX2DTM2 in order to allow fast, efficient
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * access to the DTM model. Some nested iterators in DTMDefaultBaseIterators
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * are also overridden in SAX2DTM2 for performance reasons.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * Performance is the biggest consideration in the design of SAX2DTM2. To make the code most
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * efficient, the incremental support is dropped in SAX2DTM2, which means that you should not
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * use it in incremental situation. To reduce the overhead of pulling data from the DTM model,
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * a few core interfaces in SAX2DTM2 have direct access to the internal arrays of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * SuballocatedIntVectors.
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * The design of SAX2DTM2 may limit its extensibilty. If you have a reason to extend the
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 * SAX2DTM model, please extend from SAX2DTM instead of this class.
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
 * %MK% The code in this class is critical to the XSLTC_DTM performance. Be very careful
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
 * when making changes here!
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
public class SAX2DTM2 extends SAX2DTM
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  /****************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
   *       Optimized version of the nested iterators
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
   ****************************************************************/
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
   * Iterator that returns all immediate children of a given node
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
  public final class ChildrenIterator extends InternalAxisIteratorBase
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
     * Setting start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
     * If the iterator is not restartable, this has no effect.
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
     * %REVIEW% Should it return/throw something in that case,
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
     * or set current node to END, to indicate request-not-honored?
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    public DTMAxisIterator setStartNode(int node)
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
    {
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    93
      //%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
      if (node == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
        node = getDocument();
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
    96
      if (_isRestartable) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
        _startNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
        _currentNode = (node == DTM.NULL) ? DTM.NULL
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
                                          : _firstch2(makeNodeIdentity(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
     * @return The next node handle in the iteration, or END if no more
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
     * are available.
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   113
    public int next() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
      if (_currentNode != NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
        int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
        _currentNode = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
        return returnNode(makeNodeHandle(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
      return END;
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
  }  // end of ChildrenIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
   * Iterator that returns the parent of a given node. Note that
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
   * this delivers only a single node; if you want all the ancestors,
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
   * see AncestorIterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
  public final class ParentIterator extends InternalAxisIteratorBase
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    /** The extended type ID that was requested. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    private int _nodeType = DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
     * Set start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   143
    public DTMAxisIterator setStartNode(int node) {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   144
      //%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
      if (node == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
        node = getDocument();
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   147
      if (_isRestartable) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
        _startNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
        if (node != DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
          _currentNode = _parent2(makeNodeIdentity(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
          _currentNode = DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
     * Set the node type of the parent that we're looking for.
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
     * Note that this does _not_ mean "find the nearest ancestor of
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     * this type", but "yield the parent if it is of this type".
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     * @param type extended type ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
     * @return ParentIterator configured with the type filter set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    public DTMAxisIterator setNodeType(final int type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
      _nodeType = type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
     * Get the next node in the iteration. In this case, we return
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
     * only the immediate parent, _if_ it matches the requested nodeType.
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
    public int next()
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
      int result = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
      if (result == END)
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
      // %OPT% The most common case is handled first.
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
      if (_nodeType == NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
        _currentNode = END;
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
        return returnNode(makeNodeHandle(result));
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
      else if (_nodeType >= DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
        if (_nodeType == _exptype2(result)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
          _currentNode = END;
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
          return returnNode(makeNodeHandle(result));
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
      else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
        if (_nodeType == _type2(result)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
          _currentNode = END;
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
          return returnNode(makeNodeHandle(result));
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
      return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
  }  // end of ParentIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
   * Iterator that returns children of a given type for a given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
   * The functionality chould be achieved by putting a filter on top
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
   * of a basic child iterator, but a specialised iterator is used
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
   * for efficiency (both speed and size of translet).
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
  public final class TypedChildrenIterator extends InternalAxisIteratorBase
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    /** The extended type ID that was requested. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
    private final int _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
     * Constructor TypedChildrenIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
     * @param nodeType The extended type ID being requested.
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   231
    public TypedChildrenIterator(int nodeType) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
      _nodeType = nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
     * Set start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   243
    public DTMAxisIterator setStartNode(int node) {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   244
      //%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
      if (node == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
        node = getDocument();
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   247
      if (_isRestartable) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
        _startNode = node;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   249
        _currentNode = (node == DTM.NULL) ? DTM.NULL :
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   250
                         _firstch2(makeNodeIdentity(_startNode));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   263
    public int next() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
      int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
      if (node == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
        return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
      final int nodeType = _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
      if (nodeType != DTM.ELEMENT_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        while (node != DTM.NULL && _exptype2(node) != nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
          node = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
      // %OPT% If the nodeType is element (matching child::*), we only
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
      // need to compare the expType with DTM.NTYPES. A child node of
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
      // an element can be either an element, text, comment or
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
      // processing instruction node. Only element node has an extended
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
      // type greater than or equal to DTM.NTYPES.
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
      else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
        int eType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
        while (node != DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
          eType = _exptype2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
          if (eType >= DTM.NTYPES)
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
            node = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
      if (node == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
        _currentNode = DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
        return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
      } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
        _currentNode = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
        return returnNode(makeNodeHandle(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
     * Return the node at the given position.
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   303
    public int getNodeByPosition(int position) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
      if (position <= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
      int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
      int pos = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
      final int nodeType = _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
      if (nodeType != DTM.ELEMENT_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
        while (node != DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
          if (_exptype2(node) == nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
            pos++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
            if (pos == position)
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
              return makeNodeHandle(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
          node = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
        return NULL;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   322
      } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
        while (node != DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
          if (_exptype2(node) >= DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
            pos++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
            if (pos == position)
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
              return makeNodeHandle(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
          node = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
  }  // end of TypedChildrenIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
   * Iterator that returns the namespace nodes as defined by the XPath data model
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
   * for a given node, filtered by extended type ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
  public class TypedRootIterator extends RootIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
    /** The extended type ID that was requested. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
    private final int _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
     * Constructor TypedRootIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
     * @param nodeType The extended type ID being requested.
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
    public TypedRootIterator(int nodeType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
      super();
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
      _nodeType = nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
    public int next()
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
      if(_startNode == _currentNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
      final int node = _startNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
      int expType = _exptype2(makeNodeIdentity(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
      _currentNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
      if (_nodeType >= DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        if (_nodeType == expType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
          return returnNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
      else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
        if (expType < DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
          if (expType == _nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
            return returnNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
          if (m_extendedTypes[expType].getNodeType() == _nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
            return returnNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
      return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
  }  // end of TypedRootIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
   * Iterator that returns all siblings of a given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
  public class FollowingSiblingIterator extends InternalAxisIteratorBase
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
     * Set start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   409
    public DTMAxisIterator setStartNode(int node) {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   410
      //%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
      if (node == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
        node = getDocument();
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   413
      if (_isRestartable) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
        _startNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
        _currentNode = makeNodeIdentity(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   428
    public int next() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
      _currentNode = (_currentNode == DTM.NULL) ? DTM.NULL
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
                                                : _nextsib2(_currentNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
      return returnNode(makeNodeHandle(_currentNode));
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
  }  // end of FollowingSiblingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
   * Iterator that returns all following siblings of a given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
  public final class TypedFollowingSiblingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
          extends FollowingSiblingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
    /** The extended type ID that was requested. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
    private final int _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
     * Constructor TypedFollowingSiblingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
     * @param type The extended type ID being requested.
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   451
    public TypedFollowingSiblingIterator(int type) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
      _nodeType = type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   460
    public int next() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
      if (_currentNode == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
        return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
      int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
      final int nodeType = _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
      if (nodeType != DTM.ELEMENT_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
        while ((node = _nextsib2(node)) != DTM.NULL && _exptype2(node) != nodeType) {}
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   470
      } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
        while ((node = _nextsib2(node)) != DTM.NULL && _exptype2(node) < DTM.NTYPES) {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
      _currentNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
      return (node == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
                      ? DTM.NULL
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
                      : returnNode(makeNodeHandle(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
  }  // end of TypedFollowingSiblingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
   * Iterator that returns attribute nodes (of what nodes?)
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   486
  public final class AttributeIterator extends InternalAxisIteratorBase {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
    // assumes caller will pass element nodes
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
     * Set start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   498
    public DTMAxisIterator setStartNode(int node) {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   499
      //%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
      if (node == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
        node = getDocument();
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   502
      if (_isRestartable) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
        _startNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
        _currentNode = getFirstAttributeIdentity(makeNodeIdentity(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   517
    public int next() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
      final int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
      if (node != NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
        _currentNode = getNextAttributeIdentity(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
        return returnNode(makeNodeHandle(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
      return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
  }  // end of AttributeIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
   * Iterator that returns attribute nodes of a given type
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
  public final class TypedAttributeIterator extends InternalAxisIteratorBase
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
    /** The extended type ID that was requested. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
    private final int _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
     * Constructor TypedAttributeIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
     * @param nodeType The extended type ID that is requested.
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   544
    public TypedAttributeIterator(int nodeType) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
      _nodeType = nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
    // assumes caller will pass element nodes
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
     * Set start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   558
    public DTMAxisIterator setStartNode(int node) {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   559
      if (_isRestartable) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
        _startNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
        _currentNode = getTypedAttribute(node, _nodeType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   573
    public int next() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
      final int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
      // singleton iterator, since there can only be one attribute of
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
      // a given type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
      _currentNode = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
      return returnNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
  }  // end of TypedAttributeIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
   * Iterator that returns preceding siblings of a given node
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
  public class PrecedingSiblingIterator extends InternalAxisIteratorBase
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
     * The node identity of _startNode for this iterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
    protected int _startNodeID;
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
     * True if this iterator has a reversed axis.
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
     * @return true.
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   600
    public boolean isReverse() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
      return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
     * Set start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   612
    public DTMAxisIterator setStartNode(int node) {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   613
      //%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
      if (node == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
        node = getDocument();
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   616
      if (_isRestartable) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
        _startNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
        node = _startNodeID = makeNodeIdentity(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   620
        if(node == NULL) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
          _currentNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
          return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
        int type = _type2(node);
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   626
        if (ExpandedNameTable.ATTRIBUTE == type ||
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   627
            ExpandedNameTable.NAMESPACE == type)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
          _currentNode = node;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   630
        } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
          // Be careful to handle the Document node properly
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
          _currentNode = _parent2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
          if(NULL!=_currentNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
            _currentNode = _firstch2(_currentNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
            _currentNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   650
    public int next() {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   651
      if (_currentNode == _startNodeID || _currentNode == DTM.NULL) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
        return NULL;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   653
      } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
        final int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
        _currentNode = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
        return returnNode(makeNodeHandle(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
  }  // end of PrecedingSiblingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
   * Iterator that returns preceding siblings of a given type for
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
   * a given node
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
  public final class TypedPrecedingSiblingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
          extends PrecedingSiblingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
    /** The extended type ID that was requested. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
    private final int _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
     * Constructor TypedPrecedingSiblingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
     * @param type The extended type ID being requested.
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   678
    public TypedPrecedingSiblingIterator(int type) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
      _nodeType = type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   687
    public int next() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
      int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
      final int nodeType = _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
      final int startNodeID = _startNodeID;
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
      if (nodeType != DTM.ELEMENT_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
        while (node != NULL && node != startNodeID && _exptype2(node) != nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
          node = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
        }
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   697
      } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
        while (node != NULL && node != startNodeID && _exptype2(node) < DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
          node = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
      if (node == DTM.NULL || node == startNodeID) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
        _currentNode = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
        return NULL;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   706
      } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
        _currentNode = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
        return returnNode(makeNodeHandle(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
     * Return the index of the last node in this iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
     */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   715
    public int getLast() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
      if (_last != -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
        return _last;
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
      setMark();
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
      int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
      final int nodeType = _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
      final int startNodeID = _startNodeID;
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
      int last = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
      if (nodeType != DTM.ELEMENT_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
        while (node != NULL && node != startNodeID) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
          if (_exptype2(node) == nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
            last++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
          node = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
        }
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   733
      } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
        while (node != NULL && node != startNodeID) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
          if (_exptype2(node) >= DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
            last++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
          node = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
      gotoMark();
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
      return (_last = last);
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
  }  // end of TypedPrecedingSiblingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
   * Iterator that returns preceding nodes of a given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
   * This includes the node set {root+1, start-1}, but excludes
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
   * all ancestors, attributes, and namespace nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
  public class PrecedingIterator extends InternalAxisIteratorBase
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
    /** The max ancestors, but it can grow... */
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
    private final int _maxAncestors = 8;
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
     * The stack of start node + ancestors up to the root of the tree,
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
     *  which we must avoid.
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
    protected int[] _stack = new int[_maxAncestors];
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
    /** (not sure yet... -sb) */
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
    protected int _sp, _oldsp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
    protected int _markedsp, _markedNode, _markedDescendant;
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
    /* _currentNode precedes candidates.  This is the identity, not the handle! */
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
     * True if this iterator has a reversed axis.
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
     * @return true since this iterator is a reversed axis.
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
    public boolean isReverse()
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
      return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
     * Returns a deep copy of this iterator.   The cloned iterator is not reset.
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
     * @return a deep copy of this iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
    public DTMAxisIterator cloneIterator()
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
      _isRestartable = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
      try
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
        final PrecedingIterator clone = (PrecedingIterator) super.clone();
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
        final int[] stackCopy = new int[_stack.length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
        System.arraycopy(_stack, 0, stackCopy, 0, _stack.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
        clone._stack = stackCopy;
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
        // return clone.reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
        return clone;
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
      catch (CloneNotSupportedException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
        throw new DTMException(XMLMessages.createXMLMessage(XMLErrorResources.ER_ITERATOR_CLONE_NOT_SUPPORTED, null)); //"Iterator clone not supported.");
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
     * Set start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
    public DTMAxisIterator setStartNode(int node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
    {
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
   818
      //%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
      if (node == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
        node = getDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
      if (_isRestartable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
        node = makeNodeIdentity(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
        // iterator is not a clone
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
        int parent, index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
       if (_type2(node) == DTM.ATTRIBUTE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
         node = _parent2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
        _startNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
        _stack[index = 0] = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
        parent=node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
        while ((parent = _parent2(parent)) != NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
          if (++index == _stack.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
            final int[] stack = new int[index*2];
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
            System.arraycopy(_stack, 0, stack, 0, index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
            _stack = stack;
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
          _stack[index] = parent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
        if(index>0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
          --index; // Pop actual root node (if not start) back off the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
        _currentNode=_stack[index]; // Last parent before root node
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
        _oldsp = _sp = index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
    public int next()
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
        // Bugzilla 8324: We were forgetting to skip Attrs and NS nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
        // Also recoded the loop controls for clarity and to flatten out
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
        // the tail-recursion.
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
        for(++_currentNode; _sp>=0; ++_currentNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
          if(_currentNode < _stack[_sp])
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
            int type = _type2(_currentNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
            if(type != ATTRIBUTE_NODE && type != NAMESPACE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
              return returnNode(makeNodeHandle(_currentNode));
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
            --_sp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
    // redefine DTMAxisIteratorBase's reset
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
     * Resets the iterator to the last start node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
     * @return A DTMAxisIterator, which may or may not be the same as this
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
     *         iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
    public DTMAxisIterator reset()
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
      _sp = _oldsp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
      return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
    public void setMark() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
        _markedsp = _sp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
        _markedNode = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
        _markedDescendant = _stack[0];
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
    public void gotoMark() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
        _sp = _markedsp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
        _currentNode = _markedNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
  }  // end of PrecedingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
   * Iterator that returns preceding nodes of agiven type for a
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
   * given node. This includes the node set {root+1, start-1}, but
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
   * excludes all ancestors.
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
  public final class TypedPrecedingIterator extends PrecedingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
    /** The extended type ID that was requested. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
    private final int _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
     * Constructor TypedPrecedingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
     * @param type The extended type ID being requested.
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
    public TypedPrecedingIterator(int type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
      _nodeType = type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
    public int next()
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
      int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
      final int nodeType = _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
      if (nodeType >= DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
        while (true) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
          node++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
          if (_sp < 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
            node = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
          else if (node >= _stack[_sp]) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
            if (--_sp < 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
              node = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
              break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
          else if (_exptype2(node) == nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
      else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
        int expType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
        while (true) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
          node++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
          if (_sp < 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
            node = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
          else if (node >= _stack[_sp]) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
            if (--_sp < 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
              node = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
              break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
          else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
            expType = _exptype2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
            if (expType < DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
              if (expType == nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
              if (m_extendedTypes[expType].getNodeType() == nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
      _currentNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
      return (node == NULL) ? NULL : returnNode(makeNodeHandle(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
  }  // end of TypedPrecedingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
   * Iterator that returns following nodes of for a given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
  public class FollowingIterator extends InternalAxisIteratorBase
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
    //DTMAxisTraverser m_traverser; // easier for now
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
    public FollowingIterator()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
      //m_traverser = getAxisTraverser(Axis.FOLLOWING);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
     * Set start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
    public DTMAxisIterator setStartNode(int node)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
//%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
      if (node == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
        node = getDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
      if (_isRestartable)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
        _startNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
        //_currentNode = m_traverser.first(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
        node = makeNodeIdentity(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
        int first;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
        int type = _type2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
        if ((DTM.ATTRIBUTE_NODE == type) || (DTM.NAMESPACE_NODE == type))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
          node = _parent2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
          first = _firstch2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
          if (NULL != first) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
            _currentNode = makeNodeHandle(first);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
            return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
        do
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
          first = _nextsib2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
          if (NULL == first)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
            node = _parent2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
        while (NULL == first && NULL != node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
        _currentNode = makeNodeHandle(first);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
        // _currentNode precedes possible following(node) nodes
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
    public int next()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
      int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
      //_currentNode = m_traverser.next(_startNode, _currentNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
      int current = makeNodeIdentity(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
      while (true)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
        current++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
        int type = _type2(current);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
        if (NULL == type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
          _currentNode = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
          return returnNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
        if (ATTRIBUTE_NODE == type || NAMESPACE_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
          continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
        _currentNode = makeNodeHandle(current);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
        return returnNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
  }  // end of FollowingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
   * Iterator that returns following nodes of a given type for a given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
  public final class TypedFollowingIterator extends FollowingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
    /** The extended type ID that was requested. */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
    private final int _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
     * Constructor TypedFollowingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
     * @param type The extended type ID being requested.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
    public TypedFollowingIterator(int type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
      _nodeType = type;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
    public int next()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
      int current;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
      int node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
      int type;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
      final int nodeType = _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
      int currentNodeID = makeNodeIdentity(_currentNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
      if (nodeType >= DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
        do {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
          node = currentNodeID;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
          current = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
          do {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
            current++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
            type = _type2(current);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
          while (type != NULL && (ATTRIBUTE_NODE == type || NAMESPACE_NODE == type));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
          currentNodeID = (type != NULL) ? current : NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
        while (node != DTM.NULL && _exptype2(node) != nodeType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
      else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
        do {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
          node = currentNodeID;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
          current = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
          do {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
            current++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
            type = _type2(current);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
          while (type != NULL && (ATTRIBUTE_NODE == type || NAMESPACE_NODE == type));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
          currentNodeID = (type != NULL) ? current : NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
        while (node != DTM.NULL
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
               && (_exptype2(node) != nodeType && _type2(node) != nodeType));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
      _currentNode = makeNodeHandle(currentNodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
      return (node == DTM.NULL ? DTM.NULL :returnNode(makeNodeHandle(node)));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
  }  // end of TypedFollowingIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
   * Iterator that returns the ancestors of a given node in document
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
   * order.  (NOTE!  This was changed from the XSLTC code!)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
  public class AncestorIterator extends InternalAxisIteratorBase
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
    // The initial size of the ancestor array
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
    private static final int m_blocksize = 32;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
    // The array for ancestor nodes. This array will grow dynamically.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
    int[] m_ancestors = new int[m_blocksize];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
    // Number of ancestor nodes in the array
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
    int m_size = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
    int m_ancestorsPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
    int m_markedPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
    /** The real start node for this axes, since _startNode will be adjusted. */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
    int m_realStartNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
     * Get start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
     * @return The root node of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
    public int getStartNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
      return m_realStartNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
     * True if this iterator has a reversed axis.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
     * @return true since this iterator is a reversed axis.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
    public final boolean isReverse()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
      return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
     * Returns a deep copy of this iterator.  The cloned iterator is not reset.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
     * @return a deep copy of this iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
    public DTMAxisIterator cloneIterator()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
      _isRestartable = false;  // must set to false for any clone
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
      try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
        final AncestorIterator clone = (AncestorIterator) super.clone();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
        clone._startNode = _startNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
        // return clone.reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
        return clone;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
      catch (CloneNotSupportedException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
        throw new DTMException(XMLMessages.createXMLMessage(XMLErrorResources.ER_ITERATOR_CLONE_NOT_SUPPORTED, null)); //"Iterator clone not supported.");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1234
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
7f561c08de6b Initial load
duke
parents:
diff changeset
  1236
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
     * Set start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
    public DTMAxisIterator setStartNode(int node)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
//%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
      if (node == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
        node = getDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
      m_realStartNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
      if (_isRestartable)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
        int nodeID = makeNodeIdentity(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
        m_size = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
        if (nodeID == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
          _currentNode = DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
          m_ancestorsPos = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
          return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
        // Start from the current node's parent if
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
        // _includeSelf is false.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
        if (!_includeSelf) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
          nodeID = _parent2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
          node = makeNodeHandle(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
        _startNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
        while (nodeID != END) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
          if (m_size >= m_ancestors.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1274
            int[] newAncestors = new int[m_size * 2];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1275
            System.arraycopy(m_ancestors, 0, newAncestors, 0, m_ancestors.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
            m_ancestors = newAncestors;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
          m_ancestors[m_size++] = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
          nodeID = _parent2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1281
          node = makeNodeHandle(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1282
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1283
7f561c08de6b Initial load
duke
parents:
diff changeset
  1284
        m_ancestorsPos = m_size - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1285
7f561c08de6b Initial load
duke
parents:
diff changeset
  1286
        _currentNode = (m_ancestorsPos>=0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1287
                               ? m_ancestors[m_ancestorsPos]
7f561c08de6b Initial load
duke
parents:
diff changeset
  1288
                               : DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1289
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1297
     * Resets the iterator to the last start node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
     * @return A DTMAxisIterator, which may or may not be the same as this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1300
     *         iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1301
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
    public DTMAxisIterator reset()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1303
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1304
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
      m_ancestorsPos = m_size - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
      _currentNode = (m_ancestorsPos >= 0) ? m_ancestors[m_ancestorsPos]
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
                                         : DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1309
7f561c08de6b Initial load
duke
parents:
diff changeset
  1310
      return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1317
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
    public int next()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1319
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
      int next = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
      int pos = --m_ancestorsPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1324
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
      _currentNode = (pos >= 0) ? m_ancestors[m_ancestorsPos]
7f561c08de6b Initial load
duke
parents:
diff changeset
  1326
                                : DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1327
7f561c08de6b Initial load
duke
parents:
diff changeset
  1328
      return returnNode(next);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1329
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1330
7f561c08de6b Initial load
duke
parents:
diff changeset
  1331
    public void setMark() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1332
        m_markedPos = m_ancestorsPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1333
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1334
7f561c08de6b Initial load
duke
parents:
diff changeset
  1335
    public void gotoMark() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1336
        m_ancestorsPos = m_markedPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1337
        _currentNode = m_ancestorsPos>=0 ? m_ancestors[m_ancestorsPos]
7f561c08de6b Initial load
duke
parents:
diff changeset
  1338
                                         : DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1339
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1340
  }  // end of AncestorIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1341
7f561c08de6b Initial load
duke
parents:
diff changeset
  1342
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1343
   * Typed iterator that returns the ancestors of a given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1344
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1345
  public final class TypedAncestorIterator extends AncestorIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1346
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1347
7f561c08de6b Initial load
duke
parents:
diff changeset
  1348
    /** The extended type ID that was requested. */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1349
    private final int _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1350
7f561c08de6b Initial load
duke
parents:
diff changeset
  1351
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1352
     * Constructor TypedAncestorIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1353
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1354
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1355
     * @param type The extended type ID being requested.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1356
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1357
    public TypedAncestorIterator(int type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1358
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1359
      _nodeType = type;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1360
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1361
7f561c08de6b Initial load
duke
parents:
diff changeset
  1362
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1363
     * Set start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1364
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1365
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1366
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1367
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1368
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1369
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1370
    public DTMAxisIterator setStartNode(int node)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1371
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1372
//%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
7f561c08de6b Initial load
duke
parents:
diff changeset
  1373
      if (node == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1374
        node = getDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1375
      m_realStartNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1376
7f561c08de6b Initial load
duke
parents:
diff changeset
  1377
      if (_isRestartable)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1378
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1379
        int nodeID = makeNodeIdentity(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1380
        m_size = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1381
7f561c08de6b Initial load
duke
parents:
diff changeset
  1382
        if (nodeID == DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1383
          _currentNode = DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1384
          m_ancestorsPos = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1385
          return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1386
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1387
7f561c08de6b Initial load
duke
parents:
diff changeset
  1388
        final int nodeType = _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1389
7f561c08de6b Initial load
duke
parents:
diff changeset
  1390
        if (!_includeSelf) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1391
          nodeID = _parent2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1392
          node = makeNodeHandle(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1393
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1394
7f561c08de6b Initial load
duke
parents:
diff changeset
  1395
        _startNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1396
7f561c08de6b Initial load
duke
parents:
diff changeset
  1397
        if (nodeType >= DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1398
          while (nodeID != END) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1399
            int eType = _exptype2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1400
7f561c08de6b Initial load
duke
parents:
diff changeset
  1401
            if (eType == nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1402
              if (m_size >= m_ancestors.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1403
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1404
                int[] newAncestors = new int[m_size * 2];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1405
                System.arraycopy(m_ancestors, 0, newAncestors, 0, m_ancestors.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1406
                m_ancestors = newAncestors;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1407
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1408
              m_ancestors[m_size++] = makeNodeHandle(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1409
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1410
            nodeID = _parent2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1411
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1412
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1413
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1414
          while (nodeID != END) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1415
            int eType = _exptype2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1416
7f561c08de6b Initial load
duke
parents:
diff changeset
  1417
            if ((eType < DTM.NTYPES && eType == nodeType)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1418
                || (eType >= DTM.NTYPES
7f561c08de6b Initial load
duke
parents:
diff changeset
  1419
                    && m_extendedTypes[eType].getNodeType() == nodeType)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1420
              if (m_size >= m_ancestors.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1421
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1422
                int[] newAncestors = new int[m_size * 2];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1423
                System.arraycopy(m_ancestors, 0, newAncestors, 0, m_ancestors.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1424
                m_ancestors = newAncestors;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1425
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1426
              m_ancestors[m_size++] = makeNodeHandle(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1427
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1428
            nodeID = _parent2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1429
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1430
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1431
        m_ancestorsPos = m_size - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1432
7f561c08de6b Initial load
duke
parents:
diff changeset
  1433
        _currentNode = (m_ancestorsPos>=0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1434
                               ? m_ancestors[m_ancestorsPos]
7f561c08de6b Initial load
duke
parents:
diff changeset
  1435
                               : DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1436
7f561c08de6b Initial load
duke
parents:
diff changeset
  1437
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1438
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1439
7f561c08de6b Initial load
duke
parents:
diff changeset
  1440
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1441
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1442
7f561c08de6b Initial load
duke
parents:
diff changeset
  1443
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1444
     * Return the node at the given position.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1445
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1446
    public int getNodeByPosition(int position)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1447
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1448
      if (position > 0 && position <= m_size) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1449
        return m_ancestors[position-1];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1450
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1451
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1452
        return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1453
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1454
7f561c08de6b Initial load
duke
parents:
diff changeset
  1455
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1456
     * Returns the position of the last node within the iteration, as
7f561c08de6b Initial load
duke
parents:
diff changeset
  1457
     * defined by XPath.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1458
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1459
    public int getLast() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1460
      return m_size;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1461
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1462
  }  // end of TypedAncestorIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1463
7f561c08de6b Initial load
duke
parents:
diff changeset
  1464
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1465
   * Iterator that returns the descendants of a given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1466
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1467
  public class DescendantIterator extends InternalAxisIteratorBase
7f561c08de6b Initial load
duke
parents:
diff changeset
  1468
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1469
7f561c08de6b Initial load
duke
parents:
diff changeset
  1470
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1471
     * Set start to END should 'close' the iterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1472
     * i.e. subsequent call to next() should return END.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1473
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1474
     * @param node Sets the root of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1475
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1476
     * @return A DTMAxisIterator set to the start of the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1477
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1478
    public DTMAxisIterator setStartNode(int node)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1479
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1480
//%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
7f561c08de6b Initial load
duke
parents:
diff changeset
  1481
      if (node == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1482
        node = getDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1483
      if (_isRestartable)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1484
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1485
        node = makeNodeIdentity(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1486
        _startNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1487
7f561c08de6b Initial load
duke
parents:
diff changeset
  1488
        if (_includeSelf)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1489
          node--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1490
7f561c08de6b Initial load
duke
parents:
diff changeset
  1491
        _currentNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1492
7f561c08de6b Initial load
duke
parents:
diff changeset
  1493
        return resetPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1494
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1495
7f561c08de6b Initial load
duke
parents:
diff changeset
  1496
      return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1497
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1498
7f561c08de6b Initial load
duke
parents:
diff changeset
  1499
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1500
     * Tell if this node identity is a descendant.  Assumes that
7f561c08de6b Initial load
duke
parents:
diff changeset
  1501
     * the node info for the element has already been obtained.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1502
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1503
     * This one-sided test works only if the parent has been
7f561c08de6b Initial load
duke
parents:
diff changeset
  1504
     * previously tested and is known to be a descendent. It fails if
7f561c08de6b Initial load
duke
parents:
diff changeset
  1505
     * the parent is the _startNode's next sibling, or indeed any node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1506
     * that follows _startNode in document order.  That may suffice
7f561c08de6b Initial load
duke
parents:
diff changeset
  1507
     * for this iterator, but it's not really an isDescendent() test.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1508
     * %REVIEW% rename?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1509
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1510
     * @param identity The index number of the node in question.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1511
     * @return true if the index is a descendant of _startNode.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1512
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1513
    protected final boolean isDescendant(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1514
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1515
      return (_parent2(identity) >= _startNode) || (_startNode == identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1516
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1517
7f561c08de6b Initial load
duke
parents:
diff changeset
  1518
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1519
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1520
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1521
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1522
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1523
    public int next()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1524
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1525
      final int startNode = _startNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1526
      if (startNode == NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1527
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1528
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1529
7f561c08de6b Initial load
duke
parents:
diff changeset
  1530
      if (_includeSelf && (_currentNode + 1) == startNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1531
          return returnNode(makeNodeHandle(++_currentNode)); // | m_dtmIdent);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1532
7f561c08de6b Initial load
duke
parents:
diff changeset
  1533
      int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1534
      int type;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1535
7f561c08de6b Initial load
duke
parents:
diff changeset
  1536
      // %OPT% If the startNode is the root node, do not need
7f561c08de6b Initial load
duke
parents:
diff changeset
  1537
      // to do the isDescendant() check.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1538
      if (startNode == ROOTNODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1539
        int eType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1540
        do {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1541
          node++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1542
          eType = _exptype2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1543
7f561c08de6b Initial load
duke
parents:
diff changeset
  1544
          if (NULL == eType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1545
            _currentNode = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1546
            return END;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1547
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1548
        } while (eType == TEXT_NODE
7f561c08de6b Initial load
duke
parents:
diff changeset
  1549
                 || (type = m_extendedTypes[eType].getNodeType()) == ATTRIBUTE_NODE
7f561c08de6b Initial load
duke
parents:
diff changeset
  1550
                 || type == NAMESPACE_NODE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1551
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1552
      else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1553
        do {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1554
          node++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1555
          type = _type2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1556
7f561c08de6b Initial load
duke
parents:
diff changeset
  1557
          if (NULL == type ||!isDescendant(node)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1558
            _currentNode = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1559
            return END;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1560
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1561
        } while(ATTRIBUTE_NODE == type || TEXT_NODE == type
7f561c08de6b Initial load
duke
parents:
diff changeset
  1562
                 || NAMESPACE_NODE == type);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1563
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1564
7f561c08de6b Initial load
duke
parents:
diff changeset
  1565
      _currentNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1566
      return returnNode(makeNodeHandle(node));  // make handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1567
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1568
7f561c08de6b Initial load
duke
parents:
diff changeset
  1569
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1570
     * Reset.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1571
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1572
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1573
  public DTMAxisIterator reset()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1574
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1575
7f561c08de6b Initial load
duke
parents:
diff changeset
  1576
    final boolean temp = _isRestartable;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1577
7f561c08de6b Initial load
duke
parents:
diff changeset
  1578
    _isRestartable = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1579
7f561c08de6b Initial load
duke
parents:
diff changeset
  1580
    setStartNode(makeNodeHandle(_startNode));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1581
7f561c08de6b Initial load
duke
parents:
diff changeset
  1582
    _isRestartable = temp;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1583
7f561c08de6b Initial load
duke
parents:
diff changeset
  1584
    return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1585
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1586
7f561c08de6b Initial load
duke
parents:
diff changeset
  1587
  }  // end of DescendantIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1588
7f561c08de6b Initial load
duke
parents:
diff changeset
  1589
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1590
   * Typed iterator that returns the descendants of a given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1591
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1592
  public final class TypedDescendantIterator extends DescendantIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1593
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1594
7f561c08de6b Initial load
duke
parents:
diff changeset
  1595
    /** The extended type ID that was requested. */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1596
    private final int _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1597
7f561c08de6b Initial load
duke
parents:
diff changeset
  1598
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1599
     * Constructor TypedDescendantIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1600
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1601
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1602
     * @param nodeType Extended type ID being requested.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1603
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1604
    public TypedDescendantIterator(int nodeType)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1605
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1606
      _nodeType = nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1607
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1608
7f561c08de6b Initial load
duke
parents:
diff changeset
  1609
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1610
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1611
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1612
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1613
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1614
    public int next()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1615
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1616
      final int startNode = _startNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1617
      if (_startNode == NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1618
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1619
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1620
7f561c08de6b Initial load
duke
parents:
diff changeset
  1621
      int node = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1622
7f561c08de6b Initial load
duke
parents:
diff changeset
  1623
      int expType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1624
      final int nodeType = _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1625
7f561c08de6b Initial load
duke
parents:
diff changeset
  1626
      if (nodeType != DTM.ELEMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1627
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1628
        do
7f561c08de6b Initial load
duke
parents:
diff changeset
  1629
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1630
          node++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1631
          expType = _exptype2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1632
7f561c08de6b Initial load
duke
parents:
diff changeset
  1633
          if (NULL == expType || _parent2(node) < startNode && startNode != node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1634
            _currentNode = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1635
            return END;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1636
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1637
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1638
        while (expType != nodeType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1639
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1640
      // %OPT% If the start node is root (e.g. in the case of //node),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1641
      // we can save the isDescendant() check, because all nodes are
7f561c08de6b Initial load
duke
parents:
diff changeset
  1642
      // descendants of root.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1643
      else if (startNode == DTMDefaultBase.ROOTNODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1644
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1645
        do
7f561c08de6b Initial load
duke
parents:
diff changeset
  1646
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1647
          node++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1648
          expType = _exptype2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1649
7f561c08de6b Initial load
duke
parents:
diff changeset
  1650
          if (NULL == expType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1651
            _currentNode = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1652
            return END;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1653
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1654
        } while (expType < DTM.NTYPES
7f561c08de6b Initial load
duke
parents:
diff changeset
  1655
                || m_extendedTypes[expType].getNodeType() != DTM.ELEMENT_NODE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1656
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1657
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1658
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1659
        do
7f561c08de6b Initial load
duke
parents:
diff changeset
  1660
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1661
          node++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1662
          expType = _exptype2(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1663
7f561c08de6b Initial load
duke
parents:
diff changeset
  1664
          if (NULL == expType || _parent2(node) < startNode && startNode != node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1665
            _currentNode = NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1666
            return END;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1667
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1668
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1669
        while (expType < DTM.NTYPES
7f561c08de6b Initial load
duke
parents:
diff changeset
  1670
               || m_extendedTypes[expType].getNodeType() != DTM.ELEMENT_NODE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1671
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1672
7f561c08de6b Initial load
duke
parents:
diff changeset
  1673
      _currentNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1674
      return returnNode(makeNodeHandle(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1675
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1676
  }  // end of TypedDescendantIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1677
7f561c08de6b Initial load
duke
parents:
diff changeset
  1678
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1679
   * Iterator that returns a given node only if it is of a given type.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1680
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1681
  public final class TypedSingletonIterator extends SingletonIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1682
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1683
7f561c08de6b Initial load
duke
parents:
diff changeset
  1684
    /** The extended type ID that was requested. */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1685
    private final int _nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1686
7f561c08de6b Initial load
duke
parents:
diff changeset
  1687
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1688
     * Constructor TypedSingletonIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1689
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1690
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1691
     * @param nodeType The extended type ID being requested.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1692
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1693
    public TypedSingletonIterator(int nodeType)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1694
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1695
      _nodeType = nodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1696
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1697
7f561c08de6b Initial load
duke
parents:
diff changeset
  1698
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1699
     * Get the next node in the iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1700
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1701
     * @return The next node handle in the iteration, or END.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1702
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1703
    public int next()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1704
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1705
7f561c08de6b Initial load
duke
parents:
diff changeset
  1706
      final int result = _currentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1707
      if (result == END)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1708
        return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1709
7f561c08de6b Initial load
duke
parents:
diff changeset
  1710
      _currentNode = END;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1711
7f561c08de6b Initial load
duke
parents:
diff changeset
  1712
      if (_nodeType >= DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1713
        if (_exptype2(makeNodeIdentity(result)) == _nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1714
          return returnNode(result);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1715
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1716
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1717
      else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1718
        if (_type2(makeNodeIdentity(result)) == _nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1719
          return returnNode(result);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1720
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1721
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1722
7f561c08de6b Initial load
duke
parents:
diff changeset
  1723
      return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1724
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1725
  }  // end of TypedSingletonIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1726
7f561c08de6b Initial load
duke
parents:
diff changeset
  1727
  /*******************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
  1728
   *                End of nested iterators
7f561c08de6b Initial load
duke
parents:
diff changeset
  1729
   *******************************************************************/
7f561c08de6b Initial load
duke
parents:
diff changeset
  1730
7f561c08de6b Initial load
duke
parents:
diff changeset
  1731
7f561c08de6b Initial load
duke
parents:
diff changeset
  1732
  // %OPT% Array references which are used to cache the map0 arrays in
7f561c08de6b Initial load
duke
parents:
diff changeset
  1733
  // SuballocatedIntVectors. Using the cached arrays reduces the level
7f561c08de6b Initial load
duke
parents:
diff changeset
  1734
  // of indirection and results in better performance than just calling
7f561c08de6b Initial load
duke
parents:
diff changeset
  1735
  // SuballocatedIntVector.elementAt().
7f561c08de6b Initial load
duke
parents:
diff changeset
  1736
  private int[] m_exptype_map0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1737
  private int[] m_nextsib_map0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1738
  private int[] m_firstch_map0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1739
  private int[] m_parent_map0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1740
7f561c08de6b Initial load
duke
parents:
diff changeset
  1741
  // Double array references to the map arrays in SuballocatedIntVectors.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1742
  private int[][] m_exptype_map;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1743
  private int[][] m_nextsib_map;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1744
  private int[][] m_firstch_map;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1745
  private int[][] m_parent_map;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1746
7f561c08de6b Initial load
duke
parents:
diff changeset
  1747
  // %OPT% Cache the array of extended types in this class
7f561c08de6b Initial load
duke
parents:
diff changeset
  1748
  protected ExtendedType[] m_extendedTypes;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1749
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1750
  // A List which is used to store the values of attribute, namespace,
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1751
  // comment and PI nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1752
  //
7f561c08de6b Initial load
duke
parents:
diff changeset
  1753
  // %OPT% These values are unlikely to be equal. Storing
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1754
  // them in a plain List is more efficient than storing in the
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1755
  // DTMStringPool because we can save the cost for hash calculation.
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1756
  protected List<String> m_values;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1757
7f561c08de6b Initial load
duke
parents:
diff changeset
  1758
  // The current index into the m_values Vector.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1759
  private int m_valueIndex = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1760
7f561c08de6b Initial load
duke
parents:
diff changeset
  1761
  // The maximum value of the current node index.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1762
  private int m_maxNodeIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1763
7f561c08de6b Initial load
duke
parents:
diff changeset
  1764
  // Cache the shift and mask values for the SuballocatedIntVectors.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1765
  protected int m_SHIFT;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1766
  protected int m_MASK;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1767
  protected int m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1768
7f561c08de6b Initial load
duke
parents:
diff changeset
  1769
  /** %OPT% If the offset and length of a Text node are within certain limits,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1770
   * we store a bitwise encoded value into an int, using 10 bits (max. 1024)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1771
   * for length and 21 bits for offset. We can save two SuballocatedIntVector
7f561c08de6b Initial load
duke
parents:
diff changeset
  1772
   * calls for each getStringValueX() and dispatchCharacterEvents() call by
7f561c08de6b Initial load
duke
parents:
diff changeset
  1773
   * doing this.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1774
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1775
  // The number of bits for the length of a Text node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1776
  protected final static int TEXT_LENGTH_BITS = 10;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1777
7f561c08de6b Initial load
duke
parents:
diff changeset
  1778
  // The number of bits for the offset of a Text node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1779
  protected final static int TEXT_OFFSET_BITS = 21;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1780
7f561c08de6b Initial load
duke
parents:
diff changeset
  1781
  // The maximum length value
7f561c08de6b Initial load
duke
parents:
diff changeset
  1782
  protected final static int TEXT_LENGTH_MAX = (1<<TEXT_LENGTH_BITS) - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1783
7f561c08de6b Initial load
duke
parents:
diff changeset
  1784
  // The maximum offset value
7f561c08de6b Initial load
duke
parents:
diff changeset
  1785
  protected final static int TEXT_OFFSET_MAX = (1<<TEXT_OFFSET_BITS) - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1786
7f561c08de6b Initial load
duke
parents:
diff changeset
  1787
  // True if we want to build the ID index table.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1788
  protected boolean m_buildIdIndex = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1789
7f561c08de6b Initial load
duke
parents:
diff changeset
  1790
  // Constant for empty String
7f561c08de6b Initial load
duke
parents:
diff changeset
  1791
  private static final String EMPTY_STR = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1792
7f561c08de6b Initial load
duke
parents:
diff changeset
  1793
  // Constant for empty XMLString
7f561c08de6b Initial load
duke
parents:
diff changeset
  1794
  private static final XMLString EMPTY_XML_STR = new XMLStringDefault("");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1795
7f561c08de6b Initial load
duke
parents:
diff changeset
  1796
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1797
   * Construct a SAX2DTM2 object using the default block size.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1798
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1799
  public SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1800
                 DTMWSFilter whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1801
                 XMLStringFactory xstringfactory,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1802
                 boolean doIndexing)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1803
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1804
7f561c08de6b Initial load
duke
parents:
diff changeset
  1805
    this(mgr, source, dtmIdentity, whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1806
          xstringfactory, doIndexing, DEFAULT_BLOCKSIZE, true, true, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1807
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1808
7f561c08de6b Initial load
duke
parents:
diff changeset
  1809
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1810
   * Construct a SAX2DTM2 object using the given block size.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1811
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1812
  public SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1813
                 DTMWSFilter whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1814
                 XMLStringFactory xstringfactory,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1815
                 boolean doIndexing,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1816
                 int blocksize,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1817
                 boolean usePrevsib,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1818
                 boolean buildIdIndex,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1819
                 boolean newNameTable)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1820
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1821
7f561c08de6b Initial load
duke
parents:
diff changeset
  1822
    super(mgr, source, dtmIdentity, whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1823
          xstringfactory, doIndexing, blocksize, usePrevsib, newNameTable);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1824
7f561c08de6b Initial load
duke
parents:
diff changeset
  1825
    // Initialize the values of m_SHIFT and m_MASK.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1826
    int shift;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1827
    for(shift=0; (blocksize>>>=1) != 0; ++shift);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1828
7f561c08de6b Initial load
duke
parents:
diff changeset
  1829
    m_blocksize = 1<<shift;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1830
    m_SHIFT = shift;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1831
    m_MASK = m_blocksize - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1832
7f561c08de6b Initial load
duke
parents:
diff changeset
  1833
    m_buildIdIndex = buildIdIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1834
7f561c08de6b Initial load
duke
parents:
diff changeset
  1835
    // Some documents do not have attribute nodes. That is why
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1836
    // we set the initial size of this ArrayList to be small.
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1837
    m_values = new ArrayList<>(32);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1838
7f561c08de6b Initial load
duke
parents:
diff changeset
  1839
    m_maxNodeIndex = 1 << DTMManager.IDENT_DTM_NODE_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1840
7f561c08de6b Initial load
duke
parents:
diff changeset
  1841
    // Set the map0 values in the constructor.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1842
    m_exptype_map0 = m_exptype.getMap0();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1843
    m_nextsib_map0 = m_nextsib.getMap0();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1844
    m_firstch_map0 = m_firstch.getMap0();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1845
    m_parent_map0  = m_parent.getMap0();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1846
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1847
7f561c08de6b Initial load
duke
parents:
diff changeset
  1848
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1849
   * Override DTMDefaultBase._exptype() by dropping the incremental code.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1850
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1851
   * <p>This one is less efficient than _exptype2. It is only used during
7f561c08de6b Initial load
duke
parents:
diff changeset
  1852
   * DTM building. _exptype2 is used after the document is fully built.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1853
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1854
  public final int _exptype(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1855
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1856
    return m_exptype.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1857
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1858
7f561c08de6b Initial load
duke
parents:
diff changeset
  1859
  /************************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
  1860
   *             DTM base accessor interfaces
7f561c08de6b Initial load
duke
parents:
diff changeset
  1861
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1862
   * %OPT% The code in the following interfaces (e.g. _exptype2, etc.) are
7f561c08de6b Initial load
duke
parents:
diff changeset
  1863
   * very important to the DTM performance. To have the best performace,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1864
   * these several interfaces have direct access to the internal arrays of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1865
   * the SuballocatedIntVectors. The final modifier also has a noticeable
7f561c08de6b Initial load
duke
parents:
diff changeset
  1866
   * impact on performance.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1867
   ***********************************************************************/
7f561c08de6b Initial load
duke
parents:
diff changeset
  1868
7f561c08de6b Initial load
duke
parents:
diff changeset
  1869
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1870
   * The optimized version of DTMDefaultBase._exptype().
7f561c08de6b Initial load
duke
parents:
diff changeset
  1871
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1872
   * @param identity A node identity, which <em>must not</em> be equal to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1873
   *        <code>DTM.NULL</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1874
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1875
  public final int _exptype2(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1876
  {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1877
    //return m_exptype.get(identity);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1878
7f561c08de6b Initial load
duke
parents:
diff changeset
  1879
    if (identity < m_blocksize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1880
      return m_exptype_map0[identity];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1881
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1882
      return m_exptype_map[identity>>>m_SHIFT][identity&m_MASK];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1883
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1884
7f561c08de6b Initial load
duke
parents:
diff changeset
  1885
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1886
   * The optimized version of DTMDefaultBase._nextsib().
7f561c08de6b Initial load
duke
parents:
diff changeset
  1887
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1888
   * @param identity A node identity, which <em>must not</em> be equal to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1889
   *        <code>DTM.NULL</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1890
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1891
  public final int _nextsib2(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1892
  {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1893
    //return m_nextsib.get(identity);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1894
7f561c08de6b Initial load
duke
parents:
diff changeset
  1895
    if (identity < m_blocksize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1896
      return m_nextsib_map0[identity];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1897
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1898
      return m_nextsib_map[identity>>>m_SHIFT][identity&m_MASK];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1899
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1900
7f561c08de6b Initial load
duke
parents:
diff changeset
  1901
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1902
   * The optimized version of DTMDefaultBase._firstch().
7f561c08de6b Initial load
duke
parents:
diff changeset
  1903
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1904
   * @param identity A node identity, which <em>must not</em> be equal to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1905
   *        <code>DTM.NULL</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1906
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1907
  public final int _firstch2(int identity) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1908
    if (identity < m_blocksize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1909
      return m_firstch_map0[identity];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1910
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1911
      return m_firstch_map[identity>>>m_SHIFT][identity&m_MASK];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1912
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1913
7f561c08de6b Initial load
duke
parents:
diff changeset
  1914
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1915
   * The optimized version of DTMDefaultBase._parent().
7f561c08de6b Initial load
duke
parents:
diff changeset
  1916
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1917
   * @param identity A node identity, which <em>must not</em> be equal to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1918
   *        <code>DTM.NULL</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1919
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1920
  public final int _parent2(int identity) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1921
    if (identity < m_blocksize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1922
      return m_parent_map0[identity];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1923
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1924
      return m_parent_map[identity>>>m_SHIFT][identity&m_MASK];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1925
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1926
7f561c08de6b Initial load
duke
parents:
diff changeset
  1927
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1928
   * The optimized version of DTMDefaultBase._type().
7f561c08de6b Initial load
duke
parents:
diff changeset
  1929
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1930
   * @param identity A node identity, which <em>must not</em> be equal to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1931
   *        <code>DTM.NULL</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1932
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1933
  public final int _type2(int identity) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1934
    int eType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1935
    if (identity < m_blocksize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1936
      eType = m_exptype_map0[identity];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1937
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1938
      eType = m_exptype_map[identity>>>m_SHIFT][identity&m_MASK];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1939
7f561c08de6b Initial load
duke
parents:
diff changeset
  1940
    if (NULL != eType)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1941
      return m_extendedTypes[eType].getNodeType();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1942
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1943
      return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1944
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1945
7f561c08de6b Initial load
duke
parents:
diff changeset
  1946
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1947
   * The optimized version of DTMDefaultBase.getExpandedTypeID(int).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1948
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1949
   * <p>This one is only used by DOMAdapter.getExpandedTypeID(int), which
7f561c08de6b Initial load
duke
parents:
diff changeset
  1950
   * is mostly called from the compiled translets.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1951
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1952
  public final int getExpandedTypeID2(int nodeHandle) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1953
    int nodeID = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1954
7f561c08de6b Initial load
duke
parents:
diff changeset
  1955
    if (nodeID != NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1956
      if (nodeID < m_blocksize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1957
        return m_exptype_map0[nodeID];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1958
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1959
        return m_exptype_map[nodeID>>>m_SHIFT][nodeID&m_MASK];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1960
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1961
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1962
      return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1963
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1964
7f561c08de6b Initial load
duke
parents:
diff changeset
  1965
  /*************************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
  1966
   *                 END of DTM base accessor interfaces
7f561c08de6b Initial load
duke
parents:
diff changeset
  1967
   *************************************************************************/
7f561c08de6b Initial load
duke
parents:
diff changeset
  1968
7f561c08de6b Initial load
duke
parents:
diff changeset
  1969
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1970
   * Return the node type from the expanded type
7f561c08de6b Initial load
duke
parents:
diff changeset
  1971
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1972
  public final int _exptype2Type(int exptype) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1973
    if (NULL != exptype)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1974
      return m_extendedTypes[exptype].getNodeType();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1975
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1976
      return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1977
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1978
7f561c08de6b Initial load
duke
parents:
diff changeset
  1979
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1980
   * Get a prefix either from the uri mapping, or just make
7f561c08de6b Initial load
duke
parents:
diff changeset
  1981
   * one up!
7f561c08de6b Initial load
duke
parents:
diff changeset
  1982
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1983
   * @param uri The namespace URI, which may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1984
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1985
   * @return The prefix if there is one, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1986
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1987
  public int getIdForNamespace(String uri) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1988
     int index = m_values.indexOf(uri);
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1989
     if (index < 0) {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1990
       m_values.add(uri);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1991
       return m_valueIndex++;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1992
     } else {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  1993
       return index;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1994
     }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1995
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1996
7f561c08de6b Initial load
duke
parents:
diff changeset
  1997
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1998
   * Override SAX2DTM.startElement()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1999
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2000
   * <p>Receive notification of the start of an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2001
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2002
   * <p>By default, do nothing.  Application writers may override this
7f561c08de6b Initial load
duke
parents:
diff changeset
  2003
   * method in a subclass to take specific actions at the start of
7f561c08de6b Initial load
duke
parents:
diff changeset
  2004
   * each element (such as allocating a new tree node or writing
7f561c08de6b Initial load
duke
parents:
diff changeset
  2005
   * output to a file).</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2006
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2007
   * @param uri The Namespace URI, or the empty string if the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2008
   *        element has no Namespace URI or if Namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  2009
   *        processing is not being performed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2010
   * @param localName The local name (without prefix), or the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2011
   *        empty string if Namespace processing is not being
7f561c08de6b Initial load
duke
parents:
diff changeset
  2012
   *        performed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2013
   * @param qName The qualified name (with prefix), or the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2014
   *        empty string if qualified names are not available.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2015
   * @param attributes The specified or defaulted attributes.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2016
   * @throws SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  2017
   *            wrapping another exception.
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2018
   * @see ContentHandler#startElement
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2019
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2020
  public void startElement(String uri, String localName, String qName,
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2021
                           Attributes attributes) throws SAXException
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2022
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2023
    charactersFlush();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2024
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2025
    // in case URI and localName are empty, the input is not using the
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2026
    // namespaces feature. Then we should take the part after the last
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2027
    // colon of qName as localName (strip all namespace prefixes)
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2028
    if ((uri == null || uri.isEmpty()) &&
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2029
        (localName == null || localName.isEmpty()))
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2030
    {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2031
      final int colon = qName.lastIndexOf(':');
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2032
      localName = (colon > -1) ? qName.substring(colon + 1) : qName;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2033
    }
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2034
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2035
    int exName = m_expandedNameTable.getExpandedTypeID(uri, localName,
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2036
                                                       DTM.ELEMENT_NODE);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2037
7f561c08de6b Initial load
duke
parents:
diff changeset
  2038
    int prefixIndex = (qName.length() != localName.length())
7f561c08de6b Initial load
duke
parents:
diff changeset
  2039
                      ? m_valuesOrPrefixes.stringToIndex(qName) : 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2040
7f561c08de6b Initial load
duke
parents:
diff changeset
  2041
    int elemNode = addNode(DTM.ELEMENT_NODE, exName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2042
                           m_parents.peek(), m_previous, prefixIndex, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2043
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2044
    if (m_indexing)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2045
      indexNode(exName, elemNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2046
7f561c08de6b Initial load
duke
parents:
diff changeset
  2047
    m_parents.push(elemNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2048
7f561c08de6b Initial load
duke
parents:
diff changeset
  2049
    int startDecls = m_contextIndexes.peek();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2050
    int nDecls = m_prefixMappings.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2051
    String prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2052
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2053
    if (!m_pastFirstElement) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2054
      // SPECIAL CASE: Implied declaration at root element
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2055
      prefix = "xml";
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2056
      String declURL = "http://www.w3.org/XML/1998/namespace";
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2057
      exName = m_expandedNameTable.getExpandedTypeID(null, prefix,
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2058
                                                     DTM.NAMESPACE_NODE);
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2059
      m_values.add(declURL);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2060
      int val = m_valueIndex++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2061
      addNode(DTM.NAMESPACE_NODE, exName, elemNode,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2062
                     DTM.NULL, val, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2063
      m_pastFirstElement=true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2064
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2065
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2066
    for (int i = startDecls; i < nDecls; i += 2) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  2067
      prefix = m_prefixMappings.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2068
7f561c08de6b Initial load
duke
parents:
diff changeset
  2069
      if (prefix == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2070
        continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2071
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  2072
      String declURL = m_prefixMappings.get(i + 1);
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2073
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2074
      exName = m_expandedNameTable.getExpandedTypeID(null, prefix,
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2075
                                                     DTM.NAMESPACE_NODE);
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2076
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2077
      m_values.add(declURL);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2078
      int val = m_valueIndex++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2079
7f561c08de6b Initial load
duke
parents:
diff changeset
  2080
      addNode(DTM.NAMESPACE_NODE, exName, elemNode, DTM.NULL, val, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2081
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2082
7f561c08de6b Initial load
duke
parents:
diff changeset
  2083
    int n = attributes.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2084
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2085
    for (int i = 0; i < n; i++) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2086
      String attrUri = attributes.getURI(i);
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2087
      String attrLocalName = attributes.getLocalName(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2088
      String attrQName = attributes.getQName(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2089
      String valString = attributes.getValue(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2090
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2091
      // in case URI and localName are empty, the input is not using the
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2092
      // namespaces feature. Then we should take the part after the last
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2093
      // colon of qName as localName (strip all namespace prefixes)
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2094
      // When the URI is empty but localName has colons then we can also
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2095
      // assume non namespace aware and prefixes can be stripped
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2096
      if (attrUri == null || attrUri.isEmpty()) {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2097
        if (attrLocalName == null || attrLocalName.isEmpty()) {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2098
          final int colon = attrQName.lastIndexOf(':');
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2099
          attrLocalName = (colon > -1) ? attrQName.substring(colon + 1) : attrQName;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2100
        } else {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2101
          final int colon = attrLocalName.lastIndexOf(':');
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2102
          attrLocalName = (colon > -1) ? attrLocalName.substring(colon + 1) : attrLocalName;
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2103
        }
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2104
      }
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2105
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2106
      int nodeType;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2107
      if ((null != attrQName) &&
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2108
          (attrQName.equals("xmlns") || attrQName.startsWith("xmlns:")))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2109
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2110
        prefix = getPrefix(attrQName, attrUri);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2111
        if (declAlreadyDeclared(prefix))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2112
          continue;  // go to the next attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2113
7f561c08de6b Initial load
duke
parents:
diff changeset
  2114
        nodeType = DTM.NAMESPACE_NODE;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2115
      } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2116
        nodeType = DTM.ATTRIBUTE_NODE;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2117
7f561c08de6b Initial load
duke
parents:
diff changeset
  2118
        if (m_buildIdIndex && attributes.getType(i).equalsIgnoreCase("ID"))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2119
          setIDAttribute(valString, elemNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2120
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2121
7f561c08de6b Initial load
duke
parents:
diff changeset
  2122
      // Bit of a hack... if somehow valString is null, stringToIndex will
7f561c08de6b Initial load
duke
parents:
diff changeset
  2123
      // return -1, which will make things very unhappy.
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2124
      if (null == valString)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2125
        valString = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
  2126
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2127
      m_values.add(valString);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2128
      int val = m_valueIndex++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2129
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2130
      if (attrLocalName.length() != attrQName.length()) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2131
        prefixIndex = m_valuesOrPrefixes.stringToIndex(attrQName);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2132
        int dataIndex = m_data.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2133
        m_data.addElement(prefixIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2134
        m_data.addElement(val);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2135
        val = -dataIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2136
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2137
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2138
      exName = m_expandedNameTable.getExpandedTypeID(attrUri, attrLocalName,
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2139
                                                     nodeType);
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2140
      addNode(nodeType, exName, elemNode, DTM.NULL, val, false);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2141
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2142
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2143
    if (null != m_wsfilter) {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2144
      short wsv = m_wsfilter.getShouldStripSpace(makeNodeHandle(elemNode),
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2145
                                                 this);
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2146
      boolean shouldStrip = (DTMWSFilter.INHERIT == wsv) ?
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2147
                            getShouldStripWhitespace() :
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2148
                            (DTMWSFilter.STRIP == wsv);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2149
7f561c08de6b Initial load
duke
parents:
diff changeset
  2150
      pushShouldStripWhitespace(shouldStrip);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2151
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2152
7f561c08de6b Initial load
duke
parents:
diff changeset
  2153
    m_previous = DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2154
7f561c08de6b Initial load
duke
parents:
diff changeset
  2155
    m_contextIndexes.push(m_prefixMappings.size());  // for the children.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2156
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2157
7f561c08de6b Initial load
duke
parents:
diff changeset
  2158
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2159
   * Receive notification of the end of an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2160
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2161
   * <p>By default, do nothing.  Application writers may override this
7f561c08de6b Initial load
duke
parents:
diff changeset
  2162
   * method in a subclass to take specific actions at the end of
7f561c08de6b Initial load
duke
parents:
diff changeset
  2163
   * each element (such as finalising a tree node or writing
7f561c08de6b Initial load
duke
parents:
diff changeset
  2164
   * output to a file).</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2165
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2166
   * @param uri The Namespace URI, or the empty string if the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2167
   *        element has no Namespace URI or if Namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  2168
   *        processing is not being performed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2169
   * @param localName The local name (without prefix), or the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2170
   *        empty string if Namespace processing is not being
7f561c08de6b Initial load
duke
parents:
diff changeset
  2171
   *        performed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2172
   * @param qName The qualified XML 1.0 name (with prefix), or the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2173
   *        empty string if qualified names are not available.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2174
   * @throws SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  2175
   *            wrapping another exception.
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2176
   * @see ContentHandler#endElement
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2177
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2178
  public void endElement(String uri, String localName, String qName)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2179
          throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2180
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2181
    charactersFlush();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2182
7f561c08de6b Initial load
duke
parents:
diff changeset
  2183
    // If no one noticed, startPrefixMapping is a drag.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2184
    // Pop the context for the last child (the one pushed by startElement)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2185
    m_contextIndexes.quickPop(1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2186
7f561c08de6b Initial load
duke
parents:
diff changeset
  2187
    // Do it again for this one (the one pushed by the last endElement).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2188
    int topContextIndex = m_contextIndexes.peek();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2189
    if (topContextIndex != m_prefixMappings.size()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2190
      m_prefixMappings.setSize(topContextIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2191
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2192
7f561c08de6b Initial load
duke
parents:
diff changeset
  2193
    m_previous = m_parents.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2194
7f561c08de6b Initial load
duke
parents:
diff changeset
  2195
    popShouldStripWhitespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2196
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2197
7f561c08de6b Initial load
duke
parents:
diff changeset
  2198
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2199
   * Report an XML comment anywhere in the document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2200
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2201
   * <p>This callback will be used for comments inside or outside the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2202
   * document element, including comments in the external DTD
7f561c08de6b Initial load
duke
parents:
diff changeset
  2203
   * subset (if read).</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2204
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2205
   * @param ch An array holding the characters in the comment.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2206
   * @param start The starting position in the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2207
   * @param length The number of characters to use from the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2208
   * @throws SAXException The application may raise an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2209
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2210
  public void comment(char ch[], int start, int length) throws SAXException {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2211
    if (m_insideDTD)      // ignore comments if we're inside the DTD
7f561c08de6b Initial load
duke
parents:
diff changeset
  2212
      return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2213
7f561c08de6b Initial load
duke
parents:
diff changeset
  2214
    charactersFlush();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2215
7f561c08de6b Initial load
duke
parents:
diff changeset
  2216
    // %OPT% Saving the comment string in a Vector has a lower cost than
7f561c08de6b Initial load
duke
parents:
diff changeset
  2217
    // saving it in DTMStringPool.
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2218
    m_values.add(new String(ch, start, length));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2219
    int dataIndex = m_valueIndex++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2220
7f561c08de6b Initial load
duke
parents:
diff changeset
  2221
    m_previous = addNode(DTM.COMMENT_NODE, DTM.COMMENT_NODE,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2222
                         m_parents.peek(), m_previous, dataIndex, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2223
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2224
7f561c08de6b Initial load
duke
parents:
diff changeset
  2225
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2226
   * Receive notification of the beginning of the document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2227
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2228
   * @throws SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  2229
   *            wrapping another exception.
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2230
   * @see ContentHandler#startDocument
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2231
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2232
  public void startDocument() throws SAXException {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2233
    int doc = addNode(DTM.DOCUMENT_NODE, DTM.DOCUMENT_NODE,
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2234
                      DTM.NULL, DTM.NULL, 0, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2235
7f561c08de6b Initial load
duke
parents:
diff changeset
  2236
    m_parents.push(doc);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2237
    m_previous = DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2238
7f561c08de6b Initial load
duke
parents:
diff changeset
  2239
    m_contextIndexes.push(m_prefixMappings.size());  // for the next element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2240
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2241
7f561c08de6b Initial load
duke
parents:
diff changeset
  2242
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2243
   * Receive notification of the end of the document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2244
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2245
   * @throws SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  2246
   *            wrapping another exception.
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2247
   * @see ContentHandler#endDocument
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2248
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2249
  public void endDocument() throws SAXException {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2250
    super.endDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2251
7f561c08de6b Initial load
duke
parents:
diff changeset
  2252
    // Add a NULL entry to the end of the node arrays as
7f561c08de6b Initial load
duke
parents:
diff changeset
  2253
    // the end indication.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2254
    m_exptype.addElement(NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2255
    m_parent.addElement(NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2256
    m_nextsib.addElement(NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2257
    m_firstch.addElement(NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2258
7f561c08de6b Initial load
duke
parents:
diff changeset
  2259
    // Set the cached references after the document is built.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2260
    m_extendedTypes = m_expandedNameTable.getExtendedTypes();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2261
    m_exptype_map = m_exptype.getMap();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2262
    m_nextsib_map = m_nextsib.getMap();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2263
    m_firstch_map = m_firstch.getMap();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2264
    m_parent_map  = m_parent.getMap();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2265
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2266
7f561c08de6b Initial load
duke
parents:
diff changeset
  2267
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2268
   * Construct the node map from the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2269
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2270
   * @param type raw type ID, one of DTM.XXX_NODE.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2271
   * @param expandedTypeID The expended type ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2272
   * @param parentIndex The current parent index.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2273
   * @param previousSibling The previous sibling index.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2274
   * @param dataOrPrefix index into m_data table, or string handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2275
   * @param canHaveFirstChild true if the node can have a first child, false
7f561c08de6b Initial load
duke
parents:
diff changeset
  2276
   *                          if it is atomic.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2277
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2278
   * @return The index identity of the node that was added.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2279
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2280
  protected final int addNode(int type, int expandedTypeID,
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2281
                              int parentIndex, int previousSibling,
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2282
                              int dataOrPrefix, boolean canHaveFirstChild)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2283
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2284
    // Common to all nodes:
7f561c08de6b Initial load
duke
parents:
diff changeset
  2285
    int nodeIndex = m_size++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2286
7f561c08de6b Initial load
duke
parents:
diff changeset
  2287
    // Have we overflowed a DTM Identity's addressing range?
7f561c08de6b Initial load
duke
parents:
diff changeset
  2288
    //if(m_dtmIdent.size() == (nodeIndex>>>DTMManager.IDENT_DTM_NODE_BITS))
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2289
    if (nodeIndex == m_maxNodeIndex) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2290
      addNewDTMID(nodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2291
      m_maxNodeIndex += (1 << DTMManager.IDENT_DTM_NODE_BITS);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2292
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2293
7f561c08de6b Initial load
duke
parents:
diff changeset
  2294
    m_firstch.addElement(DTM.NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2295
    m_nextsib.addElement(DTM.NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2296
    m_parent.addElement(parentIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2297
    m_exptype.addElement(expandedTypeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2298
    m_dataOrQName.addElement(dataOrPrefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2299
7f561c08de6b Initial load
duke
parents:
diff changeset
  2300
    if (m_prevsib != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2301
      m_prevsib.addElement(previousSibling);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2302
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2303
7f561c08de6b Initial load
duke
parents:
diff changeset
  2304
    if (m_locator != null && m_useSourceLocationProperty) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2305
      setSourceLocation();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2306
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2307
7f561c08de6b Initial load
duke
parents:
diff changeset
  2308
    // Note that nextSibling is not processed until charactersFlush()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2309
    // is called, to handle successive characters() events.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2310
7f561c08de6b Initial load
duke
parents:
diff changeset
  2311
    // Special handling by type: Declare namespaces, attach first child
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2312
    switch(type) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2313
    case DTM.NAMESPACE_NODE:
7f561c08de6b Initial load
duke
parents:
diff changeset
  2314
      declareNamespaceInContext(parentIndex,nodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2315
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2316
    case DTM.ATTRIBUTE_NODE:
7f561c08de6b Initial load
duke
parents:
diff changeset
  2317
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2318
    default:
7f561c08de6b Initial load
duke
parents:
diff changeset
  2319
      if (DTM.NULL != previousSibling) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2320
        m_nextsib.setElementAt(nodeIndex,previousSibling);
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2321
      } else if (DTM.NULL != parentIndex) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2322
        m_firstch.setElementAt(nodeIndex,parentIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2323
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2324
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2325
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2326
7f561c08de6b Initial load
duke
parents:
diff changeset
  2327
    return nodeIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2328
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2329
7f561c08de6b Initial load
duke
parents:
diff changeset
  2330
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2331
   * Check whether accumulated text should be stripped; if not,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2332
   * append the appropriate flavor of text/cdata node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2333
   */
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2334
  protected final void charactersFlush() {
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2335
    if (m_textPendingStart >= 0) { // -1 indicates no-text-in-progress
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2336
      int length = m_chars.size() - m_textPendingStart;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2337
      boolean doStrip = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2338
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2339
      if (getShouldStripWhitespace()) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2340
        doStrip = m_chars.isWhitespace(m_textPendingStart, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2341
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2342
7f561c08de6b Initial load
duke
parents:
diff changeset
  2343
      if (doStrip) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2344
        m_chars.setLength(m_textPendingStart);  // Discard accumulated text
7f561c08de6b Initial load
duke
parents:
diff changeset
  2345
      } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2346
        // Guard against characters/ignorableWhitespace events that
7f561c08de6b Initial load
duke
parents:
diff changeset
  2347
        // contained no characters.  They should not result in a node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2348
        if (length > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2349
          // If the offset and length do not exceed the given limits
7f561c08de6b Initial load
duke
parents:
diff changeset
  2350
          // (offset < 2^21 and length < 2^10), then save both the offset
7f561c08de6b Initial load
duke
parents:
diff changeset
  2351
          // and length in a bitwise encoded value.
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2352
          if (length <= TEXT_LENGTH_MAX &&
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2353
              m_textPendingStart <= TEXT_OFFSET_MAX) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2354
            m_previous = addNode(m_coalescedTextType, DTM.TEXT_NODE,
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2355
                                 m_parents.peek(), m_previous,
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2356
                                 length + (m_textPendingStart << TEXT_LENGTH_BITS),
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2357
                                 false);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2358
7f561c08de6b Initial load
duke
parents:
diff changeset
  2359
          } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2360
            // Store offset and length in the m_data array if one exceeds
7f561c08de6b Initial load
duke
parents:
diff changeset
  2361
            // the given limits. Use a negative dataIndex as an indication.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2362
            int dataIndex = m_data.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2363
            m_previous = addNode(m_coalescedTextType, DTM.TEXT_NODE,
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2364
                                 m_parents.peek(), m_previous, -dataIndex, false);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2365
7f561c08de6b Initial load
duke
parents:
diff changeset
  2366
            m_data.addElement(m_textPendingStart);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2367
            m_data.addElement(length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2368
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2369
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2370
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2371
7f561c08de6b Initial load
duke
parents:
diff changeset
  2372
      // Reset for next text block
7f561c08de6b Initial load
duke
parents:
diff changeset
  2373
      m_textPendingStart = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2374
      m_textType = m_coalescedTextType = DTM.TEXT_NODE;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2375
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2376
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2377
7f561c08de6b Initial load
duke
parents:
diff changeset
  2378
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2379
   * Override the processingInstruction() interface in SAX2DTM2.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2380
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2381
   * %OPT% This one is different from SAX2DTM.processingInstruction()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2382
   * in that we do not use extended types for PI nodes. The name of
7f561c08de6b Initial load
duke
parents:
diff changeset
  2383
   * the PI is saved in the DTMStringPool.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2384
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2385
   * Receive notification of a processing instruction.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2386
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2387
   * @param target The processing instruction target.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2388
   * @param data The processing instruction data, or null if
7f561c08de6b Initial load
duke
parents:
diff changeset
  2389
   *             none is supplied.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2390
   * @throws SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  2391
   *            wrapping another exception.
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2392
   * @see ContentHandler#processingInstruction
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2393
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2394
  public void processingInstruction(String target, String data)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2395
          throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2396
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2397
7f561c08de6b Initial load
duke
parents:
diff changeset
  2398
    charactersFlush();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2399
7f561c08de6b Initial load
duke
parents:
diff changeset
  2400
    int dataIndex = m_data.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2401
    m_previous = addNode(DTM.PROCESSING_INSTRUCTION_NODE,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2402
                         DTM.PROCESSING_INSTRUCTION_NODE,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2403
                         m_parents.peek(), m_previous,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2404
                         -dataIndex, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2405
7f561c08de6b Initial load
duke
parents:
diff changeset
  2406
    m_data.addElement(m_valuesOrPrefixes.stringToIndex(target));
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2407
    m_values.add(data);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2408
    m_data.addElement(m_valueIndex++);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2409
7f561c08de6b Initial load
duke
parents:
diff changeset
  2410
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2411
7f561c08de6b Initial load
duke
parents:
diff changeset
  2412
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2413
   * The optimized version of DTMDefaultBase.getFirstAttribute().
7f561c08de6b Initial load
duke
parents:
diff changeset
  2414
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2415
   * Given a node handle, get the index of the node's first attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2416
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2417
   * @param nodeHandle int Handle of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2418
   * @return Handle of first attribute, or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2419
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2420
  public final int getFirstAttribute(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2421
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2422
    int nodeID = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2423
7f561c08de6b Initial load
duke
parents:
diff changeset
  2424
    if (nodeID == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2425
      return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2426
7f561c08de6b Initial load
duke
parents:
diff changeset
  2427
    int type = _type2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2428
7f561c08de6b Initial load
duke
parents:
diff changeset
  2429
    if (DTM.ELEMENT_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2430
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2431
      // Assume that attributes and namespaces immediately follow the element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2432
      while (true)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2433
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2434
        nodeID++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2435
        // Assume this can not be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2436
        type = _type2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2437
7f561c08de6b Initial load
duke
parents:
diff changeset
  2438
        if (type == DTM.ATTRIBUTE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2439
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2440
          return makeNodeHandle(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2441
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2442
        else if (DTM.NAMESPACE_NODE != type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2443
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2444
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2445
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2446
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2447
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2448
7f561c08de6b Initial load
duke
parents:
diff changeset
  2449
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2450
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2451
7f561c08de6b Initial load
duke
parents:
diff changeset
  2452
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2453
   * The optimized version of DTMDefaultBase.getFirstAttributeIdentity(int).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2454
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2455
   * Given a node identity, get the index of the node's first attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2456
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2457
   * @param identity int identity of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2458
   * @return Identity of first attribute, or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2459
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2460
  protected int getFirstAttributeIdentity(int identity) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2461
    if (identity == NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2462
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2463
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2464
    int type = _type2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2465
7f561c08de6b Initial load
duke
parents:
diff changeset
  2466
    if (DTM.ELEMENT_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2467
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2468
      // Assume that attributes and namespaces immediately follow the element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2469
      while (true)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2470
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2471
        identity++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2472
7f561c08de6b Initial load
duke
parents:
diff changeset
  2473
        // Assume this can not be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2474
        type = _type2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2475
7f561c08de6b Initial load
duke
parents:
diff changeset
  2476
        if (type == DTM.ATTRIBUTE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2477
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2478
          return identity;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2479
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2480
        else if (DTM.NAMESPACE_NODE != type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2481
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2482
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2483
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2484
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2485
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2486
7f561c08de6b Initial load
duke
parents:
diff changeset
  2487
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2488
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2489
7f561c08de6b Initial load
duke
parents:
diff changeset
  2490
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2491
   * The optimized version of DTMDefaultBase.getNextAttributeIdentity(int).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2492
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2493
   * Given a node identity for an attribute, advance to the next attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2494
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2495
   * @param identity int identity of the attribute node.  This
7f561c08de6b Initial load
duke
parents:
diff changeset
  2496
   * <strong>must</strong> be an attribute node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2497
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2498
   * @return int DTM node-identity of the resolved attr,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2499
   * or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2500
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2501
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2502
  protected int getNextAttributeIdentity(int identity) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2503
    // Assume that attributes and namespace nodes immediately follow the element
7f561c08de6b Initial load
duke
parents:
diff changeset
  2504
    while (true) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2505
      identity++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2506
      int type = _type2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2507
7f561c08de6b Initial load
duke
parents:
diff changeset
  2508
      if (type == DTM.ATTRIBUTE_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2509
        return identity;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2510
      } else if (type != DTM.NAMESPACE_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2511
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2512
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2513
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2514
7f561c08de6b Initial load
duke
parents:
diff changeset
  2515
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2516
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2517
7f561c08de6b Initial load
duke
parents:
diff changeset
  2518
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2519
   * The optimized version of DTMDefaultBase.getTypedAttribute(int, int).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2520
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2521
   * Given a node handle and an expanded type ID, get the index of the node's
7f561c08de6b Initial load
duke
parents:
diff changeset
  2522
   * attribute of that type, if any.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2523
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2524
   * @param nodeHandle int Handle of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2525
   * @param attType int expanded type ID of the required attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2526
   * @return Handle of attribute of the required type, or DTM.NULL to indicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  2527
   * none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2528
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2529
  protected final int getTypedAttribute(int nodeHandle, int attType)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2530
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2531
7f561c08de6b Initial load
duke
parents:
diff changeset
  2532
    int nodeID = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2533
7f561c08de6b Initial load
duke
parents:
diff changeset
  2534
    if (nodeID == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2535
      return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2536
7f561c08de6b Initial load
duke
parents:
diff changeset
  2537
    int type = _type2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2538
7f561c08de6b Initial load
duke
parents:
diff changeset
  2539
    if (DTM.ELEMENT_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2540
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2541
      int expType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2542
      while (true)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2543
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2544
        nodeID++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2545
        expType = _exptype2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2546
7f561c08de6b Initial load
duke
parents:
diff changeset
  2547
        if (expType != DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2548
          type = m_extendedTypes[expType].getNodeType();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2549
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2550
          return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2551
7f561c08de6b Initial load
duke
parents:
diff changeset
  2552
        if (type == DTM.ATTRIBUTE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2553
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2554
          if (expType == attType) return makeNodeHandle(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2555
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2556
        else if (DTM.NAMESPACE_NODE != type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2557
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2558
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2559
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2560
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2561
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2562
7f561c08de6b Initial load
duke
parents:
diff changeset
  2563
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2564
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2565
7f561c08de6b Initial load
duke
parents:
diff changeset
  2566
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2567
   * Override SAX2DTM.getLocalName() in SAX2DTM2.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2568
   * <p>Processing for PIs is different.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2569
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2570
   * Given a node handle, return its XPath- style localname. (As defined in
7f561c08de6b Initial load
duke
parents:
diff changeset
  2571
   * Namespaces, this is the portion of the name after any colon character).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2572
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2573
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2574
   * @return String Local name of this node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2575
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2576
  public String getLocalName(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2577
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2578
    int expType = _exptype(makeNodeIdentity(nodeHandle));
7f561c08de6b Initial load
duke
parents:
diff changeset
  2579
7f561c08de6b Initial load
duke
parents:
diff changeset
  2580
    if (expType == DTM.PROCESSING_INSTRUCTION_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2581
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2582
      int dataIndex = _dataOrQName(makeNodeIdentity(nodeHandle));
7f561c08de6b Initial load
duke
parents:
diff changeset
  2583
      dataIndex = m_data.elementAt(-dataIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2584
      return m_valuesOrPrefixes.indexToString(dataIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2585
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2586
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2587
      return m_expandedNameTable.getLocalName(expType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2588
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2589
7f561c08de6b Initial load
duke
parents:
diff changeset
  2590
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2591
   * The optimized version of SAX2DTM.getNodeNameX().
7f561c08de6b Initial load
duke
parents:
diff changeset
  2592
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2593
   * Given a node handle, return the XPath node name. This should be the name
7f561c08de6b Initial load
duke
parents:
diff changeset
  2594
   * as described by the XPath data model, NOT the DOM- style name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2595
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2596
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2597
   * @return String Name of this node, which may be an empty string.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2598
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2599
  public final String getNodeNameX(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2600
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2601
7f561c08de6b Initial load
duke
parents:
diff changeset
  2602
    int nodeID = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2603
    int eType = _exptype2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2604
7f561c08de6b Initial load
duke
parents:
diff changeset
  2605
    if (eType == DTM.PROCESSING_INSTRUCTION_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2606
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2607
      int dataIndex = _dataOrQName(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2608
      dataIndex = m_data.elementAt(-dataIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2609
      return m_valuesOrPrefixes.indexToString(dataIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2610
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2611
7f561c08de6b Initial load
duke
parents:
diff changeset
  2612
    final ExtendedType extType = m_extendedTypes[eType];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2613
7f561c08de6b Initial load
duke
parents:
diff changeset
  2614
    if (extType.getNamespace().length() == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2615
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2616
      return extType.getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2617
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2618
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2619
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2620
      int qnameIndex = m_dataOrQName.elementAt(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2621
7f561c08de6b Initial load
duke
parents:
diff changeset
  2622
      if (qnameIndex == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2623
        return extType.getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2624
7f561c08de6b Initial load
duke
parents:
diff changeset
  2625
      if (qnameIndex < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2626
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2627
        qnameIndex = -qnameIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2628
        qnameIndex = m_data.elementAt(qnameIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2629
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2630
7f561c08de6b Initial load
duke
parents:
diff changeset
  2631
      return m_valuesOrPrefixes.indexToString(qnameIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2632
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2633
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2634
7f561c08de6b Initial load
duke
parents:
diff changeset
  2635
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2636
   * The optimized version of SAX2DTM.getNodeName().
7f561c08de6b Initial load
duke
parents:
diff changeset
  2637
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2638
   * Given a node handle, return its DOM-style node name. This will include
7f561c08de6b Initial load
duke
parents:
diff changeset
  2639
   * names such as #text or #document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2640
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2641
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2642
   * @return String Name of this node, which may be an empty string.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2643
   * %REVIEW% Document when empty string is possible...
7f561c08de6b Initial load
duke
parents:
diff changeset
  2644
   * %REVIEW-COMMENT% It should never be empty, should it?
7f561c08de6b Initial load
duke
parents:
diff changeset
  2645
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2646
  public String getNodeName(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2647
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2648
7f561c08de6b Initial load
duke
parents:
diff changeset
  2649
    int nodeID = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2650
    int eType = _exptype2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2651
7f561c08de6b Initial load
duke
parents:
diff changeset
  2652
    final ExtendedType extType = m_extendedTypes[eType];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2653
    if (extType.getNamespace().length() == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2654
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2655
      int type = extType.getNodeType();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2656
7f561c08de6b Initial load
duke
parents:
diff changeset
  2657
      String localName = extType.getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2658
      if (type == DTM.NAMESPACE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2659
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2660
        if (localName.length() == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2661
          return "xmlns";
7f561c08de6b Initial load
duke
parents:
diff changeset
  2662
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2663
          return "xmlns:" + localName;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2664
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2665
      else if (type == DTM.PROCESSING_INSTRUCTION_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2666
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2667
        int dataIndex = _dataOrQName(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2668
        dataIndex = m_data.elementAt(-dataIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2669
        return m_valuesOrPrefixes.indexToString(dataIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2670
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2671
      else if (localName.length() == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2672
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2673
        return getFixedNames(type);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2674
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2675
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2676
        return localName;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2677
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2678
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2679
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2680
      int qnameIndex = m_dataOrQName.elementAt(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2681
7f561c08de6b Initial load
duke
parents:
diff changeset
  2682
      if (qnameIndex == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2683
        return extType.getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2684
7f561c08de6b Initial load
duke
parents:
diff changeset
  2685
      if (qnameIndex < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2686
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2687
        qnameIndex = -qnameIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2688
        qnameIndex = m_data.elementAt(qnameIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2689
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2690
7f561c08de6b Initial load
duke
parents:
diff changeset
  2691
      return m_valuesOrPrefixes.indexToString(qnameIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2692
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2693
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2694
7f561c08de6b Initial load
duke
parents:
diff changeset
  2695
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2696
   * Override SAX2DTM.getStringValue(int)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2697
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2698
   * This method is only used by Xalan-J Interpretive. It is not used by XSLTC.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2699
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2700
   * If the caller supplies an XMLStringFactory, the getStringValue() interface
7f561c08de6b Initial load
duke
parents:
diff changeset
  2701
   * in SAX2DTM will be called. Otherwise just calls getStringValueX() and
7f561c08de6b Initial load
duke
parents:
diff changeset
  2702
   * wraps the returned String in an XMLString.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2703
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2704
   * Get the string-value of a node as a String object
7f561c08de6b Initial load
duke
parents:
diff changeset
  2705
   * (see http://www.w3.org/TR/xpath#data-model
7f561c08de6b Initial load
duke
parents:
diff changeset
  2706
   * for the definition of a node's string-value).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2707
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2708
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2709
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2710
   * @return A string object that represents the string-value of the given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2711
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2712
  public XMLString getStringValue(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2713
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2714
    int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2715
    if (identity == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2716
      return EMPTY_XML_STR;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2717
7f561c08de6b Initial load
duke
parents:
diff changeset
  2718
    int type= _type2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2719
7f561c08de6b Initial load
duke
parents:
diff changeset
  2720
    if (type == DTM.ELEMENT_NODE || type == DTM.DOCUMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2721
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2722
      int startNode = identity;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2723
      identity = _firstch2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2724
      if (DTM.NULL != identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2725
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2726
        int offset = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2727
        int length = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2728
7f561c08de6b Initial load
duke
parents:
diff changeset
  2729
        do
7f561c08de6b Initial load
duke
parents:
diff changeset
  2730
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2731
          type = _exptype2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2732
7f561c08de6b Initial load
duke
parents:
diff changeset
  2733
          if (type == DTM.TEXT_NODE || type == DTM.CDATA_SECTION_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2734
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2735
            int dataIndex = m_dataOrQName.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2736
            if (dataIndex >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2737
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2738
              if (-1 == offset)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2739
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2740
                offset = dataIndex >>> TEXT_LENGTH_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2741
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2742
7f561c08de6b Initial load
duke
parents:
diff changeset
  2743
              length += dataIndex & TEXT_LENGTH_MAX;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2744
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2745
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2746
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2747
              if (-1 == offset)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2748
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2749
                offset = m_data.elementAt(-dataIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2750
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2751
7f561c08de6b Initial load
duke
parents:
diff changeset
  2752
              length += m_data.elementAt(-dataIndex + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2753
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2754
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2755
7f561c08de6b Initial load
duke
parents:
diff changeset
  2756
          identity++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2757
        } while (_parent2(identity) >= startNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2758
7f561c08de6b Initial load
duke
parents:
diff changeset
  2759
        if (length > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2760
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2761
          if (m_xstrf != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2762
            return m_xstrf.newstr(m_chars, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2763
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2764
            return new XMLStringDefault(m_chars.getString(offset, length));
7f561c08de6b Initial load
duke
parents:
diff changeset
  2765
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2766
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2767
          return EMPTY_XML_STR;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2768
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2769
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2770
        return EMPTY_XML_STR;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2771
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2772
    else if (DTM.TEXT_NODE == type || DTM.CDATA_SECTION_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2773
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2774
      int dataIndex = m_dataOrQName.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2775
      if (dataIndex >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2776
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2777
        if (m_xstrf != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2778
          return m_xstrf.newstr(m_chars, dataIndex >>> TEXT_LENGTH_BITS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2779
                         dataIndex & TEXT_LENGTH_MAX);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2780
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2781
          return new XMLStringDefault(m_chars.getString(dataIndex >>> TEXT_LENGTH_BITS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2782
                                      dataIndex & TEXT_LENGTH_MAX));
7f561c08de6b Initial load
duke
parents:
diff changeset
  2783
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2784
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2785
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2786
        if (m_xstrf != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2787
          return m_xstrf.newstr(m_chars, m_data.elementAt(-dataIndex),
7f561c08de6b Initial load
duke
parents:
diff changeset
  2788
                                m_data.elementAt(-dataIndex+1));
7f561c08de6b Initial load
duke
parents:
diff changeset
  2789
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2790
          return new XMLStringDefault(m_chars.getString(m_data.elementAt(-dataIndex),
7f561c08de6b Initial load
duke
parents:
diff changeset
  2791
                                   m_data.elementAt(-dataIndex+1)));
7f561c08de6b Initial load
duke
parents:
diff changeset
  2792
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2793
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2794
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2795
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2796
      int dataIndex = m_dataOrQName.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2797
7f561c08de6b Initial load
duke
parents:
diff changeset
  2798
      if (dataIndex < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2799
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2800
        dataIndex = -dataIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2801
        dataIndex = m_data.elementAt(dataIndex + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2802
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2803
7f561c08de6b Initial load
duke
parents:
diff changeset
  2804
      if (m_xstrf != null)
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2805
        return m_xstrf.newstr(m_values.get(dataIndex));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2806
      else
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2807
        return new XMLStringDefault(m_values.get(dataIndex));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2808
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2809
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2810
7f561c08de6b Initial load
duke
parents:
diff changeset
  2811
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2812
   * The optimized version of SAX2DTM.getStringValue(int).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2813
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2814
   * %OPT% This is one of the most often used interfaces. Performance is
7f561c08de6b Initial load
duke
parents:
diff changeset
  2815
   * critical here. This one is different from SAX2DTM.getStringValue(int) in
7f561c08de6b Initial load
duke
parents:
diff changeset
  2816
   * that it returns a String instead of a XMLString.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2817
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2818
   * Get the string- value of a node as a String object (see http: //www. w3.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2819
   * org/TR/xpath#data- model for the definition of a node's string- value).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2820
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2821
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2822
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2823
   * @return A string object that represents the string-value of the given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2824
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2825
  public final String getStringValueX(final int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2826
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2827
    int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2828
    if (identity == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2829
      return EMPTY_STR;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2830
7f561c08de6b Initial load
duke
parents:
diff changeset
  2831
    int type= _type2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2832
7f561c08de6b Initial load
duke
parents:
diff changeset
  2833
    if (type == DTM.ELEMENT_NODE || type == DTM.DOCUMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2834
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2835
      int startNode = identity;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2836
      identity = _firstch2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2837
      if (DTM.NULL != identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2838
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2839
        int offset = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2840
        int length = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2841
7f561c08de6b Initial load
duke
parents:
diff changeset
  2842
        do
7f561c08de6b Initial load
duke
parents:
diff changeset
  2843
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2844
          type = _exptype2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2845
7f561c08de6b Initial load
duke
parents:
diff changeset
  2846
          if (type == DTM.TEXT_NODE || type == DTM.CDATA_SECTION_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2847
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2848
            int dataIndex = m_dataOrQName.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2849
            if (dataIndex >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2850
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2851
              if (-1 == offset)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2852
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2853
                offset = dataIndex >>> TEXT_LENGTH_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2854
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2855
7f561c08de6b Initial load
duke
parents:
diff changeset
  2856
              length += dataIndex & TEXT_LENGTH_MAX;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2857
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2858
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2859
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2860
              if (-1 == offset)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2861
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2862
                offset = m_data.elementAt(-dataIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2863
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2864
7f561c08de6b Initial load
duke
parents:
diff changeset
  2865
              length += m_data.elementAt(-dataIndex + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2866
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2867
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2868
7f561c08de6b Initial load
duke
parents:
diff changeset
  2869
          identity++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2870
        } while (_parent2(identity) >= startNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2871
7f561c08de6b Initial load
duke
parents:
diff changeset
  2872
        if (length > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2873
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2874
          return m_chars.getString(offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2875
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2876
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2877
          return EMPTY_STR;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2878
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2879
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2880
        return EMPTY_STR;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2881
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2882
    else if (DTM.TEXT_NODE == type || DTM.CDATA_SECTION_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2883
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2884
      int dataIndex = m_dataOrQName.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2885
      if (dataIndex >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2886
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2887
        return m_chars.getString(dataIndex >>> TEXT_LENGTH_BITS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2888
                                  dataIndex & TEXT_LENGTH_MAX);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2889
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2890
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2891
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2892
        return m_chars.getString(m_data.elementAt(-dataIndex),
7f561c08de6b Initial load
duke
parents:
diff changeset
  2893
                                  m_data.elementAt(-dataIndex+1));
7f561c08de6b Initial load
duke
parents:
diff changeset
  2894
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2895
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2896
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2897
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2898
      int dataIndex = m_dataOrQName.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2899
7f561c08de6b Initial load
duke
parents:
diff changeset
  2900
      if (dataIndex < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2901
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2902
        dataIndex = -dataIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2903
        dataIndex = m_data.elementAt(dataIndex + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2904
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2905
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  2906
      return m_values.get(dataIndex);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2907
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2908
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2909
7f561c08de6b Initial load
duke
parents:
diff changeset
  2910
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2911
   * Returns the string value of the entire tree
7f561c08de6b Initial load
duke
parents:
diff changeset
  2912
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2913
  public String getStringValue()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2914
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2915
    int child = _firstch2(ROOTNODE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2916
    if (child == DTM.NULL) return EMPTY_STR;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2917
7f561c08de6b Initial load
duke
parents:
diff changeset
  2918
    // optimization: only create StringBuffer if > 1 child
7f561c08de6b Initial load
duke
parents:
diff changeset
  2919
    if ((_exptype2(child) == DTM.TEXT_NODE) && (_nextsib2(child) == DTM.NULL))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2920
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2921
      int dataIndex = m_dataOrQName.elementAt(child);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2922
      if (dataIndex >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2923
        return m_chars.getString(dataIndex >>> TEXT_LENGTH_BITS, dataIndex & TEXT_LENGTH_MAX);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2924
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2925
        return m_chars.getString(m_data.elementAt(-dataIndex),
7f561c08de6b Initial load
duke
parents:
diff changeset
  2926
                                  m_data.elementAt(-dataIndex + 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
  2927
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2928
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2929
      return getStringValueX(getDocument());
7f561c08de6b Initial load
duke
parents:
diff changeset
  2930
7f561c08de6b Initial load
duke
parents:
diff changeset
  2931
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2932
7f561c08de6b Initial load
duke
parents:
diff changeset
  2933
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2934
   * The optimized version of SAX2DTM.dispatchCharactersEvents(int, ContentHandler, boolean).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2935
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2936
   * Directly call the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2937
   * characters method on the passed ContentHandler for the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2938
   * string-value of the given node (see http://www.w3.org/TR/xpath#data-model
7f561c08de6b Initial load
duke
parents:
diff changeset
  2939
   * for the definition of a node's string-value). Multiple calls to the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2940
   * ContentHandler's characters methods may well occur for a single call to
7f561c08de6b Initial load
duke
parents:
diff changeset
  2941
   * this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2942
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2943
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2944
   * @param ch A non-null reference to a ContentHandler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2945
   * @param normalize true if the content should be normalized according to
7f561c08de6b Initial load
duke
parents:
diff changeset
  2946
   * the rules for the XPath
7f561c08de6b Initial load
duke
parents:
diff changeset
  2947
   * <a href="http://www.w3.org/TR/xpath#function-normalize-space">normalize-space</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2948
   * function.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2949
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2950
   * @throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2951
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2952
  public final void dispatchCharactersEvents(int nodeHandle, ContentHandler ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2953
                                             boolean normalize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2954
          throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2955
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2956
7f561c08de6b Initial load
duke
parents:
diff changeset
  2957
    int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2958
7f561c08de6b Initial load
duke
parents:
diff changeset
  2959
    if (identity == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2960
      return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2961
7f561c08de6b Initial load
duke
parents:
diff changeset
  2962
    int type = _type2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2963
7f561c08de6b Initial load
duke
parents:
diff changeset
  2964
    if (type == DTM.ELEMENT_NODE || type == DTM.DOCUMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2965
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2966
      int startNode = identity;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2967
      identity = _firstch2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2968
      if (DTM.NULL != identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2969
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2970
        int offset = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2971
        int length = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2972
7f561c08de6b Initial load
duke
parents:
diff changeset
  2973
        do
7f561c08de6b Initial load
duke
parents:
diff changeset
  2974
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2975
          type = _exptype2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2976
7f561c08de6b Initial load
duke
parents:
diff changeset
  2977
          if (type == DTM.TEXT_NODE || type == DTM.CDATA_SECTION_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2978
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2979
            int dataIndex = m_dataOrQName.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2980
7f561c08de6b Initial load
duke
parents:
diff changeset
  2981
            if (dataIndex >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2982
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2983
              if (-1 == offset)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2984
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2985
                offset = dataIndex >>> TEXT_LENGTH_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2986
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2987
7f561c08de6b Initial load
duke
parents:
diff changeset
  2988
              length += dataIndex & TEXT_LENGTH_MAX;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2989
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2990
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2991
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2992
              if (-1 == offset)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2993
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2994
                offset = m_data.elementAt(-dataIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2995
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2996
7f561c08de6b Initial load
duke
parents:
diff changeset
  2997
              length += m_data.elementAt(-dataIndex + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2998
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2999
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3000
7f561c08de6b Initial load
duke
parents:
diff changeset
  3001
          identity++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3002
        } while (_parent2(identity) >= startNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3003
7f561c08de6b Initial load
duke
parents:
diff changeset
  3004
        if (length > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3005
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3006
          if(normalize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3007
            m_chars.sendNormalizedSAXcharacters(ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3008
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3009
            m_chars.sendSAXcharacters(ch, offset, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3010
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3011
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3012
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3013
    else if (DTM.TEXT_NODE == type || DTM.CDATA_SECTION_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3014
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3015
      int dataIndex = m_dataOrQName.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3016
7f561c08de6b Initial load
duke
parents:
diff changeset
  3017
      if (dataIndex >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3018
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3019
        if (normalize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3020
          m_chars.sendNormalizedSAXcharacters(ch, dataIndex >>> TEXT_LENGTH_BITS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3021
                                              dataIndex & TEXT_LENGTH_MAX);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3022
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3023
          m_chars.sendSAXcharacters(ch, dataIndex >>> TEXT_LENGTH_BITS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3024
                                    dataIndex & TEXT_LENGTH_MAX);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3025
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3026
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3027
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3028
        if (normalize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3029
          m_chars.sendNormalizedSAXcharacters(ch, m_data.elementAt(-dataIndex),
7f561c08de6b Initial load
duke
parents:
diff changeset
  3030
                                              m_data.elementAt(-dataIndex+1));
7f561c08de6b Initial load
duke
parents:
diff changeset
  3031
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3032
          m_chars.sendSAXcharacters(ch, m_data.elementAt(-dataIndex),
7f561c08de6b Initial load
duke
parents:
diff changeset
  3033
                                    m_data.elementAt(-dataIndex+1));
7f561c08de6b Initial load
duke
parents:
diff changeset
  3034
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3035
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3036
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3037
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3038
      int dataIndex = m_dataOrQName.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3039
7f561c08de6b Initial load
duke
parents:
diff changeset
  3040
      if (dataIndex < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3041
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3042
        dataIndex = -dataIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3043
        dataIndex = m_data.elementAt(dataIndex + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3044
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3045
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  3046
      String str = m_values.get(dataIndex);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3047
7f561c08de6b Initial load
duke
parents:
diff changeset
  3048
      if(normalize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3049
        FastStringBuffer.sendNormalizedSAXcharacters(str.toCharArray(),
7f561c08de6b Initial load
duke
parents:
diff changeset
  3050
                                                     0, str.length(), ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3051
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3052
        ch.characters(str.toCharArray(), 0, str.length());
7f561c08de6b Initial load
duke
parents:
diff changeset
  3053
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3054
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3055
7f561c08de6b Initial load
duke
parents:
diff changeset
  3056
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3057
   * Given a node handle, return its node value. This is mostly
7f561c08de6b Initial load
duke
parents:
diff changeset
  3058
   * as defined by the DOM, but may ignore some conveniences.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3059
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  3060
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  3061
   * @param nodeHandle The node id.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3062
   * @return String Value of this node, or null if not
7f561c08de6b Initial load
duke
parents:
diff changeset
  3063
   * meaningful for this node type.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3064
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3065
  public String getNodeValue(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3066
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3067
7f561c08de6b Initial load
duke
parents:
diff changeset
  3068
    int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3069
    int type = _type2(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3070
7f561c08de6b Initial load
duke
parents:
diff changeset
  3071
    if (type == DTM.TEXT_NODE || type == DTM.CDATA_SECTION_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3072
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3073
      int dataIndex = _dataOrQName(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3074
      if (dataIndex > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3075
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3076
        return m_chars.getString(dataIndex >>> TEXT_LENGTH_BITS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3077
                                  dataIndex & TEXT_LENGTH_MAX);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3078
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3079
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3080
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3081
        return m_chars.getString(m_data.elementAt(-dataIndex),
7f561c08de6b Initial load
duke
parents:
diff changeset
  3082
                                  m_data.elementAt(-dataIndex+1));
7f561c08de6b Initial load
duke
parents:
diff changeset
  3083
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3084
    }
30989
1f747213d6c9 8081392: getNodeValue should return 'null' value for Element nodes
aefimov
parents: 25868
diff changeset
  3085
    else if (DTM.ELEMENT_NODE == type || DTM.DOCUMENT_FRAGMENT_NODE == type
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3086
             || DTM.DOCUMENT_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3087
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3088
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3089
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3090
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3091
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3092
      int dataIndex = m_dataOrQName.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3093
7f561c08de6b Initial load
duke
parents:
diff changeset
  3094
      if (dataIndex < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3095
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3096
        dataIndex = -dataIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3097
        dataIndex = m_data.elementAt(dataIndex + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3098
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3099
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  3100
      return m_values.get(dataIndex);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3101
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3102
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3103
7f561c08de6b Initial load
duke
parents:
diff changeset
  3104
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3105
     * Copy the String value of a Text node to a SerializationHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
  3106
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3107
    protected final void copyTextNode(final int nodeID, SerializationHandler handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3108
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  3109
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3110
        if (nodeID != DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3111
            int dataIndex = m_dataOrQName.elementAt(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3112
            if (dataIndex >= 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3113
                m_chars.sendSAXcharacters(handler,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3114
                                          dataIndex >>> TEXT_LENGTH_BITS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3115
                                          dataIndex & TEXT_LENGTH_MAX);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3116
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3117
                m_chars.sendSAXcharacters(handler, m_data.elementAt(-dataIndex),
7f561c08de6b Initial load
duke
parents:
diff changeset
  3118
                                          m_data.elementAt(-dataIndex+1));
7f561c08de6b Initial load
duke
parents:
diff changeset
  3119
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3120
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3121
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3122
7f561c08de6b Initial load
duke
parents:
diff changeset
  3123
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3124
     * Copy an Element node to a SerializationHandler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3125
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  3126
     * @param nodeID The node identity
7f561c08de6b Initial load
duke
parents:
diff changeset
  3127
     * @param exptype The expanded type of the Element node
7f561c08de6b Initial load
duke
parents:
diff changeset
  3128
     * @param handler The SerializationHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
  3129
     * @return The qualified name of the Element node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3130
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3131
    protected final String copyElement(int nodeID, int exptype,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3132
                               SerializationHandler handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3133
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  3134
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3135
        final ExtendedType extType = m_extendedTypes[exptype];
7f561c08de6b Initial load
duke
parents:
diff changeset
  3136
        String uri = extType.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3137
        String name = extType.getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3138
7f561c08de6b Initial load
duke
parents:
diff changeset
  3139
        if (uri.length() == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3140
            handler.startElement(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3141
            return name;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  3142
        } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3143
            int qnameIndex = m_dataOrQName.elementAt(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3144
7f561c08de6b Initial load
duke
parents:
diff changeset
  3145
            if (qnameIndex == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3146
                handler.startElement(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3147
                handler.namespaceAfterStartElement(EMPTY_STR, uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3148
                return name;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3149
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3150
7f561c08de6b Initial load
duke
parents:
diff changeset
  3151
            if (qnameIndex < 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3152
                qnameIndex = -qnameIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3153
                qnameIndex = m_data.elementAt(qnameIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3154
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3155
7f561c08de6b Initial load
duke
parents:
diff changeset
  3156
            String qName = m_valuesOrPrefixes.indexToString(qnameIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3157
            handler.startElement(qName);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3158
            int prefixIndex = qName.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
  3159
            String prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3160
            if (prefixIndex > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3161
                prefix = qName.substring(0, prefixIndex);
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  3162
            } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3163
                prefix = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3164
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3165
            handler.namespaceAfterStartElement(prefix, uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3166
            return qName;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3167
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3168
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3169
7f561c08de6b Initial load
duke
parents:
diff changeset
  3170
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3171
     * Copy  namespace nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3172
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  3173
     * @param nodeID The Element node identity
7f561c08de6b Initial load
duke
parents:
diff changeset
  3174
     * @param handler The SerializationHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
  3175
     * @param inScope  true if all namespaces in scope should be copied,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3176
     *  false if only the namespace declarations should be copied.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3177
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3178
    protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3179
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  3180
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3181
        // %OPT% Optimization for documents which does not have any explicit
7f561c08de6b Initial load
duke
parents:
diff changeset
  3182
        // namespace nodes. For these documents, there is an implicit
7f561c08de6b Initial load
duke
parents:
diff changeset
  3183
        // namespace node (xmlns:xml="http://www.w3.org/XML/1998/namespace")
7f561c08de6b Initial load
duke
parents:
diff changeset
  3184
        // declared on the root element node. In this case, there is no
7f561c08de6b Initial load
duke
parents:
diff changeset
  3185
        // need to do namespace copying. We can safely return without
7f561c08de6b Initial load
duke
parents:
diff changeset
  3186
        // doing anything.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3187
        if (m_namespaceDeclSetElements != null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
  3188
            m_namespaceDeclSetElements.size() == 1 &&
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  3189
            m_namespaceDeclSets != null && (m_namespaceDeclSets.get(0)).size() == 1)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3190
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3191
7f561c08de6b Initial load
duke
parents:
diff changeset
  3192
        SuballocatedIntVector nsContext = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3193
        int nextNSNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3194
7f561c08de6b Initial load
duke
parents:
diff changeset
  3195
        // Find the first namespace node
7f561c08de6b Initial load
duke
parents:
diff changeset
  3196
        if (inScope) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3197
            nsContext = findNamespaceContext(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3198
            if (nsContext == null || nsContext.size() < 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3199
                return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3200
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3201
                nextNSNode = makeNodeIdentity(nsContext.elementAt(0));
7f561c08de6b Initial load
duke
parents:
diff changeset
  3202
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3203
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3204
            nextNSNode = getNextNamespaceNode2(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3205
7f561c08de6b Initial load
duke
parents:
diff changeset
  3206
        int nsIndex = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3207
        while (nextNSNode != DTM.NULL) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3208
            // Retrieve the name of the namespace node
7f561c08de6b Initial load
duke
parents:
diff changeset
  3209
            int eType = _exptype2(nextNSNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3210
            String nodeName = m_extendedTypes[eType].getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3211
7f561c08de6b Initial load
duke
parents:
diff changeset
  3212
            // Retrieve the node value of the namespace node
7f561c08de6b Initial load
duke
parents:
diff changeset
  3213
            int dataIndex = m_dataOrQName.elementAt(nextNSNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3214
7f561c08de6b Initial load
duke
parents:
diff changeset
  3215
            if (dataIndex < 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3216
                dataIndex = -dataIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3217
                dataIndex = m_data.elementAt(dataIndex + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3218
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3219
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  3220
            String nodeValue = m_values.get(dataIndex);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3221
7f561c08de6b Initial load
duke
parents:
diff changeset
  3222
            handler.namespaceAfterStartElement(nodeName, nodeValue);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3223
7f561c08de6b Initial load
duke
parents:
diff changeset
  3224
            if (inScope) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3225
                if (nsIndex < nsContext.size()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3226
                    nextNSNode = makeNodeIdentity(nsContext.elementAt(nsIndex));
7f561c08de6b Initial load
duke
parents:
diff changeset
  3227
                    nsIndex++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3228
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3229
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3230
                    return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3231
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3232
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3233
                nextNSNode = getNextNamespaceNode2(nextNSNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3234
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3235
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3236
7f561c08de6b Initial load
duke
parents:
diff changeset
  3237
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3238
     * Return the next namespace node following the given base node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3239
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  3240
     * @baseID The node identity of the base node, which can be an
7f561c08de6b Initial load
duke
parents:
diff changeset
  3241
     * element, attribute or namespace node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3242
     * @return The namespace node immediately following the base node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3243
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3244
    protected final int getNextNamespaceNode2(int baseID) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3245
        int type;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3246
        while ((type = _type2(++baseID)) == DTM.ATTRIBUTE_NODE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3247
7f561c08de6b Initial load
duke
parents:
diff changeset
  3248
        if (type == DTM.NAMESPACE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3249
            return baseID;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3250
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  3251
            return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3252
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3253
7f561c08de6b Initial load
duke
parents:
diff changeset
  3254
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3255
     * Copy  attribute nodes from an element .
7f561c08de6b Initial load
duke
parents:
diff changeset
  3256
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  3257
     * @param nodeID The Element node identity
7f561c08de6b Initial load
duke
parents:
diff changeset
  3258
     * @param handler The SerializationHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
  3259
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3260
    protected final void copyAttributes(final int nodeID, SerializationHandler handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3261
        throws SAXException{
7f561c08de6b Initial load
duke
parents:
diff changeset
  3262
7f561c08de6b Initial load
duke
parents:
diff changeset
  3263
       for(int current = getFirstAttributeIdentity(nodeID); current != DTM.NULL; current = getNextAttributeIdentity(current)){
7f561c08de6b Initial load
duke
parents:
diff changeset
  3264
            int eType = _exptype2(current);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3265
            copyAttribute(current, eType, handler);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3266
       }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3267
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3268
7f561c08de6b Initial load
duke
parents:
diff changeset
  3269
7f561c08de6b Initial load
duke
parents:
diff changeset
  3270
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3271
     * Copy an Attribute node to a SerializationHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
  3272
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  3273
     * @param nodeID The node identity
7f561c08de6b Initial load
duke
parents:
diff changeset
  3274
     * @param exptype The expanded type of the Element node
7f561c08de6b Initial load
duke
parents:
diff changeset
  3275
     * @param handler The SerializationHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
  3276
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3277
    protected final void copyAttribute(int nodeID, int exptype,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3278
        SerializationHandler handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3279
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  3280
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3281
        final ExtendedType extType = m_extendedTypes[exptype];
7f561c08de6b Initial load
duke
parents:
diff changeset
  3282
        final String uri = extType.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3283
        final String localName = extType.getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3284
7f561c08de6b Initial load
duke
parents:
diff changeset
  3285
        String prefix = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3286
        String qname = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3287
        int dataIndex = _dataOrQName(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3288
        int valueIndex = dataIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3289
            if (dataIndex <= 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3290
                int prefixIndex = m_data.elementAt(-dataIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3291
                valueIndex = m_data.elementAt(-dataIndex+1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3292
                qname = m_valuesOrPrefixes.indexToString(prefixIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3293
                int colonIndex = qname.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
  3294
                if (colonIndex > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3295
                    prefix = qname.substring(0, colonIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3296
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3297
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3298
            if (uri.length() != 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3299
                handler.namespaceAfterStartElement(prefix, uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3300
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3301
7f561c08de6b Initial load
duke
parents:
diff changeset
  3302
        String nodeName = (prefix != null) ? qname : localName;
43123
dd12865718f3 8169631: [JAXP] XALAN: transformation of XML via namespace-unaware SAX input yields a different result than namespace-unaware DOM input
clanger
parents: 30989
diff changeset
  3303
        String nodeValue = m_values.get(valueIndex);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3304
7f561c08de6b Initial load
duke
parents:
diff changeset
  3305
        handler.addAttribute(uri, localName, nodeName, "CDATA", nodeValue);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3306
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3307
7f561c08de6b Initial load
duke
parents:
diff changeset
  3308
}