Xalan-C++ API Reference 1.12.0
XPathExecutionContext.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(XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680)
19#define XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680
20
21
22
23// Base include file. Must be first.
25
26
27
28#include <cassert>
29
30
31
33
34
35
37
38
39
40// Base class header file...
42
43
44
46
47
48
49namespace XERCES_CPP_NAMESPACE
50{
51 class ErrorHandler;
52}
53
54
55
56namespace XALAN_CPP_NAMESPACE {
57
58
59
60class XalanDecimalFormatSymbols;
61class PrefixResolver;
62class XalanQName;
63class XObject;
64class XObjectPtr;
65class XObjectFactory;
66class XalanDocument;
67class XalanElement;
68class XalanNode;
69class XalanText;
70
71
72
73using xercesc::ErrorHandler;
74
75
76
77//
78// An abstract class which provides support for executing XPath functions
79// and extension functions.
80//
81
83{
84public:
85
87
89
90 explicit
92 MemoryManager& theMemoryManager,
94
95 virtual
97
98 /**
99 * Reset the instance. This must be called before another
100 * execution is attempted.
101 */
102 virtual void
103 reset() = 0;
104
105 /**
106 * Retrieve the node currently being executed.
107 *
108 * @return current node
109 */
110 virtual XalanNode*
111 getCurrentNode() const = 0;
112
113 /**
114 * Change the node currently being executed.
115 *
116 * @param theCurrentNode new current node
117 */
118 virtual void
120
121 /**
122 * Reset the node currently being executed.
123 */
124 virtual void
126
128 {
129 public:
130
138
140 {
141 m_executionContext.popCurrentNode();
142 }
143
144 private:
145
146 XPathExecutionContext& m_executionContext;
147 };
148
149 /**
150 * Retrieve the factory object for creating XObjects.
151 *
152 * @return factory object instance
153 */
156 {
157 assert(m_xobjectFactory != 0);
158
159 return *m_xobjectFactory;
160 }
161
162 /**
163 * Determine if a node is after another node, in document order.
164 *
165 * @param node1 The first node
166 * @param node2 The second node
167 * @return true if node1 one is after node2, or false if it is not.
168 */
169 virtual bool
171 const XalanNode& node1,
172 const XalanNode& node2) const = 0;
173
174 /**
175 * Push the node list for current context.
176 *
177 * @param theList new node list
178 */
179 virtual void
181
182 /**
183 * Pop the node list for current context.
184 */
185 virtual void
187
189 {
190 public:
191
195 m_executionContext(theExecutionContext)
196 {
197 m_executionContext.pushContextNodeList(theNodeList);
198 }
199
201 {
202 m_executionContext.popContextNodeList();
203 }
204
205 private:
206
207 XPathExecutionContext& m_executionContext;
208 };
209
210 /**
211 * Get the node list for current context.
212 *
213 * @return node list
214 */
215 virtual const NodeRefListBase&
217
218 /*
219 * Get the count of nodes in the current context node list.
220 *
221 * @return length of list
222 */
223 virtual size_type
225
226 /*
227 * Get the position of the node in the current context node list.
228 * Note that this is 1-based indexing (XPath/XSLT-style), not 0-based.
229 * Thus, 0 will be returned if the node was not found.
230 *
231 * @return position in list
232 */
233 virtual size_type
235
236 /**
237 * Determine if an external element is available.
238 *
239 * @param theQName The QName of the element
240 *
241 * @return whether the given element is available or not
242 */
243
244 virtual bool
246
247 /**
248 * Determine if an external element is available by resolving
249 * a string to a QName.
250 *
251 * @param theName The name of the element
252 * @param locator A Locator instance for error reporting
253 *
254 * @return whether the given element is available or not
255 */
256 virtual bool
258 const XalanDOMString& theName,
259 const Locator* locator) const = 0;
260
261 /**
262 * Determine if a function is available.
263 *
264 * @param theQName The QName of the function
265 *
266 * @return whether the function is available or not
267 */
268 virtual bool
270
271 /**
272 * Determine if a function is available.
273 *
274 * @param theName The name of the function
275 * @param locator A Locator instance for error reporting
276 *
277 * @return whether the function is available or not
278 */
279 virtual bool
281 const XalanDOMString& theName,
282 const Locator* locator) const = 0;
283
284 /**
285 * Handle an extension function.
286 *
287 * @param theNamespace namespace of function
288 * @param functionName extension function name
289 * @param context The context node
290 * @param argVec vector of arguments to function
291 * @param locator A Locator instance for error reporting
292 * @return pointer to XObject result
293 */
294 virtual const XObjectPtr
297 const XalanDOMString& functionName,
300 const Locator* locator) = 0;
301
302 /**
303 * Provides support for XML parsing service.
304 *
305 * @param theManager The MemoryManager instance to use.
306 * @param urlString location of the XML
307 * @param base base location for URI
308 * @param theErrorHandler An optional ErrorHandler instance for error reporting.
309 * @return parsed document
310 */
311 virtual XalanDocument*
313 MemoryManager& theManager,
315 const XalanDOMString& base,
316 ErrorHandler* theErrorHandler = 0) const = 0;
317
318 /**
319 * Borrow a cached MutableNodeRefList instance.
320 *
321 * @return A pointer to the instance.
322 */
323 virtual MutableNodeRefList*
325
326 /**
327 * Return a previously borrowed MutableNodeRefList instance.
328 *
329 * @param theList A pointer the to previously borrowed instance.
330 * @return true if the list was borrowed (at therefore, destroyed), false if not.
331 */
332 virtual bool
334
336 {
337 public:
338
340 m_xpathExecutionContext(&executionContext),
341 m_mutableNodeRefList(executionContext.borrowMutableNodeRefList())
342 {
343 assert(m_mutableNodeRefList != 0);
344 }
345
346 // N.B. Non-const copy constructor semantics (like std::auto_ptr)
348 m_xpathExecutionContext(theSource.m_xpathExecutionContext),
349 m_mutableNodeRefList(theSource.m_mutableNodeRefList)
350 {
351 assert(m_mutableNodeRefList != 0);
352
353 ((BorrowReturnMutableNodeRefList&)theSource).m_mutableNodeRefList = 0;
354 }
355
357 {
358 release();
359 }
360
362 operator*() const
363 {
364 assert(m_mutableNodeRefList != 0);
365
366 return *m_mutableNodeRefList;
367 }
368
370 get() const
371 {
372 return m_mutableNodeRefList;
373 }
374
377 {
378 return get();
379 }
380
381 void
383 {
384 assert(m_xpathExecutionContext != 0);
385
386 if (m_mutableNodeRefList != 0)
387 {
388 m_xpathExecutionContext->returnMutableNodeRefList(m_mutableNodeRefList);
389
390 m_mutableNodeRefList = 0;
391 }
392 }
393
395 clone() const
396 {
397 assert(m_xpathExecutionContext != 0);
398
399 GetCachedNodeList theResult(*m_xpathExecutionContext);
400
401 *theResult = *m_mutableNodeRefList;
402
403 return theResult;
404 }
405
406 // N.B. Non-const assignment operator semantics.
409 {
410 release();
411
412 m_xpathExecutionContext = theRHS.m_xpathExecutionContext;
413
414 m_mutableNodeRefList = theRHS.m_mutableNodeRefList;
415
416 theRHS.m_mutableNodeRefList = 0;
417
418 return *this;
419 }
420
421 private:
422
423 XPathExecutionContext* m_xpathExecutionContext;
424
425 MutableNodeRefList* m_mutableNodeRefList;
426 };
427
429
430 /**
431 * Get a cached string for temporary use.
432 *
433 * @return A reference to the string
434 */
435 virtual XalanDOMString&
437
438 /**
439 * Return a cached string.
440 *
441 * @param theString The string to release.
442 *
443 * @return true if the string was released successfully.
444 */
445 virtual bool
447
449 {
450 public:
451
453 m_executionContext(&theExecutionContext),
454 m_string(&theExecutionContext.getCachedString())
455 {
456 }
457
458 // Note non-const copy semantics...
460 m_executionContext(theSource.m_executionContext),
461 m_string(theSource.m_string)
462 {
463 theSource.m_string = 0;
464 }
465
467 {
468 if (m_string != 0)
469 {
470 m_executionContext->releaseCachedString(*m_string);
471 }
472 }
473
475 get() const
476 {
477 assert(m_string != 0);
478
479 return *m_string;
480 }
481
484 {
485 return *m_executionContext;
486 }
487
488 private:
489
490 // Not implemented...
492
494
496 operator=(const GetCachedString&);
497
498
499 // Data members...
500 XPathExecutionContext* m_executionContext;
501
502 XalanDOMString* m_string;
503 };
504
506
507 /**
508 * Create a MutableNodeRefList with the appropriate context.
509 *
510 * @return pointer to node list created
511 */
512 virtual MutableNodeRefList*
513 createMutableNodeRefList(MemoryManager& theManager) const = 0;
514
515 /**
516 * Given a valid element key, return the corresponding node list.
517 *
518 * @param context context node
519 * @param name qname of the key, which must match the 'name'
520 * attribute on xsl:key
521 * @param ref value that must match the value found by the
522 * 'match' attribute on xsl:key
523 * @param locator The Locator to use for error reporting. Can be 0.
524 * @param nodelist A node list to contain the nodes found
525 */
526 virtual void
529 const XalanQName& qname,
530 const XalanDOMString& ref,
531 const Locator* locator,
533
534 /**
535 * Given a valid element key, return the corresponding node list.
536 *
537 * @param context context node
538 * @param name name of the key, which must match the 'name'
539 * attribute on xsl:key. Will be resolved to a
540 * qname using the provided resolver.
541 * @param ref value that must match the value found by the
542 * 'match' attribute on xsl:key
543 * @param locator The Locator to use for error reporting. Can be 0.
544 * @param nodelist A node list to contain the nodes found
545 */
546 virtual void
549 const XalanDOMString& name,
550 const XalanDOMString& ref,
551 const Locator* locator,
553
554 /**
555 * Given a name, locate a variable in the current context, and return
556 * a pointer to the object.
557 *
558 * @param theName name of variable
559 * @return An XObjectPtr instance. If the variable is not found, an exception
560 * is thrown, or the routine returns an instance of XUnknown.
561 */
562 virtual const XObjectPtr
564 const XalanQName& name,
565 const Locator* locator = 0) = 0;
566
567 /**
568 * Retrieve the resolver for namespaces.
569 *
570 * @return object for namespace resolution
571 */
572 virtual const PrefixResolver*
573 getPrefixResolver() const = 0;
574
575 /**
576 * Change the resolver for namespaces.
577 *
578 * @param thePrefixResolver new object for namespace resolution
579 */
580 virtual void
582
584 {
585 public:
586
590 m_executionContext(theExecutionContext),
591 m_savedResolver(theExecutionContext.getPrefixResolver())
592 {
593 m_executionContext.setPrefixResolver(theResolver);
594 }
595
600 m_executionContext(theExecutionContext),
601 m_savedResolver(theOldResolver)
602 {
603 m_executionContext.setPrefixResolver(theNewResolver);
604 }
605
607 {
608 m_executionContext.setPrefixResolver(m_savedResolver);
609 }
610
611 private:
612
613 XPathExecutionContext& m_executionContext;
614 const PrefixResolver* const m_savedResolver;
615 };
616
617 /**
618 * Retrieve the URI corresponding to a namespace prefix
619 *
620 * @param prefix prefix for a namespace
621 * @return URI corresponding to namespace
622 */
623 virtual const XalanDOMString*
625
626 /**
627 * Given a DOM Document, tell what URI was used to parse it. Needed for
628 * relative resolution.
629 *
630 * @param owner source document
631 * @return document URI
632 */
633 virtual const XalanDOMString&
635
636 /**
637 * The getUnparsedEntityURI function returns the URI of the unparsed
638 * entity with the specified name in the same document as the context
639 * node (see [3.3 Unparsed Entities]). It returns the empty string if
640 * there is no such entity.
641 *
642 * @param theName name of entity
643 * @param theDocument document containing entity
644 * @return URI for the entity
645 */
646 virtual const XalanDOMString&
648 const XalanDOMString& theName,
649 const XalanDocument& theDocument) const = 0;
650
651 /**
652 * Get the document associated with the given URI.
653 *
654 * @param theURI document URI
655 * @return a pointer to the document instance, if any.
656 */
657 virtual XalanDocument*
659
660 /**
661 * Associate a document with a given URI.
662 *
663 * @param theURI document URI
664 * @param theDocument source document
665 */
666 virtual void
668 const XalanDOMString& theURI,
670
671 /**
672 * Formats a number according to the specified pattern.
673 *
674 * @param number the number to be formatted
675 * @param pattern the format pattern
676 * @param theResult the formatted number
677 * @param context the source node
678 * @param locator the locator
679 */
680 virtual void formatNumber(
681 double number,
682 const XalanDOMString& pattern,
684 const XalanNode* context = 0,
685 const Locator* locator = 0) = 0;
686
687 /**
688 * Formats a number according to the specified pattern.
689 *
690 * @param number the number to be formatted
691 * @param pattern the format pattern
692 * @param dfsName the name of decimal format to use
693 * @param theResult the formatted number
694 * @param context the source node
695 * @param locator the locator
696 * @return a pointer to the functor, 0 if none was found
697 */
698 virtual void formatNumber(
699 double number,
700 const XalanDOMString& pattern,
701 const XalanDOMString& dfsName,
703 const XalanNode* context = 0,
704 const Locator* locator = 0) = 0;
705
706 // These interfaces are inherited from ExecutionContext...
707
708 virtual void
710 eSource source,
712 const XalanDOMString& msg,
713 const Locator* locator,
714 const XalanNode* sourceNode) = 0;
715
716 virtual void
718 eSource source,
720 const XalanDOMString& msg,
721 const XalanNode* sourceNode) = 0;
722
723 virtual bool
725
726protected:
727
729};
730
731
732
733}
734
735
736
737#endif // XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680
#define XALAN_XPATH_EXPORT
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Local implementation of MutableNodeRefList.
Local implementation of NodeRefList.
This class defines an interface for classes that resolve namespace prefixes to their URIs.
This class handles the creation of XObjects and manages their lifetime.
Class to hold XObjectPtr return types.
Definition XObject.hpp:884
ContextNodeListPushAndPop(XPathExecutionContext &theExecutionContext, const NodeRefListBase &theNodeList)
CurrentNodePushAndPop(XPathExecutionContext &theExecutionContext, XalanNode *theNewNode)
GetCachedNodeList(XPathExecutionContext &executionContext)
GetCachedNodeList & operator=(GetCachedNodeList &theRHS)
GetCachedNodeList(const GetCachedNodeList &theSource)
GetCachedString(XPathExecutionContext &theExecutionContext)
PrefixResolverSetAndRestore(XPathExecutionContext &theExecutionContext, const PrefixResolver *theOldResolver, const PrefixResolver *theNewResolver)
PrefixResolverSetAndRestore(XPathExecutionContext &theExecutionContext, const PrefixResolver *theResolver)
virtual bool functionAvailable(const XalanQName &theQName) const =0
Determine if a function is available.
virtual void problem(eSource source, eClassification classification, const XalanDOMString &msg, const Locator *locator, const XalanNode *sourceNode)=0
Function that is called when a problem event occurs.
virtual void setSourceDocument(const XalanDOMString &theURI, XalanDocument *theDocument)=0
Associate a document with a given URI.
virtual XalanDocument * parseXML(MemoryManager &theManager, const XalanDOMString &urlString, const XalanDOMString &base, ErrorHandler *theErrorHandler=0) const =0
Provides support for XML parsing service.
virtual const XObjectPtr getVariable(const XalanQName &name, const Locator *locator=0)=0
Given a name, locate a variable in the current context, and return a pointer to the object.
XObjectFactory & getXObjectFactory() const
Retrieve the factory object for creating XObjects.
virtual XalanDOMString & getCachedString()=0
Get a cached string for temporary use.
virtual void popCurrentNode()=0
Reset the node currently being executed.
NodeRefListBase::size_type size_type
virtual void popContextNodeList()=0
Pop the node list for current context.
virtual MutableNodeRefList * createMutableNodeRefList(MemoryManager &theManager) const =0
Create a MutableNodeRefList with the appropriate context.
virtual void pushCurrentNode(XalanNode *theCurrentNode)=0
Change the node currently being executed.
virtual void formatNumber(double number, const XalanDOMString &pattern, XalanDOMString &theResult, const XalanNode *context=0, const Locator *locator=0)=0
Formats a number according to the specified pattern.
XPathExecutionContext(MemoryManager &theMemoryManager, XObjectFactory *theXObjectFactory=0)
virtual bool functionAvailable(const XalanDOMString &theName, const Locator *locator) const =0
Determine if a function is available.
virtual bool elementAvailable(const XalanDOMString &theName, const Locator *locator) const =0
Determine if an external element is available by resolving a string to a QName.
virtual void problem(eSource source, eClassification classification, const XalanDOMString &msg, const XalanNode *sourceNode)=0
Function that is called when a problem event occurs.
virtual XalanNode * getCurrentNode() const =0
Retrieve the node currently being executed.
virtual void getNodeSetByKey(XalanNode *context, const XalanQName &qname, const XalanDOMString &ref, const Locator *locator, MutableNodeRefList &nodelist)=0
Given a valid element key, return the corresponding node list.
virtual XalanDocument * getSourceDocument(const XalanDOMString &theURI) const =0
Get the document associated with the given URI.
virtual size_type getContextNodeListPosition(const XalanNode &contextNode) const =0
XalanVector< XObjectPtr > XObjectArgVectorType
virtual const NodeRefListBase & getContextNodeList() const =0
Get the node list for current context.
virtual bool shouldStripSourceNode(const XalanText &node)=0
Determine if a text node should be stripped from the source tree, as if it weren't there.
virtual const XObjectPtr extFunction(const XalanDOMString &theNamespace, const XalanDOMString &functionName, XalanNode *context, const XObjectArgVectorType &argVec, const Locator *locator)=0
Handle an extension function.
virtual void getNodeSetByKey(XalanNode *context, const XalanDOMString &name, const XalanDOMString &ref, const Locator *locator, MutableNodeRefList &nodelist)=0
Given a valid element key, return the corresponding node list.
virtual void formatNumber(double number, const XalanDOMString &pattern, const XalanDOMString &dfsName, XalanDOMString &theResult, const XalanNode *context=0, const Locator *locator=0)=0
Formats a number according to the specified pattern.
virtual void pushContextNodeList(const NodeRefListBase &theList)=0
Push the node list for current context.
virtual const PrefixResolver * getPrefixResolver() const =0
Retrieve the resolver for namespaces.
virtual const XalanDOMString * getNamespaceForPrefix(const XalanDOMString &prefix) const =0
Retrieve the URI corresponding to a namespace prefix.
virtual bool returnMutableNodeRefList(MutableNodeRefList *theList)=0
Return a previously borrowed MutableNodeRefList instance.
virtual bool elementAvailable(const XalanQName &theQName) const =0
Determine if an external element is available.
virtual void reset()=0
Reset the instance.
virtual void setPrefixResolver(const PrefixResolver *thePrefixResolver)=0
Change the resolver for namespaces.
virtual size_type getContextNodeListLength() const =0
virtual const XalanDOMString & findURIFromDoc(const XalanDocument *owner) const =0
Given a DOM Document, tell what URI was used to parse it.
virtual MutableNodeRefList * borrowMutableNodeRefList()=0
Borrow a cached MutableNodeRefList instance.
virtual const XalanDOMString & getUnparsedEntityURI(const XalanDOMString &theName, const XalanDocument &theDocument) const =0
The getUnparsedEntityURI function returns the URI of the unparsed entity with the specified name in t...
virtual bool releaseCachedString(XalanDOMString &theString)=0
Return a cached string.
virtual bool isNodeAfter(const XalanNode &node1, const XalanNode &node2) const =0
Determine if a node is after another node, in document order.
Class to represent a qualified name.