src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/DTMDefaultBase.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) 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
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
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
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    21
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xml.internal.dtm.ref;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.xml.internal.dtm.*;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    25
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
    26
import com.sun.org.apache.xml.internal.res.XMLMessages;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xml.internal.utils.BoolStack;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    28
import com.sun.org.apache.xml.internal.utils.SuballocatedIntVector;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xml.internal.utils.XMLString;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xml.internal.utils.XMLStringFactory;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import java.io.*; // for dumpDTM
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    32
import java.util.Vector;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    33
import javax.xml.transform.Source;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * The <code>DTMDefaultBase</code> class serves as a helper base for DTMs.
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * It sets up structures for navigation and type, while leaving data
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * management and construction to the derived classes.
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
public abstract class DTMDefaultBase implements DTM
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
    static final boolean JJK_DEBUG=false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
  // This constant is likely to be removed in the future. Use the
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
  // getDocument() method instead of ROOTNODE to get at the root
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
  // node of a DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
  /** The identity of the root node. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
  public static final int ROOTNODE = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
   * The number of nodes, which is also used to determine the next
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
   *  node index.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
  protected int m_size = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
  /** The expanded names, one array element for each node. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
  protected SuballocatedIntVector m_exptype;
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
  /** First child values, one array element for each node. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
  protected SuballocatedIntVector m_firstch;
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
  /** Next sibling values, one array element for each node. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
  protected SuballocatedIntVector m_nextsib;
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
  /** Previous sibling values, one array element for each node. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
  protected SuballocatedIntVector m_prevsib;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
  /** Previous sibling values, one array element for each node. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  protected SuballocatedIntVector m_parent;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
  /** Vector of SuballocatedIntVectors of NS decl sets */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    72
  protected Vector<SuballocatedIntVector> m_namespaceDeclSets = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
  /** SuballocatedIntVector  of elements at which corresponding
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
   * namespaceDeclSets were defined */
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
  protected SuballocatedIntVector m_namespaceDeclSetElements = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   * These hold indexes to elements based on namespace and local name.
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   * The base lookup is the the namespace.  The second lookup is the local
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   * name, and the last array contains the the first free element
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   * at the start, and the list of element handles following.
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
  protected int[][][] m_elemIndexes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
  /** The default block size of the node arrays */
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  public static final int DEFAULT_BLOCKSIZE = 512;  // favor small docs.
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
  /** The number of blocks for the node arrays */
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
  public static final int DEFAULT_NUMBLOCKS = 32;
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
  /** The number of blocks used for small documents & RTFs */
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
  public static final int DEFAULT_NUMBLOCKS_SMALL = 4;
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
  /** The block size of the node arrays */
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
  //protected final int m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
   * The value to use when the information has not been built yet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
  protected static final int NOTPROCESSED = DTM.NULL - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
   * The DTM manager who "owns" this DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
  public DTMManager m_mgr;
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   * m_mgr cast to DTMManagerDefault, or null if it isn't an instance
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   * (Efficiency hook)
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
  protected DTMManagerDefault m_mgrDefault=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
  /** The document identity number(s). If we have overflowed the addressing
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
   * range of the first that was assigned to us, we may add others. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
  protected SuballocatedIntVector m_dtmIdent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
  /** The mask for the identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
      %REVIEW% Should this really be set to the _DEFAULT? What if
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
      a particular DTM wanted to use another value? */
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
  //protected final static int m_mask = DTMManager.IDENT_NODE_DEFAULT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
  /** The base URI for this document. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
  protected String m_documentBaseURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
   * The whitespace filter that enables elements to strip whitespace or not.
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
  protected DTMWSFilter m_wsfilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
  /** Flag indicating whether to strip whitespace nodes */
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
  protected boolean m_shouldStripWS = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
  /** Stack of flags indicating whether to strip whitespace nodes */
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
  protected BoolStack m_shouldStripWhitespaceStack;
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
  /** The XMLString factory for creating XMLStrings. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
  protected XMLStringFactory m_xstrf;
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
   * The table for exandedNameID lookups.  This may or may not be the same
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
   * table as is contained in the DTMManagerDefault.
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
  protected ExpandedNameTable m_expandedNameTable;
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
  /** true if indexing is turned on. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
  protected boolean m_indexing;
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
   * Construct a DTMDefaultBase object using the default block size.
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
   * @param mgr The DTMManager who owns this DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
   * @param source The object that is used to specify the construction source.
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
   * @param dtmIdentity The DTM identity ID for this DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
   * @param whiteSpaceFilter The white space filter for this DTM, which may
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
   *                         be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
   * @param xstringfactory The factory to use for creating XMLStrings.
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
   * @param doIndexing true if the caller considers it worth it to use
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
   *                   indexing schemes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
  public DTMDefaultBase(DTMManager mgr, Source source, int dtmIdentity,
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
                        DTMWSFilter whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
                        XMLStringFactory xstringfactory, boolean doIndexing)
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
    this(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory,
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
         doIndexing, DEFAULT_BLOCKSIZE, true, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
   * Construct a DTMDefaultBase object from a DOM node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
   * @param mgr The DTMManager who owns this DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
   * @param source The object that is used to specify the construction source.
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
   * @param dtmIdentity The DTM identity ID for this DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
   * @param whiteSpaceFilter The white space filter for this DTM, which may
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
   *                         be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
   * @param xstringfactory The factory to use for creating XMLStrings.
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
   * @param doIndexing true if the caller considers it worth it to use
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
   *                   indexing schemes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
   * @param blocksize The block size of the DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
   * @param usePrevsib true if we want to build the previous sibling node array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
   * @param newNameTable true if we want to use a new ExpandedNameTable for this DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
  public DTMDefaultBase(DTMManager mgr, Source source, int dtmIdentity,
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
                        DTMWSFilter whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
                        XMLStringFactory xstringfactory, boolean doIndexing,
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
                        int blocksize, boolean usePrevsib,
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
                        boolean newNameTable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    // Use smaller sizes for the internal node arrays if the block size
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    // is small.
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
    int numblocks;
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
    if (blocksize <= 64)
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
      numblocks = DEFAULT_NUMBLOCKS_SMALL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
      m_dtmIdent= new SuballocatedIntVector(4, 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
      numblocks = DEFAULT_NUMBLOCKS;
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
      m_dtmIdent= new SuballocatedIntVector(32);
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    m_exptype = new SuballocatedIntVector(blocksize, numblocks);
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
    m_firstch = new SuballocatedIntVector(blocksize, numblocks);
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    m_nextsib = new SuballocatedIntVector(blocksize, numblocks);
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    m_parent  = new SuballocatedIntVector(blocksize, numblocks);
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    // Only create the m_prevsib array if the usePrevsib flag is true.
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
    // Some DTM implementations (e.g. SAXImpl) do not need this array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    // We can save the time to build it in those cases.
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
    if (usePrevsib)
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
      m_prevsib = new SuballocatedIntVector(blocksize, numblocks);
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    m_mgr = mgr;
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    if(mgr instanceof DTMManagerDefault)
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
      m_mgrDefault=(DTMManagerDefault)mgr;
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
    m_documentBaseURI = (null != source) ? source.getSystemId() : null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    m_dtmIdent.setElementAt(dtmIdentity,0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
    m_wsfilter = whiteSpaceFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
    m_xstrf = xstringfactory;
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
    m_indexing = doIndexing;
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
    if (doIndexing)
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
      m_expandedNameTable = new ExpandedNameTable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
      // Note that this fails if we aren't talking to an instance of
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
      // DTMManagerDefault
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
      m_expandedNameTable = m_mgrDefault.getExpandedNameTable(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
    if (null != whiteSpaceFilter)
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
      m_shouldStripWhitespaceStack = new BoolStack();
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
      pushShouldStripWhitespace(false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
   * Ensure that the size of the element indexes can hold the information.
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
   * @param namespaceID Namespace ID index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
   * @param LocalNameID Local name ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
  protected void ensureSizeOfIndex(int namespaceID, int LocalNameID)
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
    if (null == m_elemIndexes)
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
      m_elemIndexes = new int[namespaceID + 20][][];
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
    else if (m_elemIndexes.length <= namespaceID)
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
      int[][][] indexes = m_elemIndexes;
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
      m_elemIndexes = new int[namespaceID + 20][][];
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
      System.arraycopy(indexes, 0, m_elemIndexes, 0, indexes.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
    int[][] localNameIndex = m_elemIndexes[namespaceID];
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
    if (null == localNameIndex)
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
      localNameIndex = new int[LocalNameID + 100][];
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
      m_elemIndexes[namespaceID] = localNameIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
    else if (localNameIndex.length <= LocalNameID)
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
      int[][] indexes = localNameIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
      localNameIndex = new int[LocalNameID + 100][];
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
      System.arraycopy(indexes, 0, localNameIndex, 0, indexes.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
      m_elemIndexes[namespaceID] = localNameIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
    int[] elemHandles = localNameIndex[LocalNameID];
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
    if (null == elemHandles)
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
      elemHandles = new int[128];
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
      localNameIndex[LocalNameID] = elemHandles;
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
      elemHandles[0] = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
    else if (elemHandles.length <= elemHandles[0] + 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
      int[] indexes = elemHandles;
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
      elemHandles = new int[elemHandles[0] + 1024];
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
      System.arraycopy(indexes, 0, elemHandles, 0, indexes.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
      localNameIndex[LocalNameID] = elemHandles;
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
   * Add a node to the element indexes. The node will not be added unless
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
   * it's an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
   * @param expandedTypeID The expanded type ID of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
   * @param identity The node identity index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
  protected void indexNode(int expandedTypeID, int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
    ExpandedNameTable ent = m_expandedNameTable;
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
    short type = ent.getType(expandedTypeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
    if (DTM.ELEMENT_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
      int namespaceID = ent.getNamespaceID(expandedTypeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
      int localNameID = ent.getLocalNameID(expandedTypeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
      ensureSizeOfIndex(namespaceID, localNameID);
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
      int[] index = m_elemIndexes[namespaceID][localNameID];
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
      index[index[0]] = identity;
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
      index[0]++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
    }
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
   * Find the first index that occurs in the list that is greater than or
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
   * equal to the given value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
   * @param list A list of integers.
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
   * @param start The start index to begin the search.
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
   * @param len The number of items to search.
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
   * @param value Find the slot that has a value that is greater than or
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
   * identical to this argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
   * @return The index in the list of the slot that is higher or identical
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
   * to the identity argument, or -1 if no node is higher or equal.
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
  protected int findGTE(int[] list, int start, int len, int value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
    int low = start;
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
    int high = start + (len - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
    int end = high;
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
    while (low <= high)
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
      int mid = (low + high) / 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
      int c = list[mid];
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
      if (c > value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
        high = mid - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
      else if (c < value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
        low = mid + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
        return mid;
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
    return (low <= end && list[low] > value) ? low : -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
   * Find the first matching element from the index at or after the
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
   * given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
   * @param nsIndex The namespace index lookup.
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
   * @param lnIndex The local name index lookup.
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
   * @param firstPotential The first potential match that is worth looking at.
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
   * @return The first node that is greater than or equal to the
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
   *         firstPotential argument, or DTM.NOTPROCESSED if not found.
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
  int findElementFromIndex(int nsIndex, int lnIndex, int firstPotential)
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
    int[][][] indexes = m_elemIndexes;
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
    if (null != indexes && nsIndex < indexes.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
      int[][] lnIndexs = indexes[nsIndex];
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
      if (null != lnIndexs && lnIndex < lnIndexs.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
        int[] elems = lnIndexs[lnIndex];
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
        if (null != elems)
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
          int pos = findGTE(elems, 1, elems[0], firstPotential);
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
          if (pos > -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
            return elems[pos];
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
    return NOTPROCESSED;
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
   * Get the next node identity value in the list, and call the iterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
   * if it hasn't been added yet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
   * @param identity The node identity (index).
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
   * @return identity+1, or DTM.NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
  protected abstract int getNextNodeIdentity(int identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
   * This method should try and build one or more nodes in the table.
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
   * @return The true if a next node is found or false if
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
   *         there are no more nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
  protected abstract boolean nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
   * Get the number of nodes that have been added.
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
   * @return the number of nodes that have been mapped.
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
  protected abstract int getNumberOfNodes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
  /** Stateless axis traversers, lazely built. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
  protected DTMAxisTraverser[] m_traversers;
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
//    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
//     * Ensure that the size of the information arrays can hold another entry
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
//     * at the given index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
//     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
//     * @param index On exit from this function, the information arrays sizes must be
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
//     * at least index+1.
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
//     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
//    protected void ensureSize(int index)
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
//    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
//        // We've cut over to Suballocated*Vector, which are self-sizing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
//    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
   * Get the simple type ID for the given node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
   * @param identity The node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
   * @return The simple type ID, or DTM.NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
  protected short _type(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
    int info = _exptype(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
    if (NULL != info)
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
      return m_expandedNameTable.getType(info);
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
      return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
   * Get the expanded type ID for the given node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
   * @param identity The node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
   * @return The expanded type ID, or DTM.NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
  protected int _exptype(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
        if (identity == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
    // Reorganized test and loop into single flow
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
    // Tiny performance improvement, saves a few bytes of code, clearer.
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
    // %OPT% Other internal getters could be treated simliarly
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
    while (identity>=m_size)
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
      if (!nextNode() && identity >= m_size)
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
    return m_exptype.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
   * Get the level in the tree for the given node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
   * @param identity The node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
   * @return The tree level, or DTM.NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
  protected int _level(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
    while (identity>=m_size)
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
      boolean isMore = nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
      if (!isMore && identity >= m_size)
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
    int i=0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
    while(NULL != (identity=_parent(identity)))
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
      ++i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
    return i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
   * Get the first child for the given node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
   * @param identity The node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
   * @return The first child identity, or DTM.NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
  protected int _firstch(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
    // Boiler-plate code for each of the _xxx functions, except for the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
    int info = (identity >= m_size) ? NOTPROCESSED : m_firstch.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
    // Check to see if the information requested has been processed, and,
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
    // if not, advance the iterator until we the information has been
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
    // processed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
    while (info == NOTPROCESSED)
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
      boolean isMore = nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
      if (identity >= m_size &&!isMore)
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
        info = m_firstch.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
        if(info == NOTPROCESSED && !isMore)
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
          return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
    return info;
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
   * Get the next sibling for the given node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
   * @param identity The node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
   * @return The next sibling identity, or DTM.NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
  protected int _nextsib(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
    // Boiler-plate code for each of the _xxx functions, except for the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
    int info = (identity >= m_size) ? NOTPROCESSED : m_nextsib.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
    // Check to see if the information requested has been processed, and,
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
    // if not, advance the iterator until we the information has been
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
    // processed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
    while (info == NOTPROCESSED)
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
      boolean isMore = nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
      if (identity >= m_size &&!isMore)
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
        info = m_nextsib.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
        if(info == NOTPROCESSED && !isMore)
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
          return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
    return info;
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
   * Get the previous sibling for the given node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
   * @param identity The node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
   * @return The previous sibling identity, or DTM.NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
  protected int _prevsib(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
    if (identity < m_size)
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
      return m_prevsib.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
    // Check to see if the information requested has been processed, and,
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
    // if not, advance the iterator until we the information has been
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
    // processed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
    while (true)
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
      boolean isMore = nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
      if (identity >= m_size && !isMore)
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
      else if (identity < m_size)
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
        return m_prevsib.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
   * Get the parent for the given node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
   * @param identity The node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
   * @return The parent identity, or DTM.NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
  protected int _parent(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
    if (identity < m_size)
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
      return m_parent.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
    // Check to see if the information requested has been processed, and,
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
    // if not, advance the iterator until we the information has been
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
    // processed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
    while (true)
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
      boolean isMore = nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
      if (identity >= m_size && !isMore)
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
      else if (identity < m_size)
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
        return m_parent.elementAt(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
   * Diagnostics function to dump the DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
  public void dumpDTM(OutputStream os)
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
      if(os==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
              File f = new File("DTMDump"+((Object)this).hashCode()+".txt");
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
              System.err.println("Dumping... "+f.getAbsolutePath());
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
              os=new FileOutputStream(f);
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
      PrintStream ps = new PrintStream(os);
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
      while (nextNode()){}
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
      int nRecords = m_size;
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
      ps.println("Total nodes: " + nRecords);
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
      for (int index = 0; index < nRecords; ++index)
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
        int i=makeNodeHandle(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
        ps.println("=========== index=" + index + " handle=" + i + " ===========");
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
        ps.println("NodeName: " + getNodeName(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
        ps.println("NodeNameX: " + getNodeNameX(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
        ps.println("LocalName: " + getLocalName(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
        ps.println("NamespaceURI: " + getNamespaceURI(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
        ps.println("Prefix: " + getPrefix(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
        int exTypeID = _exptype(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
        ps.println("Expanded Type ID: "
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
                           + Integer.toHexString(exTypeID));
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
        int type = _type(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
        String typestring;
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
        switch (type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
        case DTM.ATTRIBUTE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
          typestring = "ATTRIBUTE_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
        case DTM.CDATA_SECTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
          typestring = "CDATA_SECTION_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
        case DTM.COMMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
          typestring = "COMMENT_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
        case DTM.DOCUMENT_FRAGMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
          typestring = "DOCUMENT_FRAGMENT_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
        case DTM.DOCUMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
          typestring = "DOCUMENT_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
        case DTM.DOCUMENT_TYPE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
          typestring = "DOCUMENT_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
        case DTM.ELEMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
          typestring = "ELEMENT_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
        case DTM.ENTITY_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
          typestring = "ENTITY_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
        case DTM.ENTITY_REFERENCE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
          typestring = "ENTITY_REFERENCE_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
        case DTM.NAMESPACE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
          typestring = "NAMESPACE_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
        case DTM.NOTATION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
          typestring = "NOTATION_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
        case DTM.NULL :
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
          typestring = "NULL";
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
        case DTM.PROCESSING_INSTRUCTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
          typestring = "PROCESSING_INSTRUCTION_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
        case DTM.TEXT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
          typestring = "TEXT_NODE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
        default :
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
          typestring = "Unknown!";
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
        ps.println("Type: " + typestring);
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
        int firstChild = _firstch(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
        if (DTM.NULL == firstChild)
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
          ps.println("First child: DTM.NULL");
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
        else if (NOTPROCESSED == firstChild)
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
          ps.println("First child: NOTPROCESSED");
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
          ps.println("First child: " + firstChild);
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
        if (m_prevsib != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
          int prevSibling = _prevsib(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
          if (DTM.NULL == prevSibling)
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
            ps.println("Prev sibling: DTM.NULL");
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
          else if (NOTPROCESSED == prevSibling)
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
            ps.println("Prev sibling: NOTPROCESSED");
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
            ps.println("Prev sibling: " + prevSibling);
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
        int nextSibling = _nextsib(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
        if (DTM.NULL == nextSibling)
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
          ps.println("Next sibling: DTM.NULL");
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
        else if (NOTPROCESSED == nextSibling)
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
          ps.println("Next sibling: NOTPROCESSED");
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
          ps.println("Next sibling: " + nextSibling);
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
        int parent = _parent(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
        if (DTM.NULL == parent)
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
          ps.println("Parent: DTM.NULL");
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
        else if (NOTPROCESSED == parent)
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
          ps.println("Parent: NOTPROCESSED");
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
          ps.println("Parent: " + parent);
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
        int level = _level(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
        ps.println("Level: " + level);
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
        ps.println("Node Value: " + getNodeValue(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
        ps.println("String Value: " + getStringValue(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
    catch(IOException ioe)
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
      ioe.printStackTrace(System.err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
        throw new RuntimeException(ioe.getMessage());
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
   * Diagnostics function to dump a single node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
   * %REVIEW% KNOWN GLITCH: If you pass it a node index rather than a
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
   * node handle, it works just fine... but the displayed identity
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
   * number before the colon is different, which complicates comparing
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
   * it with nodes printed the other way. We could always OR the DTM ID
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
   * into the value, to suppress that distinction...
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
   * %REVIEW% This might want to be moved up to DTMDefaultBase, or possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
   * DTM itself, since it's a useful diagnostic and uses only DTM's public
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
   * APIs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
  public String dumpNode(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
          if(nodeHandle==DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
                  return "[null]";
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
        String typestring;
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
        switch (getNodeType(nodeHandle))
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
        case DTM.ATTRIBUTE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
          typestring = "ATTR";
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
        case DTM.CDATA_SECTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
          typestring = "CDATA";
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
        case DTM.COMMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
          typestring = "COMMENT";
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
        case DTM.DOCUMENT_FRAGMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
          typestring = "DOC_FRAG";
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
        case DTM.DOCUMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
          typestring = "DOC";
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
        case DTM.DOCUMENT_TYPE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
          typestring = "DOC_TYPE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
        case DTM.ELEMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
          typestring = "ELEMENT";
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
        case DTM.ENTITY_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
          typestring = "ENTITY";
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
        case DTM.ENTITY_REFERENCE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
          typestring = "ENT_REF";
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
        case DTM.NAMESPACE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
          typestring = "NAMESPACE";
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
        case DTM.NOTATION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
          typestring = "NOTATION";
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
        case DTM.NULL :
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
          typestring = "null";
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
        case DTM.PROCESSING_INSTRUCTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
          typestring = "PI";
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
        case DTM.TEXT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
          typestring = "TEXT";
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
        default :
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
          typestring = "Unknown!";
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   841
      return "[" + nodeHandle + ": " + typestring +
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   842
              "(0x" + Integer.toHexString(getExpandedTypeID(nodeHandle)) + ") " +
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   843
              getNodeNameX(nodeHandle) + " {" + getNamespaceURI(nodeHandle) + "}" +
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   844
              "=\"" + getNodeValue(nodeHandle) + "\"]";
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
  // ========= DTM Implementation Control Functions. ==============
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
   * Set an implementation dependent feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
   * %REVIEW% Do we really expect to set features on DTMs?
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
   * @param featureId A feature URL.
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
   * @param state true if this feature should be on, false otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
  public void setFeature(String featureId, boolean state){}
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
  // ========= Document Navigation Functions =========
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
   * Given a node handle, test if it has child nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
   * <p> %REVIEW% This is obviously useful at the DOM layer, where it
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
   * would permit testing this without having to create a proxy
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
   * node. It's less useful in the DTM API, where
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
   * (dtm.getFirstChild(nodeHandle)!=DTM.NULL) is just as fast and
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
   * almost as self-evident. But it's a convenience, and eases porting
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
   * of DOM code to DTM.  </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
   * @param nodeHandle int Handle of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
   * @return int true if the given node has child nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
  public boolean hasChildNodes(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
    int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
    int firstChild = _firstch(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
    return firstChild != DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
  /** Given a node identity, return a node handle. If extended addressing
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
   * has been used (multiple DTM IDs), we need to map the high bits of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
   * identity into the proper DTM ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
   * This has been made FINAL to facilitate inlining, since we do not expect
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
   * any subclass of DTMDefaultBase to ever change the algorithm. (I don't
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
   * really like doing so, and would love to have an excuse not to...)
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
   * %REVIEW% Is it worth trying to specialcase small documents?
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
   * %REVIEW% Should this be exposed at the package/public layers?
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
   * @param nodeIdentity Internal offset to this node's records.
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
   * @return NodeHandle (external representation of node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
  final public int makeNodeHandle(int nodeIdentity)
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
    if(NULL==nodeIdentity) return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
    if(JJK_DEBUG && nodeIdentity>DTMManager.IDENT_NODE_DEFAULT)
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
      System.err.println("GONK! (only useful in limited situations)");
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
    return m_dtmIdent.elementAt(nodeIdentity >>> DTMManager.IDENT_DTM_NODE_BITS)
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
      + (nodeIdentity & DTMManager.IDENT_NODE_DEFAULT) ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
  /** Given a node handle, return a node identity. If extended addressing
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
   * has been used (multiple DTM IDs), we need to map the high bits of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
   * identity into the proper DTM ID and thence find the proper offset
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
   * to add to the low bits of the identity
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
   * This has been made FINAL to facilitate inlining, since we do not expect
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
   * any subclass of DTMDefaultBase to ever change the algorithm. (I don't
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
   * really like doing so, and would love to have an excuse not to...)
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
   * %OPT% Performance is critical for this operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
   * %REVIEW% Should this be exposed at the package/public layers?
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
   * @param nodeHandle (external representation of node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
   * @return nodeIdentity Internal offset to this node's records.
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
  final public int makeNodeIdentity(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
    if(NULL==nodeHandle) return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
    if(m_mgrDefault!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
      // Optimization: use the DTMManagerDefault's fast DTMID-to-offsets
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
      // table.  I'm not wild about this solution but this operation
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
      // needs need extreme speed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
      int whichDTMindex=nodeHandle>>>DTMManager.IDENT_DTM_NODE_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
      // %REVIEW% Wish I didn't have to perform the pre-test, but
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
      // someone is apparently asking DTMs whether they contain nodes
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
      // which really don't belong to them. That's probably a bug
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
      // which should be fixed, but until it is:
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
      if(m_mgrDefault.m_dtms[whichDTMindex]!=this)
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
        return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
        return
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
          m_mgrDefault.m_dtm_offsets[whichDTMindex]
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
          | (nodeHandle & DTMManager.IDENT_NODE_DEFAULT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
    int whichDTMid=m_dtmIdent.indexOf(nodeHandle & DTMManager.IDENT_DTM_DEFAULT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
    return (whichDTMid==NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
      ? NULL
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
      : (whichDTMid << DTMManager.IDENT_DTM_NODE_BITS)
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
      + (nodeHandle & DTMManager.IDENT_NODE_DEFAULT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
   * Given a node handle, get the handle of the node's first child.
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
   * If not yet resolved, waits for more nodes to be added to the document and
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
   * tries again.
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
   * @param nodeHandle int Handle of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
   * @return int DTM node-number of first child, or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
  public int getFirstChild(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
    int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
    int firstChild = _firstch(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
    return makeNodeHandle(firstChild);
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
   * Given a node handle, get the handle of the node's first child.
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
   * If not yet resolved, waits for more nodes to be added to the document and
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
   * tries again.
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
   * @param nodeHandle int Handle of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
   * @return int DTM node-number of first child, or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
  public int getTypedFirstChild(int nodeHandle, int nodeType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
    int firstChild, eType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
    if (nodeType < DTM.NTYPES) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
      for (firstChild = _firstch(makeNodeIdentity(nodeHandle));
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
           firstChild != DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
           firstChild = _nextsib(firstChild)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
        eType = _exptype(firstChild);
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
        if (eType == nodeType
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
               || (eType >= DTM.NTYPES
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
                      && m_expandedNameTable.getType(eType) == nodeType)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
          return makeNodeHandle(firstChild);
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
    } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
      for (firstChild = _firstch(makeNodeIdentity(nodeHandle));
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
           firstChild != DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
           firstChild = _nextsib(firstChild)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
        if (_exptype(firstChild) == nodeType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
          return makeNodeHandle(firstChild);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
   * Given a node handle, advance to its last child.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
   * If not yet resolved, waits for more nodes to be added to the document and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
   * tries again.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
   * @param nodeHandle int Handle of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
   * @return int Node-number of last child,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
   * or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
  public int getLastChild(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
    int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
    int child = _firstch(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
    int lastChild = DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
    while (child != DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
      lastChild = child;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
      child = _nextsib(child);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
    return makeNodeHandle(lastChild);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
   * Retrieves an attribute node by by qualified name and namespace URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
   * @param nodeHandle int Handle of the node upon which to look up this attribute..
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
   * @param namespaceURI The namespace URI of the attribute to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
   *   retrieve, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
   * @param name The local name of the attribute to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
   *   retrieve.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
   * @return The attribute node handle with the specified name (
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
   *   <code>nodeName</code>) or <code>DTM.NULL</code> if there is no such
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
   *   attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
  public abstract int getAttributeNode(int nodeHandle, String namespaceURI,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
                                       String name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
   * Given a node handle, get the index of the node's first attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
   * @param nodeHandle int Handle of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
   * @return Handle of first attribute, or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
  public int getFirstAttribute(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
    int nodeID = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
    return makeNodeHandle(getFirstAttributeIdentity(nodeID));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
   * Given a node identity, get the index of the node's first attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
   * @param identity int identity of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
   * @return Identity of first attribute, or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
  protected int getFirstAttributeIdentity(int identity) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
    int type = _type(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
    if (DTM.ELEMENT_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
      // Assume that attributes and namespaces immediately follow the element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
      while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
        // Assume this can not be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
        type = _type(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
        if (type == DTM.ATTRIBUTE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
          return identity;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
        else if (DTM.NAMESPACE_NODE != type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
   * Given a node handle and an expanded type ID, get the index of the node's
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
   * attribute of that type, if any.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
   * @param nodeHandle int Handle of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
   * @param attType int expanded type ID of the required attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
   * @return Handle of attribute of the required type, or DTM.NULL to indicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
   * none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
  protected int getTypedAttribute(int nodeHandle, int attType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
    int type = getNodeType(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
    if (DTM.ELEMENT_NODE == type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
      int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
      while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
        type = _type(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
        if (type == DTM.ATTRIBUTE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
          if (_exptype(identity) == attType) return makeNodeHandle(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
        else if (DTM.NAMESPACE_NODE != type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
   * Given a node handle, advance to its next sibling.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
   * If not yet resolved, waits for more nodes to be added to the document and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
   * tries again.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
   * @param nodeHandle int Handle of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
   * @return int Node-number of next sibling,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
   * or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
  public int getNextSibling(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
        if (nodeHandle == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
        return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
    return makeNodeHandle(_nextsib(makeNodeIdentity(nodeHandle)));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
   * Given a node handle, advance to its next sibling.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
   * If not yet resolved, waits for more nodes to be added to the document and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
   * tries again.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
   * @param nodeHandle int Handle of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
   * @return int Node-number of next sibling,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
   * or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
  public int getTypedNextSibling(int nodeHandle, int nodeType)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
        if (nodeHandle == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
        return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
        int node = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
        int eType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
        while ((node = _nextsib(node)) != DTM.NULL &&
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
        ((eType = _exptype(node)) != nodeType &&
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
        m_expandedNameTable.getType(eType)!= nodeType));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
        //_type(node) != nodeType));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
    return (node == DTM.NULL ? DTM.NULL : makeNodeHandle(node));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
   * Given a node handle, find its preceeding sibling.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
   * WARNING: DTM is asymmetric; this operation is resolved by search, and is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
   * relatively expensive.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
   * @return int Node-number of the previous sib,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
   * or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
  public int getPreviousSibling(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
    if (nodeHandle == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
      return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
    if (m_prevsib != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
      return makeNodeHandle(_prevsib(makeNodeIdentity(nodeHandle)));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
      // If the previous sibling array is not built, we get at
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
      // the previous sibling using the parent, firstch and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
      // nextsib arrays.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
      int nodeID = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
      int parent = _parent(nodeID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
      int node = _firstch(parent);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
      int result = DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
      while (node != nodeID)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
        result = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
        node = _nextsib(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
      return makeNodeHandle(result);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
   * Given a node handle, advance to the next attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
   * If an attr, we advance to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
   * the next attr on the same node.  If not an attribute, we return NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
   * @param nodeHandle int Handle of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
   * @return int DTM node-number of the resolved attr,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
   * or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
  public int getNextAttribute(int nodeHandle) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
    int nodeID = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
    if (_type(nodeID) == DTM.ATTRIBUTE_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
      return makeNodeHandle(getNextAttributeIdentity(nodeID));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
   * Given a node identity for an attribute, advance to the next attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
   * @param identity int identity of the attribute node.  This
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
   * <strong>must</strong> be an attribute node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
   * @return int DTM node-identity of the resolved attr,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
   * or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
  protected int getNextAttributeIdentity(int identity) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
    // Assume that attributes and namespace nodes immediately follow the element
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
    while (DTM.NULL != (identity = getNextNodeIdentity(identity))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
      int type = _type(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
      if (type == DTM.ATTRIBUTE_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
        return identity;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
      } else if (type != DTM.NAMESPACE_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
        break;
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
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
  /** Build table of namespace declaration
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1241
   * locations during DTM construction. Table is aArrayList<>of
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
   * SuballocatedIntVectors containing the namespace node HANDLES declared at
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
   * that ID, plus an SuballocatedIntVector of the element node INDEXES at which
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
   * these declarations appeared.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
   * NOTE: Since this occurs during model build, nodes will be encountered
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
   * in doucment order and thus the table will be ordered by element,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
   * permitting binary-search as a possible retrieval optimization.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
   * %REVIEW% Directly managed arrays rather than vectors?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
   * %REVIEW% Handles or IDs? Given usage, I think handles.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
  protected void declareNamespaceInContext(int elementNodeIndex,int namespaceNodeIndex)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
    SuballocatedIntVector nsList=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
    if(m_namespaceDeclSets==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
        // First
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
        m_namespaceDeclSetElements=new SuballocatedIntVector(32);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
        m_namespaceDeclSetElements.addElement(elementNodeIndex);
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1262
        m_namespaceDeclSets=new Vector<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
        nsList=new SuballocatedIntVector(32);
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1264
        m_namespaceDeclSets.add(nsList);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
        // Most recent. May be -1 (none) if DTM was pruned.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
        // %OPT% Is there a lastElement() method? Should there be?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
        int last=m_namespaceDeclSetElements.size()-1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
        if(last>=0 && elementNodeIndex==m_namespaceDeclSetElements.elementAt(last))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
          {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1274
            nsList=m_namespaceDeclSets.get(last);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1275
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
    if(nsList==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
        m_namespaceDeclSetElements.addElement(elementNodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
7f561c08de6b Initial load
duke
parents:
diff changeset
  1281
        SuballocatedIntVector inherited =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1282
                                findNamespaceContext(_parent(elementNodeIndex));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1283
7f561c08de6b Initial load
duke
parents:
diff changeset
  1284
        if (inherited!=null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1285
            // %OPT% Count-down might be faster, but debuggability may
7f561c08de6b Initial load
duke
parents:
diff changeset
  1286
            // be better this way, and if we ever decide we want to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1287
            // keep this ordered by expanded-type...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1288
            int isize=inherited.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1289
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
            // Base the size of a new namespace list on the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
            // size of the inherited list - but within reason!
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
            nsList=new SuballocatedIntVector(Math.max(Math.min(isize+16,2048),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
                                                      32));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
            for(int i=0;i<isize;++i)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1297
                nsList.addElement(inherited.elementAt(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1300
            nsList=new SuballocatedIntVector(32);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1301
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1303
        m_namespaceDeclSets.add(nsList);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1304
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
    // Handle overwriting inherited.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
    // %OPT% Keep sorted? (By expanded-name rather than by doc order...)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
    // Downside: Would require insertElementAt if not found,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1309
    // which has recopying costs. But these are generally short lists...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1310
    int newEType=_exptype(namespaceNodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
    for(int i=nsList.size()-1;i>=0;--i)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
        if(newEType==getExpandedTypeID(nsList.elementAt(i)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
            nsList.setElementAt(makeNodeHandle(namespaceNodeIndex),i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1317
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1319
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
    nsList.addElement(makeNodeHandle(namespaceNodeIndex));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
  /** Retrieve list of namespace declaration locations
7f561c08de6b Initial load
duke
parents:
diff changeset
  1324
     * active at this node. List is an SuballocatedIntVector whose
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
     * entries are the namespace node HANDLES declared at that ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1326
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1327
     * %REVIEW% Directly managed arrays rather than vectors?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1328
     * %REVIEW% Handles or IDs? Given usage, I think handles.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1329
     * */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1330
  protected SuballocatedIntVector findNamespaceContext(int elementNodeIndex)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1331
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1332
    if (null!=m_namespaceDeclSetElements)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1333
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1334
        // %OPT% Is binary-search really saving us a lot versus linear?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1335
        // (... It may be, in large docs with many NS decls.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1336
        int wouldBeAt=findInSortedSuballocatedIntVector(m_namespaceDeclSetElements,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1337
                                            elementNodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1338
        if(wouldBeAt>=0) // Found it
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1339
          return m_namespaceDeclSets.get(wouldBeAt);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1340
        if(wouldBeAt == -1) // -1-wouldbeat == 0
7f561c08de6b Initial load
duke
parents:
diff changeset
  1341
          return null; // Not after anything; definitely not found
7f561c08de6b Initial load
duke
parents:
diff changeset
  1342
7f561c08de6b Initial load
duke
parents:
diff changeset
  1343
        // Not found, but we know where it should have been.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1344
        // Search back until we find an ancestor or run out.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1345
        wouldBeAt=-1-wouldBeAt;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1346
7f561c08de6b Initial load
duke
parents:
diff changeset
  1347
        // Decrement wouldBeAt to find last possible ancestor
7f561c08de6b Initial load
duke
parents:
diff changeset
  1348
        int candidate=m_namespaceDeclSetElements.elementAt(-- wouldBeAt);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1349
        int ancestor=_parent(elementNodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1350
7f561c08de6b Initial load
duke
parents:
diff changeset
  1351
        // Special case: if the candidate is before the given node, and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1352
        // is in the earliest possible position in the document, it
7f561c08de6b Initial load
duke
parents:
diff changeset
  1353
        // must have the namespace declarations we're interested in.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1354
        if (wouldBeAt == 0 && candidate < ancestor) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1355
          int rootHandle = getDocumentRoot(makeNodeHandle(elementNodeIndex));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1356
          int rootID = makeNodeIdentity(rootHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1357
          int uppermostNSCandidateID;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1358
7f561c08de6b Initial load
duke
parents:
diff changeset
  1359
          if (getNodeType(rootHandle) == DTM.DOCUMENT_NODE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1360
            int ch = _firstch(rootID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1361
            uppermostNSCandidateID = (ch != DTM.NULL) ? ch : rootID;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1362
          } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1363
            uppermostNSCandidateID = rootID;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1364
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1365
7f561c08de6b Initial load
duke
parents:
diff changeset
  1366
          if (candidate == uppermostNSCandidateID) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1367
            return m_namespaceDeclSets.get(wouldBeAt);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1368
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1369
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1370
7f561c08de6b Initial load
duke
parents:
diff changeset
  1371
        while(wouldBeAt>=0 && ancestor>0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1372
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1373
            if (candidate==ancestor) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1374
                // Found ancestor in list
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1375
                return m_namespaceDeclSets.get(wouldBeAt);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1376
            } else if (candidate<ancestor) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1377
                // Too deep in tree
7f561c08de6b Initial load
duke
parents:
diff changeset
  1378
                do {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1379
                  ancestor=_parent(ancestor);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1380
                } while (candidate < ancestor);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1381
            } else if(wouldBeAt > 0){
7f561c08de6b Initial load
duke
parents:
diff changeset
  1382
              // Too late in list
7f561c08de6b Initial load
duke
parents:
diff changeset
  1383
              candidate=m_namespaceDeclSetElements.elementAt(--wouldBeAt);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1384
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1385
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1386
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1387
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1388
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1389
7f561c08de6b Initial load
duke
parents:
diff changeset
  1390
    return null; // No namespaces known at this node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1391
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1392
7f561c08de6b Initial load
duke
parents:
diff changeset
  1393
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1394
     * Subroutine: Locate the specified node within
7f561c08de6b Initial load
duke
parents:
diff changeset
  1395
     * m_namespaceDeclSetElements, or the last element which
7f561c08de6b Initial load
duke
parents:
diff changeset
  1396
     * preceeds it in document order
7f561c08de6b Initial load
duke
parents:
diff changeset
  1397
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1398
     * %REVIEW% Inlne this into findNamespaceContext? Create SortedSuballocatedIntVector type?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1399
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1400
     * @return If positive or zero, the index of the found item.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1401
     * If negative, index of the point at which it would have appeared,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1402
     * encoded as -1-index and hence reconvertable by subtracting
7f561c08de6b Initial load
duke
parents:
diff changeset
  1403
     * it from -1. (Encoding because I don't want to recompare the strings
7f561c08de6b Initial load
duke
parents:
diff changeset
  1404
     * but don't want to burn bytes on a datatype to hold a flagged value.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1405
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1406
  protected int findInSortedSuballocatedIntVector(SuballocatedIntVector vector, int lookfor)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1407
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1408
    // Binary search
7f561c08de6b Initial load
duke
parents:
diff changeset
  1409
    int i = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1410
    if(vector != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1411
      int first = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1412
      int last  = vector.size() - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1413
7f561c08de6b Initial load
duke
parents:
diff changeset
  1414
      while (first <= last) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1415
        i = (first + last) / 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1416
        int test = lookfor-vector.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1417
        if(test == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1418
          return i; // Name found
7f561c08de6b Initial load
duke
parents:
diff changeset
  1419
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1420
        else if (test < 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1421
          last = i - 1; // looked too late
7f561c08de6b Initial load
duke
parents:
diff changeset
  1422
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1423
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1424
          first = i + 1; // looked ot early
7f561c08de6b Initial load
duke
parents:
diff changeset
  1425
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1426
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1427
7f561c08de6b Initial load
duke
parents:
diff changeset
  1428
      if (first > i) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1429
        i = first; // Clean up at loop end
7f561c08de6b Initial load
duke
parents:
diff changeset
  1430
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1431
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1432
7f561c08de6b Initial load
duke
parents:
diff changeset
  1433
    return -1 - i; // not-found has to be encoded.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1434
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1435
7f561c08de6b Initial load
duke
parents:
diff changeset
  1436
7f561c08de6b Initial load
duke
parents:
diff changeset
  1437
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1438
   * Given a node handle, get the index of the node's first child.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1439
   * If not yet resolved, waits for more nodes to be added to the document and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1440
   * tries again
7f561c08de6b Initial load
duke
parents:
diff changeset
  1441
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1442
   * @param nodeHandle handle to node, which should probably be an element
7f561c08de6b Initial load
duke
parents:
diff changeset
  1443
   *                   node, but need not be.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1444
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1445
   * @param inScope    true if all namespaces in scope should be returned,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1446
   *                   false if only the namespace declarations should be
7f561c08de6b Initial load
duke
parents:
diff changeset
  1447
   *                   returned.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1448
   * @return handle of first namespace, or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1449
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1450
  public int getFirstNamespaceNode(int nodeHandle, boolean inScope)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1451
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1452
        if(inScope)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1453
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1454
            int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1455
            if (_type(identity) == DTM.ELEMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1456
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1457
              SuballocatedIntVector nsContext=findNamespaceContext(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1458
              if(nsContext==null || nsContext.size()<1)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1459
                return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1460
7f561c08de6b Initial load
duke
parents:
diff changeset
  1461
              return nsContext.elementAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1462
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1463
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1464
              return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1465
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1466
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1467
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1468
            // Assume that attributes and namespaces immediately
7f561c08de6b Initial load
duke
parents:
diff changeset
  1469
            // follow the element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1470
            //
7f561c08de6b Initial load
duke
parents:
diff changeset
  1471
            // %OPT% Would things be faster if all NS nodes were built
7f561c08de6b Initial load
duke
parents:
diff changeset
  1472
            // before all Attr nodes? Some costs at build time for 2nd
7f561c08de6b Initial load
duke
parents:
diff changeset
  1473
            // pass...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1474
            int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1475
            if (_type(identity) == DTM.ELEMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1476
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1477
              while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1478
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1479
                int type = _type(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1480
                if (type == DTM.NAMESPACE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1481
                    return makeNodeHandle(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1482
                else if (DTM.ATTRIBUTE_NODE != type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1483
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1484
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1485
              return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1486
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1487
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1488
              return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1489
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1490
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1491
7f561c08de6b Initial load
duke
parents:
diff changeset
  1492
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1493
   * Given a namespace handle, advance to the next namespace.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1494
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1495
   * @param baseHandle handle to original node from where the first namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1496
   * was relative to (needed to return nodes in document order).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1497
   * @param nodeHandle A namespace handle for which we will find the next node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1498
   * @param inScope true if all namespaces that are in scope should be processed,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1499
   * otherwise just process the nodes in the given element handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1500
   * @return handle of next namespace, or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1501
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1502
  public int getNextNamespaceNode(int baseHandle, int nodeHandle,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1503
                                  boolean inScope)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1504
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1505
        if(inScope)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1506
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1507
            //Since we've been given the base, try direct lookup
7f561c08de6b Initial load
duke
parents:
diff changeset
  1508
            //(could look from nodeHandle but this is at least one
7f561c08de6b Initial load
duke
parents:
diff changeset
  1509
            //comparison/get-parent faster)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1510
            //SuballocatedIntVector nsContext=findNamespaceContext(nodeHandle & m_mask);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1511
7f561c08de6b Initial load
duke
parents:
diff changeset
  1512
                SuballocatedIntVector nsContext=findNamespaceContext(makeNodeIdentity(baseHandle));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1513
7f561c08de6b Initial load
duke
parents:
diff changeset
  1514
            if(nsContext==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1515
              return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1516
            int i=1 + nsContext.indexOf(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1517
            if(i<=0 || i==nsContext.size())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1518
              return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1519
7f561c08de6b Initial load
duke
parents:
diff changeset
  1520
            return nsContext.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1521
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1522
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1523
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1524
            // Assume that attributes and namespace nodes immediately follow the element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1525
            int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1526
            while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1527
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1528
                int type = _type(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1529
                if (type == DTM.NAMESPACE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1530
                  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1531
                    return makeNodeHandle(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1532
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1533
                else if (type != DTM.ATTRIBUTE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1534
                  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1535
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1536
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1537
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1538
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1539
     return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1540
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1541
7f561c08de6b Initial load
duke
parents:
diff changeset
  1542
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1543
   * Given a node handle, find its parent node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1544
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1545
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1546
   * @return int Node-number of parent,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1547
   * or DTM.NULL to indicate none exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1548
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1549
  public int getParent(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1550
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1551
7f561c08de6b Initial load
duke
parents:
diff changeset
  1552
    int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1553
7f561c08de6b Initial load
duke
parents:
diff changeset
  1554
    if (identity > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1555
      return makeNodeHandle(_parent(identity));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1556
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1557
      return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1558
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1559
7f561c08de6b Initial load
duke
parents:
diff changeset
  1560
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1561
   * Find the Document node handle for the document currently under construction.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1562
   * PLEASE NOTE that most people should use getOwnerDocument(nodeHandle) instead;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1563
   * this version of the operation is primarily intended for use during negotiation
7f561c08de6b Initial load
duke
parents:
diff changeset
  1564
   * with the DTM Manager.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1565
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1566
   *  @return int Node handle of document, which should always be valid.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1567
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1568
  public int getDocument()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1569
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1570
    return m_dtmIdent.elementAt(0); // makeNodeHandle(0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1571
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1572
7f561c08de6b Initial load
duke
parents:
diff changeset
  1573
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1574
   * Given a node handle, find the owning document node.  This has the exact
7f561c08de6b Initial load
duke
parents:
diff changeset
  1575
   * same semantics as the DOM Document method of the same name, in that if
7f561c08de6b Initial load
duke
parents:
diff changeset
  1576
   * the nodeHandle is a document node, it will return NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1577
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1578
   * <p>%REVIEW% Since this is DOM-specific, it may belong at the DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
  1579
   * binding layer. Included here as a convenience function and to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1580
   * aid porting of DOM code to DTM.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1581
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1582
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1583
   * @return int Node handle of owning document, or -1 if the node was a Docment
7f561c08de6b Initial load
duke
parents:
diff changeset
  1584
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1585
  public int getOwnerDocument(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1586
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1587
7f561c08de6b Initial load
duke
parents:
diff changeset
  1588
    if (DTM.DOCUMENT_NODE == getNodeType(nodeHandle))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1589
            return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1590
7f561c08de6b Initial load
duke
parents:
diff changeset
  1591
    return getDocumentRoot(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1592
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1593
7f561c08de6b Initial load
duke
parents:
diff changeset
  1594
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1595
   * Given a node handle, find the owning document node.  Unlike the DOM,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1596
   * this considers the owningDocument of a Document to be itself.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1597
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1598
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1599
   * @return int Node handle of owning document, or the nodeHandle if it is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1600
   *             a Document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1601
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1602
  public int getDocumentRoot(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1603
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1604
    return getManager().getDTM(nodeHandle).getDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1605
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1606
7f561c08de6b Initial load
duke
parents:
diff changeset
  1607
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1608
   * Get the string-value of a node as a String object
7f561c08de6b Initial load
duke
parents:
diff changeset
  1609
   * (see http://www.w3.org/TR/xpath#data-model
7f561c08de6b Initial load
duke
parents:
diff changeset
  1610
   * for the definition of a node's string-value).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1611
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1612
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1613
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1614
   * @return A string object that represents the string-value of the given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1615
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1616
  public abstract XMLString getStringValue(int nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1617
7f561c08de6b Initial load
duke
parents:
diff changeset
  1618
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1619
   * Get number of character array chunks in
7f561c08de6b Initial load
duke
parents:
diff changeset
  1620
   * the string-value of a node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1621
   * (see http://www.w3.org/TR/xpath#data-model
7f561c08de6b Initial load
duke
parents:
diff changeset
  1622
   * for the definition of a node's string-value).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1623
   * Note that a single text node may have multiple text chunks.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1624
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1625
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1626
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1627
   * @return number of character array chunks in
7f561c08de6b Initial load
duke
parents:
diff changeset
  1628
   *         the string-value of a node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1629
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1630
  public int getStringValueChunkCount(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1631
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1632
7f561c08de6b Initial load
duke
parents:
diff changeset
  1633
    // %TBD%
7f561c08de6b Initial load
duke
parents:
diff changeset
  1634
    error(XMLMessages.createXMLMessage(XMLErrorResources.ER_METHOD_NOT_SUPPORTED, null));//("getStringValueChunkCount not yet supported!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1635
7f561c08de6b Initial load
duke
parents:
diff changeset
  1636
    return 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1637
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1638
7f561c08de6b Initial load
duke
parents:
diff changeset
  1639
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1640
   * Get a character array chunk in the string-value of a node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1641
   * (see http://www.w3.org/TR/xpath#data-model
7f561c08de6b Initial load
duke
parents:
diff changeset
  1642
   * for the definition of a node's string-value).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1643
   * Note that a single text node may have multiple text chunks.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1644
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1645
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1646
   * @param chunkIndex Which chunk to get.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1647
   * @param startAndLen An array of 2 where the start position and length of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1648
   *                    the chunk will be returned.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1649
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1650
   * @return The character array reference where the chunk occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1651
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1652
  public char[] getStringValueChunk(int nodeHandle, int chunkIndex,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1653
                                    int[] startAndLen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1654
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1655
7f561c08de6b Initial load
duke
parents:
diff changeset
  1656
    // %TBD%
7f561c08de6b Initial load
duke
parents:
diff changeset
  1657
    error(XMLMessages.createXMLMessage(XMLErrorResources.ER_METHOD_NOT_SUPPORTED, null));//"getStringValueChunk not yet supported!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1658
7f561c08de6b Initial load
duke
parents:
diff changeset
  1659
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1660
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1661
7f561c08de6b Initial load
duke
parents:
diff changeset
  1662
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1663
   * Given a node handle, return an ID that represents the node's expanded name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1664
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1665
   * @param nodeHandle The handle to the node in question.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1666
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1667
   * @return the expanded-name id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1668
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1669
  public int getExpandedTypeID(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1670
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1671
    // %REVIEW% This _should_ only be null if someone asked the wrong DTM about the node...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1672
    // which one would hope would never happen...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1673
    int id=makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1674
    if(id==NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1675
      return NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1676
    return _exptype(id);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1677
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1678
7f561c08de6b Initial load
duke
parents:
diff changeset
  1679
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1680
   * Given an expanded name, return an ID.  If the expanded-name does not
7f561c08de6b Initial load
duke
parents:
diff changeset
  1681
   * exist in the internal tables, the entry will be created, and the ID will
7f561c08de6b Initial load
duke
parents:
diff changeset
  1682
   * be returned.  Any additional nodes that are created that have this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1683
   * expanded name will use this ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1684
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1685
   * @param type The simple type, i.e. one of ELEMENT, ATTRIBUTE, etc.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1686
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1687
   * @param namespace The namespace URI, which may be null, may be an empty
7f561c08de6b Initial load
duke
parents:
diff changeset
  1688
   *                  string (which will be the same as null), or may be a
7f561c08de6b Initial load
duke
parents:
diff changeset
  1689
   *                  namespace URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1690
   * @param localName The local name string, which must be a valid
7f561c08de6b Initial load
duke
parents:
diff changeset
  1691
   *                  <a href="http://www.w3.org/TR/REC-xml-names/">NCName</a>.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1692
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1693
   * @return the expanded-name id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1694
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1695
  public int getExpandedTypeID(String namespace, String localName, int type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1696
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1697
7f561c08de6b Initial load
duke
parents:
diff changeset
  1698
    ExpandedNameTable ent = m_expandedNameTable;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1699
7f561c08de6b Initial load
duke
parents:
diff changeset
  1700
    return ent.getExpandedTypeID(namespace, localName, type);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1701
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1702
7f561c08de6b Initial load
duke
parents:
diff changeset
  1703
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1704
   * Given an expanded-name ID, return the local name part.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1705
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1706
   * @param expandedNameID an ID that represents an expanded-name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1707
   * @return String Local name of this node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1708
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1709
  public String getLocalNameFromExpandedNameID(int expandedNameID)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1710
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1711
    return m_expandedNameTable.getLocalName(expandedNameID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1712
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1713
7f561c08de6b Initial load
duke
parents:
diff changeset
  1714
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1715
   * Given an expanded-name ID, return the namespace URI part.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1716
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1717
   * @param expandedNameID an ID that represents an expanded-name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1718
   * @return String URI value of this node's namespace, or null if no
7f561c08de6b Initial load
duke
parents:
diff changeset
  1719
   * namespace was resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1720
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1721
  public String getNamespaceFromExpandedNameID(int expandedNameID)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1722
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1723
    return m_expandedNameTable.getNamespace(expandedNameID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1724
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1725
7f561c08de6b Initial load
duke
parents:
diff changeset
  1726
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1727
   * Returns the namespace type of a specific node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1728
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1729
   * @return the ID of the namespace.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1730
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1731
  public int getNamespaceType(final int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1732
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1733
7f561c08de6b Initial load
duke
parents:
diff changeset
  1734
    int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1735
    int expandedNameID = _exptype(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1736
7f561c08de6b Initial load
duke
parents:
diff changeset
  1737
    return m_expandedNameTable.getNamespaceID(expandedNameID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1738
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1739
7f561c08de6b Initial load
duke
parents:
diff changeset
  1740
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1741
   * Given a node handle, return its DOM-style node name. This will
7f561c08de6b Initial load
duke
parents:
diff changeset
  1742
   * include names such as #text or #document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1743
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1744
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1745
   * @return String Name of this node, which may be an empty string.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1746
   * %REVIEW% Document when empty string is possible...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1747
   * %REVIEW-COMMENT% It should never be empty, should it?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1748
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1749
  public abstract String getNodeName(int nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1750
7f561c08de6b Initial load
duke
parents:
diff changeset
  1751
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1752
   * Given a node handle, return the XPath node name.  This should be
7f561c08de6b Initial load
duke
parents:
diff changeset
  1753
   * the name as described by the XPath data model, NOT the DOM-style
7f561c08de6b Initial load
duke
parents:
diff changeset
  1754
   * name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1755
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1756
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1757
   * @return String Name of this node, which may be an empty string.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1758
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1759
  public String getNodeNameX(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1760
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1761
7f561c08de6b Initial load
duke
parents:
diff changeset
  1762
    /** @todo: implement this com.sun.org.apache.xml.internal.dtm.DTMDefaultBase abstract method */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1763
    error(XMLMessages.createXMLMessage(XMLErrorResources.ER_METHOD_NOT_SUPPORTED, null));//"Not yet supported!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1764
7f561c08de6b Initial load
duke
parents:
diff changeset
  1765
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1766
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1767
7f561c08de6b Initial load
duke
parents:
diff changeset
  1768
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1769
   * Given a node handle, return its XPath-style localname.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1770
   * (As defined in Namespaces, this is the portion of the name after any
7f561c08de6b Initial load
duke
parents:
diff changeset
  1771
   * colon character).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1772
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1773
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1774
   * @return String Local name of this node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1775
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1776
  public abstract String getLocalName(int nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1777
7f561c08de6b Initial load
duke
parents:
diff changeset
  1778
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1779
   * Given a namespace handle, return the prefix that the namespace decl is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1780
   * mapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1781
   * Given a node handle, return the prefix used to map to the namespace.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1782
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1783
   * <p> %REVIEW% Are you sure you want "" for no prefix?  </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1784
   * <p> %REVIEW-COMMENT% I think so... not totally sure. -sb  </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1785
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1786
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1787
   * @return String prefix of this node's name, or "" if no explicit
7f561c08de6b Initial load
duke
parents:
diff changeset
  1788
   * namespace prefix was given.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1789
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1790
  public abstract String getPrefix(int nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1791
7f561c08de6b Initial load
duke
parents:
diff changeset
  1792
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1793
   * Given a node handle, return its DOM-style namespace URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  1794
   * (As defined in Namespaces, this is the declared URI which this node's
7f561c08de6b Initial load
duke
parents:
diff changeset
  1795
   * prefix -- or default in lieu thereof -- was mapped to.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1796
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1797
   * <p>%REVIEW% Null or ""? -sb</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1798
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1799
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1800
   * @return String URI value of this node's namespace, or null if no
7f561c08de6b Initial load
duke
parents:
diff changeset
  1801
   * namespace was resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1802
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1803
  public abstract String getNamespaceURI(int nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1804
7f561c08de6b Initial load
duke
parents:
diff changeset
  1805
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1806
   * Given a node handle, return its node value. This is mostly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1807
   * as defined by the DOM, but may ignore some conveniences.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1808
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1809
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1810
   * @param nodeHandle The node id.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1811
   * @return String Value of this node, or null if not
7f561c08de6b Initial load
duke
parents:
diff changeset
  1812
   * meaningful for this node type.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1813
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1814
  public abstract String getNodeValue(int nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1815
7f561c08de6b Initial load
duke
parents:
diff changeset
  1816
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1817
   * Given a node handle, return its DOM-style node type.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1818
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1819
   * %REVIEW% Generally, returning short is false economy. Return int?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1820
   * %REVIEW% Make assumption that node has already arrived.  Is OK?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1821
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1822
   * @param nodeHandle The node id.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1823
   * @return int Node type, as per the DOM's Node._NODE constants.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1824
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1825
  public short getNodeType(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1826
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1827
        if (nodeHandle == DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1828
        return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1829
    return m_expandedNameTable.getType(_exptype(makeNodeIdentity(nodeHandle)));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1830
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1831
7f561c08de6b Initial load
duke
parents:
diff changeset
  1832
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1833
   * Get the depth level of this node in the tree (equals 1 for
7f561c08de6b Initial load
duke
parents:
diff changeset
  1834
   * a parentless node).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1835
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1836
   * @param nodeHandle The node id.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1837
   * @return the number of ancestors, plus one
7f561c08de6b Initial load
duke
parents:
diff changeset
  1838
   * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
  1839
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1840
  public short getLevel(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1841
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1842
    // Apparently, the axis walker stuff requires levels to count from 1.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1843
    int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1844
    return (short) (_level(identity) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1845
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1846
7f561c08de6b Initial load
duke
parents:
diff changeset
  1847
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1848
   * Get the identity of this node in the tree
7f561c08de6b Initial load
duke
parents:
diff changeset
  1849
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1850
   * @param nodeHandle The node handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1851
   * @return the node identity
7f561c08de6b Initial load
duke
parents:
diff changeset
  1852
   * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
  1853
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1854
  public int getNodeIdent(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1855
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1856
    /*if (nodeHandle != DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1857
      return nodeHandle & m_mask;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1858
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1859
      return DTM.NULL;*/
7f561c08de6b Initial load
duke
parents:
diff changeset
  1860
7f561c08de6b Initial load
duke
parents:
diff changeset
  1861
      return makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1862
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1863
7f561c08de6b Initial load
duke
parents:
diff changeset
  1864
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1865
   * Get the handle of this node in the tree
7f561c08de6b Initial load
duke
parents:
diff changeset
  1866
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1867
   * @param nodeId The node identity.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1868
   * @return the node handle
7f561c08de6b Initial load
duke
parents:
diff changeset
  1869
   * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
  1870
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1871
  public int getNodeHandle(int nodeId)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1872
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1873
    /*if (nodeId != DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1874
      return nodeId | m_dtmIdent;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1875
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1876
      return DTM.NULL;*/
7f561c08de6b Initial load
duke
parents:
diff changeset
  1877
7f561c08de6b Initial load
duke
parents:
diff changeset
  1878
      return makeNodeHandle(nodeId);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1879
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1880
7f561c08de6b Initial load
duke
parents:
diff changeset
  1881
  // ============== Document query functions ==============
7f561c08de6b Initial load
duke
parents:
diff changeset
  1882
7f561c08de6b Initial load
duke
parents:
diff changeset
  1883
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1884
   * Tests whether DTM DOM implementation implements a specific feature and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1885
   * that feature is supported by this node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1886
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1887
   * @param feature The name of the feature to test.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1888
   * @param version This is the version number of the feature to test.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1889
   *   If the version is not
7f561c08de6b Initial load
duke
parents:
diff changeset
  1890
   *   specified, supporting any version of the feature will cause the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1891
   *   method to return <code>true</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1892
   * @return Returns <code>true</code> if the specified feature is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1893
   *   supported on this node, <code>false</code> otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1894
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1895
  public boolean isSupported(String feature, String version)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1896
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1897
7f561c08de6b Initial load
duke
parents:
diff changeset
  1898
    // %TBD%
7f561c08de6b Initial load
duke
parents:
diff changeset
  1899
    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1900
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1901
7f561c08de6b Initial load
duke
parents:
diff changeset
  1902
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1903
   * Return the base URI of the document entity. If it is not known
7f561c08de6b Initial load
duke
parents:
diff changeset
  1904
   * (because the document was parsed from a socket connection or from
7f561c08de6b Initial load
duke
parents:
diff changeset
  1905
   * standard input, for example), the value of this property is unknown.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1906
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1907
   * @return the document base URI String object or null if unknown.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1908
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1909
  public String getDocumentBaseURI()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1910
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1911
    return m_documentBaseURI;
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
   * Set the base URI of the document entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1916
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1917
   * @param baseURI the document base URI String object or null if unknown.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1918
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1919
  public void setDocumentBaseURI(String baseURI)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1920
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1921
    m_documentBaseURI = baseURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1922
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1923
7f561c08de6b Initial load
duke
parents:
diff changeset
  1924
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1925
   * Return the system identifier of the document entity. If
7f561c08de6b Initial load
duke
parents:
diff changeset
  1926
   * it is not known, the value of this property is unknown.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1927
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1928
   * @param nodeHandle The node id, which can be any valid node handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1929
   * @return the system identifier String object or null if unknown.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1930
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1931
  public String getDocumentSystemIdentifier(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1932
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1933
7f561c08de6b Initial load
duke
parents:
diff changeset
  1934
    // %REVIEW%  OK? -sb
7f561c08de6b Initial load
duke
parents:
diff changeset
  1935
    return m_documentBaseURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1936
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1937
7f561c08de6b Initial load
duke
parents:
diff changeset
  1938
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1939
   * Return the name of the character encoding scheme
7f561c08de6b Initial load
duke
parents:
diff changeset
  1940
   *        in which the document entity is expressed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1941
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1942
   * @param nodeHandle The node id, which can be any valid node handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1943
   * @return the document encoding String object.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1944
   * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
  1945
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1946
  public String getDocumentEncoding(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1947
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1948
7f561c08de6b Initial load
duke
parents:
diff changeset
  1949
    // %REVIEW%  OK??  -sb
7f561c08de6b Initial load
duke
parents:
diff changeset
  1950
    return "UTF-8";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1951
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1952
7f561c08de6b Initial load
duke
parents:
diff changeset
  1953
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1954
   * Return an indication of the standalone status of the document,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1955
   *        either "yes" or "no". This property is derived from the optional
7f561c08de6b Initial load
duke
parents:
diff changeset
  1956
   *        standalone document declaration in the XML declaration at the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1957
   *        beginning of the document entity, and has no value if there is no
7f561c08de6b Initial load
duke
parents:
diff changeset
  1958
   *        standalone document declaration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1959
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1960
   * @param nodeHandle The node id, which can be any valid node handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1961
   * @return the document standalone String object, either "yes", "no", or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1962
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1963
  public String getDocumentStandalone(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1964
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1965
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1966
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1967
7f561c08de6b Initial load
duke
parents:
diff changeset
  1968
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1969
   * Return a string representing the XML version of the document. This
7f561c08de6b Initial load
duke
parents:
diff changeset
  1970
   * property is derived from the XML declaration optionally present at the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1971
   * beginning of the document entity, and has no value if there is no XML
7f561c08de6b Initial load
duke
parents:
diff changeset
  1972
   * declaration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1973
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1974
   * @param documentHandle The document handle
7f561c08de6b Initial load
duke
parents:
diff changeset
  1975
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1976
   * @return the document version String object.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1977
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1978
  public String getDocumentVersion(int documentHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1979
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1980
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1981
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1982
7f561c08de6b Initial load
duke
parents:
diff changeset
  1983
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1984
   * Return an indication of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1985
   * whether the processor has read the complete DTD. Its value is a
7f561c08de6b Initial load
duke
parents:
diff changeset
  1986
   * boolean. If it is false, then certain properties (indicated in their
7f561c08de6b Initial load
duke
parents:
diff changeset
  1987
   * descriptions below) may be unknown. If it is true, those properties
7f561c08de6b Initial load
duke
parents:
diff changeset
  1988
   * are never unknown.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1989
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1990
   * @return <code>true</code> if all declarations were processed;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1991
   *         <code>false</code> otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1992
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1993
  public boolean getDocumentAllDeclarationsProcessed()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1994
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1995
7f561c08de6b Initial load
duke
parents:
diff changeset
  1996
    // %REVIEW% OK?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1997
    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1998
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1999
7f561c08de6b Initial load
duke
parents:
diff changeset
  2000
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2001
   *   A document type declaration information item has the following properties:
7f561c08de6b Initial load
duke
parents:
diff changeset
  2002
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2003
   *     1. [system identifier] The system identifier of the external subset, if
7f561c08de6b Initial load
duke
parents:
diff changeset
  2004
   *        it exists. Otherwise this property has no value.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2005
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2006
   * @return the system identifier String object, or null if there is none.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2007
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2008
  public abstract String getDocumentTypeDeclarationSystemIdentifier();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2009
7f561c08de6b Initial load
duke
parents:
diff changeset
  2010
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2011
   * Return the public identifier of the external subset,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2012
   * normalized as described in 4.2.2 External Entities [XML]. If there is
7f561c08de6b Initial load
duke
parents:
diff changeset
  2013
   * no external subset or if it has no public identifier, this property
7f561c08de6b Initial load
duke
parents:
diff changeset
  2014
   * has no value.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2015
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2016
   * @return the public identifier String object, or null if there is none.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2017
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2018
  public abstract String getDocumentTypeDeclarationPublicIdentifier();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2019
7f561c08de6b Initial load
duke
parents:
diff changeset
  2020
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2021
   * Returns the <code>Element</code> whose <code>ID</code> is given by
7f561c08de6b Initial load
duke
parents:
diff changeset
  2022
   * <code>elementId</code>. If no such element exists, returns
7f561c08de6b Initial load
duke
parents:
diff changeset
  2023
   * <code>DTM.NULL</code>. Behavior is not defined if more than one element
7f561c08de6b Initial load
duke
parents:
diff changeset
  2024
   * has this <code>ID</code>. Attributes (including those
7f561c08de6b Initial load
duke
parents:
diff changeset
  2025
   * with the name "ID") are not of type ID unless so defined by DTD/Schema
7f561c08de6b Initial load
duke
parents:
diff changeset
  2026
   * information available to the DTM implementation.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2027
   * Implementations that do not know whether attributes are of type ID or
7f561c08de6b Initial load
duke
parents:
diff changeset
  2028
   * not are expected to return <code>DTM.NULL</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2029
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2030
   * <p>%REVIEW% Presumably IDs are still scoped to a single document,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2031
   * and this operation searches only within a single document, right?
7f561c08de6b Initial load
duke
parents:
diff changeset
  2032
   * Wouldn't want collisions between DTMs in the same process.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2033
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2034
   * @param elementId The unique <code>id</code> value for an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2035
   * @return The handle of the matching element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2036
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2037
  public abstract int getElementById(String elementId);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2038
7f561c08de6b Initial load
duke
parents:
diff changeset
  2039
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2040
   * The getUnparsedEntityURI function returns the URI of the unparsed
7f561c08de6b Initial load
duke
parents:
diff changeset
  2041
   * entity with the specified name in the same document as the context
7f561c08de6b Initial load
duke
parents:
diff changeset
  2042
   * node (see [3.3 Unparsed Entities]). It returns the empty string if
7f561c08de6b Initial load
duke
parents:
diff changeset
  2043
   * there is no such entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2044
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2045
   * XML processors may choose to use the System Identifier (if one
7f561c08de6b Initial load
duke
parents:
diff changeset
  2046
   * is provided) to resolve the entity, rather than the URI in the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2047
   * Public Identifier. The details are dependent on the processor, and
7f561c08de6b Initial load
duke
parents:
diff changeset
  2048
   * we would have to support some form of plug-in resolver to handle
7f561c08de6b Initial load
duke
parents:
diff changeset
  2049
   * this properly. Currently, we simply return the System Identifier if
7f561c08de6b Initial load
duke
parents:
diff changeset
  2050
   * present, and hope that it a usable URI or that our caller can
7f561c08de6b Initial load
duke
parents:
diff changeset
  2051
   * map it to one.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2052
   * TODO: Resolve Public Identifiers... or consider changing function name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2053
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2054
   * If we find a relative URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  2055
   * reference, XML expects it to be resolved in terms of the base URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  2056
   * of the document. The DOM doesn't do that for us, and it isn't
7f561c08de6b Initial load
duke
parents:
diff changeset
  2057
   * entirely clear whether that should be done here; currently that's
7f561c08de6b Initial load
duke
parents:
diff changeset
  2058
   * pushed up to a higher level of our application. (Note that DOM Level
7f561c08de6b Initial load
duke
parents:
diff changeset
  2059
   * 1 didn't store the document's base URI.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2060
   * TODO: Consider resolving Relative URIs.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2061
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2062
   * (The DOM's statement that "An XML processor may choose to
7f561c08de6b Initial load
duke
parents:
diff changeset
  2063
   * completely expand entities before the structure model is passed
7f561c08de6b Initial load
duke
parents:
diff changeset
  2064
   * to the DOM" refers only to parsed entities, not unparsed, and hence
7f561c08de6b Initial load
duke
parents:
diff changeset
  2065
   * doesn't affect this function.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2066
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2067
   * @param name A string containing the Entity Name of the unparsed
7f561c08de6b Initial load
duke
parents:
diff changeset
  2068
   * entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2069
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2070
   * @return String containing the URI of the Unparsed Entity, or an
7f561c08de6b Initial load
duke
parents:
diff changeset
  2071
   * empty string if no such entity exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2072
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2073
  public abstract String getUnparsedEntityURI(String name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2074
7f561c08de6b Initial load
duke
parents:
diff changeset
  2075
  // ============== Boolean methods ================
7f561c08de6b Initial load
duke
parents:
diff changeset
  2076
7f561c08de6b Initial load
duke
parents:
diff changeset
  2077
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2078
   * Return true if the xsl:strip-space or xsl:preserve-space was processed
7f561c08de6b Initial load
duke
parents:
diff changeset
  2079
   * during construction of the DTM document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2080
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2081
   * @return true if this DTM supports prestripping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2082
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2083
  public boolean supportsPreStripping()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2084
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2085
    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2086
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2087
7f561c08de6b Initial load
duke
parents:
diff changeset
  2088
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2089
   * Figure out whether nodeHandle2 should be considered as being later
7f561c08de6b Initial load
duke
parents:
diff changeset
  2090
   * in the document than nodeHandle1, in Document Order as defined
7f561c08de6b Initial load
duke
parents:
diff changeset
  2091
   * by the XPath model. This may not agree with the ordering defined
7f561c08de6b Initial load
duke
parents:
diff changeset
  2092
   * by other XML applications.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2093
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2094
   * There are some cases where ordering isn't defined, and neither are
7f561c08de6b Initial load
duke
parents:
diff changeset
  2095
   * the results of this function -- though we'll generally return false.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2096
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2097
   * @param nodeHandle1 Node handle to perform position comparison on.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2098
   * @param nodeHandle2 Second Node handle to perform position comparison on .
7f561c08de6b Initial load
duke
parents:
diff changeset
  2099
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2100
   * @return true if node1 comes before node2, otherwise return false.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2101
   * You can think of this as
7f561c08de6b Initial load
duke
parents:
diff changeset
  2102
   * <code>(node1.documentOrderPosition &lt;= node2.documentOrderPosition)</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2103
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2104
  public boolean isNodeAfter(int nodeHandle1, int nodeHandle2)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2105
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2106
                // These return NULL if the node doesn't belong to this document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2107
    int index1 = makeNodeIdentity(nodeHandle1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2108
    int index2 = makeNodeIdentity(nodeHandle2);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2109
7f561c08de6b Initial load
duke
parents:
diff changeset
  2110
    return index1!=NULL && index2!=NULL && index1 <= index2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2111
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2112
7f561c08de6b Initial load
duke
parents:
diff changeset
  2113
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2114
   *     2. [element content whitespace] A boolean indicating whether the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2115
   *        character is white space appearing within element content (see [XML],
7f561c08de6b Initial load
duke
parents:
diff changeset
  2116
   *        2.10 "White Space Handling"). Note that validating XML processors are
7f561c08de6b Initial load
duke
parents:
diff changeset
  2117
   *        required by XML 1.0 to provide this information. If there is no
7f561c08de6b Initial load
duke
parents:
diff changeset
  2118
   *        declaration for the containing element, this property has no value for
7f561c08de6b Initial load
duke
parents:
diff changeset
  2119
   *        white space characters. If no declaration has been read, but the [all
7f561c08de6b Initial load
duke
parents:
diff changeset
  2120
   *        declarations processed] property of the document information item is
7f561c08de6b Initial load
duke
parents:
diff changeset
  2121
   *        false (so there may be an unread declaration), then the value of this
7f561c08de6b Initial load
duke
parents:
diff changeset
  2122
   *        property is unknown for white space characters. It is always false for
7f561c08de6b Initial load
duke
parents:
diff changeset
  2123
   *        characters that are not white space.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2124
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2125
   * @param nodeHandle the node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2126
   * @return <code>true</code> if the character data is whitespace;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2127
   *         <code>false</code> otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2128
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2129
  public boolean isCharacterElementContentWhitespace(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2130
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2131
7f561c08de6b Initial load
duke
parents:
diff changeset
  2132
    // %TBD%
7f561c08de6b Initial load
duke
parents:
diff changeset
  2133
    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2134
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2135
7f561c08de6b Initial load
duke
parents:
diff changeset
  2136
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2137
   *    10. [all declarations processed] This property is not strictly speaking
7f561c08de6b Initial load
duke
parents:
diff changeset
  2138
   *        part of the infoset of the document. Rather it is an indication of
7f561c08de6b Initial load
duke
parents:
diff changeset
  2139
   *        whether the processor has read the complete DTD. Its value is a
7f561c08de6b Initial load
duke
parents:
diff changeset
  2140
   *        boolean. If it is false, then certain properties (indicated in their
7f561c08de6b Initial load
duke
parents:
diff changeset
  2141
   *        descriptions below) may be unknown. If it is true, those properties
7f561c08de6b Initial load
duke
parents:
diff changeset
  2142
   *        are never unknown.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2143
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2144
   * @param documentHandle A node handle that must identify a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2145
   * @return <code>true</code> if all declarations were processed;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2146
   *         <code>false</code> otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2147
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2148
  public boolean isDocumentAllDeclarationsProcessed(int documentHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2149
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2150
    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2151
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2152
7f561c08de6b Initial load
duke
parents:
diff changeset
  2153
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2154
   *     5. [specified] A flag indicating whether this attribute was actually
7f561c08de6b Initial load
duke
parents:
diff changeset
  2155
   *        specified in the start-tag of its element, or was defaulted from the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2156
   *        DTD.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2157
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2158
   * @param attributeHandle The attribute handle in question.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2159
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2160
   * @return <code>true</code> if the attribute was specified;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2161
   *         <code>false</code> if it was defaulted.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2162
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2163
  public abstract boolean isAttributeSpecified(int attributeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2164
7f561c08de6b Initial load
duke
parents:
diff changeset
  2165
  // ========== Direct SAX Dispatch, for optimization purposes ========
7f561c08de6b Initial load
duke
parents:
diff changeset
  2166
7f561c08de6b Initial load
duke
parents:
diff changeset
  2167
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2168
   * Directly call the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2169
   * characters method on the passed ContentHandler for the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2170
   * string-value of the given node (see http://www.w3.org/TR/xpath#data-model
7f561c08de6b Initial load
duke
parents:
diff changeset
  2171
   * for the definition of a node's string-value). Multiple calls to the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2172
   * ContentHandler's characters methods may well occur for a single call to
7f561c08de6b Initial load
duke
parents:
diff changeset
  2173
   * this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2174
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2175
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2176
   * @param ch A non-null reference to a ContentHandler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2177
   * @param normalize true if the content should be normalized according to
7f561c08de6b Initial load
duke
parents:
diff changeset
  2178
   * the rules for the XPath
7f561c08de6b Initial load
duke
parents:
diff changeset
  2179
   * <a href="http://www.w3.org/TR/xpath#function-normalize-space">normalize-space</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2180
   * function.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2181
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2182
   * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2183
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2184
  public abstract void dispatchCharactersEvents(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2185
    int nodeHandle, org.xml.sax.ContentHandler ch, boolean normalize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2186
      throws org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2187
7f561c08de6b Initial load
duke
parents:
diff changeset
  2188
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2189
   * Directly create SAX parser events from a subtree.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2190
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2191
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2192
   * @param ch A non-null reference to a ContentHandler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2193
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2194
   * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2195
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2196
  public abstract void dispatchToEvents(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2197
    int nodeHandle, org.xml.sax.ContentHandler ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2198
      throws org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2199
7f561c08de6b Initial load
duke
parents:
diff changeset
  2200
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2201
   * Return an DOM node for the given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2202
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2203
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2204
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2205
   * @return A node representation of the DTM node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2206
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2207
  public org.w3c.dom.Node getNode(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2208
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2209
    return new DTMNodeProxy(this, nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2210
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2211
7f561c08de6b Initial load
duke
parents:
diff changeset
  2212
  // ==== Construction methods (may not be supported by some implementations!) =====
7f561c08de6b Initial load
duke
parents:
diff changeset
  2213
7f561c08de6b Initial load
duke
parents:
diff changeset
  2214
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2215
   * Append a child to the end of the document. Please note that the node
7f561c08de6b Initial load
duke
parents:
diff changeset
  2216
   * is always cloned if it is owned by another document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2217
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2218
   * <p>%REVIEW% "End of the document" needs to be defined more clearly.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2219
   * Does it become the last child of the Document? Of the root element?</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2220
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2221
   * @param newChild Must be a valid new node handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2222
   * @param clone true if the child should be cloned into the document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2223
   * @param cloneDepth if the clone argument is true, specifies that the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2224
   *                   clone should include all it's children.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2225
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2226
  public void appendChild(int newChild, boolean clone, boolean cloneDepth)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2227
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2228
    error(XMLMessages.createXMLMessage(XMLErrorResources.ER_METHOD_NOT_SUPPORTED, null));//"appendChild not yet supported!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  2229
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2230
7f561c08de6b Initial load
duke
parents:
diff changeset
  2231
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2232
   * Append a text node child that will be constructed from a string,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2233
   * to the end of the document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2234
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2235
   * <p>%REVIEW% "End of the document" needs to be defined more clearly.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2236
   * Does it become the last child of the Document? Of the root element?</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2237
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2238
   * @param str Non-null reverence to a string.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2239
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2240
  public void appendTextChild(String str)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2241
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2242
    error(XMLMessages.createXMLMessage(XMLErrorResources.ER_METHOD_NOT_SUPPORTED, null));//"appendTextChild not yet supported!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  2243
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2244
7f561c08de6b Initial load
duke
parents:
diff changeset
  2245
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2246
   * Simple error for asserts and the like.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2247
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2248
   * @param msg Error message to report.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2249
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2250
  protected void error(String msg)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2251
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2252
    throw new DTMException(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2253
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2254
7f561c08de6b Initial load
duke
parents:
diff changeset
  2255
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2256
   * Find out whether or not to strip whispace nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2257
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2258
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2259
   * @return whether or not to strip whispace nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2260
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2261
  protected boolean getShouldStripWhitespace()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2262
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2263
    return m_shouldStripWS;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2264
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2265
7f561c08de6b Initial load
duke
parents:
diff changeset
  2266
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2267
   * Set whether to strip whitespaces and push in current value of
7f561c08de6b Initial load
duke
parents:
diff changeset
  2268
   * m_shouldStripWS in m_shouldStripWhitespaceStack.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2269
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2270
   * @param shouldStrip Flag indicating whether to strip whitespace nodes
7f561c08de6b Initial load
duke
parents:
diff changeset
  2271
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2272
  protected void pushShouldStripWhitespace(boolean shouldStrip)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2273
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2274
7f561c08de6b Initial load
duke
parents:
diff changeset
  2275
    m_shouldStripWS = shouldStrip;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2276
7f561c08de6b Initial load
duke
parents:
diff changeset
  2277
    if (null != m_shouldStripWhitespaceStack)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2278
      m_shouldStripWhitespaceStack.push(shouldStrip);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2279
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2280
7f561c08de6b Initial load
duke
parents:
diff changeset
  2281
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2282
   * Set whether to strip whitespaces at this point by popping out
7f561c08de6b Initial load
duke
parents:
diff changeset
  2283
   * m_shouldStripWhitespaceStack.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2284
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2285
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2286
  protected void popShouldStripWhitespace()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2287
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2288
    if (null != m_shouldStripWhitespaceStack)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2289
      m_shouldStripWS = m_shouldStripWhitespaceStack.popAndTop();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2290
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2291
7f561c08de6b Initial load
duke
parents:
diff changeset
  2292
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2293
   * Set whether to strip whitespaces and set the top of the stack to
7f561c08de6b Initial load
duke
parents:
diff changeset
  2294
   * the current value of m_shouldStripWS.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2295
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2296
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2297
   * @param shouldStrip Flag indicating whether to strip whitespace nodes
7f561c08de6b Initial load
duke
parents:
diff changeset
  2298
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2299
  protected void setShouldStripWhitespace(boolean shouldStrip)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2300
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2301
7f561c08de6b Initial load
duke
parents:
diff changeset
  2302
    m_shouldStripWS = shouldStrip;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2303
7f561c08de6b Initial load
duke
parents:
diff changeset
  2304
    if (null != m_shouldStripWhitespaceStack)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2305
      m_shouldStripWhitespaceStack.setTop(shouldStrip);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2306
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2307
7f561c08de6b Initial load
duke
parents:
diff changeset
  2308
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2309
   * A dummy routine to satisify the abstract interface. If the DTM
7f561c08de6b Initial load
duke
parents:
diff changeset
  2310
   * implememtation that extends the default base requires notification
7f561c08de6b Initial load
duke
parents:
diff changeset
  2311
   * of registration, they can override this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2312
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2313
   public void documentRegistration()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2314
   {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2315
   }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2316
7f561c08de6b Initial load
duke
parents:
diff changeset
  2317
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2318
   * A dummy routine to satisify the abstract interface. If the DTM
7f561c08de6b Initial load
duke
parents:
diff changeset
  2319
   * implememtation that extends the default base requires notification
7f561c08de6b Initial load
duke
parents:
diff changeset
  2320
   * when the document is being released, they can override this method
7f561c08de6b Initial load
duke
parents:
diff changeset
  2321
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2322
   public void documentRelease()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2323
   {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2324
   }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2325
7f561c08de6b Initial load
duke
parents:
diff changeset
  2326
   /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2327
    * Migrate a DTM built with an old DTMManager to a new DTMManager.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2328
    * After the migration, the new DTMManager will treat the DTM as
7f561c08de6b Initial load
duke
parents:
diff changeset
  2329
    * one that is built by itself.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2330
    * This is used to support DTM sharing between multiple transformations.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2331
    * @param mgr the DTMManager
7f561c08de6b Initial load
duke
parents:
diff changeset
  2332
    */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2333
   public void migrateTo(DTMManager mgr)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2334
   {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2335
     m_mgr = mgr;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2336
     if(mgr instanceof DTMManagerDefault)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2337
       m_mgrDefault=(DTMManagerDefault)mgr;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2338
   }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2339
7f561c08de6b Initial load
duke
parents:
diff changeset
  2340
         /** Query which DTMManager this DTM is currently being handled by.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2341
          *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2342
          * %REVEW% Should this become part of the base DTM API?
7f561c08de6b Initial load
duke
parents:
diff changeset
  2343
          *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2344
          * @return a DTMManager, or null if this is a "stand-alone" DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2345
          */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2346
         public DTMManager getManager()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2347
         {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2348
                 return m_mgr;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2349
         }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2350
7f561c08de6b Initial load
duke
parents:
diff changeset
  2351
         /** Query which DTMIDs this DTM is currently using within the DTMManager.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2352
          *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2353
          * %REVEW% Should this become part of the base DTM API?
7f561c08de6b Initial load
duke
parents:
diff changeset
  2354
          *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2355
          * @return an IntVector, or null if this is a "stand-alone" DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2356
          */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2357
         public SuballocatedIntVector getDTMIDs()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2358
         {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2359
                 if(m_mgr==null) return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2360
                 return m_dtmIdent;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2361
         }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2362
}