jaxp/src/com/sun/org/apache/xpath/internal/compiler/Compiler.java
author lana
Tue, 18 Mar 2014 17:49:48 -0700
changeset 23377 2af1ddf102a4
parent 12457 c348e06f0e82
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: Compiler.java,v 1.2.4.1 2005/09/14 19:47:10 jeffsuttor Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xpath.internal.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import javax.xml.transform.ErrorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import javax.xml.transform.SourceLocator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import javax.xml.transform.TransformerException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xalan.internal.res.XSLMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xml.internal.dtm.Axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xml.internal.dtm.DTMFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xml.internal.utils.PrefixResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xml.internal.utils.QName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.utils.SAXSourceLocator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xpath.internal.Expression;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xpath.internal.axes.UnionPathIterator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xpath.internal.axes.WalkerFactory;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xpath.internal.functions.FuncExtFunction;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.xpath.internal.functions.FuncExtFunctionAvailable;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.xpath.internal.functions.Function;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xpath.internal.functions.WrongNumberArgsException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.xpath.internal.objects.XNumber;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.xpath.internal.objects.XString;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.xpath.internal.operations.And;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import com.sun.org.apache.xpath.internal.operations.Div;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import com.sun.org.apache.xpath.internal.operations.Equals;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
import com.sun.org.apache.xpath.internal.operations.Gt;
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
import com.sun.org.apache.xpath.internal.operations.Gte;
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
import com.sun.org.apache.xpath.internal.operations.Lt;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
import com.sun.org.apache.xpath.internal.operations.Lte;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
import com.sun.org.apache.xpath.internal.operations.Minus;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
import com.sun.org.apache.xpath.internal.operations.Mod;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
import com.sun.org.apache.xpath.internal.operations.Mult;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
import com.sun.org.apache.xpath.internal.operations.Neg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
import com.sun.org.apache.xpath.internal.operations.NotEquals;
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
import com.sun.org.apache.xpath.internal.operations.Operation;
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
import com.sun.org.apache.xpath.internal.operations.Or;
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
import com.sun.org.apache.xpath.internal.operations.Plus;
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
import com.sun.org.apache.xpath.internal.operations.UnaryOperation;
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
import com.sun.org.apache.xpath.internal.operations.Variable;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
import com.sun.org.apache.xpath.internal.patterns.FunctionPattern;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
import com.sun.org.apache.xpath.internal.patterns.NodeTest;
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
import com.sun.org.apache.xpath.internal.patterns.StepPattern;
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
import com.sun.org.apache.xpath.internal.patterns.UnionPattern;
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
 * An instance of this class compiles an XPath string expression into
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
 * a Expression object.  This class compiles the string into a sequence
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
 * of operation codes (op map) and then builds from that into an Expression
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
 * tree.
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
 * @xsl.usage advanced
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
public class Compiler extends OpMap
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   * Construct a Compiler object with a specific ErrorListener and
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   * SourceLocator where the expression is located.
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   * @param errorHandler Error listener where messages will be sent, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   *                     if messages should be sent to System err.
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   * @param locator The location object where the expression lives, which
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   *                may be null, but which, if not null, must be valid over
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
   *                the long haul, in other words, it will not be cloned.
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
   * @param fTable  The FunctionTable object where the xpath build-in
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
   *                functions are stored.
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
  public Compiler(ErrorListener errorHandler, SourceLocator locator,
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
            FunctionTable fTable)
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    m_errorHandler = errorHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    m_locator = locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
    m_functionTable = fTable;
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
   * Construct a Compiler instance that has a null error listener and a
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   * null source locator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
  public Compiler()
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    m_errorHandler = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    m_locator = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * Execute the XPath object from a given opcode position.
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   * @param opPos The current position in the xpath.m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   * @return The result of the XPath.
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
   * @throws TransformerException if there is a syntax or other error.
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   * @xsl.usage advanced
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
  public Expression compile(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    int op = getOp(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    Expression expr = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    // System.out.println(getPatternString()+"op: "+op);
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    switch (op)
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    case OpCodes.OP_XPATH :
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
      expr = compile(opPos + 2); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    case OpCodes.OP_OR :
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
      expr = or(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    case OpCodes.OP_AND :
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
      expr = and(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    case OpCodes.OP_NOTEQUALS :
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
      expr = notequals(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    case OpCodes.OP_EQUALS :
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
      expr = equals(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    case OpCodes.OP_LTE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
      expr = lte(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    case OpCodes.OP_LT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
      expr = lt(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    case OpCodes.OP_GTE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
      expr = gte(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    case OpCodes.OP_GT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
      expr = gt(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    case OpCodes.OP_PLUS :
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
      expr = plus(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
    case OpCodes.OP_MINUS :
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
      expr = minus(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
    case OpCodes.OP_MULT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
      expr = mult(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
    case OpCodes.OP_DIV :
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
      expr = div(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
    case OpCodes.OP_MOD :
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
      expr = mod(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
//    case OpCodes.OP_QUO :
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
//      expr = quo(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
    case OpCodes.OP_NEG :
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
      expr = neg(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
    case OpCodes.OP_STRING :
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
      expr = string(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
    case OpCodes.OP_BOOL :
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
      expr = bool(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
    case OpCodes.OP_NUMBER :
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
      expr = number(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    case OpCodes.OP_UNION :
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
      expr = union(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
    case OpCodes.OP_LITERAL :
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
      expr = literal(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
    case OpCodes.OP_VARIABLE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
      expr = variable(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
    case OpCodes.OP_GROUP :
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
      expr = group(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    case OpCodes.OP_NUMBERLIT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
      expr = numberlit(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
    case OpCodes.OP_ARGUMENT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
      expr = arg(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
    case OpCodes.OP_EXTFUNCTION :
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
      expr = compileExtension(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
    case OpCodes.OP_FUNCTION :
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
      expr = compileFunction(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
    case OpCodes.OP_LOCATIONPATH :
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
      expr = locationPath(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    case OpCodes.OP_PREDICATE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
      expr = null; break;  // should never hit this here.
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
    case OpCodes.OP_MATCHPATTERN :
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
      expr = matchPattern(opPos + 2); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
    case OpCodes.OP_LOCATIONPATHPATTERN :
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
      expr = locationPathPattern(opPos); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
    case OpCodes.OP_QUO:
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
      error(XPATHErrorResources.ER_UNKNOWN_OPCODE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
            new Object[]{ "quo" });  //"ERROR! Unknown op code: "+m_opMap[opPos]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    default :
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
      error(XPATHErrorResources.ER_UNKNOWN_OPCODE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
            new Object[]{ Integer.toString(getOp(opPos)) });  //"ERROR! Unknown op code: "+m_opMap[opPos]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
//    if(null != expr)
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
//      expr.setSourceLocator(m_locator);
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    return expr;
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
   * Bottle-neck compilation of an operation with left and right operands.
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
   * @param operation non-null reference to parent operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
   * @param opPos The op map position of the parent operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Operation} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
   * @throws TransformerException if there is a syntax or other error.
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
  private Expression compileOperation(Operation operation, int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
          throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    int leftPos = getFirstChildPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
    int rightPos = getNextOpPos(leftPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    operation.setLeftRight(compile(leftPos), compile(rightPos));
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    return operation;
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
   * Bottle-neck compilation of a unary operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
   * @param unary The parent unary operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
   * @param opPos The position in the op map of the parent operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
   * @return The unary argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
   * @throws TransformerException if syntax or other error occurs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
  private Expression compileUnary(UnaryOperation unary, int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
          throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    int rightPos = getFirstChildPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
    unary.setRight(compile(rightPos));
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
    return unary;
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
   * Compile an 'or' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Or} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
  protected Expression or(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
    return compileOperation(new Or(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
   * Compile an 'and' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.And} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
  protected Expression and(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
    return compileOperation(new And(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
   * Compile a '!=' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.NotEquals} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
  protected Expression notequals(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
    return compileOperation(new NotEquals(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
   * Compile a '=' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Equals} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
  protected Expression equals(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
    return compileOperation(new Equals(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
   * Compile a '<=' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Lte} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
  protected Expression lte(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
    return compileOperation(new Lte(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
   * Compile a '<' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Lt} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
  protected Expression lt(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
    return compileOperation(new Lt(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
   * Compile a '>=' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Gte} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
  protected Expression gte(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
    return compileOperation(new Gte(), opPos);
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
   * Compile a '>' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Gt} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
  protected Expression gt(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
    return compileOperation(new Gt(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
   * Compile a '+' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Plus} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
  protected Expression plus(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
    return compileOperation(new Plus(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
   * Compile a '-' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Minus} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
  protected Expression minus(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
    return compileOperation(new Minus(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
   * Compile a '*' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Mult} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
  protected Expression mult(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
    return compileOperation(new Mult(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
   * Compile a 'div' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Div} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
  protected Expression div(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
    return compileOperation(new Div(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
   * Compile a 'mod' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Mod} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
  protected Expression mod(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
    return compileOperation(new Mod(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
  /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
   * Compile a 'quo' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Quo} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
//  protected Expression quo(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
//  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
//    return compileOperation(new Quo(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
//  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
   * Compile a unary '-' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Neg} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
  protected Expression neg(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
    return compileUnary(new Neg(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
   * Compile a 'string(...)' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.String} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
  protected Expression string(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
    return compileUnary(new com.sun.org.apache.xpath.internal.operations.String(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
   * Compile a 'boolean(...)' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Bool} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
  protected Expression bool(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
    return compileUnary(new com.sun.org.apache.xpath.internal.operations.Bool(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
   * Compile a 'number(...)' operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Number} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
  protected Expression number(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
    return compileUnary(new com.sun.org.apache.xpath.internal.operations.Number(), opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
   * Compile a literal string value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
   * @return reference to {@link com.sun.org.apache.xpath.internal.objects.XString} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
  protected Expression literal(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
    opPos = getFirstChildPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
    return (XString) getTokenQueue().elementAt(getOp(opPos));
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
   * Compile a literal number value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
   * @return reference to {@link com.sun.org.apache.xpath.internal.objects.XNumber} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
  protected Expression numberlit(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
    opPos = getFirstChildPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
    return (XNumber) getTokenQueue().elementAt(getOp(opPos));
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
   * Compile a variable reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
   * @return reference to {@link com.sun.org.apache.xpath.internal.operations.Variable} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
  protected Expression variable(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
    Variable var = new Variable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
    opPos = getFirstChildPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
    int nsPos = getOp(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
    java.lang.String namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
      = (OpCodes.EMPTY == nsPos) ? null
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
                                   : (java.lang.String) getTokenQueue().elementAt(nsPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
    java.lang.String localname
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
      = (java.lang.String) getTokenQueue().elementAt(getOp(opPos+1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
    QName qname = new QName(namespace, localname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
    var.setQName(qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
    return var;
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
   * Compile an expression group.
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
   * @return reference to the contained expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
  protected Expression group(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
    // no-op
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
    return compile(opPos + 2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
   * Compile a function argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
   * @return reference to the argument expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
  protected Expression arg(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
    // no-op
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
    return compile(opPos + 2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
   * Compile a location path union. The UnionPathIterator itself may create
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
   * {@link com.sun.org.apache.xpath.internal.axes.LocPathIterator} children.
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
   * @return reference to {@link com.sun.org.apache.xpath.internal.axes.LocPathIterator} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
  protected Expression union(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
    locPathDepth++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
      return UnionPathIterator.createUnionIterator(this, opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
    finally
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
      locPathDepth--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
  private int locPathDepth = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
   * Get the level of the location path or union being constructed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
   * @return 0 if it is a top-level path.
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
  public int getLocationPathDepth()
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
    return locPathDepth;
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
   * Get the function table
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
  FunctionTable getFunctionTable()
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
    return m_functionTable;
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
   * Compile a location path.  The LocPathIterator itself may create
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
   * {@link com.sun.org.apache.xpath.internal.axes.AxesWalker} children.
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
   * @return reference to {@link com.sun.org.apache.xpath.internal.axes.LocPathIterator} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
  public Expression locationPath(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
    locPathDepth++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
      DTMIterator iter = WalkerFactory.newDTMIterator(this, opPos, (locPathDepth == 0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
      return (Expression)iter; // cast OK, I guess.
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
    finally
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
      locPathDepth--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
   * Compile a location step predicate expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
   * @return the contained predicate expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
  public Expression predicate(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
    return compile(opPos + 2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
   * Compile an entire match pattern expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
   * @return reference to {@link com.sun.org.apache.xpath.internal.patterns.UnionPattern} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
  protected Expression matchPattern(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
    locPathDepth++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
      // First, count...
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
      int nextOpPos = opPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
      int i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
      for (i = 0; getOp(nextOpPos) == OpCodes.OP_LOCATIONPATHPATTERN; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
        nextOpPos = getNextOpPos(nextOpPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
      if (i == 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
        return compile(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
      UnionPattern up = new UnionPattern();
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
      StepPattern[] patterns = new StepPattern[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
      for (i = 0; getOp(opPos) == OpCodes.OP_LOCATIONPATHPATTERN; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
        nextOpPos = getNextOpPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
        patterns[i] = (StepPattern) compile(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
        opPos = nextOpPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
      up.setPatterns(patterns);
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
      return up;
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
    finally
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
      locPathDepth--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
   * Compile a location match pattern unit expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
   * @return reference to {@link com.sun.org.apache.xpath.internal.patterns.StepPattern} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
  public Expression locationPathPattern(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
          throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
    opPos = getFirstChildPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
    return stepPattern(opPos, 0, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
   * Get a {@link org.w3c.dom.traversal.NodeFilter} bit set that tells what
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
   * to show for a given node test.
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
   * @param opPos the op map position for the location step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
   * @return {@link org.w3c.dom.traversal.NodeFilter} bit set that tells what
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
   *         to show for a given node test.
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
  public int getWhatToShow(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
    int axesType = getOp(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
    int testType = getOp(opPos + 3);
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
    // System.out.println("testType: "+testType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
    switch (testType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
    case OpCodes.NODETYPE_COMMENT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
      return DTMFilter.SHOW_COMMENT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
    case OpCodes.NODETYPE_TEXT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
//      return DTMFilter.SHOW_TEXT | DTMFilter.SHOW_COMMENT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
      return DTMFilter.SHOW_TEXT | DTMFilter.SHOW_CDATA_SECTION ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
    case OpCodes.NODETYPE_PI :
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
      return DTMFilter.SHOW_PROCESSING_INSTRUCTION;
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
    case OpCodes.NODETYPE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
//      return DTMFilter.SHOW_ALL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
      switch (axesType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
      case OpCodes.FROM_NAMESPACE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
        return DTMFilter.SHOW_NAMESPACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
      case OpCodes.FROM_ATTRIBUTES :
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
      case OpCodes.MATCH_ATTRIBUTE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
        return DTMFilter.SHOW_ATTRIBUTE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
      case OpCodes.FROM_SELF:
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
      case OpCodes.FROM_ANCESTORS_OR_SELF:
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
      case OpCodes.FROM_DESCENDANTS_OR_SELF:
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
        return DTMFilter.SHOW_ALL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
      default:
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
        if (getOp(0) == OpCodes.OP_MATCHPATTERN)
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
          return ~DTMFilter.SHOW_ATTRIBUTE
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
                  & ~DTMFilter.SHOW_DOCUMENT
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
                  & ~DTMFilter.SHOW_DOCUMENT_FRAGMENT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
          return ~DTMFilter.SHOW_ATTRIBUTE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
    case OpCodes.NODETYPE_ROOT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
      return DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
    case OpCodes.NODETYPE_FUNCTEST :
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
      return NodeTest.SHOW_BYFUNCTION;
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
    case OpCodes.NODENAME :
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
      switch (axesType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
      case OpCodes.FROM_NAMESPACE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
        return DTMFilter.SHOW_NAMESPACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
      case OpCodes.FROM_ATTRIBUTES :
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
      case OpCodes.MATCH_ATTRIBUTE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
        return DTMFilter.SHOW_ATTRIBUTE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
      // break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
      case OpCodes.MATCH_ANY_ANCESTOR :
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
      case OpCodes.MATCH_IMMEDIATE_ANCESTOR :
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
        return DTMFilter.SHOW_ELEMENT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
      // break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
      default :
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
        return DTMFilter.SHOW_ELEMENT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
    default :
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
      // System.err.println("We should never reach here.");
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
      return DTMFilter.SHOW_ALL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
private static final boolean DEBUG = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
   * Compile a step pattern unit expression, used for both location paths
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
   * and match patterns.
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
   * @param stepCount The number of steps to expect.
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
   * @param ancestorPattern The owning StepPattern, which may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
   * @return reference to {@link com.sun.org.apache.xpath.internal.patterns.StepPattern} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
  protected StepPattern stepPattern(
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
          int opPos, int stepCount, StepPattern ancestorPattern)
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
            throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
    int startOpPos = opPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
    int stepType = getOp(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
    if (OpCodes.ENDOP == stepType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
    boolean addMagicSelf = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
    int endStep = getNextOpPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
    // int nextStepType = getOpMap()[endStep];
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
    StepPattern pattern;
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
    // boolean isSimple = ((OpCodes.ENDOP == nextStepType) && (stepCount == 0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
    int argLen;
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
    switch (stepType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
    case OpCodes.OP_FUNCTION :
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
      if(DEBUG)
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
        System.out.println("MATCH_FUNCTION: "+m_currentPattern);
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
      addMagicSelf = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
      argLen = getOp(opPos + OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
      pattern = new FunctionPattern(compileFunction(opPos), Axis.PARENT, Axis.CHILD);
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
    case OpCodes.FROM_ROOT :
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
      if(DEBUG)
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
        System.out.println("FROM_ROOT, "+m_currentPattern);
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
      addMagicSelf = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
      argLen = getArgLengthOfStep(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
      opPos = getFirstChildPosOfStep(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
      pattern = new StepPattern(DTMFilter.SHOW_DOCUMENT |
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
                                DTMFilter.SHOW_DOCUMENT_FRAGMENT,
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
                                Axis.PARENT, Axis.CHILD);
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
    case OpCodes.MATCH_ATTRIBUTE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
     if(DEBUG)
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
        System.out.println("MATCH_ATTRIBUTE: "+getStepLocalName(startOpPos)+", "+m_currentPattern);
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
      argLen = getArgLengthOfStep(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
      opPos = getFirstChildPosOfStep(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
      pattern = new StepPattern(DTMFilter.SHOW_ATTRIBUTE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
                                getStepNS(startOpPos),
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
                                getStepLocalName(startOpPos),
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
                                Axis.PARENT, Axis.ATTRIBUTE);
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
    case OpCodes.MATCH_ANY_ANCESTOR :
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
      if(DEBUG)
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
        System.out.println("MATCH_ANY_ANCESTOR: "+getStepLocalName(startOpPos)+", "+m_currentPattern);
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
      argLen = getArgLengthOfStep(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
      opPos = getFirstChildPosOfStep(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
      int what = getWhatToShow(startOpPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
      // bit-o-hackery, but this code is due for the morgue anyway...
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
      if(0x00000500 == what)
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
        addMagicSelf = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
      pattern = new StepPattern(getWhatToShow(startOpPos),
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
                                        getStepNS(startOpPos),
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
                                        getStepLocalName(startOpPos),
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
                                        Axis.ANCESTOR, Axis.CHILD);
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
    case OpCodes.MATCH_IMMEDIATE_ANCESTOR :
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
      if(DEBUG)
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
        System.out.println("MATCH_IMMEDIATE_ANCESTOR: "+getStepLocalName(startOpPos)+", "+m_currentPattern);
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
      argLen = getArgLengthOfStep(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
      opPos = getFirstChildPosOfStep(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
      pattern = new StepPattern(getWhatToShow(startOpPos),
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
                                getStepNS(startOpPos),
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
                                getStepLocalName(startOpPos),
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
                                Axis.PARENT, Axis.CHILD);
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
    default :
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
      error(XPATHErrorResources.ER_UNKNOWN_MATCH_OPERATION, null);  //"unknown match operation!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
    pattern.setPredicates(getCompiledPredicates(opPos + argLen));
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
    if(null == ancestorPattern)
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
      // This is the magic and invisible "." at the head of every
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
      // match pattern, and corresponds to the current node in the context
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
      // list, from where predicates are counted.
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
      // So, in order to calculate "foo[3]", it has to count from the
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
      // current node in the context list, so, from that current node,
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
      // the full pattern is really "self::node()/child::foo[3]".  If you
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
      // translate this to a select pattern from the node being tested,
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
      // which is really how we're treating match patterns, it works out to
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
      // self::foo/parent::node[child::foo[3]]", or close enough.
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
        /*      if(addMagicSelf && pattern.getPredicateCount() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
        StepPattern selfPattern = new StepPattern(DTMFilter.SHOW_ALL,
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
                                                  Axis.PARENT, Axis.CHILD);
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
        // We need to keep the new nodetest from affecting the score...
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
        XNumber score = pattern.getStaticScore();
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
        pattern.setRelativePathPattern(selfPattern);
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
        pattern.setStaticScore(score);
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
        selfPattern.setStaticScore(score);
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
        }*/
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
      // System.out.println("Setting "+ancestorPattern+" as relative to "+pattern);
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
      pattern.setRelativePathPattern(ancestorPattern);
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
    StepPattern relativePathPattern = stepPattern(endStep, stepCount + 1,
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
                                        pattern);
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
    return (null != relativePathPattern) ? relativePathPattern : pattern;
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
   * Compile a zero or more predicates for a given match pattern.
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
   * @param opPos The position of the first predicate the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
   * @return reference to array of {@link com.sun.org.apache.xpath.internal.Expression} instances.
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
  public Expression[] getCompiledPredicates(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
          throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
    int count = countPredicates(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
    if (count > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
      Expression[] predicates = new Expression[count];
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
      compilePredicates(opPos, predicates);
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
      return predicates;
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
   * Count the number of predicates in the step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
   * @param opPos The position of the first predicate the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
   * @return The number of predicates for this step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
  public int countPredicates(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
    int count = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
    while (OpCodes.OP_PREDICATE == getOp(opPos))
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
      count++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
      opPos = getNextOpPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
    return count;
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
   * Compiles predicates in the step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
   * @param opPos The position of the first predicate the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
   * @param predicates An empty pre-determined array of
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
   *            {@link com.sun.org.apache.xpath.internal.Expression}s, that will be filled in.
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
   * @throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
  private void compilePredicates(int opPos, Expression[] predicates)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
          throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
    for (int i = 0; OpCodes.OP_PREDICATE == getOp(opPos); i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
      predicates[i] = predicate(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
      opPos = getNextOpPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
   * Compile a built-in XPath function.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
   * @return reference to {@link com.sun.org.apache.xpath.internal.functions.Function} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
  Expression compileFunction(int opPos) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
    int endFunc = opPos + getOp(opPos + 1) - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
    opPos = getFirstChildPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
    int funcID = getOp(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
    opPos++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
    if (-1 != funcID)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
      Function func = m_functionTable.getFunction(funcID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
      /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
       * It is a trick for function-available. Since the function table is an
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
       * instance field, insert this table at compilation time for later usage
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
       */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
      if (func instanceof FuncExtFunctionAvailable)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
          ((FuncExtFunctionAvailable) func).setFunctionTable(m_functionTable);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
      func.postCompileStep(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
      try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
        int i = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
        for (int p = opPos; p < endFunc; p = getNextOpPos(p), i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
          // System.out.println("argPos: "+ p);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
          // System.out.println("argCode: "+ m_opMap[p]);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
          func.setArg(compile(p), i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
        func.checkNumberArgs(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
      catch (WrongNumberArgsException wnae)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
        java.lang.String name = m_functionTable.getFunctionName(funcID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
        m_errorHandler.fatalError( new TransformerException(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
                  XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ONLY_ALLOWS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
                      new Object[]{name, wnae.getMessage()}), m_locator));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
              //"name + " only allows " + wnae.getMessage() + " arguments", m_locator));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
      return func;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
      error(XPATHErrorResources.ER_FUNCTION_TOKEN_NOT_FOUND, null);  //"function token not found.");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
  // The current id for extension functions.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
  private static long s_nextMethodId = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
   * Get the next available method id
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
  synchronized private long getNextMethodId()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
    if (s_nextMethodId == Long.MAX_VALUE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
      s_nextMethodId = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
    return s_nextMethodId++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
   * Compile an extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
   * @param opPos The current position in the m_opMap array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
   * @return reference to {@link com.sun.org.apache.xpath.internal.functions.FuncExtFunction} instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
   * @throws TransformerException if a error occurs creating the Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
  private Expression compileExtension(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
          throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
    int endExtFunc = opPos + getOp(opPos + 1) - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
    opPos = getFirstChildPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
    java.lang.String ns = (java.lang.String) getTokenQueue().elementAt(getOp(opPos));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
    opPos++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
    java.lang.String funcName =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
      (java.lang.String) getTokenQueue().elementAt(getOp(opPos));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
    opPos++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
    // We create a method key to uniquely identify this function so that we
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
    // can cache the object needed to invoke it.  This way, we only pay the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
    // reflection overhead on the first call.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
    Function extension = new FuncExtFunction(ns, funcName, String.valueOf(getNextMethodId()));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
      int i = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
      while (opPos < endExtFunc)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
        int nextOpPos = getNextOpPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
        extension.setArg(this.compile(opPos), i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
        opPos = nextOpPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
        i++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
    catch (WrongNumberArgsException wnae)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
      ;  // should never happen
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
    return extension;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
   * Warn the user of an problem.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
   * @param msg An error msgkey that corresponds to one of the constants found
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
   *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
   *            a key for a format string.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
   * @param args An array of arguments represented in the format string, which
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
   *             may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
   * @throws TransformerException if the current ErrorListoner determines to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
   *                              throw an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
  public void warn(String msg, Object[] args) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
    java.lang.String fmsg = XSLMessages.createXPATHWarning(msg, args);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
    if (null != m_errorHandler)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
      m_errorHandler.warning(new TransformerException(fmsg, m_locator));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
      System.out.println(fmsg
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
                          +"; file "+m_locator.getSystemId()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
                          +"; line "+m_locator.getLineNumber()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
                          +"; column "+m_locator.getColumnNumber());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
    }
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
   * Tell the user of an assertion error, and probably throw an
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
   * exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
   * @param b  If false, a runtime exception will be thrown.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
   * @param msg The assertion message, which should be informative.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
   * @throws RuntimeException if the b argument is false.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
  public void assertion(boolean b, java.lang.String msg)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
    if (!b)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
      java.lang.String fMsg = XSLMessages.createXPATHMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
        XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
        new Object[]{ msg });
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
      throw new RuntimeException(fMsg);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
   * Tell the user of an error, and probably throw an
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
   * exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
   * @param msg An error msgkey that corresponds to one of the constants found
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
   *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
   *            a key for a format string.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
   * @param args An array of arguments represented in the format string, which
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
   *             may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
   * @throws TransformerException if the current ErrorListoner determines to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
   *                              throw an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
  public void error(String msg, Object[] args) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
    java.lang.String fmsg = XSLMessages.createXPATHMessage(msg, args);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
    if (null != m_errorHandler)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
      m_errorHandler.fatalError(new TransformerException(fmsg, m_locator));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
      // System.out.println(te.getMessage()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
      //                    +"; file "+te.getSystemId()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
      //                    +"; line "+te.getLineNumber()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
      //                    +"; column "+te.getColumnNumber());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
      throw new TransformerException(fmsg, (SAXSourceLocator)m_locator);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
7f561c08de6b Initial load
duke
parents:
diff changeset
  1234
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
   * The current prefixResolver for the execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1236
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
  private PrefixResolver m_currentPrefixResolver = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
   * Get the current namespace context for the xpath.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
   * @return The current prefix resolver, *may* be null, though hopefully not.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
  public PrefixResolver getNamespaceContext()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
    return m_currentPrefixResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
   * Set the current namespace context for the xpath.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
   * @param pr The resolver for prefixes in the XPath expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
  public void setNamespaceContext(PrefixResolver pr)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
    m_currentPrefixResolver = pr;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
  /** The error listener where errors will be sent.  If this is null, errors
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
   *  and warnings will be sent to System.err.  May be null.    */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
  ErrorListener m_errorHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
  /** The source locator for the expression being compiled.  May be null. */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
  SourceLocator m_locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
   * The FunctionTable for all xpath build-in functions
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
  private FunctionTable m_functionTable;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
}