mmidy       99/12/03 14:30:56

  Modified:    src      makexpath4j
               src/org/apache/xalan/xpath XPath.java
  Added:       src/org/apache/xalan/xpath FuncLoader.java
  Log:
  Implement a function loader for XPATH functions
  
  Revision  Changes    Path
  1.10      +1 -0      xml-xalan/src/makexpath4j
  
  Index: makexpath4j
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/makexpath4j,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- makexpath4j       1999/12/03 08:43:11     1.9
  +++ makexpath4j       1999/12/03 22:30:56     1.10
  @@ -46,6 +46,7 @@
        $(XPATHDIR)$(PATHSEP)FuncKey.java \
        $(XPATHDIR)$(PATHSEP)FuncLang.java \
        $(XPATHDIR)$(PATHSEP)FuncLast.java \
  +     $(XPATHDIR)$(PATHSEP)FuncLoader.java \
        $(XPATHDIR)$(PATHSEP)FuncLocalPart.java \
        $(XPATHDIR)$(PATHSEP)FuncNamespace.java \
        $(XPATHDIR)$(PATHSEP)FuncNormalizeSpace.java \
  
  
  
  1.8       +47 -35    xml-xalan/src/org/apache/xalan/xpath/XPath.java
  
  Index: XPath.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/XPath.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XPath.java        1999/11/29 06:26:19     1.7
  +++ XPath.java        1999/12/03 22:30:56     1.8
  @@ -430,9 +430,21 @@
     /**
      * Install a built-in function.
      * @param name The unqualified name of the function.
  +   * @param funcIndex The index of the function in the table.
      * @param func A Implementation of an XPath Function object.
      * @return the position of the function in the internal index.
      */
  +  public void installFunction (String name, int funcIndex, Function func)
  +  {            
  +    m_functions[funcIndex] = func;    
  +  }
  +  
  +  /**
  +   * Install a built-in function.
  +   * @param name The unqualified name of the function.
  +   * @param func A Implementation of an XPath Function object.
  +   * @return the position of the function in the internal index.
  +   */
     public static int installFunction(String name, Function func)
     {
       int funcIndex;
  @@ -2109,43 +2121,43 @@
     static
     {
       m_functions = new Function[NUM_BUILT_IN_FUNCS+NUM_ALLOWABLE_ADDINS];
  -    m_functions[FUNC_CURRENT] = new FuncCurrent();
  -    m_functions[FUNC_LAST] = new FuncLast();
  -    m_functions[FUNC_POSITION] = new FuncPosition();
  -    m_functions[FUNC_COUNT] = new FuncCount();
  -    m_functions[FUNC_ID] = new FuncId();
  -    m_functions[FUNC_KEY] = new FuncKey();
  +    m_functions[FUNC_CURRENT] = new FuncLoader("FuncCurrent", FUNC_CURRENT);
  +    m_functions[FUNC_LAST] = new FuncLoader("FuncLast", FUNC_LAST);
  +    m_functions[FUNC_POSITION] = new FuncLoader("FuncPosition", 
FUNC_POSITION);
  +    m_functions[FUNC_COUNT] = new FuncLoader("FuncCount", FUNC_COUNT);
  +    m_functions[FUNC_ID] = new FuncLoader("FuncId", FUNC_ID);
  +    m_functions[FUNC_KEY] = new FuncLoader("FuncKey", FUNC_KEY);
       // m_functions[FUNC_DOC] = new FuncDoc();
  -    m_functions[FUNC_LOCAL_PART] = new FuncLocalPart();
  -    m_functions[FUNC_NAMESPACE] = new FuncNamespace();
  -    m_functions[FUNC_QNAME] = new FuncQname();
  -    m_functions[FUNC_GENERATE_ID] = new FuncGenerateId();
  -    m_functions[FUNC_NOT] = new FuncNot();
  -    m_functions[FUNC_TRUE] = new FuncTrue();
  -    m_functions[FUNC_FALSE] = new FuncFalse();
  -    m_functions[FUNC_BOOLEAN] = new FuncBoolean();
  -    m_functions[FUNC_LANG] = new FuncLang();
  -    m_functions[FUNC_NUMBER] = new FuncNumber();
  -    m_functions[FUNC_FLOOR] = new FuncFloor();
  -    m_functions[FUNC_CEILING] = new FuncCeiling();
  -    m_functions[FUNC_ROUND] = new FuncRound();
  -    m_functions[FUNC_SUM] = new FuncSum();
  -    m_functions[FUNC_STRING] = new FuncString();
  -    m_functions[FUNC_STARTS_WITH] = new FuncStartsWith();
  -    m_functions[FUNC_CONTAINS] = new FuncContains();
  -    m_functions[FUNC_SUBSTRING_BEFORE] = new FuncSubstringBefore();
  -    m_functions[FUNC_SUBSTRING_AFTER] = new FuncSubstringAfter();
  -    m_functions[FUNC_NORMALIZE_SPACE] = new FuncNormalizeSpace();
  -    m_functions[FUNC_TRANSLATE] = new FuncTranslate();
  -    m_functions[FUNC_CONCAT] = new FuncConcat();
  +    m_functions[FUNC_LOCAL_PART] = new FuncLoader("FuncLocalPart", 
FUNC_LOCAL_PART);
  +    m_functions[FUNC_NAMESPACE] = new FuncLoader("FuncNamespace", 
FUNC_NAMESPACE);
  +    m_functions[FUNC_QNAME] = new FuncLoader("FuncQname", FUNC_QNAME);
  +    m_functions[FUNC_GENERATE_ID] = new FuncLoader("FuncGenerateId", 
FUNC_GENERATE_ID);
  +    m_functions[FUNC_NOT] = new FuncLoader("FuncNot", FUNC_NOT);
  +    m_functions[FUNC_TRUE] = new FuncLoader("FuncTrue", FUNC_TRUE);
  +    m_functions[FUNC_FALSE] = new FuncLoader("FuncFalse", FUNC_FALSE);
  +    m_functions[FUNC_BOOLEAN] = new FuncLoader("FuncBoolean", FUNC_BOOLEAN);
  +    m_functions[FUNC_LANG] = new FuncLoader("FuncLang", FUNC_LANG);
  +    m_functions[FUNC_NUMBER] = new FuncLoader("FuncNumber", FUNC_NUMBER);
  +    m_functions[FUNC_FLOOR] = new FuncLoader("FuncFloor", FUNC_FLOOR);
  +    m_functions[FUNC_CEILING] = new FuncLoader("FuncCeiling", FUNC_CEILING);
  +    m_functions[FUNC_ROUND] = new FuncLoader("FuncRound", FUNC_ROUND);
  +    m_functions[FUNC_SUM] = new FuncLoader("FuncSum", FUNC_SUM);
  +    m_functions[FUNC_STRING] = new FuncLoader("FuncString", FUNC_STRING);
  +    m_functions[FUNC_STARTS_WITH] = new FuncLoader("FuncStartsWith", 
FUNC_STARTS_WITH);
  +    m_functions[FUNC_CONTAINS] = new FuncLoader("FuncContains", 
FUNC_CONTAINS);
  +    m_functions[FUNC_SUBSTRING_BEFORE] = new 
FuncLoader("FuncSubstringBefore", FUNC_SUBSTRING_BEFORE);
  +    m_functions[FUNC_SUBSTRING_AFTER] = new FuncLoader("FuncSubstringAfter", 
FUNC_SUBSTRING_AFTER);
  +    m_functions[FUNC_NORMALIZE_SPACE] = new FuncLoader("FuncNormalizeSpace", 
FUNC_NORMALIZE_SPACE);
  +    m_functions[FUNC_TRANSLATE] = new FuncLoader("FuncTranslate", 
FUNC_TRANSLATE);
  +    m_functions[FUNC_CONCAT] = new FuncLoader("FuncConcat", FUNC_CONCAT);
       //m_functions[FUNC_FORMAT_NUMBER] = new FuncFormatNumber();
  -    m_functions[FUNC_SYSTEM_PROPERTY] = new FuncSystemProperty();
  -    m_functions[FUNC_EXT_FUNCTION_AVAILABLE] = new 
FuncExtFunctionAvailable();
  -    m_functions[FUNC_EXT_ELEM_AVAILABLE] = new FuncExtElementAvailable();
  -    m_functions[FUNC_SUBSTRING] = new FuncSubstring();
  -    m_functions[FUNC_STRING_LENGTH] = new FuncStringLength();
  -    m_functions[FUNC_DOCLOCATION] = new FuncDoclocation();
  -    m_functions[FUNC_UNPARSED_ENTITY_URI] = new FuncUnparsedEntityURI();
  +    m_functions[FUNC_SYSTEM_PROPERTY] = new FuncLoader("FuncSystemProperty", 
FUNC_SYSTEM_PROPERTY);
  +    m_functions[FUNC_EXT_FUNCTION_AVAILABLE] = new 
FuncLoader("FuncExtFunctionAvailable", FUNC_EXT_FUNCTION_AVAILABLE);
  +    m_functions[FUNC_EXT_ELEM_AVAILABLE] = new 
FuncLoader("FuncExtElementAvailable", FUNC_EXT_ELEM_AVAILABLE);
  +    m_functions[FUNC_SUBSTRING] = new FuncLoader("FuncSubstring", 
FUNC_SUBSTRING);
  +    m_functions[FUNC_STRING_LENGTH] = new FuncLoader("FuncStringLength", 
FUNC_STRING_LENGTH);
  +    m_functions[FUNC_DOCLOCATION] = new FuncLoader("FuncDoclocation", 
FUNC_DOCLOCATION);
  +    m_functions[FUNC_UNPARSED_ENTITY_URI] = new 
FuncLoader("FuncUnparsedEntityURI", FUNC_UNPARSED_ENTITY_URI);
       
     }
   
  
  
  
  1.1                  xml-xalan/src/org/apache/xalan/xpath/FuncLoader.java
  
  Index: FuncLoader.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "XSLT4J" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.xalan.xpath; 
  
  import java.lang.Class;
  import java.util.Vector;
  import org.w3c.dom.*;
  import org.apache.xalan.xpath.res.XPATHErrorResources;
  
  /**
   * Load functions in function table as needed
   */
  public class FuncLoader extends Function
  {
    private int m_funcID;
    private String m_funcName, test;
    
    public FuncLoader(String funcName, int funcID)
    {
      super();
      m_funcID = funcID;
      m_funcName = funcName;
    }
    
    /**
     * Replace the current function (us) in the table with
     * the actual function the call the function's execute method.
     * @param path The executing xpath.
     * @param context The current context.
     * @param opPos The current op position.
     * @param args A list of XObject arguments.
     * @return A valid XObject.
     */
    public XObject execute(XPath path, XPathSupport execContext, Node context, 
int opPos, Vector args) 
      throws org.xml.sax.SAXException
    {
      try
      {
        Class function;
        // first get package name if necessary
        if ( m_funcName.indexOf(".") < 0 )
        {  
          String thisName = this.getClass().getName();
          int lastdot = thisName.lastIndexOf(".");
          String classname = thisName.substring(0,lastdot+1) + m_funcName;      
          function = Class.forName(classname);
        }
        else
          function = Class.forName(m_funcName);
        
        Function func = (Function)function.newInstance();
        path.installFunction(m_funcName, m_funcID, func);
        return func.execute(path, execContext, context, opPos, args);
      }
      catch(ClassNotFoundException e)
      {
        e.printStackTrace();
        path.warn(XPATHErrorResources.WARNING0009, new Object[] {m_funcName});
        return null;
      }
      catch(IllegalAccessException e)
      {
        e.printStackTrace();
        path.warn(XPATHErrorResources.WARNING0009, new Object[] {m_funcName});
        return null;
      } 
      catch(InstantiationException e)
      {
        e.printStackTrace();
        path.warn(XPATHErrorResources.WARNING0009, new Object[] {m_funcName});
        return null;
      } 
    }
  }
  
  
  

Reply via email to