src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/FuncExtFunction.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 44797 jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/FuncExtFunction.java@8b3b3b911b8a
child 47359 e1a6c0168741
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    21
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xpath.internal.functions;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import java.util.Vector;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xalan.internal.res.XSLMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xpath.internal.Expression;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xpath.internal.ExpressionNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xpath.internal.ExpressionOwner;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xpath.internal.ExtensionsProvider;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xpath.internal.XPathContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xpath.internal.XPathVisitor;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xpath.internal.objects.XNull;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xpath.internal.objects.XObject;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xpath.internal.res.XPATHMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * An object of this class represents an extension call expression.  When
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * the expression executes, it calls ExtensionsTable#extFunction, and then
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * converts the result to the appropriate XObject.
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * @xsl.usage advanced
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
public class FuncExtFunction extends Function
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
    static final long serialVersionUID = 5196115554693708718L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   * The namespace for the extension function, which should not normally
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   *  be null or empty.
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
   *  @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
  String m_namespace;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
   * The local name of the extension.
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
   *  @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
  String m_extensionName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   * Unique method key, which is passed to ExtensionsTable#extFunction in
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
   *  order to allow caching of the method.
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
   *  @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
  Object m_methodKey;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
   * Array of static expressions which represent the parameters to the
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
   *  function.
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
   *  @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
  Vector m_argVec = new Vector();
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
   * This function is used to fixup variables from QNames to stack frame
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
   * indexes at stylesheet build time.
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
   * @param vars List of QNames that correspond to variables.  This list
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   * should be searched backwards for the first qualified name that
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   * corresponds to the variable reference qname.  The position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   * QName in the vector from the start of the vector will be its position
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   * in the stack frame (but variables above the globalsTop value will need
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   * to be offset to the current stack frame).
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   * NEEDSDOC @param globalsSize
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
  public void fixupVariables(java.util.Vector vars, int globalsSize)
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    if (null != m_argVec)
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
      int nArgs = m_argVec.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
      for (int i = 0; i < nArgs; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
        Expression arg = (Expression) m_argVec.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
        arg.fixupVariables(vars, globalsSize);
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
   * Return the namespace of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
   * @return The namespace of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
  public String getNamespace()
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    return m_namespace;
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
   * Return the name of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
   * @return The name of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
  public String getFunctionName()
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    return m_extensionName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
   * Return the method key of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
   * @return The method key of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
  public Object getMethodKey()
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    return m_methodKey;
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
   * Return the nth argument passed to the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
   * @param n The argument number index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
   * @return The Expression object at the given index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
  public Expression getArg(int n) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    if (n >= 0 && n < m_argVec.size())
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
      return (Expression) m_argVec.elementAt(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
   * Return the number of arguments that were passed
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
   * into this extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
   * @return The number of arguments.
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
  public int getArgCount() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
    return m_argVec.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
   * Create a new FuncExtFunction based on the qualified name of the extension,
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
   * and a unique method key.
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
   * @param namespace The namespace for the extension function, which should
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
   *                  not normally be null or empty.
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
   * @param extensionName The local name of the extension.
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
   * @param methodKey Unique method key, which is passed to
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
   *                  ExtensionsTable#extFunction in order to allow caching
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
   *                  of the method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
  public FuncExtFunction(java.lang.String namespace,
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
                         java.lang.String extensionName, Object methodKey)
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
    //try{throw new Exception("FuncExtFunction() " + namespace + " " + extensionName);} catch (Exception e){e.printStackTrace();}
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
    m_namespace = namespace;
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    m_extensionName = extensionName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
    m_methodKey = methodKey;
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
   * Execute the function.  The function must return
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
   * a valid object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
   * @param xctxt The current execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
   * @return A valid XObject.
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
  public XObject execute(XPathContext xctxt)
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
          throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    if (xctxt.isSecureProcessing())
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
      throw new javax.xml.transform.TransformerException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
        XPATHMessages.createXPATHMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
          XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED,
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
          new Object[] {toString()}));
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    XObject result;
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    Vector argVec = new Vector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
    int nArgs = m_argVec.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    for (int i = 0; i < nArgs; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
      Expression arg = (Expression) m_argVec.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
      XObject xobj = arg.execute(xctxt);
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
      /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
       * Should cache the arguments for func:function
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
       */
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
      xobj.allowDetachToRelease(false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
      argVec.addElement(xobj);
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
    //dml
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject();
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    Object val = extProvider.extFunction(this, argVec);
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    if (null != val)
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
      result = XObject.create(val, xctxt);
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
      result = new XNull();
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    return result;
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
   * Set an argument expression for a function.  This method is called by the
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
   * XPath compiler.
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
   * @param arg non-null expression that represents the argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
   * @param argNum The argument number index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
   * @throws WrongNumberArgsException If the argNum parameter is beyond what
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
   * is specified for this function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
  public void setArg(Expression arg, int argNum)
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
          throws WrongNumberArgsException
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
    m_argVec.addElement(arg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    arg.exprSetParent(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
   * Check that the number of arguments passed to this function is correct.
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
   * @param argNum The number of arguments that is being passed to the function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
   * @throws WrongNumberArgsException
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
  public void checkNumberArgs(int argNum) throws WrongNumberArgsException{}
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
  class ArgExtOwner implements ExpressionOwner
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
    Expression m_exp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
        ArgExtOwner(Expression exp)
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
                m_exp = exp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
     * @see ExpressionOwner#getExpression()
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
    public Expression getExpression()
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
      return m_exp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
     * @see ExpressionOwner#setExpression(Expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
    public void setExpression(Expression exp)
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
        exp.exprSetParent(FuncExtFunction.this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        m_exp = exp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
   * Call the visitors for the function arguments.
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
  public void callArgVisitors(XPathVisitor visitor)
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
      for (int i = 0; i < m_argVec.size(); i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
         Expression exp = (Expression)m_argVec.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
         exp.callVisitors(new ArgExtOwner(exp), visitor);
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
   * Set the parent node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
   * For an extension function, we also need to set the parent
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
   * node for all argument expressions.
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
   * @param n The parent node
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
  public void exprSetParent(ExpressionNode n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    super.exprSetParent(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
    int nArgs = m_argVec.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
    for (int i = 0; i < nArgs; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
      Expression arg = (Expression) m_argVec.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
      arg.exprSetParent(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
   * Constructs and throws a WrongNumberArgException with the appropriate
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
   * message for this function object.  This class supports an arbitrary
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
   * number of arguments, so this method must never be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
   * @throws WrongNumberArgsException
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
  protected void reportWrongNumberArgs() throws WrongNumberArgsException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
    String fMsg = XSLMessages.createXPATHMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
        XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
        new Object[]{ "Programmer's assertion:  the method FunctionMultiArgs.reportWrongNumberArgs() should never be called." });
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
    throw new RuntimeException(fMsg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
   * Return the name of the extesion function in string format
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
  public String toString()
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
    if (m_namespace != null && m_namespace.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
      return "{" + m_namespace + "}" + m_extensionName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
      return m_extensionName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
}