Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

XPathExecutionContext.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #if !defined(XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680)
17 #define XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680
18 
19 
20 
21 // Base include file. Must be first.
23 
24 
25 
26 #include <cassert>
27 
28 
29 
31 
32 
33 
35 
36 
37 
41 // Base class header file...
43 
44 
45 
47 
48 
49 
50 XALAN_CPP_NAMESPACE_BEGIN
51 
52 
53 
55 class PrefixResolver;
56 class XalanQName;
57 class XObject;
58 class XObjectPtr;
59 class XObjectFactory;
60 class XalanDocument;
61 class XalanElement;
62 class XalanNode;
63 class XalanText;
64 
65 
66 
67 //
68 // An abstract class which provides support for executing XPath functions
69 // and extension functions.
70 //
71 
73 {
74 public:
75 
77 
79 
80  explicit
81  XPathExecutionContext(MemoryManagerType& m_memoryManager, XObjectFactory* theXObjectFactory = 0);
82 
83  virtual
85 
90  virtual void
91  reset() = 0;
92 
98  virtual XalanNode*
99  getCurrentNode() const = 0;
100 
106  virtual void
107  pushCurrentNode(XalanNode* theCurrentNode) = 0;
108 
112  virtual void
113  popCurrentNode() = 0;
114 
116  {
117  public:
118 
120  XPathExecutionContext& theExecutionContext,
121  XalanNode* theNewNode) :
122  m_executionContext(theExecutionContext)
123  {
124  theExecutionContext.pushCurrentNode(theNewNode);
125  }
126 
128  {
129  m_executionContext.popCurrentNode();
130  }
131 
132  private:
133 
134  XPathExecutionContext& m_executionContext;
135  };
136 
143  getXObjectFactory() const
144  {
145  assert(m_xobjectFactory != 0);
146 
147  return *m_xobjectFactory;
148  }
149 
157  virtual bool
158  isNodeAfter(
159  const XalanNode& node1,
160  const XalanNode& node2) const = 0;
161 
167  virtual void
168  pushContextNodeList(const NodeRefListBase& theList) = 0;
169 
173  virtual void
174  popContextNodeList() = 0;
175 
177  {
178  public:
179 
181  XPathExecutionContext& theExecutionContext,
182  const NodeRefListBase& theNodeList) :
183  m_executionContext(theExecutionContext)
184  {
185  m_executionContext.pushContextNodeList(theNodeList);
186  }
187 
189  {
190  m_executionContext.popContextNodeList();
191  }
192 
193  private:
194 
195  XPathExecutionContext& m_executionContext;
196  };
197 
203  virtual const NodeRefListBase&
204  getContextNodeList() const = 0;
205 
206  /*
207  * Get the count of nodes in the current context node list.
208  *
209  * @return length of list
210  */
211  virtual size_type
212  getContextNodeListLength() const = 0;
213 
214  /*
215  * Get the position of the node in the current context node list.
216  * Note that this is 1-based indexing (XPath/XSLT-style), not 0-based.
217  * Thus, 0 will be returned if the node was not found.
218  *
219  * @return position in list
220  */
221  virtual size_type
222  getContextNodeListPosition(const XalanNode& contextNode) const = 0;
223 
231  virtual bool
232  elementAvailable(const XalanQName& theQName) const = 0;
233 
243  virtual bool
244  elementAvailable(
245  const XalanDOMString& theName,
246  const LocatorType* locator) const = 0;
247 
255  virtual bool
256  functionAvailable(const XalanQName& theQName) const = 0;
257 
266  virtual bool
267  functionAvailable(
268  const XalanDOMString& theName,
269  const LocatorType* locator) const = 0;
270 
281  virtual const XObjectPtr
282  extFunction(
283  const XalanDOMString& theNamespace,
284  const XalanDOMString& functionName,
285  XalanNode* context,
286  const XObjectArgVectorType& argVec,
287  const LocatorType* locator) = 0;
288 
296  virtual XalanDocument*
297  parseXML(
298  MemoryManagerType& theManager,
299  const XalanDOMString& urlString,
300  const XalanDOMString& base) const = 0;
301 
307  virtual MutableNodeRefList*
308  borrowMutableNodeRefList() = 0;
309 
316  virtual bool
317  returnMutableNodeRefList(MutableNodeRefList* theList) = 0;
318 
320  {
321  public:
322 
324  m_xpathExecutionContext(&executionContext),
325  m_mutableNodeRefList(executionContext.borrowMutableNodeRefList())
326  {
327  assert(m_mutableNodeRefList != 0);
328  }
329 
330  // N.B. Non-const copy constructor semantics (like std::auto_ptr)
332  m_xpathExecutionContext(theSource.m_xpathExecutionContext),
333  m_mutableNodeRefList(theSource.m_mutableNodeRefList)
334  {
335  assert(m_mutableNodeRefList != 0);
336 
337  ((BorrowReturnMutableNodeRefList&)theSource).m_mutableNodeRefList = 0;
338  }
339 
341  {
342  release();
343  }
344 
346  operator*() const
347  {
348  assert(m_mutableNodeRefList != 0);
349 
350  return *m_mutableNodeRefList;
351  }
352 
354  get() const
355  {
356  return m_mutableNodeRefList;
357  }
358 
360  operator->() const
361  {
362  return get();
363  }
364 
365  void
366  release()
367  {
368  assert(m_xpathExecutionContext != 0);
369 
370  if (m_mutableNodeRefList != 0)
371  {
372  m_xpathExecutionContext->returnMutableNodeRefList(m_mutableNodeRefList);
373 
374  m_mutableNodeRefList = 0;
375  }
376  }
377 
379  clone() const
380  {
381  assert(m_xpathExecutionContext != 0);
382 
383  BorrowReturnMutableNodeRefList theResult(*m_xpathExecutionContext);
384 
385  *theResult = *m_mutableNodeRefList;
386 
387  return theResult;
388  }
389 
390  // N.B. Non-const assignment operator semantics.
393  {
394  release();
395 
396  m_xpathExecutionContext = theRHS.m_xpathExecutionContext;
397 
398  m_mutableNodeRefList = theRHS.m_mutableNodeRefList;
399 
400  theRHS.m_mutableNodeRefList = 0;
401 
402  return *this;
403  }
404 
405  private:
406 
407  XPathExecutionContext* m_xpathExecutionContext;
408 
409  MutableNodeRefList* m_mutableNodeRefList;
410  };
411 
417  virtual XalanDOMString&
418  getCachedString() = 0;
419 
427  virtual bool
428  releaseCachedString(XalanDOMString& theString) = 0;
429 
431  {
432  public:
433 
435  m_executionContext(&theExecutionContext),
436  m_string(&theExecutionContext.getCachedString())
437  {
438  }
439 
440  // Note non-const copy semantics...
442  m_executionContext(theSource.m_executionContext),
443  m_string(theSource.m_string)
444  {
445  theSource.m_string = 0;
446  }
447 
449  {
450  if (m_string != 0)
451  {
452  m_executionContext->releaseCachedString(*m_string);
453  }
454  }
455 
457  get() const
458  {
459  assert(m_string != 0);
460 
461  return *m_string;
462  }
463 
465  getExecutionContext() const
466  {
467  return *m_executionContext;
468  }
469 
470  private:
471 
472  // Not implemented...
474  operator=(const GetAndReleaseCachedString&);
475 
476 
477  // Data members...
478  XPathExecutionContext* m_executionContext;
479 
480  XalanDOMString* m_string;
481  };
482 
484 
490  virtual MutableNodeRefList*
491  createMutableNodeRefList(MemoryManagerType& theManager) const = 0;
492 
503  virtual void
504  getNodeSetByKey(
505  XalanDocument* doc,
506  const XalanQName& qname,
507  const XalanDOMString& ref,
508  MutableNodeRefList& nodelist) = 0;
509 
522  virtual void
523  getNodeSetByKey(
524  XalanDocument* doc,
525  const XalanDOMString& name,
526  const XalanDOMString& ref,
527  const LocatorType* locator,
528  MutableNodeRefList& nodelist) = 0;
529 
538  virtual const XObjectPtr
539  getVariable(
540  const XalanQName& name,
541  const LocatorType* locator = 0) = 0;
542 
548  virtual const PrefixResolver*
549  getPrefixResolver() const = 0;
550 
556  virtual void
557  setPrefixResolver(const PrefixResolver* thePrefixResolver) = 0;
558 
560  {
561  public:
562 
564  XPathExecutionContext& theExecutionContext,
565  const PrefixResolver* theResolver) :
566  m_executionContext(theExecutionContext),
567  m_savedResolver(theExecutionContext.getPrefixResolver())
568  {
569  m_executionContext.setPrefixResolver(theResolver);
570  }
571 
573  XPathExecutionContext& theExecutionContext,
574  const PrefixResolver* theOldResolver,
575  const PrefixResolver* theNewResolver) :
576  m_executionContext(theExecutionContext),
577  m_savedResolver(theOldResolver)
578  {
579  m_executionContext.setPrefixResolver(theNewResolver);
580  }
581 
583  {
584  m_executionContext.setPrefixResolver(m_savedResolver);
585  }
586 
587  private:
588 
589  XPathExecutionContext& m_executionContext;
590  const PrefixResolver* const m_savedResolver;
591  };
592 
599  virtual const XalanDOMString*
600  getNamespaceForPrefix(const XalanDOMString& prefix) const = 0;
601 
609  virtual const XalanDOMString&
610  findURIFromDoc(const XalanDocument* owner) const = 0;
611 
622  virtual const XalanDOMString&
623  getUnparsedEntityURI(
624  const XalanDOMString& theName,
625  const XalanDocument& theDocument) const = 0;
626 
637  virtual bool
638  shouldStripSourceNode(const XalanText& node) = 0;
639 
646  virtual XalanDocument*
647  getSourceDocument(const XalanDOMString& theURI) const = 0;
648 
655  virtual void
656  setSourceDocument(
657  const XalanDOMString& theURI,
658  XalanDocument* theDocument) = 0;
659 
669  virtual void formatNumber(
670  double number,
671  const XalanDOMString& pattern,
672  XalanDOMString& theResult,
673  const XalanNode* context = 0,
674  const LocatorType* locator = 0) = 0;
675 
687  virtual void formatNumber(
688  double number,
689  const XalanDOMString& pattern,
690  const XalanDOMString& dfsName,
691  XalanDOMString& theResult,
692  const XalanNode* context = 0,
693  const LocatorType* locator = 0) = 0;
694 
695  // These interfaces are inherited from ExecutionContext...
696 
697  virtual void
698  error(
699  const XalanDOMString& msg,
700  const XalanNode* sourceNode = 0,
701  const LocatorType* locator = 0) const = 0;
702 
703  virtual void
704  warn(
705  const XalanDOMString& msg,
706  const XalanNode* sourceNode = 0,
707  const LocatorType* locator = 0) const = 0;
708 
709  virtual void
710  message(
711  const XalanDOMString& msg,
712  const XalanNode* sourceNode = 0,
713  const LocatorType* locator = 0) const = 0;
714 
715 protected:
716 
718 };
719 
720 
721 
722 XALAN_CPP_NAMESPACE_END
723 
724 
725 
726 #endif // XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680

Interpreting class diagrams

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

dot

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

Apache Logo