00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * 00005 * Copyright (c) 1999 The Apache Software Foundation. All rights 00006 * reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * 00020 * 3. The end-user documentation included with the redistribution, 00021 * if any, must include the following acknowledgment: 00022 * "This product includes software developed by the 00023 * Apache Software Foundation (http://www.apache.org/)." 00024 * Alternately, this acknowledgment may appear in the software itself, 00025 * if and wherever such third-party acknowledgments normally appear. 00026 * 00027 * 4. The names "Xalan" and "Apache Software Foundation" must 00028 * not be used to endorse or promote products derived from this 00029 * software without prior written permission. For written 00030 * permission, please contact apache@apache.org. 00031 * 00032 * 5. Products derived from this software may not be called "Apache", 00033 * nor may "Apache" appear in their name, without prior written 00034 * permission of the Apache Software Foundation. 00035 * 00036 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00037 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00038 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00039 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00040 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00041 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00042 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00043 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00044 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00045 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00046 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00047 * SUCH DAMAGE. 00048 * ==================================================================== 00049 * 00050 * This software consists of voluntary contributions made by many 00051 * individuals on behalf of the Apache Software Foundation and was 00052 * originally based on software copyright (c) 1999, International 00053 * Business Machines, Inc., http://www.ibm.com. For more 00054 * information on the Apache Software Foundation, please see 00055 * <http://www.apache.org/>. 00056 * 00057 * @author <a href="mailto:david_n_bertoni@lotus.com">David N. Bertoni</a> 00058 */ 00059 #if !defined(XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680) 00060 #define XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680 00061 00062 00063 00064 // Base include file. Must be first. 00065 #include <XPath/XPathDefinitions.hpp> 00066 00067 00068 00069 #include <cassert> 00070 #include <vector> 00071 00072 00073 00074 #include <XalanDOM/XalanDOMString.hpp> 00075 00076 00077 00078 // Base class header file... 00079 #include <PlatformSupport/ExecutionContext.hpp> 00080 00081 00082 00083 #include <XPath/MutableNodeRefList.hpp> 00084 #include <XPath/ResultTreeFragBase.hpp> 00085 00086 00087 00088 class XalanDecimalFormatSymbols; 00089 class PrefixResolver; 00090 class XalanQName; 00091 class XLocator; 00092 class XMLURL; 00093 class XObject; 00094 class XObjectPtr; 00095 class XObjectFactory; 00096 class XalanDocument; 00097 class XalanElement; 00098 class XalanNode; 00099 class XalanText; 00100 00101 00102 00103 // 00104 // An abstract class which provides support for executing XPath functions 00105 // and extension functions. 00106 // 00107 00108 class XALAN_XPATH_EXPORT XPathExecutionContext : public ExecutionContext 00109 { 00110 public: 00111 00112 #if defined(XALAN_NO_NAMESPACES) 00113 typedef vector<XObjectPtr> XObjectArgVectorType; 00114 #else 00115 typedef std::vector<XObjectPtr> XObjectArgVectorType; 00116 #endif 00117 00118 typedef NodeRefListBase::size_type size_type; 00119 00120 explicit 00121 XPathExecutionContext(XObjectFactory* theXObjectFactory = 0); 00122 00123 virtual 00124 ~XPathExecutionContext(); 00125 00130 virtual void 00131 reset() = 0; 00132 00138 virtual XalanNode* 00139 getCurrentNode() const = 0; 00140 00146 virtual void 00147 setCurrentNode(XalanNode* theCurrentNode) = 0; 00148 00149 class CurrentNodeSetAndRestore 00150 { 00151 public: 00152 00153 CurrentNodeSetAndRestore( 00154 XPathExecutionContext& theExecutionContext, 00155 XalanNode* theNode) : 00156 m_executionContext(theExecutionContext), 00157 m_savedNode(theExecutionContext.getCurrentNode()) 00158 { 00159 m_executionContext.setCurrentNode(theNode); 00160 } 00161 00162 ~CurrentNodeSetAndRestore() 00163 { 00164 m_executionContext.setCurrentNode(m_savedNode); 00165 } 00166 00167 private: 00168 00169 XPathExecutionContext& m_executionContext; 00170 XalanNode* const m_savedNode; 00171 }; 00172 00178 XObjectFactory& 00179 getXObjectFactory() const 00180 { 00181 assert(m_xobjectFactory != 0); 00182 00183 return *m_xobjectFactory; 00184 } 00185 00193 virtual XObjectPtr 00194 createNodeSet(XalanNode& theNode) = 0; 00195 00203 virtual bool 00204 isNodeAfter( 00205 const XalanNode& node1, 00206 const XalanNode& node2) const = 0; 00207 00213 virtual const NodeRefListBase& 00214 getContextNodeList() const = 0; 00215 00221 virtual void 00222 setContextNodeList(const NodeRefListBase& theList) = 0; 00223 00224 class ContextNodeListSetAndRestore 00225 { 00226 public: 00227 00228 ContextNodeListSetAndRestore( 00229 XPathExecutionContext& theExecutionContext, 00230 const NodeRefListBase& theNodeList) : 00231 m_executionContext(theExecutionContext), 00232 m_savedNodeList(theExecutionContext.getContextNodeList()) 00233 { 00234 m_executionContext.setContextNodeList(theNodeList); 00235 } 00236 00237 ~ContextNodeListSetAndRestore() 00238 { 00239 m_executionContext.setContextNodeList(m_savedNodeList); 00240 } 00241 00242 private: 00243 00244 XPathExecutionContext& m_executionContext; 00245 const NodeRefListBase& m_savedNodeList; 00246 }; 00247 00248 /* 00249 * Get the count of nodes in the current context node list. 00250 * 00251 * @return length of list 00252 */ 00253 virtual size_type 00254 getContextNodeListLength() const = 0; 00255 00256 /* 00257 * Get the position of the node in the current context node list. 00258 * Note that this is 1-based indexing (XPath/XSLT-style), not 0-based. 00259 * Thus, 0 will be returned if the node was not found. 00260 * 00261 * @return position in list 00262 */ 00263 virtual size_type 00264 getContextNodeListPosition(const XalanNode& contextNode) const = 0; 00265 00273 virtual bool 00274 elementAvailable( 00275 const XalanDOMString& theNamespace, 00276 const XalanDOMString& elementName) const = 0; 00277 00287 virtual bool 00288 functionAvailable( 00289 const XalanDOMString& theNamespace, 00290 const XalanDOMString& functionName) const = 0; 00291 00302 virtual const XObjectPtr 00303 extFunction( 00304 const XalanDOMString& theNamespace, 00305 const XalanDOMString& functionName, 00306 XalanNode* context, 00307 const XObjectArgVectorType& argVec, 00308 const Locator* locator) = 0; 00309 00317 virtual XalanDocument* 00318 parseXML( 00319 const XalanDOMString& urlString, 00320 const XalanDOMString& base) const = 0; 00321 00327 virtual MutableNodeRefList* 00328 borrowMutableNodeRefList() = 0; 00329 00336 virtual bool 00337 returnMutableNodeRefList(MutableNodeRefList* theList) = 0; 00338 00339 class BorrowReturnMutableNodeRefList 00340 { 00341 public: 00342 00343 BorrowReturnMutableNodeRefList(XPathExecutionContext& executionContext) : 00344 m_xpathExecutionContext(&executionContext), 00345 m_mutableNodeRefList(executionContext.borrowMutableNodeRefList()) 00346 { 00347 assert(m_mutableNodeRefList != 0); 00348 } 00349 00350 // N.B. Non-const copy constructor semantics (like std::auto_ptr) 00351 BorrowReturnMutableNodeRefList(const BorrowReturnMutableNodeRefList& theSource) : 00352 m_xpathExecutionContext(theSource.m_xpathExecutionContext), 00353 m_mutableNodeRefList(theSource.m_mutableNodeRefList) 00354 { 00355 assert(m_mutableNodeRefList != 0); 00356 00357 ((BorrowReturnMutableNodeRefList&)theSource).m_mutableNodeRefList = 0; 00358 } 00359 00360 ~BorrowReturnMutableNodeRefList() 00361 { 00362 release(); 00363 } 00364 00365 MutableNodeRefList& 00366 operator*() const 00367 { 00368 assert(m_mutableNodeRefList != 0); 00369 00370 return *m_mutableNodeRefList; 00371 } 00372 00373 MutableNodeRefList* 00374 get() const 00375 { 00376 return m_mutableNodeRefList; 00377 } 00378 00379 MutableNodeRefList* 00380 operator->() const 00381 { 00382 return get(); 00383 } 00384 00385 void 00386 release() 00387 { 00388 assert(m_xpathExecutionContext != 0); 00389 00390 if (m_mutableNodeRefList != 0) 00391 { 00392 m_xpathExecutionContext->returnMutableNodeRefList(m_mutableNodeRefList); 00393 00394 m_mutableNodeRefList = 0; 00395 } 00396 } 00397 00398 BorrowReturnMutableNodeRefList 00399 clone() const 00400 { 00401 assert(m_xpathExecutionContext != 0); 00402 00403 BorrowReturnMutableNodeRefList theResult(*m_xpathExecutionContext); 00404 00405 *theResult = *m_mutableNodeRefList; 00406 00407 return theResult; 00408 } 00409 00410 // N.B. Non-const assignment operator semantics. 00411 BorrowReturnMutableNodeRefList& 00412 operator=(BorrowReturnMutableNodeRefList& theRHS) 00413 { 00414 release(); 00415 00416 m_xpathExecutionContext = theRHS.m_xpathExecutionContext; 00417 00418 m_mutableNodeRefList = theRHS.m_mutableNodeRefList; 00419 00420 theRHS.m_mutableNodeRefList = 0; 00421 00422 return *this; 00423 } 00424 00425 private: 00426 00427 XPathExecutionContext* m_xpathExecutionContext; 00428 00429 MutableNodeRefList* m_mutableNodeRefList; 00430 }; 00431 00432 virtual XalanDOMString& 00433 getCachedString() = 0; 00434 00435 virtual bool 00436 releaseCachedString(XalanDOMString& theString) = 0; 00437 00438 class GetAndReleaseCachedString 00439 { 00440 public: 00441 00442 GetAndReleaseCachedString(XPathExecutionContext& theExecutionContext) : 00443 m_executionContext(&theExecutionContext), 00444 m_string(&theExecutionContext.getCachedString()) 00445 { 00446 } 00447 00448 // Note non-const copy semantics... 00449 GetAndReleaseCachedString(GetAndReleaseCachedString& theSource) : 00450 m_executionContext(theSource.m_executionContext), 00451 m_string(theSource.m_string) 00452 { 00453 theSource.m_string = 0; 00454 } 00455 00456 ~GetAndReleaseCachedString() 00457 { 00458 if (m_string != 0) 00459 { 00460 m_executionContext->releaseCachedString(*m_string); 00461 } 00462 } 00463 00464 XalanDOMString& 00465 get() const 00466 { 00467 assert(m_string != 0); 00468 00469 return *m_string; 00470 } 00471 00472 XPathExecutionContext& 00473 getExecutionContext() const 00474 { 00475 return *m_executionContext; 00476 } 00477 00478 private: 00479 00480 // Not implemented... 00481 GetAndReleaseCachedString& 00482 operator=(const GetAndReleaseCachedString&); 00483 00484 00485 // Data members... 00486 XPathExecutionContext* m_executionContext; 00487 00488 XalanDOMString* m_string; 00489 }; 00490 00496 virtual MutableNodeRefList* 00497 createMutableNodeRefList() const = 0; 00498 00510 virtual void 00511 getNodeSetByKey( 00512 XalanNode* doc, 00513 const XalanDOMString& name, 00514 const XalanDOMString& ref, 00515 const PrefixResolver& resolver, 00516 MutableNodeRefList& nodelist) = 0; 00517 00525 virtual const XObjectPtr 00526 getVariable( 00527 const XalanQName& name, 00528 const Locator* locator = 0) = 0; 00529 00535 virtual const PrefixResolver* 00536 getPrefixResolver() const = 0; 00537 00543 virtual void 00544 setPrefixResolver(const PrefixResolver* thePrefixResolver) = 0; 00545 00546 class PrefixResolverSetAndRestore 00547 { 00548 public: 00549 00550 PrefixResolverSetAndRestore( 00551 XPathExecutionContext& theExecutionContext, 00552 const PrefixResolver* theResolver) : 00553 m_executionContext(theExecutionContext), 00554 m_savedResolver(theExecutionContext.getPrefixResolver()) 00555 { 00556 m_executionContext.setPrefixResolver(theResolver); 00557 } 00558 00559 PrefixResolverSetAndRestore( 00560 XPathExecutionContext& theExecutionContext, 00561 const PrefixResolver* theOldResolver, 00562 const PrefixResolver* theNewResolver) : 00563 m_executionContext(theExecutionContext), 00564 m_savedResolver(theOldResolver) 00565 { 00566 m_executionContext.setPrefixResolver(theNewResolver); 00567 } 00568 00569 ~PrefixResolverSetAndRestore() 00570 { 00571 m_executionContext.setPrefixResolver(m_savedResolver); 00572 } 00573 00574 private: 00575 00576 XPathExecutionContext& m_executionContext; 00577 const PrefixResolver* const m_savedResolver; 00578 }; 00579 00586 virtual const XalanDOMString* 00587 getNamespaceForPrefix(const XalanDOMString& prefix) const = 0; 00588 00596 virtual XalanDOMString 00597 findURIFromDoc(const XalanDocument* owner) const = 0; 00598 00609 virtual const XalanDOMString& 00610 getUnparsedEntityURI( 00611 const XalanDOMString& theName, 00612 const XalanDocument& theDocument) const = 0; 00613 00624 virtual bool 00625 shouldStripSourceNode(const XalanNode& node) = 0; 00626 00634 virtual bool 00635 getThrowFoundIndex() const = 0; 00636 00644 virtual void 00645 setThrowFoundIndex(bool fThrow) = 0; 00646 00647 virtual XalanDocument* 00648 getSourceDocument(const XalanDOMString& theURI) const = 0; 00649 00656 virtual void 00657 setSourceDocument( 00658 const XalanDOMString& theURI, 00659 XalanDocument* theDocument) = 0; 00660 00661 00669 virtual const XalanDecimalFormatSymbols* 00670 getDecimalFormatSymbols(const XalanQName& qname) = 0; 00671 00672 // These interfaces are inherited from ExecutionContext... 00673 00674 virtual void 00675 error( 00676 const XalanDOMString& msg, 00677 const XalanNode* sourceNode = 0, 00678 const XalanNode* styleNode = 0) const = 0; 00679 00680 virtual void 00681 error( 00682 const XalanDOMString& msg, 00683 const XalanNode* sourceNode, 00684 const Locator* locator) const = 0; 00685 00686 virtual void 00687 error( 00688 const char* msg, 00689 const XalanNode* sourceNode = 0, 00690 const XalanNode* styleNode = 0) const = 0; 00691 00692 virtual void 00693 error( 00694 const char* msg, 00695 const XalanNode* sourceNode, 00696 const Locator* locator) const = 0; 00697 00698 virtual void 00699 warn( 00700 const XalanDOMString& msg, 00701 const XalanNode* sourceNode = 0, 00702 const XalanNode* styleNode = 0) const = 0; 00703 00704 virtual void 00705 warn( 00706 const XalanDOMString& msg, 00707 const XalanNode* sourceNode, 00708 const Locator* locator) const = 0; 00709 00710 virtual void 00711 warn( 00712 const char* msg, 00713 const XalanNode* sourceNode = 0, 00714 const XalanNode* styleNode = 0) const = 0; 00715 00716 virtual void 00717 warn( 00718 const char* msg, 00719 const XalanNode* sourceNode, 00720 const Locator* locator) const = 0; 00721 00722 virtual void 00723 message( 00724 const XalanDOMString& msg, 00725 const XalanNode* sourceNode = 0, 00726 const XalanNode* styleNode = 0) const = 0; 00727 00728 virtual void 00729 message( 00730 const XalanDOMString& msg, 00731 const XalanNode* sourceNode, 00732 const Locator* locator) const = 0; 00733 00734 virtual void 00735 message( 00736 const char* msg, 00737 const XalanNode* sourceNode = 0, 00738 const XalanNode* styleNode = 0) const = 0; 00739 00740 virtual void 00741 message( 00742 const char* msg, 00743 const XalanNode* sourceNode, 00744 const Locator* locator) const = 0; 00745 00746 protected: 00747 00748 XObjectFactory* m_xobjectFactory; 00749 }; 00750 00751 00752 00753 #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.4 |
|