Xalan-C++ API Reference  1.12.0
XPathEvaluator.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 #if !defined(XPATHEVALUATOR_HEADER_GUARD_1357924680)
19 #define XPATHEVALUATOR_HEADER_GUARD_1357924680
20 
21 
22 
24 
25 
26 
27 #if defined(XALAN_AUTO_PTR_REQUIRES_DEFINITION)
32 #endif
33 
34 
35 
37 
38 
39 
41 
42 
43 
44 namespace XALAN_CPP_NAMESPACE {
45 
46 
47 
48 #if !defined(XALAN_AUTO_PTR_REQUIRES_DEFINITION)
49 class XObjectFactory;
50 class XPathFactoryDefault;
51 class XPathConstructionContextDefault;
52 class XPathExecutionContextDefault;
53 #endif
54 
55 
56 
57 class DOMSupport;
58 class NodeRefList;
59 class PrefixResolver;
60 class XalanNode;
61 class XalanElement;
62 class XObjectPtr;
63 class XPath;
64 class XPathEnvSupport;
65 class XPathExecutionContext;
66 
67 
68 
70 {
71 public:
72 
73  // Static initializer to be called before any instances are
74  // created. The call is _not_ thread-safe, you must only call
75  // it once, unless you have called terminate previously, and
76  // you want to re-initialize the library.
77  static void
78  initialize(MemoryManager& theManager XALAN_DEFAULT_MEMMGR);
79 
80  // Static terminator to be called after all instances
81  // are destroyed. The call is _not_ thread-safe. Once
82  // terminated, you can call initialize() again, to
83  // re-initialize the library.
84  static void
85  terminate();
86 
87 
88  XPathEvaluator(MemoryManager& theManager XALAN_DEFAULT_MEMMGR);
89 
90  ~XPathEvaluator();
91 
92  /**
93  * Evaluate the supplied XPath expression, within the given context. If
94  * the expression doesn't select a node, 0 is returned. If it selects
95  * more than one node, only the first is returned.
96  *
97  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
98  * @param contextNode The source tree context node
99  * @param xpathString The XPath expression to evaluate
100  * @param namespaceNode A node to use for namespace prefix resolution.
101  * @return A pointer to the node selected by the expression, if any.
102  */
103  XalanNode*
104  selectSingleNode(
105  DOMSupport& domSupport,
106  XalanNode* contextNode,
107  const XalanDOMChar* xpathString,
108  const XalanElement* namespaceNode = 0);
109 
110  /**
111  * Evaluate the supplied XPath expression, within the given context. If
112  * the expression doesn't select a node, 0 is returned. If it selects
113  * more than one node, only the first is returned.
114  *
115  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
116  * @param contextNode The source tree context node
117  * @param xpathString The XPath expression to evaluate
118  * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
119  * @return A pointer to the node selected by the expression, if any.
120  */
121  XalanNode*
122  selectSingleNode(
123  DOMSupport& domSupport,
124  XalanNode* contextNode,
125  const XalanDOMChar* xpathString,
126  const PrefixResolver& prefixResolver);
127 
128  /**
129  * Evaluate the supplied XPath, within the given context. If
130  * the expression doesn't select a node, 0 is returned. If it selects
131  * more than one node, only the first is returned.
132  *
133  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
134  * @param contextNode The source tree context node
135  * @param xpath A reference to a compiled XPath expression.
136  * @param namespaceNode A node to use for namespace prefix resolution.
137  * @return A pointer to the node selected by the expression, if any.
138  */
139  XalanNode*
140  selectSingleNode(
141  DOMSupport& domSupport,
142  XalanNode* contextNode,
143  const XPath& xpath,
144  const XalanElement* namespaceNode = 0);
145 
146  /**
147  * Evaluate the supplied XPath, within the given context. If
148  * the expression doesn't select a node, 0 is returned. If it selects
149  * more than one node, only the first is returned.
150  *
151  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
152  * @param contextNode The source tree context node
153  * @param xpath A reference to a compiled XPath expression.
154  * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
155  * @return A pointer to the node selected by the expression, if any.
156  */
157  XalanNode*
158  selectSingleNode(
159  DOMSupport& domSupport,
160  XalanNode* contextNode,
161  const XPath& xpath,
162  const PrefixResolver& prefixResolver);
163 
164  /**
165  * Evaluate the supplied XPath expression, within the given context. If
166  * the expression doesn't select a node, an empty list is returned.
167  *
168  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
169  * @param contextNode The source tree context node
170  * @param xpathString The XPath expression to evaluate
171  * @param namespaceNode A node to use for namespace prefix resolution.
172  * @return A list of selected nodes.
173  */
174  NodeRefList&
175  selectNodeList(
176  NodeRefList& result,
177  DOMSupport& domSupport,
178  XalanNode* contextNode,
179  const XalanDOMChar* xpathString,
180  const XalanElement* namespaceNode = 0);
181 
182  /**
183  * Evaluate the supplied XPath expression, within the given context. If
184  * the expression doesn't select a node, an empty list is returned.
185  *
186  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
187  * @param contextNode The source tree context node
188  * @param xpathString The XPath expression to evaluate
189  * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
190  * @return A list of selected nodes.
191  */
192  NodeRefList&
193  selectNodeList(
194  NodeRefList& result,
195  DOMSupport& domSupport,
196  XalanNode* contextNode,
197  const XalanDOMChar* xpathString,
198  const PrefixResolver& prefixResolver);
199 
200  /**
201  * Evaluate the supplied XPath, within the given context. If
202  * the expression doesn't select a node, an empty list is returned.
203  *
204  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
205  * @param contextNode The source tree context node
206  * @param xpath A reference to a compiled XPath expression.
207  * @param namespaceNode A node to use for namespace prefix resolution.
208  * @return A list of selected nodes.
209  */
210  NodeRefList&
211  selectNodeList(
212  NodeRefList& result,
213  DOMSupport& domSupport,
214  XalanNode* contextNode,
215  const XPath& xpath,
216  const XalanElement* namespaceNode = 0);
217 
218  /**
219  * Evaluate the supplied XPath, within the given context. If
220  * the expression doesn't select a node, an empty list is returned.
221  *
222  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
223  * @param contextNode The source tree context node
224  * @param xpath A reference to a compiled XPath expression.
225  * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
226  * @return A list of selected nodes.
227  */
228  NodeRefList&
229  selectNodeList(
230  NodeRefList& result,
231  DOMSupport& domSupport,
232  XalanNode* contextNode,
233  const XPath& xpath,
234  const PrefixResolver& prefixResolver);
235 
236  /**
237  * Evaluate the supplied XPath expression, within the given context. The
238  * result is returned as a generalized object. The object will be
239  * destroyed when the user's copy of the returned XObjectPtr goes out of
240  * scope, or when the XPathEvaluator goes out of scope or another expression
241  * is evaluated.
242  *
243  * The user's XObjectPtr copy _must_ no longer be in scope when the XPathEvaluator
244  * instance goes out of scope, or another expression is evaluated.
245  *
246  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
247  * @param contextNode The source tree context node
248  * @param xpathString The XPath expression to evaluate
249  * @param namespaceNode A node to use for namespace prefix resolution.
250  * @return The result of evaluting the XPath expression.
251  */
252  XObjectPtr
253  evaluate(
254  DOMSupport& domSupport,
255  XalanNode* contextNode,
256  const XalanDOMChar* xpathString,
257  const XalanElement* namespaceNode = 0);
258 
259  /**
260  * Evaluate the supplied XPath expression, within the given context. The
261  * result is returned as a generalized object. The object will be
262  * destroyed when the user's copy of the returned XObjectPtr goes out of
263  * scope, or when the XPathEvaluator goes out of scope or another expression
264  * is evaluated.
265  *
266  * The user's XObjectPtr copy _must_ no longer be in scope when the XPathEvaluator
267  * instance goes out of scope, or another expression is evaluated.
268  *
269  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
270  * @param contextNode The source tree context node
271  * @param xpathString The XPath expression to evaluate
272  * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
273  * @return The result of evaluting the XPath expression.
274  */
275  XObjectPtr
276  evaluate(
277  DOMSupport& domSupport,
278  XalanNode* contextNode,
279  const XalanDOMChar* xpathString,
280  const PrefixResolver& prefixResolver);
281 
282  /**
283  * Evaluate the supplied XPath expression, within the given context. The
284  * result is returned as a generalized object. The object will be
285  * destroyed when the user's copy of the returned XObjectPtr goes out of
286  * scope, or when the XPathEvaluator goes out of scope or another expression
287  * is evaluated.
288  *
289  * The user's XObjectPtr copy _must_ no longer be in scope when the XPathEvaluator
290  * instance goes out of scope, or another expression is evaluated.
291  *
292  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
293  * @param contextNode The source tree context node
294  * @param xpath A reference to a compiled XPath expression.
295  * @param namespaceNode A node to use for namespace prefix resolution.
296  * @return The result of evaluting the XPath expression.
297  */
298  XObjectPtr
299  evaluate(
300  DOMSupport& domSupport,
301  XalanNode* contextNode,
302  const XPath& xpath,
303  const XalanElement* namespaceNode = 0);
304 
305  /**
306  * Evaluate the supplied XPath expression, within the given context. The
307  * result is returned as a generalized object. The object will be
308  * destroyed when the user's copy of the returned XObjectPtr goes out of
309  * scope, or when the XPathEvaluator goes out of scope or another expression
310  * is evaluated.
311  *
312  * The user's XObjectPtr copy _must_ no longer be in scope when the XPathEvaluator
313  * instance goes out of scope, or another expression is evaluated.
314  *
315  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
316  * @param contextNode The source tree context node
317  * @param xpath A reference to a compiled XPath expression.
318  * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
319  * @return The result of evaluting the XPath expression.
320  */
321  XObjectPtr
322  evaluate(
323  DOMSupport& domSupport,
324  XalanNode* contextNode,
325  const XPath& xpath,
326  const PrefixResolver& prefixResolver);
327 
328  /**
329  * Compile an XPath expression into an object which can be used multiple times.
330  * Call destroyXPath() when finished with the instance. Otherwise, the object
331  * will be destroyed when the XPathEvaluator instance goes out of scope. Since
332  * no PrefixResolver is supplied, the XPath expression may not contain any
333  * namespace prefixes.
334  *
335  * @param xpathString The XPath expression to evaluate
336  * @return A pointer to an XPath instance.
337  */
338  XPath*
339  createXPath(const XalanDOMChar* xpathString);
340 
341  /**
342  * Compile an XPath expression into an object which can be used multiple times.
343  * Call destroyXPath() when finished with the instance. Otherwise, the object
344  * will be destroyed when the XPathEvaluator instance goes out of scope.
345  *
346  * @param xpathString The XPath expression to evaluate
347  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
348  * @param namespaceNode A node to use for namespace prefix resolution.
349  * @return A pointer to an XPath instance.
350  */
351  XPath*
352  createXPath(
353  const XalanDOMChar* xpathString,
354  DOMSupport& domSupport,
355  const XalanElement* namespaceNode);
356 
357  /**
358  * Compile an XPath expression into an object which can be used multiple times.
359  * Call destroyXPath() when finished with the instance. Otherwise, the object
360  * will be destroyed when the XPathEvaluator instance goes out of scope.
361  *
362  * @param xpathString The XPath expression to evaluate
363  * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
364  * @return A pointer to an XPath instance.
365  */
366  XPath*
367  createXPath(
368  const XalanDOMChar* xpathString,
369  const PrefixResolver& prefixResolver);
370 
371  /**
372  * Destory a compiled XPath instance. The instance must have
373  * been created using createXPath().
374  *
375  * @param theXPath The XPath instance to destroy
376  * @return true if the instance was successfully destroyed
377  */
378  bool
379  destroyXPath(XPath* theXPath);
380 
382  getExecutionContext();
383 
384 private:
385 
386  /**
387  * A helper function to evaluate the supplied XPath expression, within
388  * the given context.
389  *
390  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
391  * @param contextNode The source tree context node
392  * @param xpathString The XPath expression to evaluate
393  * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
394  * @param envSupport The XPathEnvSupport instance to use.
395  * @return The result of evaluting the XPath expression.
396  */
397  XObjectPtr
398  evaluate(
399  DOMSupport& domSupport,
400  XalanNode* contextNode,
401  const XalanDOMChar* xpathString,
402  const PrefixResolver& prefixResolver,
403  XPathEnvSupport& envSupport);
404 
405  /**
406  * A helper function to evaluate the supplied XPath expression, within
407  * the given context.
408  *
409  * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
410  * @param contextNode The source tree context node
411  * @param xpath The XPath to evaluate
412  * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
413  * @param envSupport The XPathEnvSupport instance to use.
414  * @return The result of evaluting the XPath expression.
415  */
416  XObjectPtr
417  evaluate(
418  DOMSupport& domSupport,
419  XalanNode* contextNode,
420  const XPath& xpath,
421  const PrefixResolver& prefixResolver,
422  XPathEnvSupport& envSupport);
423 
424  // Data members...
425  const XalanMemMgrAutoPtr<XObjectFactory> m_xobjectFactory;
426 
427  const XalanMemMgrAutoPtr<XPathFactoryDefault> m_xpathFactory;
428 
429  const XalanMemMgrAutoPtr<XPathConstructionContextDefault> m_constructionContext;
430 
431  const XalanMemMgrAutoPtr<XPathExecutionContextDefault> m_executionContext;
432 
433  MemoryManager& m_memoryManager;
434 };
435 
436 
437 
438 }
439 
440 
441 
442 #endif // XPATHEVALUATOR_HEADER_GUARD_1357924680
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanNode
Definition: XalanNode.hpp:38
XalanDOMString.hpp
xalanc::XPath
Definition: XPath.hpp:67
xalanc::XPathEvaluator
Definition: XPathEvaluator.hpp:69
xalanc::NodeRefList
Local implementation of NodeRefList.
Definition: NodeRefList.hpp:43
XALAN_DEFAULT_MEMMGR
#define XALAN_DEFAULT_MEMMGR
Definition: XalanMemoryManagement.hpp:516
XALAN_XPATH_EXPORT
#define XALAN_XPATH_EXPORT
Definition: XPathDefinitions.hpp:35
xalanc::XObjectPtr
Class to hold XObjectPtr return types.
Definition: XObject.hpp:883
XPathConstructionContextDefault.hpp
xalanc::PrefixResolver
This class defines an interface for classes that resolve namespace prefixes to their URIs.
Definition: PrefixResolver.hpp:39
xalanc::DOMSupport
Definition: DOMSupport.hpp:41
XObjectFactory.hpp
xalanc::XalanMemMgrAutoPtr
Definition: XalanMemMgrAutoPtr.hpp:46
xalanc::XPathEnvSupport
Definition: XPathEnvSupport.hpp:60
xalanc::XalanElement
Definition: XalanElement.hpp:44
xalanc::XPathExecutionContext
Definition: XPathExecutionContext.hpp:82
XPathFactoryDefault.hpp
XPathExecutionContextDefault.hpp
XPathDefinitions.hpp
XalanMemMgrAutoPtr.hpp