jaxp/src/com/sun/org/apache/xpath/internal/compiler/FunctionTable.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-2005 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: FunctionTable.java,v 1.3 2005/09/28 13:49:34 pvedula 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 com.sun.org.apache.xpath.internal.Expression;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xpath.internal.functions.Function;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import java.util.HashMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import javax.xml.transform.TransformerException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * The function table for XPath.
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
public class FunctionTable
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
  /** The 'current()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
  public static final int FUNC_CURRENT = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
  /** The 'last()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
  public static final int FUNC_LAST = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
  /** The 'position()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
  public static final int FUNC_POSITION = 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
  /** The 'count()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
  public static final int FUNC_COUNT = 3;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
  /** The 'id()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
  public static final int FUNC_ID = 4;
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
  /** The 'key()' id (XSLT). */
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
  public static final int FUNC_KEY = 5;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
  /** The 'local-name()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
  public static final int FUNC_LOCAL_PART = 7;
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
  /** The 'namespace-uri()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
  public static final int FUNC_NAMESPACE = 8;
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
  /** The 'name()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
  public static final int FUNC_QNAME = 9;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
  /** The 'generate-id()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
  public static final int FUNC_GENERATE_ID = 10;
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
  /** The 'not()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
  public static final int FUNC_NOT = 11;
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  /** The 'true()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
  public static final int FUNC_TRUE = 12;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
  /** The 'false()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
  public static final int FUNC_FALSE = 13;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
  /** The 'boolean()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
  public static final int FUNC_BOOLEAN = 14;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
  /** The 'number()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
  public static final int FUNC_NUMBER = 15;
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  /** The 'floor()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
  public static final int FUNC_FLOOR = 16;
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
  /** The 'ceiling()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
  public static final int FUNC_CEILING = 17;
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  /** The 'round()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
  public static final int FUNC_ROUND = 18;
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
  /** The 'sum()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
  public static final int FUNC_SUM = 19;
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
  /** The 'string()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
  public static final int FUNC_STRING = 20;
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
  /** The 'starts-with()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  public static final int FUNC_STARTS_WITH = 21;
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
  /** The 'contains()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
  public static final int FUNC_CONTAINS = 22;
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
  /** The 'substring-before()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
  public static final int FUNC_SUBSTRING_BEFORE = 23;
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
  /** The 'substring-after()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  public static final int FUNC_SUBSTRING_AFTER = 24;
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
  /** The 'normalize-space()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
  public static final int FUNC_NORMALIZE_SPACE = 25;
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
  /** The 'translate()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
  public static final int FUNC_TRANSLATE = 26;
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
  /** The 'concat()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
  public static final int FUNC_CONCAT = 27;
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
  /** The 'substring()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
  public static final int FUNC_SUBSTRING = 29;
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
  /** The 'string-length()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
  public static final int FUNC_STRING_LENGTH = 30;
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
  /** The 'system-property()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
  public static final int FUNC_SYSTEM_PROPERTY = 31;
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
  /** The 'lang()' id. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
  public static final int FUNC_LANG = 32;
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
  /** The 'function-available()' id (XSLT). */
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
  public static final int FUNC_EXT_FUNCTION_AVAILABLE = 33;
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
  /** The 'element-available()' id (XSLT). */
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
  public static final int FUNC_EXT_ELEM_AVAILABLE = 34;
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
  /** The 'unparsed-entity-uri()' id (XSLT). */
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
  public static final int FUNC_UNPARSED_ENTITY_URI = 36;
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
  // Proprietary
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
  /** The 'document-location()' id (Proprietary). */
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
  public static final int FUNC_DOCLOCATION = 35;
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
   * The function table.
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
  private static Class m_functions[];
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
  /** Table of function name to function ID associations. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
  private static HashMap m_functionID = new HashMap();
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
   * The function table contains customized functions
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
  private Class m_functions_customer[] = new Class[NUM_ALLOWABLE_ADDINS];
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
   * Table of function name to function ID associations for customized functions
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
  private HashMap m_functionID_customer = new HashMap();
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
   * Number of built in functions.  Be sure to update this as
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
   * built-in functions are added.
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
  private static final int NUM_BUILT_IN_FUNCS = 37;
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
   * Number of built-in functions that may be added.
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
  private static final int NUM_ALLOWABLE_ADDINS = 30;
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
   * The index to the next free function index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
  private int m_funcNextFreeIndex = NUM_BUILT_IN_FUNCS;
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
  static
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
    m_functions = new Class[NUM_BUILT_IN_FUNCS];
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
    m_functions[FUNC_CURRENT] = com.sun.org.apache.xpath.internal.functions.FuncCurrent.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    m_functions[FUNC_LAST] = com.sun.org.apache.xpath.internal.functions.FuncLast.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
    m_functions[FUNC_POSITION] = com.sun.org.apache.xpath.internal.functions.FuncPosition.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
    m_functions[FUNC_COUNT] = com.sun.org.apache.xpath.internal.functions.FuncCount.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    m_functions[FUNC_ID] = com.sun.org.apache.xpath.internal.functions.FuncId.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
    // J2SE does not support Xalan interpretive
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    // m_functions[FUNC_KEY] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
    //   com.sun.org.apache.xalan.internal.templates.FuncKey.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    m_functions[FUNC_LOCAL_PART] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
      com.sun.org.apache.xpath.internal.functions.FuncLocalPart.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    m_functions[FUNC_NAMESPACE] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
      com.sun.org.apache.xpath.internal.functions.FuncNamespace.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    m_functions[FUNC_QNAME] = com.sun.org.apache.xpath.internal.functions.FuncQname.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    m_functions[FUNC_GENERATE_ID] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
      com.sun.org.apache.xpath.internal.functions.FuncGenerateId.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
    m_functions[FUNC_NOT] = com.sun.org.apache.xpath.internal.functions.FuncNot.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    m_functions[FUNC_TRUE] = com.sun.org.apache.xpath.internal.functions.FuncTrue.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    m_functions[FUNC_FALSE] = com.sun.org.apache.xpath.internal.functions.FuncFalse.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    m_functions[FUNC_BOOLEAN] = com.sun.org.apache.xpath.internal.functions.FuncBoolean.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    m_functions[FUNC_LANG] = com.sun.org.apache.xpath.internal.functions.FuncLang.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
    m_functions[FUNC_NUMBER] = com.sun.org.apache.xpath.internal.functions.FuncNumber.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
    m_functions[FUNC_FLOOR] = com.sun.org.apache.xpath.internal.functions.FuncFloor.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
    m_functions[FUNC_CEILING] = com.sun.org.apache.xpath.internal.functions.FuncCeiling.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
    m_functions[FUNC_ROUND] = com.sun.org.apache.xpath.internal.functions.FuncRound.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    m_functions[FUNC_SUM] = com.sun.org.apache.xpath.internal.functions.FuncSum.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
    m_functions[FUNC_STRING] = com.sun.org.apache.xpath.internal.functions.FuncString.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    m_functions[FUNC_STARTS_WITH] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
      com.sun.org.apache.xpath.internal.functions.FuncStartsWith.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    m_functions[FUNC_CONTAINS] = com.sun.org.apache.xpath.internal.functions.FuncContains.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    m_functions[FUNC_SUBSTRING_BEFORE] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
      com.sun.org.apache.xpath.internal.functions.FuncSubstringBefore.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    m_functions[FUNC_SUBSTRING_AFTER] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
      com.sun.org.apache.xpath.internal.functions.FuncSubstringAfter.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    m_functions[FUNC_NORMALIZE_SPACE] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
      com.sun.org.apache.xpath.internal.functions.FuncNormalizeSpace.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    m_functions[FUNC_TRANSLATE] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
      com.sun.org.apache.xpath.internal.functions.FuncTranslate.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    m_functions[FUNC_CONCAT] = com.sun.org.apache.xpath.internal.functions.FuncConcat.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    m_functions[FUNC_SYSTEM_PROPERTY] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
      com.sun.org.apache.xpath.internal.functions.FuncSystemProperty.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    m_functions[FUNC_EXT_FUNCTION_AVAILABLE] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
      com.sun.org.apache.xpath.internal.functions.FuncExtFunctionAvailable.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    m_functions[FUNC_EXT_ELEM_AVAILABLE] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
      com.sun.org.apache.xpath.internal.functions.FuncExtElementAvailable.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
    m_functions[FUNC_SUBSTRING] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
      com.sun.org.apache.xpath.internal.functions.FuncSubstring.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
    m_functions[FUNC_STRING_LENGTH] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
      com.sun.org.apache.xpath.internal.functions.FuncStringLength.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
    m_functions[FUNC_DOCLOCATION] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
      com.sun.org.apache.xpath.internal.functions.FuncDoclocation.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
    m_functions[FUNC_UNPARSED_ENTITY_URI] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
      com.sun.org.apache.xpath.internal.functions.FuncUnparsedEntityURI.class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
  static{
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
          m_functionID.put(Keywords.FUNC_CURRENT_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
                          new Integer(FunctionTable.FUNC_CURRENT));
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
          m_functionID.put(Keywords.FUNC_LAST_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
                          new Integer(FunctionTable.FUNC_LAST));
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
          m_functionID.put(Keywords.FUNC_POSITION_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
                          new Integer(FunctionTable.FUNC_POSITION));
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
          m_functionID.put(Keywords.FUNC_COUNT_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
                          new Integer(FunctionTable.FUNC_COUNT));
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
          m_functionID.put(Keywords.FUNC_ID_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
                          new Integer(FunctionTable.FUNC_ID));
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
          m_functionID.put(Keywords.FUNC_KEY_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
                          new Integer(FunctionTable.FUNC_KEY));
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
          m_functionID.put(Keywords.FUNC_LOCAL_PART_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
                          new Integer(FunctionTable.FUNC_LOCAL_PART));
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
          m_functionID.put(Keywords.FUNC_NAMESPACE_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
                          new Integer(FunctionTable.FUNC_NAMESPACE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
          m_functionID.put(Keywords.FUNC_NAME_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
                          new Integer(FunctionTable.FUNC_QNAME));
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
          m_functionID.put(Keywords.FUNC_GENERATE_ID_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
                          new Integer(FunctionTable.FUNC_GENERATE_ID));
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
          m_functionID.put(Keywords.FUNC_NOT_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                          new Integer(FunctionTable.FUNC_NOT));
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
          m_functionID.put(Keywords.FUNC_TRUE_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
                          new Integer(FunctionTable.FUNC_TRUE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
          m_functionID.put(Keywords.FUNC_FALSE_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
                          new Integer(FunctionTable.FUNC_FALSE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
          m_functionID.put(Keywords.FUNC_BOOLEAN_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
                          new Integer(FunctionTable.FUNC_BOOLEAN));
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
          m_functionID.put(Keywords.FUNC_LANG_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
                          new Integer(FunctionTable.FUNC_LANG));
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
          m_functionID.put(Keywords.FUNC_NUMBER_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
                          new Integer(FunctionTable.FUNC_NUMBER));
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
          m_functionID.put(Keywords.FUNC_FLOOR_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
                          new Integer(FunctionTable.FUNC_FLOOR));
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
          m_functionID.put(Keywords.FUNC_CEILING_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
                          new Integer(FunctionTable.FUNC_CEILING));
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
          m_functionID.put(Keywords.FUNC_ROUND_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
                          new Integer(FunctionTable.FUNC_ROUND));
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
          m_functionID.put(Keywords.FUNC_SUM_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
                          new Integer(FunctionTable.FUNC_SUM));
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
          m_functionID.put(Keywords.FUNC_STRING_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
                          new Integer(FunctionTable.FUNC_STRING));
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
          m_functionID.put(Keywords.FUNC_STARTS_WITH_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
                          new Integer(FunctionTable.FUNC_STARTS_WITH));
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
          m_functionID.put(Keywords.FUNC_CONTAINS_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
                          new Integer(FunctionTable.FUNC_CONTAINS));
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
          m_functionID.put(Keywords.FUNC_SUBSTRING_BEFORE_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
                          new Integer(FunctionTable.FUNC_SUBSTRING_BEFORE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
          m_functionID.put(Keywords.FUNC_SUBSTRING_AFTER_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
                          new Integer(FunctionTable.FUNC_SUBSTRING_AFTER));
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
          m_functionID.put(Keywords.FUNC_NORMALIZE_SPACE_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
                          new Integer(FunctionTable.FUNC_NORMALIZE_SPACE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
          m_functionID.put(Keywords.FUNC_TRANSLATE_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
                          new Integer(FunctionTable.FUNC_TRANSLATE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
          m_functionID.put(Keywords.FUNC_CONCAT_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
                          new Integer(FunctionTable.FUNC_CONCAT));
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
          m_functionID.put(Keywords.FUNC_SYSTEM_PROPERTY_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
                          new Integer(FunctionTable.FUNC_SYSTEM_PROPERTY));
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
          m_functionID.put(Keywords.FUNC_EXT_FUNCTION_AVAILABLE_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
                        new Integer(FunctionTable.FUNC_EXT_FUNCTION_AVAILABLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
          m_functionID.put(Keywords.FUNC_EXT_ELEM_AVAILABLE_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
                          new Integer(FunctionTable.FUNC_EXT_ELEM_AVAILABLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
          m_functionID.put(Keywords.FUNC_SUBSTRING_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
                          new Integer(FunctionTable.FUNC_SUBSTRING));
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
          m_functionID.put(Keywords.FUNC_STRING_LENGTH_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
                          new Integer(FunctionTable.FUNC_STRING_LENGTH));
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
          m_functionID.put(Keywords.FUNC_UNPARSED_ENTITY_URI_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
                          new Integer(FunctionTable.FUNC_UNPARSED_ENTITY_URI));
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
          m_functionID.put(Keywords.FUNC_DOCLOCATION_STRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
                          new Integer(FunctionTable.FUNC_DOCLOCATION));
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
  public FunctionTable(){
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
   * Return the name of the a function in the static table. Needed to avoid
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
   * making the table publicly available.
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
  String getFunctionName(int funcID) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
      if (funcID < NUM_BUILT_IN_FUNCS) return m_functions[funcID].getName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
      else return m_functions_customer[funcID - NUM_BUILT_IN_FUNCS].getName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
   * Obtain a new Function object from a function ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
   * @param which  The function ID, which may correspond to one of the FUNC_XXX
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
   *    values found in {@link com.sun.org.apache.xpath.internal.compiler.FunctionTable}, but may
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
   *    be a value installed by an external module.
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
   * @return a a new Function instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
   * @throws javax.xml.transform.TransformerException if ClassNotFoundException,
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
   *    IllegalAccessException, or InstantiationException is thrown.
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
  Function getFunction(int which)
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
          throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
          try{
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
              if (which < NUM_BUILT_IN_FUNCS)
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
                  return (Function) m_functions[which].newInstance();
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
              else
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
                  return (Function) m_functions_customer[
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
                      which-NUM_BUILT_IN_FUNCS].newInstance();
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
          }catch (IllegalAccessException ex){
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
                  throw new TransformerException(ex.getMessage());
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
          }catch (InstantiationException ex){
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
                  throw new TransformerException(ex.getMessage());
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
   * Obtain a function ID from a given function name
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
   * @param key the function name in a java.lang.String format.
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
   * @return a function ID, which may correspond to one of the FUNC_XXX values
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
   * found in {@link com.sun.org.apache.xpath.internal.compiler.FunctionTable}, but may be a
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
   * value installed by an external module.
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
  Object getFunctionID(String key){
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
          Object id = m_functionID_customer.get(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
          if (null == id) id = m_functionID.get(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
          return id;
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
   * Install a built-in function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
   * @param name The unqualified name of the function, must not be null
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
   * @param func A Implementation of an XPath Function object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
   * @return the position of the function in the internal index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
  public int installFunction(String name, Class func)
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
    int funcIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
    Object funcIndexObj = getFunctionID(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
    if (null != funcIndexObj)
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
      funcIndex = ((Integer) funcIndexObj).intValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
      if (funcIndex < NUM_BUILT_IN_FUNCS){
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
              funcIndex = m_funcNextFreeIndex++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
              m_functionID_customer.put(name, new Integer(funcIndex));
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
      m_functions_customer[funcIndex - NUM_BUILT_IN_FUNCS] = func;
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
            funcIndex = m_funcNextFreeIndex++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
            m_functions_customer[funcIndex-NUM_BUILT_IN_FUNCS] = func;
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
            m_functionID_customer.put(name,
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
                new Integer(funcIndex));
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
    return funcIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
   * Tell if a built-in, non-namespaced function is available.
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
   * @param methName The local name of the function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
   * @return True if the function can be executed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
  public boolean functionAvailable(String methName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
      Object tblEntry = m_functionID.get(methName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
      if (null != tblEntry) return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
      else{
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
              tblEntry = m_functionID_customer.get(methName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
              return (null != tblEntry)? true : false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
}