KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > extensions > ExtensionHandler


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ExtensionHandler.java,v 1.21 2004/02/23 10:29:34 aruny Exp $
18  */

19 package org.apache.xalan.extensions;
20
21 import java.io.IOException JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 import javax.xml.transform.TransformerException JavaDoc;
25
26 import org.apache.xalan.templates.ElemTemplateElement;
27 import org.apache.xalan.templates.Stylesheet;
28 import org.apache.xalan.transformer.TransformerImpl;
29 import org.apache.xpath.functions.FuncExtFunction;
30
31 /**
32  * Abstract base class for handling an extension namespace for XPath.
33  * Provides functions to test a function's existence and call a function.
34  * Also provides functions for calling an element and testing for
35  * an element's existence.
36  *
37  * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
38  * @xsl.usage internal
39  */

40 public abstract class ExtensionHandler
41 {
42
43   /** uri of the extension namespace */
44   protected String JavaDoc m_namespaceUri;
45
46   /** scripting language of implementation */
47   protected String JavaDoc m_scriptLang;
48
49   /**
50    * This method loads a class using the context class loader if we're
51    * running under Java2 or higher.
52    *
53    * @param className Name of the class to load
54    */

55   static Class JavaDoc getClassForName(String JavaDoc className)
56       throws ClassNotFoundException JavaDoc
57   {
58     // Hack for backwards compatibility with XalanJ1 stylesheets
59
if(className.equals("org.apache.xalan.xslt.extensions.Redirect")) {
60       className = "org.apache.xalan.lib.Redirect";
61     }
62
63     return ObjectFactory.findProviderClass(
64         className, ObjectFactory.findClassLoader(), true);
65   }
66
67   /**
68    * Construct a new extension namespace handler given all the information
69    * needed.
70    *
71    * @param namespaceUri the extension namespace URI that I'm implementing
72    * @param scriptLang language of code implementing the extension
73    */

74   protected ExtensionHandler(String JavaDoc namespaceUri, String JavaDoc scriptLang)
75   {
76     m_namespaceUri = namespaceUri;
77     m_scriptLang = scriptLang;
78   }
79
80   /**
81    * Tests whether a certain function name is known within this namespace.
82    * @param function name of the function being tested
83    * @return true if its known, false if not.
84    */

85   public abstract boolean isFunctionAvailable(String JavaDoc function);
86
87   /**
88    * Tests whether a certain element name is known within this namespace.
89    * @param function name of the function being tested
90    *
91    * @param element Name of element to check
92    * @return true if its known, false if not.
93    */

94   public abstract boolean isElementAvailable(String JavaDoc element);
95
96   /**
97    * Process a call to a function.
98    *
99    * @param funcName Function name.
100    * @param args The arguments of the function call.
101    * @param methodKey A key that uniquely identifies this class and method call.
102    * @param exprContext The context in which this expression is being executed.
103    *
104    * @return the return value of the function evaluation.
105    *
106    * @throws TransformerException if parsing trouble
107    */

108   public abstract Object JavaDoc callFunction(
109     String JavaDoc funcName, Vector JavaDoc args, Object JavaDoc methodKey,
110       ExpressionContext exprContext) throws TransformerException JavaDoc;
111
112   /**
113    * Process a call to a function.
114    *
115    * @param extFunction The XPath extension function.
116    * @param args The arguments of the function call.
117    * @param exprContext The context in which this expression is being executed.
118    *
119    * @return the return value of the function evaluation.
120    *
121    * @throws TransformerException if parsing trouble
122    */

123   public abstract Object JavaDoc callFunction(
124     FuncExtFunction extFunction, Vector JavaDoc args,
125       ExpressionContext exprContext) throws TransformerException JavaDoc;
126
127   /**
128    * Process a call to this extension namespace via an element. As a side
129    * effect, the results are sent to the TransformerImpl's result tree.
130    *
131    * @param localPart Element name's local part.
132    * @param element The extension element being processed.
133    * @param transformer Handle to TransformerImpl.
134    * @param stylesheetTree The compiled stylesheet tree.
135    * @param mode The current mode.
136    * @param sourceTree The root of the source tree (but don't assume
137    * it's a Document).
138    * @param sourceNode The current context node.
139    * @param methodKey A key that uniquely identifies this class and method call.
140    *
141    * @throws XSLProcessorException thrown if something goes wrong
142    * while running the extension handler.
143    * @throws MalformedURLException if loading trouble
144    * @throws FileNotFoundException if loading trouble
145    * @throws IOException if loading trouble
146    * @throws TransformerException if parsing trouble
147    */

148   public abstract void processElement(
149     String JavaDoc localPart, ElemTemplateElement element, TransformerImpl transformer,
150       Stylesheet stylesheetTree, Object JavaDoc methodKey) throws TransformerException JavaDoc, IOException JavaDoc;
151 }
152
Popular Tags