src/java.xml/share/classes/com/sun/org/apache/xpath/internal/XPathContext.java
author henryjen
Mon, 22 Jan 2018 23:37:23 -0800
changeset 48657 7e5fbd3a2254
parent 48577 8dff65f1d611
child 53593 1ceebbe2c1da
permissions -rw-r--r--
8195989: JDK-8186080 merge add back @LastModified removed by JDK-8193586 Reviewed-by: joehw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
     2
 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     5
 * 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
     6
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * 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
     9
 * (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
    10
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    20
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xpath.internal;
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
import com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.xalan.internal.res.XSLMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.xml.internal.dtm.Axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xml.internal.dtm.DTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xml.internal.dtm.DTMFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xml.internal.dtm.DTMManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2RTFDTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.utils.IntStack;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xml.internal.utils.NodeVector;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xml.internal.utils.ObjectStack;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.utils.PrefixResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.utils.XMLString;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xpath.internal.axes.SubContextList;
18352
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
    38
import com.sun.org.apache.xpath.internal.objects.DTMXRTreeFrag;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xpath.internal.objects.XObject;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.xpath.internal.objects.XString;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
18352
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
    42
import java.lang.reflect.Method;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    43
import java.util.ArrayList;
18352
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
    44
import java.util.HashMap;
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
    45
import java.util.Iterator;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    46
import java.util.List;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    47
import java.util.Map;
18352
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
    48
import java.util.Stack;
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
    49
import javax.xml.transform.ErrorListener;
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
    50
import javax.xml.transform.SourceLocator;
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
    51
import javax.xml.transform.URIResolver;
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
    52
import jdk.xml.internal.JdkXmlUtils;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
import org.xml.sax.XMLReader;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * Default class for the runtime execution context for XPath.
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * <p>This class extends DTMManager but does not directly implement it.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * @xsl.usage advanced
48409
5ab69533994b 8193568: @LastModified tag in license header
joehw
parents: 47359
diff changeset
    60
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
public class XPathContext extends DTMManager // implements ExpressionContext
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
        IntStack m_last_pushed_rtfdtm=new IntStack();
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   * Stack of cached "reusable" DTMs for Result Tree Fragments.
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
   * This is a kluge to handle the problem of starting an RTF before
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
   * the old one is complete.
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
   * %REVIEW% I'm using a Vector rather than Stack so we can reuse
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
   * the DTMs if the problem occurs multiple times. I'm not sure that's
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
   * really a net win versus discarding the DTM and starting a new one...
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
   * but the retained RTF DTM will have been tail-pruned so should be small.
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
   */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    75
  private List<DTM> m_rtfdtm_stack=null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
  /** Index of currently active RTF DTM in m_rtfdtm_stack */
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  private int m_which_rtfdtm=-1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
 /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   * Most recent "reusable" DTM for Global Result Tree Fragments. No stack is
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   * required since we're never going to pop these.
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
  private SAX2RTFDTM m_global_rtfdtm=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
   * HashMap of cached the DTMXRTreeFrag objects, which are identified by DTM IDs.
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
   * The object are just wrappers for DTMs which are used in  XRTreeFrag.
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
   */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    89
  private Map<Integer, DTMXRTreeFrag> m_DTMXRTreeFrags = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   * state of the secure processing feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
  private boolean m_isSecureProcessing = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
    96
  private boolean m_overrideDefaultParser;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    97
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
   * Though XPathContext context extends
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   * the DTMManager, it really is a proxy for this object, which
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   * is the real DTMManager.
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
   */
20959
674f4eb04ac9 8008733: Psr:perf:osb performance regression (18%) in wss_bodyenc
aefimov
parents: 18352
diff changeset
   103
  protected DTMManager m_dtmManager = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
   * Return the DTMManager object.  Though XPathContext context extends
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
   * the DTMManager, it really is a proxy for the real DTMManager.  If a
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
   * caller needs to make a lot of calls to the DTMManager, it is faster
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * if it gets the real one from this function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   public DTMManager getDTMManager()
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
   {
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
     return m_dtmManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   }
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
   * Set the state of the secure processing feature
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
  public void setSecureProcessing(boolean flag)
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    m_isSecureProcessing = flag;
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
   * Return the state of the secure processing feature
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
  public boolean isSecureProcessing()
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    return m_isSecureProcessing;
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
   * Get an instance of a DTM, loaded with the content from the
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
   * specified source.  If the unique flag is true, a new instance will
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
   * always be returned.  Otherwise it is up to the DTMManager to return a
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
   * new instance or an instance that it already created and may be being used
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
   * by someone else.
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
   * (I think more parameters will need to be added for error handling, and entity
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
   * resolution).
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
   * @param source the specification of the source object, which may be null,
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
   *               in which case it is assumed that node construction will take
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
   *               by some other means.
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
   * @param unique true if the returned DTM must be unique, probably because it
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
   * is going to be mutated.
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
   * @param wsfilter Enables filtering of whitespace nodes, and may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
   * @param incremental true if the construction should try and be incremental.
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
   * @param doIndexing true if the caller considers it worth it to use
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
   *                   indexing schemes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
   * @return a non-null DTM reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
  public DTM getDTM(javax.xml.transform.Source source, boolean unique,
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
                    DTMWSFilter wsfilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
                    boolean incremental,
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
                    boolean doIndexing)
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
    return m_dtmManager.getDTM(source, unique, wsfilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
                               incremental, doIndexing);
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
   * Get an instance of a DTM that "owns" a node handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
   * @param nodeHandle the nodeHandle.
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
   * @return a non-null DTM reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
  public DTM getDTM(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    return m_dtmManager.getDTM(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
   * Given a W3C DOM node, try and return a DTM handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
   * Note: calling this may be non-optimal.
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
   * @param node Non-null reference to a DOM node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
   * @return a valid DTM handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
  public int getDTMHandleFromNode(org.w3c.dom.Node node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    return m_dtmManager.getDTMHandleFromNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
//
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
//
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
   * %TBD% Doc
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
  public int getDTMIdentity(DTM dtm)
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    return m_dtmManager.getDTMIdentity(dtm);
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
//
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
   * Creates an empty <code>DocumentFragment</code> object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
   * @return A new <code>DocumentFragment handle</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
  public DTM createDocumentFragment()
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
    return m_dtmManager.createDocumentFragment();
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
//
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
   * Release a DTM either to a lru pool, or completely remove reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
   * DTMs without system IDs are always hard deleted.
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
   * State: experimental.
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
   * @param dtm The DTM to be released.
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
   * @param shouldHardDelete True if the DTM should be removed no matter what.
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
   * @return true if the DTM was removed, false if it was put back in a lru pool.
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
  public boolean release(DTM dtm, boolean shouldHardDelete)
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
    // %REVIEW% If it's a DTM which may contain multiple Result Tree
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    // Fragments, we can't discard it unless we know not only that it
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    // is empty, but that the XPathContext itself is going away. So do
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    // _not_ accept the request. (May want to do it as part of
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    // reset(), though.)
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
    if(m_rtfdtm_stack!=null && m_rtfdtm_stack.contains(dtm))
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
      return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
    return m_dtmManager.release(dtm, shouldHardDelete);
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
   * Create a new <code>DTMIterator</code> based on an XPath
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
   * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
   * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
   * @param xpathCompiler ??? Somehow we need to pass in a subpart of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
   * expression.  I hate to do this with strings, since the larger expression
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
   * has already been parsed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
   * @param pos The position in the expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
   * @return The newly created <code>DTMIterator</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
  public DTMIterator createDTMIterator(Object xpathCompiler, int pos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
    return m_dtmManager.createDTMIterator(xpathCompiler, pos);
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
   * Create a new <code>DTMIterator</code> based on an XPath
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
   * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
   * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
   * @param xpathString Must be a valid string expressing a
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
   * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
   * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
   * @param presolver An object that can resolve prefixes to namespace URLs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
   * @return The newly created <code>DTMIterator</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
  public DTMIterator createDTMIterator(String xpathString,
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
          PrefixResolver presolver)
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
    return m_dtmManager.createDTMIterator(xpathString, presolver);
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
//
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
   * Create a new <code>DTMIterator</code> based only on a whatToShow and
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
   * a DTMFilter.  The traversal semantics are defined as the descendant
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
   * access.
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
   * @param whatToShow This flag specifies which node types may appear in
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
   *   the logical view of the tree presented by the iterator. See the
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
   *   description of <code>NodeFilter</code> for the set of possible
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
   *   <code>SHOW_</code> values.These flags can be combined using
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
   *   <code>OR</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
   * @param filter The <code>NodeFilter</code> to be used with this
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
   *   <code>TreeWalker</code>, or <code>null</code> to indicate no filter.
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
   * @param entityReferenceExpansion The value of this flag determines
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
   *   whether entity reference nodes are expanded.
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
   * @return The newly created <code>NodeIterator</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
  public DTMIterator createDTMIterator(int whatToShow,
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
          DTMFilter filter, boolean entityReferenceExpansion)
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
    return m_dtmManager.createDTMIterator(whatToShow, filter, entityReferenceExpansion);
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
   * Create a new <code>DTMIterator</code> that holds exactly one node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
   * @param node The node handle that the DTMIterator will iterate to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
   * @return The newly created <code>DTMIterator</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
  public DTMIterator createDTMIterator(int node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
    // DescendantIterator iter = new DescendantIterator();
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
    DTMIterator iter = new com.sun.org.apache.xpath.internal.axes.OneStepIteratorForward(Axis.SELF);
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
    iter.setRoot(node, this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
    return iter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
    // return m_dtmManager.createDTMIterator(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
   * Create an XPathContext instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
  public XPathContext()
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
  {
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
   309
    this(false);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
   312
  public XPathContext(boolean overrideDefaultParser) {
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
   313
      init(overrideDefaultParser);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   314
  }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
  /**
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   316
   **This constructor doesn't seem to be used anywhere -- huizhe wang**
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
   * Create an XPathContext instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
   * @param owner Value that can be retrieved via the getOwnerObject() method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
   * @see #getOwnerObject
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
  public XPathContext(Object owner)
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
    m_owner = owner;
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
    try {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   325
      m_ownerGetErrorListener = m_owner.getClass().getMethod("getErrorListener", new Class<?>[] {});
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
    catch (NoSuchMethodException nsme) {}
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
   328
    init(false);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   329
  }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   330
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
   331
  private void init(boolean overrideDefaultParser) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
    m_prefixResolvers.push(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
    m_currentNodes.push(DTM.NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
    m_currentExpressionNodes.push(DTM.NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
    m_saxLocations.push(null);
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
   336
    m_overrideDefaultParser = overrideDefaultParser;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   337
    m_dtmManager = DTMManager.newInstance(
18352
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
   338
                   com.sun.org.apache.xpath.internal.objects.XMLStringFactoryImpl.getFactory()
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
   339
                   );
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
   * Reset for new run.
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
  public void reset()
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
    releaseDTMXRTreeFrags();
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   348
    // These couldn't be disposed of earlier (see comments in release()); zap them now.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   349
    if(m_rtfdtm_stack!=null) {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   350
        for (DTM dtm : m_rtfdtm_stack) {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   351
            m_dtmManager.release(dtm, true);
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   352
        }
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   353
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
    m_rtfdtm_stack=null; // drop our references too
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
    m_which_rtfdtm=-1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
    if(m_global_rtfdtm!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
                        m_dtmManager.release(m_global_rtfdtm,true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
    m_global_rtfdtm=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
    m_dtmManager = DTMManager.newInstance(
18352
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
   364
                   com.sun.org.apache.xpath.internal.objects.XMLStringFactoryImpl.getFactory()
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
   365
                   );
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
    m_saxLocations.removeAllElements();
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   368
    m_axesIteratorStack.removeAllElements();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   369
    m_contextNodeLists.removeAllElements();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   370
    m_currentExpressionNodes.removeAllElements();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   371
    m_currentNodes.removeAllElements();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   372
    m_iteratorRoots.RemoveAllNoClear();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   373
    m_predicatePos.removeAllElements();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   374
    m_predicateRoots.RemoveAllNoClear();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   375
    m_prefixResolvers.removeAllElements();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   377
    m_prefixResolvers.push(null);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
    m_currentNodes.push(DTM.NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
    m_currentExpressionNodes.push(DTM.NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
    m_saxLocations.push(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
  /** The current stylesheet locator. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
  ObjectStack m_saxLocations = new ObjectStack(RECURSIONLIMIT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
   * Set the current locater in the stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
   * @param location The location within the stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
  public void setSAXLocator(SourceLocator location)
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
    m_saxLocations.setTop(location);
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
   * Set the current locater in the stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
   * @param location The location within the stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
  public void pushSAXLocator(SourceLocator location)
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
    m_saxLocations.push(location);
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
   * Push a slot on the locations stack so that setSAXLocator can be
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
   * repeatedly called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
  public void pushSAXLocatorNull()
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
    m_saxLocations.push(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
   * Pop the current locater.
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
  public void popSAXLocator()
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
    m_saxLocations.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
   * Get the current locater in the stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
   * @return The location within the stylesheet, or null if not known.
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
  public SourceLocator getSAXLocator()
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
    return (SourceLocator) m_saxLocations.peek();
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
  /** The owner context of this XPathContext.  In the case of XSLT, this will be a
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
   *  Transformer object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
  private Object m_owner;
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
  /** The owner context of this XPathContext.  In the case of XSLT, this will be a
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
   *  Transformer object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
  private Method m_ownerGetErrorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
   * Get the "owner" context of this context, which should be,
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
   * in the case of XSLT, the Transformer object.  This is needed
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
   * so that XSLT functions can get the Transformer.
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
   * @return The owner object passed into the constructor, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
  public Object getOwnerObject()
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
    return m_owner;
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
  // ================ VarStack ===================
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
   * The stack of Variable stacks.  A VariableStack will be
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
   * pushed onto this stack for each template invocation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
  private VariableStack m_variableStacks = new VariableStack();
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
   * Get the variable stack, which is in charge of variables and
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
   * parameters.
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
   * @return the variable stack, which should not be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
  public final VariableStack getVarStack()
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
    return m_variableStacks;
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
   * Get the variable stack, which is in charge of variables and
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
   * parameters.
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
   * @param varStack non-null reference to the variable stack.
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
  public final void setVarStack(VariableStack varStack)
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
    m_variableStacks = varStack;
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
  // ================ SourceTreeManager ===================
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
  /** The source tree manager, which associates Source objects to source
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
   *  tree nodes. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
  private SourceTreeManager m_sourceTreeManager = new SourceTreeManager();
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
   * Get the SourceTreeManager associated with this execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
   * @return the SourceTreeManager associated with this execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
  public final SourceTreeManager getSourceTreeManager()
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
    return m_sourceTreeManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
   * Set the SourceTreeManager associated with this execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
   * @param mgr the SourceTreeManager to be associated with this
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
   *        execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
  public void setSourceTreeManager(SourceTreeManager mgr)
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
    m_sourceTreeManager = mgr;
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
  // =================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
  /** The ErrorListener where errors and warnings are to be reported.   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
  private ErrorListener m_errorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
  /** A default ErrorListener in case our m_errorListener was not specified and our
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
   *  owner either does not have an ErrorListener or has a null one.
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
  private ErrorListener m_defaultErrorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
   * Get the ErrorListener where errors and warnings are to be reported.
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
   * @return A non-null ErrorListener reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
  public final ErrorListener getErrorListener()
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
    if (null != m_errorListener)
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
        return m_errorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
    ErrorListener retval = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
    try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
      if (null != m_ownerGetErrorListener)
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
        retval = (ErrorListener) m_ownerGetErrorListener.invoke(m_owner, new Object[] {});
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
    catch (Exception e) {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
    if (null == retval)
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
      if (null == m_defaultErrorListener)
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
        m_defaultErrorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
      retval = m_defaultErrorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
    return retval;
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
   * Set the ErrorListener where errors and warnings are to be reported.
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
   * @param listener A non-null ErrorListener reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
  public void setErrorListener(ErrorListener listener) throws IllegalArgumentException
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
    if (listener == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
      throw new IllegalArgumentException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, null)); //"Null error handler");
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
    m_errorListener = listener;
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
  // =================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
  /** The TrAX URI Resolver for resolving URIs from the document(...)
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
   *  function to source tree nodes.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
  private URIResolver m_uriResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
   * Get the URIResolver associated with this execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
   * @return a URI resolver, which may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
  public final URIResolver getURIResolver()
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
    return m_uriResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
   * Set the URIResolver associated with this execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
   * @param resolver the URIResolver to be associated with this
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
   *        execution context, may be null to clear an already set resolver.
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
  public void setURIResolver(URIResolver resolver)
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
    m_uriResolver = resolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
  // =================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
  /** The reader of the primary source tree.    */
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
  public XMLReader m_primaryReader;
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
   * Get primary XMLReader associated with this execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
   * @return The reader of the primary source tree.
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
  public final XMLReader getPrimaryReader()
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
    return m_primaryReader;
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
   * Set primary XMLReader associated with this execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
   * @param reader The reader of the primary source tree.
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
  public void setPrimaryReader(XMLReader reader)
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
    m_primaryReader = reader;
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
  // =================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
  /** Misnamed string manager for XPath messages.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
  // private static XSLMessages m_XSLMessages = new XSLMessages();
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
  //==========================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
  // SECTION: Execution context state tracking
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
  //==========================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
   * The current context node list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
   */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   630
  private Stack<DTMIterator> m_contextNodeLists = new Stack<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   632
  public Stack<DTMIterator> getContextNodeListsStack() { return m_contextNodeLists; }
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   633
  public void setContextNodeListsStack(Stack<DTMIterator> s) { m_contextNodeLists = s; }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
   * Get the current context node list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
   * @return  the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>,
18352
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
   639
   * also referred to here as a <term>context node list</term>.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
  public final DTMIterator getContextNodeList()
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
    if (m_contextNodeLists.size() > 0)
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   645
      return m_contextNodeLists.peek();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
   * Set the current context node list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
   * @param nl the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>,
18352
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
   654
   * also referred to here as a <term>context node list</term>.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
   * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
  public final void pushContextNodeList(DTMIterator nl)
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
    m_contextNodeLists.push(nl);
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
   * Pop the current context node list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
   * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
  public final void popContextNodeList()
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
        if(m_contextNodeLists.isEmpty())
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
          System.err.println("Warning: popContextNodeList when stack is empty!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
      m_contextNodeLists.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
  /**
18352
a1e183c996d6 8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents: 12458
diff changeset
   675
   * The amount to use for stacks that record information during the
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
   * recursive execution.
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
  public static final int RECURSIONLIMIT = (1024*4);
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
  /** The stack of <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a> objects.
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
   *  Not to be confused with the current node list.  %REVIEW% Note that there
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
   *  are no bounds check and resize for this stack, so if it is blown, it's all
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
   *  over.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
  private IntStack m_currentNodes = new IntStack(RECURSIONLIMIT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
//  private NodeVector m_currentNodes = new NodeVector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
  public IntStack getCurrentNodeStack() {return m_currentNodes; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
  public void setCurrentNodeStack(IntStack nv) { m_currentNodes = nv; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
   * Get the current context node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
   * @return the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
  public final int getCurrentNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
    return m_currentNodes.peek();
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
   * Set the current context node and expression node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
   * @param cn the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
   * @param en the sub-expression context node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
  public final void pushCurrentNodeAndExpression(int cn, int en)
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
    m_currentNodes.push(cn);
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
    m_currentExpressionNodes.push(cn);
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
   * Set the current context node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
  public final void popCurrentNodeAndExpression()
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
    m_currentNodes.quickPop(1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
    m_currentExpressionNodes.quickPop(1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
   * Push the current context node, expression node, and prefix resolver.
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
   * @param cn the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
   * @param en the sub-expression context node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
   * @param nc the namespace context (prefix resolver.
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
  public final void pushExpressionState(int cn, int en, PrefixResolver nc)
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
    m_currentNodes.push(cn);
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
    m_currentExpressionNodes.push(cn);
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
    m_prefixResolvers.push(nc);
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
   * Pop the current context node, expression node, and prefix resolver.
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
  public final void popExpressionState()
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
    m_currentNodes.quickPop(1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
    m_currentExpressionNodes.quickPop(1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
    m_prefixResolvers.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
   * Set the current context node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
   * @param n the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
  public final void pushCurrentNode(int n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
    m_currentNodes.push(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
   * Pop the current context node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
  public final void popCurrentNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
    m_currentNodes.quickPop(1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
   * Set the current predicate root.
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
  public final void pushPredicateRoot(int n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
    m_predicateRoots.push(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
   * Pop the current predicate root.
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
  public final void popPredicateRoot()
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
    m_predicateRoots.popQuick();
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
   * Get the current predicate root.
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
  public final int getPredicateRoot()
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
    return m_predicateRoots.peepOrNull();
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
   * Set the current location path iterator root.
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
  public final void pushIteratorRoot(int n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
    m_iteratorRoots.push(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
   * Pop the current location path iterator root.
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
  public final void popIteratorRoot()
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
    m_iteratorRoots.popQuick();
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
   * Get the current location path iterator root.
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
  public final int getIteratorRoot()
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
    return m_iteratorRoots.peepOrNull();
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
  /** A stack of the current sub-expression nodes.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
  private NodeVector m_iteratorRoots = new NodeVector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
  /** A stack of the current sub-expression nodes.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
  private NodeVector m_predicateRoots = new NodeVector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
  /** A stack of the current sub-expression nodes.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
  private IntStack m_currentExpressionNodes = new IntStack(RECURSIONLIMIT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
  public IntStack getCurrentExpressionNodeStack() { return m_currentExpressionNodes; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
  public void setCurrentExpressionNodeStack(IntStack nv) { m_currentExpressionNodes = nv; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
  private IntStack m_predicatePos = new IntStack();
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
  public final int getPredicatePos()
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
    return m_predicatePos.peek();
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
  public final void pushPredicatePos(int n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
    m_predicatePos.push(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
  public final void popPredicatePos()
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
    m_predicatePos.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
   * Get the current node that is the expression's context (i.e. for current() support).
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
   * @return The current sub-expression node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
  public final int getCurrentExpressionNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
    return m_currentExpressionNodes.peek();
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
   * Set the current node that is the expression's context (i.e. for current() support).
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
   * @param n The sub-expression node to be current.
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
  public final void pushCurrentExpressionNode(int n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
    m_currentExpressionNodes.push(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
   * Pop the current node that is the expression's context
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
   * (i.e. for current() support).
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
  public final void popCurrentExpressionNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
    m_currentExpressionNodes.quickPop(1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
  private ObjectStack m_prefixResolvers
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
                                   = new ObjectStack(RECURSIONLIMIT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
   * Get the current namespace context for the xpath.
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
   * @return the current prefix resolver for resolving prefixes to
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
   *         namespace URLs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
  public final PrefixResolver getNamespaceContext()
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
    return (PrefixResolver) m_prefixResolvers.peek();
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
   * Get the current namespace context for the xpath.
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
   * @param pr the prefix resolver to be used for resolving prefixes to
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
   *         namespace URLs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
  public final void setNamespaceContext(PrefixResolver pr)
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
    m_prefixResolvers.setTop(pr);
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
   * Push a current namespace context for the xpath.
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
   * @param pr the prefix resolver to be used for resolving prefixes to
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
   *         namespace URLs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
  public final void pushNamespaceContext(PrefixResolver pr)
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
    m_prefixResolvers.push(pr);
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
   * Just increment the namespace contest stack, so that setNamespaceContext
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
   * can be used on the slot.
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
  public final void pushNamespaceContextNull()
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
    m_prefixResolvers.push(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
   * Pop the current namespace context for the xpath.
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
  public final void popNamespaceContext()
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
    m_prefixResolvers.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
  //==========================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
  // SECTION: Current TreeWalker contexts (for internal use)
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
  //==========================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
   * Stack of AxesIterators.
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
   */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   933
  private Stack<SubContextList> m_axesIteratorStack = new Stack<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   935
  public Stack<SubContextList> getAxesIteratorStackStacks() { return m_axesIteratorStack; }
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   936
  public void setAxesIteratorStackStacks(Stack<SubContextList> s) { m_axesIteratorStack = s; }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
   * Push a TreeWalker on the stack.
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
   * @param iter A sub-context AxesWalker.
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
   * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
  public final void pushSubContextList(SubContextList iter)
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
    m_axesIteratorStack.push(iter);
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
   * Pop the last pushed axes iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
   * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
  public final void popSubContextList()
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
    m_axesIteratorStack.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
   * Get the current axes iterator, or return null if none.
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
   * @return the sub-context node list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
   * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
  public SubContextList getSubContextList()
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
  {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   966
    return m_axesIteratorStack.isEmpty() ? null : m_axesIteratorStack.peek();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
   * Get the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
   * as defined by the XSLT spec.
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
   * @return the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
   * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
  public com.sun.org.apache.xpath.internal.axes.SubContextList getCurrentNodeList()
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
  {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   979
    return m_axesIteratorStack.isEmpty() ? null : m_axesIteratorStack.get(0);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
  //==========================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
  // SECTION: Implementation of ExpressionContext interface
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
  //==========================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
   * Get the current context node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
   * @return The current context node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
  public final int getContextNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
    return this.getCurrentNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
   * Get the current context node list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
   * @return An iterator for the current context list, as
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
   * defined in XSLT.
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
  public final DTMIterator getContextNodes()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
      DTMIterator cnl = getContextNodeList();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
      if (null != cnl)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
        return cnl.cloneWithReset();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
        return null;  // for now... this might ought to be an empty iterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
    catch (CloneNotSupportedException cnse)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
      return null;  // error reporting?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
  XPathExpressionContext expressionContext = new XPathExpressionContext();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
   * The the expression context for extensions for this context.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
   * @return An object that implements the ExpressionContext.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
  public ExpressionContext getExpressionContext()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
    return expressionContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
  public class XPathExpressionContext implements ExpressionContext
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
     * Return the XPathContext associated with this XPathExpressionContext.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
     * Extensions should use this judiciously and only when special processing
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
     * requirements cannot be met another way.  Consider requesting an enhancement
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
     * to the ExpressionContext interface to avoid having to call this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
     * @return the XPathContext associated with this XPathExpressionContext.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
     public XPathContext getXPathContext()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
     {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
       return XPathContext.this;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
     }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
     * Return the DTMManager object.  Though XPathContext context extends
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
     * the DTMManager, it really is a proxy for the real DTMManager.  If a
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
     * caller needs to make a lot of calls to the DTMManager, it is faster
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
     * if it gets the real one from this function.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
     public DTMManager getDTMManager()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
     {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
       return m_dtmManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
     }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
     * Get the current context node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
     * @return The current context node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
    public org.w3c.dom.Node getContextNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
      int context = getCurrentNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
      return getDTM(context).getNode(context);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
     * Get the current context node list.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
     * @return An iterator for the current context list, as
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
     * defined in XSLT.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
    public org.w3c.dom.traversal.NodeIterator getContextNodes()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
      return new com.sun.org.apache.xml.internal.dtm.ref.DTMNodeIterator(getContextNodeList());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
     * Get the error listener.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
     * @return The registered error listener.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
    public ErrorListener getErrorListener()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
      return XPathContext.this.getErrorListener();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
    }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1083
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1084
     * Return the state of the services mechanism feature.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1085
     */
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
  1086
    public boolean overrideDefaultParser() {
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
  1087
        return m_overrideDefaultParser;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1088
    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1089
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1090
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1091
     * Set the state of the services mechanism feature.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1092
     */
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
  1093
    public void setOverrideDefaultParser(boolean flag) {
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 48409
diff changeset
  1094
        m_overrideDefaultParser = flag;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1095
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
     * Get the value of a node as a number.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
     * @param n Node to be converted to a number.  May be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
     * @return value of n as a number.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
    public double toNumber(org.w3c.dom.Node n)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
      // %REVIEW% You can't get much uglier than this...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
      int nodeHandle = getDTMHandleFromNode(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
      DTM dtm = getDTM(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
      XString xobj = (XString)dtm.getStringValue(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
      return xobj.num();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
     * Get the value of a node as a string.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
     * @param n Node to be converted to a string.  May be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
     * @return value of n as a string, or an empty string if n is null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
    public String toString(org.w3c.dom.Node n)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
      // %REVIEW% You can't get much uglier than this...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
      int nodeHandle = getDTMHandleFromNode(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
      DTM dtm = getDTM(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
      XMLString strVal = dtm.getStringValue(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
      return strVal.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
     * Get a variable based on it's qualified name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
     * @param qname The qualified name of the variable.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
     * @return The evaluated value of the variable.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
     * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
    public final XObject getVariableOrParam(com.sun.org.apache.xml.internal.utils.QName qname)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
              throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
      return m_variableStacks.getVariableOrParam(XPathContext.this, qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
    }
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
 /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
   * Get a DTM to be used as a container for a global Result Tree
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
   * Fragment. This will always be an instance of (derived from? equivalent to?)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
   * SAX2DTM, since each RTF is constructed by temporarily redirecting our SAX
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
   * output to it. It may be a single DTM containing for multiple fragments,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
   * if the implementation supports that.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
   * Note: The distinction between this method and getRTFDTM() is that the latter
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
   * allocates space from the dynamic variable stack (m_rtfdtm_stack), which may
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
   * be pruned away again as the templates which defined those variables are exited.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
   * Global variables may be bound late (see XUnresolvedVariable), and never want to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
   * be discarded, hence we need to allocate them separately and don't actually need
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
   * a stack to track them.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
   * @return a non-null DTM reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
  public DTM getGlobalRTFDTM()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
        // We probably should _NOT_ be applying whitespace filtering at this stage!
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
        // Some magic has been applied in DTMManagerDefault to recognize this set of options
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
        // and generate an instance of DTM which can contain multiple documents
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
        // (SAX2RTFDTM). Perhaps not the optimal way of achieving that result, but
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
        // I didn't want to change the manager API at this time, or expose
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
        // too many dependencies on its internals. (Ideally, I'd like to move
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
        // isTreeIncomplete all the way up to DTM, so we wouldn't need to explicitly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
        // specify the subclass here.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
        // If it doesn't exist, or if the one already existing is in the middle of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
        // being constructed, we need to obtain a new DTM to write into. I'm not sure
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
        // the latter will ever arise, but I'd rather be just a bit paranoid..
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
        if( m_global_rtfdtm==null || m_global_rtfdtm.isTreeIncomplete() )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
                m_global_rtfdtm=(SAX2RTFDTM)m_dtmManager.getDTM(null,true,null,false,false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
    return m_global_rtfdtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
   * Get a DTM to be used as a container for a dynamic Result Tree
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
   * Fragment. This will always be an instance of (derived from? equivalent to?)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
   * SAX2DTM, since each RTF is constructed by temporarily redirecting our SAX
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
   * output to it. It may be a single DTM containing for multiple fragments,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
   * if the implementation supports that.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
   * @return a non-null DTM reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
  public DTM getRTFDTM()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
        SAX2RTFDTM rtfdtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
        // We probably should _NOT_ be applying whitespace filtering at this stage!
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
        // Some magic has been applied in DTMManagerDefault to recognize this set of options
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
        // and generate an instance of DTM which can contain multiple documents
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
        // (SAX2RTFDTM). Perhaps not the optimal way of achieving that result, but
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
        // I didn't want to change the manager API at this time, or expose
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
        // too many dependencies on its internals. (Ideally, I'd like to move
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
        // isTreeIncomplete all the way up to DTM, so we wouldn't need to explicitly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
        // specify the subclass here.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
        if(m_rtfdtm_stack==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
        {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1206
            m_rtfdtm_stack=new ArrayList<>();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1207
            rtfdtm=(SAX2RTFDTM)m_dtmManager.getDTM(null,true,null,false,false);
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1208
            m_rtfdtm_stack.add(rtfdtm);
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1209
            ++m_which_rtfdtm;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
        else if(m_which_rtfdtm<0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
        {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1213
            rtfdtm=(SAX2RTFDTM)m_rtfdtm_stack.get(++m_which_rtfdtm);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
        {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1217
            rtfdtm=(SAX2RTFDTM)m_rtfdtm_stack.get(m_which_rtfdtm);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1219
            // It might already be under construction -- the classic example would be
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1220
            // an xsl:variable which uses xsl:call-template as part of its value. To
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1221
            // handle this recursion, we have to start a new RTF DTM, pushing the old
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1222
            // one onto a stack so we can return to it. This is not as uncommon a case
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1223
            // as we might wish, unfortunately, as some folks insist on coding XSLT
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1224
            // as if it were a procedural language...
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1225
            if(rtfdtm.isTreeIncomplete())
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1226
            {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1227
                if(++m_which_rtfdtm < m_rtfdtm_stack.size())
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1228
                    rtfdtm=(SAX2RTFDTM)m_rtfdtm_stack.get(m_which_rtfdtm);
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1229
                else
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
                {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1231
                    rtfdtm=(SAX2RTFDTM)m_dtmManager.getDTM(null,true,null,false,false);
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1232
                    m_rtfdtm_stack.add(rtfdtm);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
                }
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1234
            }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1236
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
    return rtfdtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
  /** Push the RTFDTM's context mark, to allows discarding RTFs added after this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
   * point. (If it doesn't exist we don't push, since we might still be able to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
   * get away with not creating it. That requires that excessive pops be harmless.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
  public void pushRTFContext()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
        m_last_pushed_rtfdtm.push(m_which_rtfdtm);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
        if(null!=m_rtfdtm_stack)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
                ((SAX2RTFDTM)(getRTFDTM())).pushRewindMark();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
  /** Pop the RTFDTM's context mark. This discards any RTFs added after the last
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
   * mark was set.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
   * If there is no RTF DTM, there's nothing to pop so this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
   * becomes a no-op. If pushes were issued before this was called, we count on
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
   * the fact that popRewindMark is defined such that overpopping just resets
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
   * to empty.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
   * Complicating factor: We need to handle the case of popping back to a previous
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
   * RTF DTM, if one of the weird produce-an-RTF-to-build-an-RTF cases arose.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
   * Basically: If pop says this DTM is now empty, then return to the previous
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
   * if one exists, in whatever state we left it in. UGLY, but hopefully the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
   * situation which forces us to consider this will arise exceedingly rarely.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
  public void popRTFContext()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
        int previous=m_last_pushed_rtfdtm.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
        if(null==m_rtfdtm_stack)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
                return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
        if(m_which_rtfdtm==previous)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
                if(previous>=0) // guard against none-active
7f561c08de6b Initial load
duke
parents:
diff changeset
  1274
                {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1275
                        boolean isEmpty=((SAX2RTFDTM)(m_rtfdtm_stack.get(previous))).popRewindMark();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
        else while(m_which_rtfdtm!=previous)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
                // Empty each DTM before popping, so it's ready for reuse
7f561c08de6b Initial load
duke
parents:
diff changeset
  1281
                // _DON'T_ pop the previous, since it's still open (which is why we
7f561c08de6b Initial load
duke
parents:
diff changeset
  1282
                // stacked up more of these) and did not receive a mark.
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1283
                boolean isEmpty=((SAX2RTFDTM)(m_rtfdtm_stack.get(m_which_rtfdtm))).popRewindMark();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1284
                --m_which_rtfdtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1285
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1286
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1287
7f561c08de6b Initial load
duke
parents:
diff changeset
  1288
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1289
   * Gets DTMXRTreeFrag object if one has already been created.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
   * Creates new DTMXRTreeFrag object and adds to m_DTMXRTreeFrags  HashMap,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
   * otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
   * @param dtmIdentity
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
   * @return DTMXRTreeFrag
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
  public DTMXRTreeFrag getDTMXRTreeFrag(int dtmIdentity){
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
    if(m_DTMXRTreeFrags == null){
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1297
      m_DTMXRTreeFrags = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 44797
diff changeset
  1300
    if(m_DTMXRTreeFrags.containsKey(dtmIdentity)){
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1301
       return m_DTMXRTreeFrags.get(dtmIdentity);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
    }else{
7f561c08de6b Initial load
duke
parents:
diff changeset
  1303
      final DTMXRTreeFrag frag = new DTMXRTreeFrag(dtmIdentity,this);
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 44797
diff changeset
  1304
      m_DTMXRTreeFrags.put(dtmIdentity,frag);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
      return frag ;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
7f561c08de6b Initial load
duke
parents:
diff changeset
  1309
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1310
   * Cleans DTMXRTreeFrag objects by removing references
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
   * to DTM and XPathContext objects.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
  private final void releaseDTMXRTreeFrags(){
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
    if(m_DTMXRTreeFrags == null){
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
      return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
    }
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1317
    final Iterator<DTMXRTreeFrag> iter = (m_DTMXRTreeFrags.values()).iterator();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
    while(iter.hasNext()){
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1319
      DTMXRTreeFrag frag = iter.next();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
      frag.destruct();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
      iter.remove();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
    m_DTMXRTreeFrags = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1324
 }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
}