Xalan-C++ API Reference  1.12.0
ExtensionFunctionHandler.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #if !defined(XALAN_EXTENSIONFUNCTIONHANDLER_HEADER_GUARD)
20 #define XALAN_EXTENSIONFUNCTIONHANDLER_HEADER_GUARD
21 
22 
23 
24 // Base include file. Must be first.
26 
27 
28 
30 
31 
32 
35 
36 
37 
39 
40 
41 
42 #include <xalanc/XPath/XObject.hpp>
43 
44 
45 
46 namespace XALAN_CPP_NAMESPACE {
47 
48 
49 
50 class XObjectPtr;
51 
52 
53 
54 /**
55  * Class handling an extension namespace for XPath. Provides functions
56  * to test a function's existence and call a function
57  */
59 {
60 
61 public:
62 
63  /**
64  * Construct a new extension namespace handler for a given extension NS.
65  * This doesn't do anything - just hang on to the namespace URI.
66  *
67  * @param namespaceUri the extension namespace URI that I'm implementing
68  */
69  ExtensionFunctionHandler(const XalanDOMString& namespaceUri,
70  MemoryManager& theManager);
71 
72  /**
73  * Construct a new extension namespace handler given all the information
74  * needed.
75  *
76  * @param namespaceUri the extension namespace URI that I'm implementing
77  * @param funcNames string containing list of functions of extension NS
78  * @param lang language of code implementing the extension
79  * @param srcURL value of src attribute (if any) - treated as a URL
80  * or a classname depending on the value of lang. If
81  * srcURL is not null, then scriptSrc is ignored.
82  * @param scriptSrc the actual script code (if any)
83  */
85  MemoryManager& theManager,
86  const XalanDOMString& namespaceUri,
87  const XalanDOMString& funcNames,
88  const XalanDOMString& lang,
89  const XalanDOMString& srcURL,
90  const XalanDOMString& scriptSrc);
91 
92 
93  virtual
95 
96  MemoryManager&
98  {
99  return m_namespaceUri.getMemoryManager();
100  }
101 
102  /**
103  * Set function local parts of extension NS.
104  *
105  * @param functions whitespace separated list of function names defined
106  * by this extension namespace.
107  */
108  virtual void
109  setFunctions(const XalanDOMString& funcNames);
110 
111  /**
112  * Set the script data for this extension NS. If srcURL is !null then
113  * the script body is read from that URL. If not the scriptSrc is used
114  * as the src. This method does not actually execute anything - that's
115  * done when the component is first hit by the user by an element or
116  * a function call.
117  *
118  * @param lang language of the script.
119  * @param srcURL value of src attribute (if any) - treated as a URL
120  * or a classname depending on the value of lang. If
121  * srcURL is not null, then scriptSrc is ignored.
122  * @param scriptSrc the actual script code (if any)
123  */
124  virtual void
125  setScript(
126  const XalanDOMString& lang,
127  const XalanDOMString& srcURL,
128  const XalanDOMString& scriptSrc);
129 
130  /**
131  * Tests whether a certain function name is known within this namespace.
132  *
133  * @param function name of the function being tested
134  * @return true if its known, false if not.
135  */
136  virtual bool
137  isFunctionAvailable(const XalanDOMString& function) const;
138 
139  /// Vector of pointers to function arguments
141 
143 
144  /**
145  * Process a call to a function.
146  *
147  * @param funcName Function name.
148  * @param args The arguments of the function call.
149  *
150  * @return the return value of the function evaluation.
151  *
152  * @exception XSLProcessorException thrown if something goes wrong
153  * while running the extension handler.
154  * @exception MalformedURLException if loading trouble
155  * @exception FileNotFoundException if loading trouble
156  * @exception IOException if loading trouble
157  * @exception SAXException if parsing trouble
158  */
159 
160  virtual XObjectPtr
161  callFunction(
162  const XalanDOMString& funcName,
163  const ArgVectorType& args);
164 
165 protected:
166 
167  XalanDOMString m_namespaceUri; // uri of the extension namespace
168  XalanDOMString m_scriptLang; // scripting language of implementation
169  XalanDOMString m_scriptSrc; // script source to run (if any)
170  XalanDOMString m_scriptSrcURL; // URL of source of script (if any)
171 
172  void* m_javaObject; // object for javaclass engine
173 
174  StringSetType m_functions; // functions of namespace
175 
176  // BSFManager mgr = new BSFManager (); // mgr used to run scripts
177 
178  bool m_componentStarted; // true when the scripts in a
179 
180  // component description (if any) have been run
181 
182  /**
183  * Start the component up by executing any script that needs to run
184  * at startup time. This needs to happen before any functions can be
185  * called on the component.
186  *
187  * @exception XPathProcessorException if something bad happens.
188  */
189  virtual void
190  startupComponent();
191 
192  static const XalanDOMChar s_tokenDelimiterCharacters[];
193 };
194 
195 
196 
197 }
198 
199 
200 
201 #endif // XALAN_EXTENSIONFUNCTIONHANDLER_HEADER_GUARD
xalanc::XalanSet< XalanDOMString >
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
XalanDOMString.hpp
xalanc::XalanVector
Definition: XalanVector.hpp:58
XALAN_XSLT_EXPORT
#define XALAN_XSLT_EXPORT
Definition: XSLTDefinitions.hpp:27
xalanc::ExtensionFunctionHandler::getMemoryManager
MemoryManager & getMemoryManager()
Definition: ExtensionFunctionHandler.hpp:97
XalanVector.hpp
xalanc::ExtensionFunctionHandler::m_scriptLang
XalanDOMString m_scriptLang
Definition: ExtensionFunctionHandler.hpp:168
xalanc::ExtensionFunctionHandler::m_namespaceUri
XalanDOMString m_namespaceUri
Definition: ExtensionFunctionHandler.hpp:167
xalanc::ExtensionFunctionHandler
Class handling an extension namespace for XPath.
Definition: ExtensionFunctionHandler.hpp:58
xalanc::XObjectPtr
Class to hold XObjectPtr return types.
Definition: XObject.hpp:883
DOMStringHelper.hpp
xalanc::ExtensionFunctionHandler::m_javaObject
void * m_javaObject
Definition: ExtensionFunctionHandler.hpp:172
xalanc::ExtensionFunctionHandler::m_functions
StringSetType m_functions
Definition: ExtensionFunctionHandler.hpp:174
xalanc::ExtensionFunctionHandler::m_componentStarted
bool m_componentStarted
Definition: ExtensionFunctionHandler.hpp:178
xalanc::ExtensionFunctionHandler::ArgVectorType
XalanVector< void * > ArgVectorType
Vector of pointers to function arguments.
Definition: ExtensionFunctionHandler.hpp:140
XSLTDefinitions.hpp
xalanc::ExtensionFunctionHandler::m_scriptSrc
XalanDOMString m_scriptSrc
Definition: ExtensionFunctionHandler.hpp:169
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::ExtensionFunctionHandler::StringSetType
XalanSet< XalanDOMString > StringSetType
Definition: ExtensionFunctionHandler.hpp:142
xalanc::ExtensionFunctionHandler::m_scriptSrcURL
XalanDOMString m_scriptSrcURL
Definition: ExtensionFunctionHandler.hpp:170
XObject.hpp
XalanSet.hpp