src/java.xml/share/classes/com/sun/org/apache/xpath/internal/operations/Variable.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    21
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xpath.internal.operations;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
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.utils.QName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xpath.internal.Expression;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xpath.internal.ExpressionOwner;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xpath.internal.XPathContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xpath.internal.XPathVisitor;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xpath.internal.axes.PathComponent;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xpath.internal.axes.WalkerFactory;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xpath.internal.objects.XNodeSet;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xpath.internal.objects.XObject;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    35
import java.util.List;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    36
import javax.xml.transform.TransformerException;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * The variable reference expression executer.
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
public class Variable extends Expression implements PathComponent
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
    static final long serialVersionUID = -4334975375609297049L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
  /** Tell if fixupVariables was called.
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
   *  @serial   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
  private boolean m_fixUpWasCalled = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
  /** The qualified name of the variable.
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   *  @serial   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
  protected QName m_qname;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
   * The index of the variable, which is either an absolute index to a
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
   * global, or, if higher than the globals area, must be adjusted by adding
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
   * the offset to the current stack frame.
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
  protected int m_index;
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * Set the index for the variable into the stack.  For advanced use only. You
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   * must know what you are doing to use this.
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
   * @param index a global or local index.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
  public void setIndex(int index)
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
        m_index = index;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
   * Set the index for the variable into the stack.  For advanced use only.
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
   * @return index a global or local index.
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
  public int getIndex()
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
        return m_index;
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   * Set whether or not this is a global reference.  For advanced use only.
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   * @param isGlobal true if this should be a global variable reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
  public void setIsGlobal(boolean isGlobal)
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        m_isGlobal = isGlobal;
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   * Set the index for the variable into the stack.  For advanced use only.
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * @return true if this should be a global variable reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
  public boolean getGlobal()
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
        return m_isGlobal;
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
  protected boolean m_isGlobal = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
   * This function is used to fixup variables from QNames to stack frame
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * indexes at stylesheet build time.
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   * @param vars List of QNames that correspond to variables.  This list
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   * should be searched backwards for the first qualified name that
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
   * corresponds to the variable reference qname.  The position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
   * QName in the vector from the start of the vector will be its position
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   * in the stack frame (but variables above the globalsTop value will need
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
   * to be offset to the current stack frame).
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
   */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   117
  public void fixupVariables(List<QName> vars, int globalsSize)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    m_fixUpWasCalled = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
    int sz = vars.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    for (int i = vars.size()-1; i >= 0; i--)
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   124
      QName qn = vars.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
      // System.out.println("qn: "+qn);
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
      if(qn.equals(m_qname))
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
        if(i < globalsSize)
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
          m_isGlobal = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
          m_index = i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
          m_index = i-globalsSize;
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
        return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    java.lang.String msg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_COULD_NOT_FIND_VAR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
                                             new Object[]{m_qname.toString()});
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    TransformerException te = new TransformerException(msg, this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
    throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(te);
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
   * Set the qualified name of the variable.
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
   * @param qname Must be a non-null reference to a qualified name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
  public void setQName(QName qname)
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    m_qname = qname;
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
   * Get the qualified name of the variable.
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
   * @return A non-null reference to a qualified name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
  public QName getQName()
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
    return m_qname;
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
   * Execute an expression in the XPath runtime context, and return the
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
   * result of the expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
   * @param xctxt The XPath runtime context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
   * @return The result of the expression in the form of a <code>XObject</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
   * @throws javax.xml.transform.TransformerException if a runtime exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
   *         occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
  public XObject execute(XPathContext xctxt)
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
        return execute(xctxt, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
   * Dereference the variable, and return the reference value.  Note that lazy
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
   * evaluation will occur.  If a variable within scope is not found, a warning
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
   * will be sent to the error listener, and an empty nodeset will be returned.
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
   * @param xctxt The runtime execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
   * @return The evaluated variable, or an empty nodeset if not found.
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
  public XObject execute(XPathContext xctxt, boolean destructiveOK) throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    com.sun.org.apache.xml.internal.utils.PrefixResolver xprefixResolver = xctxt.getNamespaceContext();
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    XObject result;
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    // Is the variable fetched always the same?
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
    // XObject result = xctxt.getVariable(m_qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    if(m_fixUpWasCalled)
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
      if(m_isGlobal)
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
        result = xctxt.getVarStack().getGlobalVariable(xctxt, m_index, destructiveOK);
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
        result = xctxt.getVarStack().getLocalVariable(xctxt, m_index, destructiveOK);
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
        result = xctxt.getVarStack().getVariableOrParam(xctxt,m_qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
      if (null == result)
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
        // This should now never happen...
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
        warn(xctxt, XPATHErrorResources.WG_ILLEGAL_VARIABLE_REFERENCE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
             new Object[]{ m_qname.getLocalPart() });  //"VariableReference given for variable out "+
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
  //      (new RuntimeException()).printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
  //      error(xctxt, XPATHErrorResources.ER_COULDNOT_GET_VAR_NAMED,
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
  //            new Object[]{ m_qname.getLocalPart() });  //"Could not get variable named "+varName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
        result = new XNodeSet(xctxt.getDTMManager());
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
      return result;
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
//    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
//    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
//    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
//      // Hack city... big time.  This is needed to evaluate xpaths from extensions,
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
//      // pending some bright light going off in my head.  Some sort of callback?
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
//      synchronized(this)
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
//      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
//              com.sun.org.apache.xalan.internal.templates.ElemVariable vvar= getElemVariable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
//              if(null != vvar)
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
//              {
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
//          m_index = vvar.getIndex();
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
//          m_isGlobal = vvar.getIsTopLevel();
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
//          m_fixUpWasCalled = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
//          return execute(xctxt);
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
//              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
//      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
//      throw new javax.xml.transform.TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VAR_NOT_RESOLVABLE, new Object[]{m_qname.toString()})); //"Variable not resolvable: "+m_qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
//    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
   * Get the XSLT ElemVariable that this sub-expression references.  In order for
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
   * this to work, the SourceLocator must be the owning ElemTemplateElement.
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
   * @return The dereference to the ElemVariable, or null if not found.
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
  // J2SE does not support Xalan interpretive
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
  /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
  public com.sun.org.apache.xalan.internal.templates.ElemVariable getElemVariable()
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
    // Get the current ElemTemplateElement, and then walk backwards in
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
    // document order, searching
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
    // for an xsl:param element or xsl:variable element that matches our
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
    // qname.  If we reach the top level, use the StylesheetRoot's composed
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
    // list of top level variables and parameters.
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
    com.sun.org.apache.xalan.internal.templates.ElemVariable vvar = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
    com.sun.org.apache.xpath.internal.ExpressionNode owner = getExpressionOwner();
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    if (null != owner && owner instanceof com.sun.org.apache.xalan.internal.templates.ElemTemplateElement)
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
      com.sun.org.apache.xalan.internal.templates.ElemTemplateElement prev =
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        (com.sun.org.apache.xalan.internal.templates.ElemTemplateElement) owner;
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
      if (!(prev instanceof com.sun.org.apache.xalan.internal.templates.Stylesheet))
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
        while ( prev != null && !(prev.getParentNode() instanceof com.sun.org.apache.xalan.internal.templates.Stylesheet) )
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
          com.sun.org.apache.xalan.internal.templates.ElemTemplateElement savedprev = prev;
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
          while (null != (prev = prev.getPreviousSiblingElem()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
            if(prev instanceof com.sun.org.apache.xalan.internal.templates.ElemVariable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
              vvar = (com.sun.org.apache.xalan.internal.templates.ElemVariable) prev;
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
              if (vvar.getName().equals(m_qname))
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
                return vvar;
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
              vvar = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
          prev = savedprev.getParentElem();
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
      if (prev != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        vvar = prev.getStylesheetRoot().getVariableOrParamComposed(m_qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
    return vvar;
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
   * Tell if this expression returns a stable number that will not change during
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
   * iterations within the expression.  This is used to determine if a proximity
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
   * position predicate can indicate that no more searching has to occur.
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
   * @return true if the expression represents a stable number.
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
  public boolean isStableNumber()
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
   * Get the analysis bits for this walker, as defined in the WalkerFactory.
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
   * @return One of WalkerFactory#BIT_DESCENDANT, etc.
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
  public int getAnalysisBits()
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
    // J2SE does not support Xalan interpretive
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
    /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
        com.sun.org.apache.xalan.internal.templates.ElemVariable vvar = getElemVariable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
        if(null != vvar)
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
                XPath xpath = vvar.getSelect();
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
                if(null != xpath)
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
                        Expression expr = xpath.getExpression();
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
                        if(null != expr && expr instanceof PathComponent)
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
                                return ((PathComponent)expr).getAnalysisBits();
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
    */
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
    return WalkerFactory.BIT_FILTER;
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
   * @see com.sun.org.apache.xpath.internal.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
        visitor.visitVariableRef(owner, this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
   * @see Expression#deepEquals(Expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
  public boolean deepEquals(Expression expr)
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
        if(!isSameClass(expr))
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
        if(!m_qname.equals(((Variable)expr).m_qname))
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
    // J2SE does not support Xalan interpretive
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
    /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
        // We have to make sure that the qname really references
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
        // the same variable element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
    if(getElemVariable() != ((Variable)expr).getElemVariable())
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        */
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
  static final java.lang.String PSUEDOVARNAMESPACE = "http://xml.apache.org/xalan/psuedovar";
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
   * Tell if this is a psuedo variable reference, declared by Xalan instead
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
   * of by the user.
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
  public boolean isPsuedoVarRef()
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
        java.lang.String ns = m_qname.getNamespaceURI();
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
        if((null != ns) && ns.equals(PSUEDOVARNAMESPACE))
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
                if(m_qname.getLocalName().startsWith("#"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
                        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
        return false;
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
}