jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/FuncExtFunction.java
author chegar
Sun, 17 Aug 2014 15:51:56 +0100
changeset 25868 686eef1e7a79
parent 12457 jaxp/src/com/sun/org/apache/xpath/internal/functions/FuncExtFunction.java@c348e06f0e82
child 44797 8b3b3b911b8a
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
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: FuncExtFunction.java,v 1.2.4.2 2005/09/14 20:18:43 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.functions;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import java.util.Vector;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xalan.internal.res.XSLMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xpath.internal.Expression;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xpath.internal.ExpressionNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xpath.internal.ExpressionOwner;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xpath.internal.ExtensionsProvider;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xpath.internal.XPathContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xpath.internal.XPathVisitor;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xpath.internal.objects.XNull;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xpath.internal.objects.XObject;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xpath.internal.res.XPATHMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * An object of this class represents an extension call expression.  When
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * the expression executes, it calls ExtensionsTable#extFunction, and then
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * converts the result to the appropriate XObject.
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * @xsl.usage advanced
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
public class FuncExtFunction extends Function
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
    static final long serialVersionUID = 5196115554693708718L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   * The namespace for the extension function, which should not normally
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
   *  be null or empty.
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
   *  @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
  String m_namespace;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
   * The local name of the extension.
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
   *  @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
  String m_extensionName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
   * Unique method key, which is passed to ExtensionsTable#extFunction in
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
   *  order to allow caching of the method.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
   *  @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
  Object m_methodKey;
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
   * Array of static expressions which represent the parameters to the
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
   *  function.
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
   *  @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
  Vector m_argVec = new Vector();
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
   * This function is used to fixup variables from QNames to stack frame
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
   * indexes at stylesheet build time.
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   * @param vars List of QNames that correspond to variables.  This list
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   * should be searched backwards for the first qualified name that
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   * corresponds to the variable reference qname.  The position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   * QName in the vector from the start of the vector will be its position
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   * in the stack frame (but variables above the globalsTop value will need
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   * to be offset to the current stack frame).
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   * NEEDSDOC @param globalsSize
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  public void fixupVariables(java.util.Vector vars, int globalsSize)
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    if (null != m_argVec)
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
      int nArgs = m_argVec.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
      for (int i = 0; i < nArgs; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        Expression arg = (Expression) m_argVec.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
        arg.fixupVariables(vars, globalsSize);
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
   * Return the namespace of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
   * @return The namespace of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
  public String getNamespace()
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    return m_namespace;
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   * Return the name of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
   * @return The name of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
  public String getFunctionName()
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
    return m_extensionName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
   * Return the method key of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
   * @return The method key of the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
  public Object getMethodKey()
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    return m_methodKey;
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
   * Return the nth argument passed to the extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
   * @param n The argument number index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
   * @return The Expression object at the given index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
  public Expression getArg(int n) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
    if (n >= 0 && n < m_argVec.size())
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
      return (Expression) m_argVec.elementAt(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
   * Return the number of arguments that were passed
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
   * into this extension function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
   * @return The number of arguments.
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
  public int getArgCount() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
    return m_argVec.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
   * Create a new FuncExtFunction based on the qualified name of the extension,
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
   * and a unique method key.
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
   * @param namespace The namespace for the extension function, which should
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
   *                  not normally be null or empty.
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
   * @param extensionName The local name of the extension.
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
   * @param methodKey Unique method key, which is passed to
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
   *                  ExtensionsTable#extFunction in order to allow caching
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
   *                  of the method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
  public FuncExtFunction(java.lang.String namespace,
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
                         java.lang.String extensionName, Object methodKey)
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
    //try{throw new Exception("FuncExtFunction() " + namespace + " " + extensionName);} catch (Exception e){e.printStackTrace();}
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    m_namespace = namespace;
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
    m_extensionName = extensionName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
    m_methodKey = methodKey;
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
   * Execute the function.  The function must return
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
   * a valid object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
   * @param xctxt The current execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
   * @return A valid XObject.
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
  public XObject execute(XPathContext xctxt)
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
          throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
    if (xctxt.isSecureProcessing())
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
      throw new javax.xml.transform.TransformerException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        XPATHMessages.createXPATHMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
          XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED,
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
          new Object[] {toString()}));
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    XObject result;
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
    Vector argVec = new Vector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
    int nArgs = m_argVec.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    for (int i = 0; i < nArgs; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
      Expression arg = (Expression) m_argVec.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
      XObject xobj = arg.execute(xctxt);
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
      /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
       * Should cache the arguments for func:function
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
       */
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
      xobj.allowDetachToRelease(false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
      argVec.addElement(xobj);
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    //dml
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject();
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
    Object val = extProvider.extFunction(this, argVec);
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
    if (null != val)
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
      result = XObject.create(val, xctxt);
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
      result = new XNull();
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
    return result;
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
   * Set an argument expression for a function.  This method is called by the
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
   * XPath compiler.
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
   * @param arg non-null expression that represents the argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
   * @param argNum The argument number index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
   * @throws WrongNumberArgsException If the argNum parameter is beyond what
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
   * is specified for this function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
  public void setArg(Expression arg, int argNum)
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
          throws WrongNumberArgsException
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    m_argVec.addElement(arg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
    arg.exprSetParent(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
   * Check that the number of arguments passed to this function is correct.
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
   * @param argNum The number of arguments that is being passed to the function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
   * @throws WrongNumberArgsException
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
  public void checkNumberArgs(int argNum) throws WrongNumberArgsException{}
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
  class ArgExtOwner implements ExpressionOwner
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
    Expression m_exp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
        ArgExtOwner(Expression exp)
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
                m_exp = exp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
     * @see ExpressionOwner#getExpression()
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
    public Expression getExpression()
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
      return m_exp;
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
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
     * @see ExpressionOwner#setExpression(Expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    public void setExpression(Expression exp)
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        exp.exprSetParent(FuncExtFunction.this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        m_exp = exp;
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
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
   * Call the visitors for the function arguments.
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
  public void callArgVisitors(XPathVisitor visitor)
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
      for (int i = 0; i < m_argVec.size(); i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
         Expression exp = (Expression)m_argVec.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
         exp.callVisitors(new ArgExtOwner(exp), visitor);
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
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
   * Set the parent node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
   * For an extension function, we also need to set the parent
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
   * node for all argument expressions.
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
   * @param n The parent node
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
  public void exprSetParent(ExpressionNode n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
    super.exprSetParent(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
    int nArgs = m_argVec.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
    for (int i = 0; i < nArgs; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
      Expression arg = (Expression) m_argVec.elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
      arg.exprSetParent(n);
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
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
   * Constructs and throws a WrongNumberArgException with the appropriate
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
   * message for this function object.  This class supports an arbitrary
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
   * number of arguments, so this method must never be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
   * @throws WrongNumberArgsException
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
  protected void reportWrongNumberArgs() throws WrongNumberArgsException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
    String fMsg = XSLMessages.createXPATHMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
        XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
        new Object[]{ "Programmer's assertion:  the method FunctionMultiArgs.reportWrongNumberArgs() should never be called." });
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
    throw new RuntimeException(fMsg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
   * Return the name of the extesion function in string format
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
  public String toString()
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
    if (m_namespace != null && m_namespace.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
      return "{" + m_namespace + "}" + m_extensionName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
      return m_extensionName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
}