Package org.apache.xalan.extensions
Class ExtensionHandlerJavaClass
java.lang.Object
org.apache.xalan.extensions.ExtensionHandler
org.apache.xalan.extensions.ExtensionHandlerJava
org.apache.xalan.extensions.ExtensionHandlerJavaClass
Represents an extension namespace for XPath that handles java classes.
It is recommended that the class URI be of the form:
xalan://fully.qualified.class.nameHowever, we do not enforce this. If the class name contains a a /, we only use the part to the right of the rightmost slash. In addition, we ignore any "class:" prefix. Provides functions to test a function's existence and call a function. Also provides functions to test an element's existence and call an element.
- Author:
- Gary L Peskin
-
Constructor Summary
ConstructorsConstructorDescriptionExtensionHandlerJavaClass
(String namespaceUri, String scriptLang, String className) Construct a new extension namespace handler given all the information needed. -
Method Summary
Modifier and TypeMethodDescriptioncallFunction
(String funcName, Vector args, Object methodKey, ExpressionContext exprContext) Process a call to a function in the java class represented by thisExtensionHandlerJavaClass
.
callFunction
(FuncExtFunction extFunction, Vector args, ExpressionContext exprContext) Process a call to an XPath extension functionboolean
isElementAvailable
(String element) Tests whether a certain element name is known within this namespace.boolean
isFunctionAvailable
(String function) Tests whether a certain function name is known within this namespace.void
processElement
(String localPart, ElemTemplateElement element, TransformerImpl transformer, Stylesheet stylesheetTree, Object methodKey) Process a call to this extension namespace via an element.Methods inherited from class org.apache.xalan.extensions.ExtensionHandlerJava
getFromCache, putToCache
-
Constructor Details
-
ExtensionHandlerJavaClass
Construct a new extension namespace handler given all the information needed.- Parameters:
namespaceUri
- the extension namespace URI that I'm implementingscriptLang
- language of code implementing the extensionclassName
- the fully qualified class name of the class
-
-
Method Details
-
isFunctionAvailable
Tests whether a certain function name is known within this namespace. Simply looks for a method with the appropriate name. There is no information regarding the arguments to the function call or whether the method implementing the function is a static method or an instance method.- Specified by:
isFunctionAvailable
in classExtensionHandler
- Parameters:
function
- name of the function being tested- Returns:
- true if its known, false if not.
-
isElementAvailable
Tests whether a certain element name is known within this namespace. Looks for a method with the appropriate name and signature. This method examines both static and instance methods.- Specified by:
isElementAvailable
in classExtensionHandler
- Parameters:
element
- name of the element being tested- Returns:
- true if its known, false if not.
-
callFunction
public Object callFunction(String funcName, Vector args, Object methodKey, ExpressionContext exprContext) throws TransformerException Process a call to a function in the java class represented by thisExtensionHandlerJavaClass
. There are three possible types of calls:
Constructor: classns:new(arg1, arg2, ...) Static method: classns:method(arg1, arg2, ...) Instance method: classns:method(obj, arg1, arg2, ...)
We use the following rules to determine the type of call made:- If the function name is "new", call the best constructor for class represented by the namespace URI
- If the first argument to the function is of the class specified in the namespace or is a subclass of that class, look for the best method of the class specified in the namespace with the specified arguments. Compare all static and instance methods with the correct method name. For static methods, use all arguments in the compare. For instance methods, use all arguments after the first.
- Otherwise, select the best static or instance method matching all of the arguments. If the best method is an instance method, call the function using a default object, creating it if needed.
- Specified by:
callFunction
in classExtensionHandler
- Parameters:
funcName
- Function name.args
- The arguments of the function call.methodKey
- A key that uniquely identifies this class and method call.exprContext
- The context in which this expression is being executed.- Returns:
- the return value of the function evaluation.
- Throws:
TransformerException
-
callFunction
public Object callFunction(FuncExtFunction extFunction, Vector args, ExpressionContext exprContext) throws TransformerException Process a call to an XPath extension function- Specified by:
callFunction
in classExtensionHandler
- Parameters:
extFunction
- The XPath extension functionargs
- The arguments of the function call.exprContext
- The context in which this expression is being executed.- Returns:
- the return value of the function evaluation.
- Throws:
TransformerException
-
processElement
public void processElement(String localPart, ElemTemplateElement element, TransformerImpl transformer, Stylesheet stylesheetTree, Object methodKey) throws TransformerException, IOException Process a call to this extension namespace via an element. As a side effect, the results are sent to the TransformerImpl's result tree. We invoke the static or instance method in the class represented by by the namespace URI. If we don't already have an instance of this class, we create one upon the first call.- Specified by:
processElement
in classExtensionHandler
- Parameters:
localPart
- Element name's local part.element
- The extension element being processed.transformer
- Handle to TransformerImpl.stylesheetTree
- The compiled stylesheet tree.methodKey
- A key that uniquely identifies this element call.- Throws:
IOException
- if loading troubleTransformerException
- if parsing trouble
-