jaxp/src/com/sun/org/apache/xpath/internal/compiler/FuncLoader.java
author lana
Tue, 18 Mar 2014 17:49:48 -0700
changeset 23377 2af1ddf102a4
parent 12458 d601e4bba306
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: FuncLoader.java,v 1.1.2.1 2005/08/01 01:30:35 jeffsuttor Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xpath.internal.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import javax.xml.transform.TransformerException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xpath.internal.functions.Function;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    28
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    29
import com.sun.org.apache.xalan.internal.utils.ConfigurationError;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * Lazy load of functions into the function table as needed, so we don't
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * have to load all the functions allowed in XPath and XSLT on startup.
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 * @xsl.usage advanced
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
public class FuncLoader
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
  /** The function ID, which may correspond to one of the FUNC_XXX values
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
   *  found in {@link com.sun.org.apache.xpath.internal.compiler.FunctionTable}, but may
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
   *  be a value installed by an external module.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
  private int m_funcID;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
  /** The class name of the function.  Must not be null.   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
  private String m_funcName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
   * Get the local class name of the function class.  If function name does
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   * not have a '.' in it, it is assumed to be relative to
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   * 'com.sun.org.apache.xpath.internal.functions'.
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
   * @return The class name of the {com.sun.org.apache.xpath.internal.functions.Function} class.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
  public String getName()
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    return m_funcName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
   * Construct a function loader
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   * @param funcName The class name of the {com.sun.org.apache.xpath.internal.functions.Function}
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
   *             class, which, if it does not have a '.' in it, is assumed to
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
   *             be relative to 'com.sun.org.apache.xpath.internal.functions'.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
   * @param funcID  The function ID, which may correspond to one of the FUNC_XXX
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   *    values found in {@link com.sun.org.apache.xpath.internal.compiler.FunctionTable}, but may
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
   *    be a value installed by an external module.
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  public FuncLoader(String funcName, int funcID)
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    super();
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    m_funcID = funcID;
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    m_funcName = funcName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   * Get a Function instance that this instance is liaisoning for.
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   * @return non-null reference to Function derivative.
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   * @throws javax.xml.transform.TransformerException if ClassNotFoundException,
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   *    IllegalAccessException, or InstantiationException is thrown.
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
  Function getFunction() throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
      String className = m_funcName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
      if (className.indexOf(".") < 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        className = "com.sun.org.apache.xpath.internal.functions." + className;
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
      //hack for loading only built-in function classes.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
      String subString = className.substring(0,className.lastIndexOf('.'));
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
      if(!(subString.equals ("com.sun.org.apache.xalan.internal.templates") ||
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
           subString.equals ("com.sun.org.apache.xpath.internal.functions"))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
            throw new TransformerException("Application can't install his own xpath function.");
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   101
      return (Function) ObjectFactory.newInstance(className, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
    }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   104
    catch (ConfigurationError e)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
      throw new TransformerException(e.getException());
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
}