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 00483 typedef GetAndReleaseCachedString GetCachedString; 00484 00490 virtual MutableNodeRefList* 00491 createMutableNodeRefList(MemoryManagerType& theManager) const = 0; 00492 00503 virtual void 00504 getNodeSetByKey( 00505 XalanDocument* doc, 00506 const XalanQName& qname, 00507 const XalanDOMString& ref, 00508 MutableNodeRefList& nodelist) = 0; 00509 00522 virtual void 00523 getNodeSetByKey( 00524 XalanDocument* doc, 00525 const XalanDOMString& name, 00526 const XalanDOMString& ref, 00527 const LocatorType* locator, 00528 MutableNodeRefList& nodelist) = 0; 00529 00538 virtual const XObjectPtr 00539 getVariable( 00540 const XalanQName& name, 00541 const LocatorType* locator = 0) = 0; 00542 00548 virtual const PrefixResolver* 00549 getPrefixResolver() const = 0; 00550 00556 virtual void 00557 setPrefixResolver(const PrefixResolver* thePrefixResolver) = 0; 00558 00559 class PrefixResolverSetAndRestore 00560 { 00561 public: 00562 00563 PrefixResolverSetAndRestore( 00564 XPathExecutionContext& theExecutionContext, 00565 const PrefixResolver* theResolver) : 00566 m_executionContext(theExecutionContext), 00567 m_savedResolver(theExecutionContext.getPrefixResolver()) 00568 { 00569 m_executionContext.setPrefixResolver(theResolver); 00570 } 00571 00572 PrefixResolverSetAndRestore( 00573 XPathExecutionContext& theExecutionContext, 00574 const PrefixResolver* theOldResolver, 00575 const PrefixResolver* theNewResolver) : 00576 m_executionContext(theExecutionContext), 00577 m_savedResolver(theOldResolver) 00578 { 00579 m_executionContext.setPrefixResolver(theNewResolver); 00580 } 00581 00582 ~PrefixResolverSetAndRestore() 00583 { 00584 m_executionContext.setPrefixResolver(m_savedResolver); 00585 } 00586 00587 private: 00588 00589 XPathExecutionContext& m_executionContext; 00590 const PrefixResolver* const m_savedResolver; 00591 }; 00592 00599 virtual const XalanDOMString* 00600 getNamespaceForPrefix(const XalanDOMString& prefix) const = 0; 00601 00609 virtual const XalanDOMString& 00610 findURIFromDoc(const XalanDocument* owner) const = 0; 00611 00622 virtual const XalanDOMString& 00623 getUnparsedEntityURI( 00624 const XalanDOMString& theName, 00625 const XalanDocument& theDocument) const = 0; 00626 00637 virtual bool 00638 shouldStripSourceNode(const XalanText& node) = 0; 00639 00646 virtual XalanDocument* 00647 getSourceDocument(const XalanDOMString& theURI) const = 0; 00648 00655 virtual void 00656 setSourceDocument( 00657 const XalanDOMString& theURI, 00658 XalanDocument* theDocument) = 0; 00659 00669 virtual void formatNumber( 00670 double number, 00671 const XalanDOMString& pattern, 00672 XalanDOMString& theResult, 00673 const XalanNode* context = 0, 00674 const LocatorType* locator = 0) = 0; 00675 00687 virtual void formatNumber( 00688 double number, 00689 const XalanDOMString& pattern, 00690 const XalanDOMString& dfsName, 00691 XalanDOMString& theResult, 00692 const XalanNode* context = 0, 00693 const LocatorType* locator = 0) = 0; 00694 00695 // These interfaces are inherited from ExecutionContext... 00696 00697 virtual void 00698 error( 00699 const XalanDOMString& msg, 00700 const XalanNode* sourceNode = 0, 00701 const LocatorType* locator = 0) const = 0; 00702 00703 virtual void 00704 warn( 00705 const XalanDOMString& msg, 00706 const XalanNode* sourceNode = 0, 00707 const LocatorType* locator = 0) const = 0; 00708 00709 virtual void 00710 message( 00711 const XalanDOMString& msg, 00712 const XalanNode* sourceNode = 0, 00713 const LocatorType* locator = 0) const = 0; 00714 00715 protected: 00716 00717 XObjectFactory* m_xobjectFactory; 00718 }; 00719 00720 00721 00722 XALAN_CPP_NAMESPACE_END 00723 00724 00725 00726 #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.10 |
|