001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 /* 019 * $Id: ExtensionHandlerJava.java 468637 2006-10-28 06:51:02Z minchau $ 020 */ 021 package org.apache.xalan.extensions; 022 023 import java.util.Hashtable; 024 025 /** 026 * Abstract base class handling the java language extensions for XPath. 027 * This base class provides cache management shared by all of the 028 * various java extension handlers. 029 * 030 * @xsl.usage internal 031 */ 032 public abstract class ExtensionHandlerJava extends ExtensionHandler 033 { 034 035 /** Extension class name */ 036 protected String m_className = ""; 037 038 /** Table of cached methods */ 039 private Hashtable m_cachedMethods = new Hashtable(); 040 041 /** 042 * Construct a new extension handler given all the information 043 * needed. 044 * 045 * @param namespaceUri the extension namespace URI that I'm implementing 046 * @param funcNames string containing list of functions of extension NS 047 * @param lang language of code implementing the extension 048 * @param srcURL value of src attribute (if any) - treated as a URL 049 * or a classname depending on the value of lang. If 050 * srcURL is not null, then scriptSrc is ignored. 051 * @param scriptSrc the actual script code (if any) 052 * @param scriptLang the scripting language 053 * @param className the extension class name 054 */ 055 protected ExtensionHandlerJava(String namespaceUri, String scriptLang, 056 String className) 057 { 058 059 super(namespaceUri, scriptLang); 060 061 m_className = className; 062 } 063 064 /** 065 * Look up the entry in the method cache. 066 * @param methodKey A key that uniquely identifies this invocation in 067 * the stylesheet. 068 * @param objType A Class object or instance object representing the type 069 * @param methodArgs An array of the XObject arguments to be used for 070 * function mangling. 071 * 072 * @return The given method from the method cache 073 */ 074 public Object getFromCache(Object methodKey, Object objType, 075 Object[] methodArgs) 076 { 077 078 // Eventually, we want to insert code to mangle the methodKey with methodArgs 079 return m_cachedMethods.get(methodKey); 080 } 081 082 /** 083 * Add a new entry into the method cache. 084 * @param methodKey A key that uniquely identifies this invocation in 085 * the stylesheet. 086 * @param objType A Class object or instance object representing the type 087 * @param methodArgs An array of the XObject arguments to be used for 088 * function mangling. 089 * @param methodObj A Class object or instance object representing the method 090 * 091 * @return The cached method object 092 */ 093 public Object putToCache(Object methodKey, Object objType, 094 Object[] methodArgs, Object methodObj) 095 { 096 097 // Eventually, we want to insert code to mangle the methodKey with methodArgs 098 return m_cachedMethods.put(methodKey, methodObj); 099 } 100 }