00001 /* 00002 * Copyright 1999-2004 The Apache Software Foundation. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #if !defined(XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680) 00017 #define XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680 00018 00019 00020 00021 // Base include file. Must be first. 00022 #include <xalanc/XPath/XPathDefinitions.hpp> 00023 00024 00025 00026 #include <cassert> 00027 00028 00029 00030 #include <xalanc/Include/XalanVector.hpp> 00031 00032 00033 00034 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00035 00036 00037 00041 // Base class header file... 00042 #include <xalanc/PlatformSupport/ExecutionContext.hpp> 00043 00044 00045 00046 #include <xalanc/XPath/MutableNodeRefList.hpp> 00047 00048 00049 00050 XALAN_CPP_NAMESPACE_BEGIN 00051 00052 00053 00054 class XalanDecimalFormatSymbols; 00055 class PrefixResolver; 00056 class XalanQName; 00057 class XObject; 00058 class XObjectPtr; 00059 class XObjectFactory; 00060 class XalanDocument; 00061 class XalanElement; 00062 class XalanNode; 00063 class XalanText; 00064 00065 00066 00067 // 00068 // An abstract class which provides support for executing XPath functions 00069 // and extension functions. 00070 // 00071 00072 class XALAN_XPATH_EXPORT XPathExecutionContext : public ExecutionContext 00073 { 00074 public: 00075 00076 typedef XalanVector<XObjectPtr> XObjectArgVectorType; 00077 00078 typedef NodeRefListBase::size_type size_type; 00079 00080 explicit 00081 XPathExecutionContext(MemoryManagerType& m_memoryManager, XObjectFactory* theXObjectFactory = 0); 00082 00083 virtual 00084 ~XPathExecutionContext(); 00085 00090 virtual void 00091 reset() = 0; 00092 00098 virtual XalanNode* 00099 getCurrentNode() const = 0; 00100 00106 virtual void 00107 pushCurrentNode(XalanNode* theCurrentNode) = 0; 00108 00112 virtual void 00113 popCurrentNode() = 0; 00114 00115 class CurrentNodePushAndPop 00116 { 00117 public: 00118 00119 CurrentNodePushAndPop( 00120 XPathExecutionContext& theExecutionContext, 00121 XalanNode* theNewNode) : 00122 m_executionContext(theExecutionContext) 00123 { 00124 theExecutionContext.pushCurrentNode(theNewNode); 00125 } 00126 00127 ~CurrentNodePushAndPop() 00128 { 00129 m_executionContext.popCurrentNode(); 00130 } 00131 00132 private: 00133 00134 XPathExecutionContext& m_executionContext; 00135 }; 00136 00142 XObjectFactory& 00143 getXObjectFactory() const 00144 { 00145 assert(m_xobjectFactory != 0); 00146 00147 return *m_xobjectFactory; 00148 } 00149 00157 virtual bool 00158 isNodeAfter( 00159 const XalanNode& node1, 00160 const XalanNode& node2) const = 0; 00161 00167 virtual void 00168 pushContextNodeList(const NodeRefListBase& theList) = 0; 00169 00173 virtual void 00174 popContextNodeList() = 0; 00175 00176 class ContextNodeListPushAndPop 00177 { 00178 public: 00179 00180 ContextNodeListPushAndPop( 00181 XPathExecutionContext& theExecutionContext, 00182 const NodeRefListBase& theNodeList) : 00183 m_executionContext(theExecutionContext) 00184 { 00185 m_executionContext.pushContextNodeList(theNodeList); 00186 } 00187 00188 ~ContextNodeListPushAndPop() 00189 { 00190 m_executionContext.popContextNodeList(); 00191 } 00192 00193 private: 00194 00195 XPathExecutionContext& m_executionContext; 00196 }; 00197 00203 virtual const NodeRefListBase& 00204 getContextNodeList() const = 0; 00205 00206 /* 00207 * Get the count of nodes in the current context node list. 00208 * 00209 * @return length of list 00210 */ 00211 virtual size_type 00212 getContextNodeListLength() const = 0; 00213 00214 /* 00215 * Get the position of the node in the current context node list. 00216 * Note that this is 1-based indexing (XPath/XSLT-style), not 0-based. 00217 * Thus, 0 will be returned if the node was not found. 00218 * 00219 * @return position in list 00220 */ 00221 virtual size_type 00222 getContextNodeListPosition(const XalanNode& contextNode) const = 0; 00223 00231 virtual bool 00232 elementAvailable(const XalanQName& theQName) const = 0; 00233 00243 virtual bool 00244 elementAvailable( 00245 const XalanDOMString& theName, 00246 const LocatorType* locator) const = 0; 00247 00255 virtual bool 00256 functionAvailable(const XalanQName& theQName) const = 0; 00257 00266 virtual bool 00267 functionAvailable( 00268 const XalanDOMString& theName, 00269 const LocatorType* locator) const = 0; 00270 00281 virtual const XObjectPtr 00282 extFunction( 00283 const XalanDOMString& theNamespace, 00284 const XalanDOMString& functionName, 00285 XalanNode* context, 00286 const XObjectArgVectorType& argVec, 00287 const LocatorType* locator) = 0; 00288 00296 virtual XalanDocument* 00297 parseXML( 00298 MemoryManagerType& theManager, 00299 const XalanDOMString& urlString, 00300 const XalanDOMString& base) const = 0; 00301 00307 virtual MutableNodeRefList* 00308 borrowMutableNodeRefList() = 0; 00309 00316 virtual bool 00317 returnMutableNodeRefList(MutableNodeRefList* theList) = 0; 00318 00319 class BorrowReturnMutableNodeRefList 00320 { 00321 public: 00322 00323 BorrowReturnMutableNodeRefList(XPathExecutionContext& executionContext) : 00324 m_xpathExecutionContext(&executionContext), 00325 m_mutableNodeRefList(executionContext.borrowMutableNodeRefList()) 00326 { 00327 assert(m_mutableNodeRefList != 0); 00328 } 00329 00330 // N.B. Non-const copy constructor semantics (like std::auto_ptr) 00331 BorrowReturnMutableNodeRefList(const BorrowReturnMutableNodeRefList& theSource) : 00332 m_xpathExecutionContext(theSource.m_xpathExecutionContext), 00333 m_mutableNodeRefList(theSource.m_mutableNodeRefList) 00334 { 00335 assert(m_mutableNodeRefList != 0); 00336 00337 ((BorrowReturnMutableNodeRefList&)theSource).m_mutableNodeRefList = 0; 00338 } 00339 00340 ~BorrowReturnMutableNodeRefList() 00341 { 00342 release(); 00343 } 00344 00345 MutableNodeRefList& 00346 operator*() const 00347 { 00348 assert(m_mutableNodeRefList != 0); 00349 00350 return *m_mutableNodeRefList; 00351 } 00352 00353 MutableNodeRefList* 00354 get() const 00355 { 00356 return m_mutableNodeRefList; 00357 } 00358 00359 MutableNodeRefList* 00360 operator->() const 00361 { 00362 return get(); 00363 } 00364 00365 void 00366 release() 00367 { 00368 assert(m_xpathExecutionContext != 0); 00369 00370 if (m_mutableNodeRefList != 0) 00371 { 00372 m_xpathExecutionContext->returnMutableNodeRefList(m_mutableNodeRefList); 00373 00374 m_mutableNodeRefList = 0; 00375 } 00376 } 00377 00378 BorrowReturnMutableNodeRefList 00379 clone() const 00380 { 00381 assert(m_xpathExecutionContext != 0); 00382 00383 BorrowReturnMutableNodeRefList theResult(*m_xpathExecutionContext); 00384 00385 *theResult = *m_mutableNodeRefList; 00386 00387 return theResult; 00388 } 00389 00390 // N.B. Non-const assignment operator semantics. 00391 BorrowReturnMutableNodeRefList& 00392 operator=(BorrowReturnMutableNodeRefList& theRHS) 00393 { 00394 release(); 00395 00396 m_xpathExecutionContext = theRHS.m_xpathExecutionContext; 00397 00398 m_mutableNodeRefList = theRHS.m_mutableNodeRefList; 00399 00400 theRHS.m_mutableNodeRefList = 0; 00401 00402 return *this; 00403 } 00404 00405 private: 00406 00407 XPathExecutionContext* m_xpathExecutionContext; 00408 00409 MutableNodeRefList* m_mutableNodeRefList; 00410 }; 00411 00417 virtual XalanDOMString& 00418 getCachedString() = 0; 00419 00427 virtual bool 00428 releaseCachedString(XalanDOMString& theString) = 0; 00429 00430 class GetAndReleaseCachedString 00431 { 00432 public: 00433 00434 GetAndReleaseCachedString(XPathExecutionContext& theExecutionContext) : 00435 m_executionContext(&theExecutionContext), 00436 m_string(&theExecutionContext.getCachedString()) 00437 { 00438 } 00439 00440 // Note non-const copy semantics... 00441 GetAndReleaseCachedString(GetAndReleaseCachedString& theSource) : 00442 m_executionContext(theSource.m_executionContext), 00443 m_string(theSource.m_string) 00444 { 00445 theSource.m_string = 0; 00446 } 00447 00448 ~GetAndReleaseCachedString() 00449 { 00450 if (m_string != 0) 00451 { 00452 m_executionContext->releaseCachedString(*m_string); 00453 } 00454 } 00455 00456 XalanDOMString& 00457 get() const 00458 { 00459 assert(m_string != 0); 00460 00461 return *m_string; 00462 } 00463 00464 XPathExecutionContext& 00465 getExecutionContext() const 00466 { 00467 return *m_executionContext; 00468 } 00469 00470 private: 00471 00472 // Not implemented... 00473 GetAndReleaseCachedString& 00474 operator=(const GetAndReleaseCachedString&); 00475 00476 00477 // Data members... 00478 XPathExecutionContext* m_executionContext; 00479 00480 XalanDOMString* m_string; 00481 }; 00482 00488 virtual MutableNodeRefList* 00489 createMutableNodeRefList(MemoryManagerType& theManager) const = 0; 00490 00501 virtual void 00502 getNodeSetByKey( 00503 XalanDocument* doc, 00504 const XalanQName& qname, 00505 const XalanDOMString& ref, 00506 MutableNodeRefList& nodelist) = 0; 00507 00520 virtual void 00521 getNodeSetByKey( 00522 XalanDocument* doc, 00523 const XalanDOMString& name, 00524 const XalanDOMString& ref, 00525 const LocatorType* locator, 00526 MutableNodeRefList& nodelist) = 0; 00527 00536 virtual const XObjectPtr 00537 getVariable( 00538 const XalanQName& name, 00539 const LocatorType* locator = 0) = 0; 00540 00546 virtual const PrefixResolver* 00547 getPrefixResolver() const = 0; 00548 00554 virtual void 00555 setPrefixResolver(const PrefixResolver* thePrefixResolver) = 0; 00556 00557 class PrefixResolverSetAndRestore 00558 { 00559 public: 00560 00561 PrefixResolverSetAndRestore( 00562 XPathExecutionContext& theExecutionContext, 00563 const PrefixResolver* theResolver) : 00564 m_executionContext(theExecutionContext), 00565 m_savedResolver(theExecutionContext.getPrefixResolver()) 00566 { 00567 m_executionContext.setPrefixResolver(theResolver); 00568 } 00569 00570 PrefixResolverSetAndRestore( 00571 XPathExecutionContext& theExecutionContext, 00572 const PrefixResolver* theOldResolver, 00573 const PrefixResolver* theNewResolver) : 00574 m_executionContext(theExecutionContext), 00575 m_savedResolver(theOldResolver) 00576 { 00577 m_executionContext.setPrefixResolver(theNewResolver); 00578 } 00579 00580 ~PrefixResolverSetAndRestore() 00581 { 00582 m_executionContext.setPrefixResolver(m_savedResolver); 00583 } 00584 00585 private: 00586 00587 XPathExecutionContext& m_executionContext; 00588 const PrefixResolver* const m_savedResolver; 00589 }; 00590 00597 virtual const XalanDOMString* 00598 getNamespaceForPrefix(const XalanDOMString& prefix) const = 0; 00599 00607 virtual const XalanDOMString& 00608 findURIFromDoc(const XalanDocument* owner) const = 0; 00609 00620 virtual const XalanDOMString& 00621 getUnparsedEntityURI( 00622 const XalanDOMString& theName, 00623 const XalanDocument& theDocument) const = 0; 00624 00635 virtual bool 00636 shouldStripSourceNode(const XalanText& node) = 0; 00637 00644 virtual XalanDocument* 00645 getSourceDocument(const XalanDOMString& theURI) const = 0; 00646 00653 virtual void 00654 setSourceDocument( 00655 const XalanDOMString& theURI, 00656 XalanDocument* theDocument) = 0; 00657 00667 virtual void formatNumber( 00668 double number, 00669 const XalanDOMString& pattern, 00670 XalanDOMString& theResult, 00671 const XalanNode* context = 0, 00672 const LocatorType* locator = 0) = 0; 00673 00685 virtual void formatNumber( 00686 double number, 00687 const XalanDOMString& pattern, 00688 const XalanDOMString& dfsName, 00689 XalanDOMString& theResult, 00690 const XalanNode* context = 0, 00691 const LocatorType* locator = 0) = 0; 00692 00693 // These interfaces are inherited from ExecutionContext... 00694 00695 virtual void 00696 error( 00697 const XalanDOMString& msg, 00698 const XalanNode* sourceNode = 0, 00699 const LocatorType* locator = 0) const = 0; 00700 00701 virtual void 00702 warn( 00703 const XalanDOMString& msg, 00704 const XalanNode* sourceNode = 0, 00705 const LocatorType* locator = 0) const = 0; 00706 00707 virtual void 00708 message( 00709 const XalanDOMString& msg, 00710 const XalanNode* sourceNode = 0, 00711 const LocatorType* locator = 0) const = 0; 00712 00713 protected: 00714 00715 XObjectFactory* m_xobjectFactory; 00716 }; 00717 00718 00719 00720 XALAN_CPP_NAMESPACE_END 00721 00722 00723 00724 #endif // XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.9 |
|