Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


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

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

Xalan-C++ XSLT Processor Version 1.11
Copyright © 1999-2012 The Apache Software Foundation.
All Rights Reserved.

Apache Logo