00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680) 00019 #define XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/XPath/XPathDefinitions.hpp> 00025 00026 00027 00028 #include <cassert> 00029 00030 00031 00032 #include <xalanc/Include/XalanVector.hpp> 00033 00034 00035 00036 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00037 00038 00039 00040 // Base class header file... 00041 #include <xalanc/PlatformSupport/ExecutionContext.hpp> 00042 00043 00044 00045 #include <xalanc/XPath/MutableNodeRefList.hpp> 00046 00047 00048 00049 XALAN_DECLARE_XERCES_CLASS(ErrorHandler) 00050 00051 00052 00053 XALAN_CPP_NAMESPACE_BEGIN 00054 00055 00056 00057 class XalanDecimalFormatSymbols; 00058 class PrefixResolver; 00059 class XalanQName; 00060 class XObject; 00061 class XObjectPtr; 00062 class XObjectFactory; 00063 class XalanDocument; 00064 class XalanElement; 00065 class XalanNode; 00066 class XalanText; 00067 00068 00069 00070 XALAN_USING_XERCES(ErrorHandler) 00071 00072 00073 00074 // 00075 // An abstract class which provides support for executing XPath functions 00076 // and extension functions. 00077 // 00078 00079 class XALAN_XPATH_EXPORT XPathExecutionContext : public ExecutionContext 00080 { 00081 public: 00082 00083 typedef XalanVector<XObjectPtr> XObjectArgVectorType; 00084 00085 typedef NodeRefListBase::size_type size_type; 00086 00087 explicit 00088 XPathExecutionContext( 00089 MemoryManager& theMemoryManager, 00090 XObjectFactory* theXObjectFactory = 0); 00091 00092 virtual 00093 ~XPathExecutionContext(); 00094 00095 /** 00096 * Reset the instance. This must be called before another 00097 * execution is attempted. 00098 */ 00099 virtual void 00100 reset() = 0; 00101 00102 /** 00103 * Retrieve the node currently being executed. 00104 * 00105 * @return current node 00106 */ 00107 virtual XalanNode* 00108 getCurrentNode() const = 0; 00109 00110 /** 00111 * Change the node currently being executed. 00112 * 00113 * @param theCurrentNode new current node 00114 */ 00115 virtual void 00116 pushCurrentNode(XalanNode* theCurrentNode) = 0; 00117 00118 /** 00119 * Reset the node currently being executed. 00120 */ 00121 virtual void 00122 popCurrentNode() = 0; 00123 00124 class CurrentNodePushAndPop 00125 { 00126 public: 00127 00128 CurrentNodePushAndPop( 00129 XPathExecutionContext& theExecutionContext, 00130 XalanNode* theNewNode) : 00131 m_executionContext(theExecutionContext) 00132 { 00133 theExecutionContext.pushCurrentNode(theNewNode); 00134 } 00135 00136 ~CurrentNodePushAndPop() 00137 { 00138 m_executionContext.popCurrentNode(); 00139 } 00140 00141 private: 00142 00143 XPathExecutionContext& m_executionContext; 00144 }; 00145 00146 /** 00147 * Retrieve the factory object for creating XObjects. 00148 * 00149 * @return factory object instance 00150 */ 00151 XObjectFactory& 00152 getXObjectFactory() const 00153 { 00154 assert(m_xobjectFactory != 0); 00155 00156 return *m_xobjectFactory; 00157 } 00158 00159 /** 00160 * Determine if a node is after another node, in document order. 00161 * 00162 * @param node1 The first node 00163 * @param node2 The second node 00164 * @return true if node1 one is after node2, or false if it is not. 00165 */ 00166 virtual bool 00167 isNodeAfter( 00168 const XalanNode& node1, 00169 const XalanNode& node2) const = 0; 00170 00171 /** 00172 * Push the node list for current context. 00173 * 00174 * @param theList new node list 00175 */ 00176 virtual void 00177 pushContextNodeList(const NodeRefListBase& theList) = 0; 00178 00179 /** 00180 * Pop the node list for current context. 00181 */ 00182 virtual void 00183 popContextNodeList() = 0; 00184 00185 class ContextNodeListPushAndPop 00186 { 00187 public: 00188 00189 ContextNodeListPushAndPop( 00190 XPathExecutionContext& theExecutionContext, 00191 const NodeRefListBase& theNodeList) : 00192 m_executionContext(theExecutionContext) 00193 { 00194 m_executionContext.pushContextNodeList(theNodeList); 00195 } 00196 00197 ~ContextNodeListPushAndPop() 00198 { 00199 m_executionContext.popContextNodeList(); 00200 } 00201 00202 private: 00203 00204 XPathExecutionContext& m_executionContext; 00205 }; 00206 00207 /** 00208 * Get the node list for current context. 00209 * 00210 * @return node list 00211 */ 00212 virtual const NodeRefListBase& 00213 getContextNodeList() const = 0; 00214 00215 /* 00216 * Get the count of nodes in the current context node list. 00217 * 00218 * @return length of list 00219 */ 00220 virtual size_type 00221 getContextNodeListLength() const = 0; 00222 00223 /* 00224 * Get the position of the node in the current context node list. 00225 * Note that this is 1-based indexing (XPath/XSLT-style), not 0-based. 00226 * Thus, 0 will be returned if the node was not found. 00227 * 00228 * @return position in list 00229 */ 00230 virtual size_type 00231 getContextNodeListPosition(const XalanNode& contextNode) const = 0; 00232 00233 /** 00234 * Determine if an external element is available. 00235 * 00236 * @param theQName The QName of the element 00237 * 00238 * @return whether the given element is available or not 00239 */ 00240 00241 virtual bool 00242 elementAvailable(const XalanQName& theQName) const = 0; 00243 00244 /** 00245 * Determine if an external element is available by resolving 00246 * a string to a QName. 00247 * 00248 * @param theName The name of the element 00249 * @param locator A Locator instance for error reporting 00250 * 00251 * @return whether the given element is available or not 00252 */ 00253 virtual bool 00254 elementAvailable( 00255 const XalanDOMString& theName, 00256 const Locator* locator) const = 0; 00257 00258 /** 00259 * Determine if a function is available. 00260 * 00261 * @param theQName The QName of the function 00262 * 00263 * @return whether the function is available or not 00264 */ 00265 virtual bool 00266 functionAvailable(const XalanQName& theQName) const = 0; 00267 00268 /** 00269 * Determine if a function is available. 00270 * 00271 * @param theName The name of the function 00272 * @param locator A Locator instance for error reporting 00273 * 00274 * @return whether the function is available or not 00275 */ 00276 virtual bool 00277 functionAvailable( 00278 const XalanDOMString& theName, 00279 const Locator* locator) const = 0; 00280 00281 /** 00282 * Handle an extension function. 00283 * 00284 * @param theNamespace namespace of function 00285 * @param functionName extension function name 00286 * @param context The context node 00287 * @param argVec vector of arguments to function 00288 * @param locator A Locator instance for error reporting 00289 * @return pointer to XObject result 00290 */ 00291 virtual const XObjectPtr 00292 extFunction( 00293 const XalanDOMString& theNamespace, 00294 const XalanDOMString& functionName, 00295 XalanNode* context, 00296 const XObjectArgVectorType& argVec, 00297 const Locator* locator) = 0; 00298 00299 /** 00300 * Provides support for XML parsing service. 00301 * 00302 * @param theManager The MemoryManager instance to use. 00303 * @param urlString location of the XML 00304 * @param base base location for URI 00305 * @param theErrorHandler An optional ErrorHandler instance for error reporting. 00306 * @return parsed document 00307 */ 00308 virtual XalanDocument* 00309 parseXML( 00310 MemoryManager& theManager, 00311 const XalanDOMString& urlString, 00312 const XalanDOMString& base, 00313 ErrorHandler* theErrorHandler = 0) const = 0; 00314 00315 /** 00316 * Borrow a cached MutableNodeRefList instance. 00317 * 00318 * @return A pointer to the instance. 00319 */ 00320 virtual MutableNodeRefList* 00321 borrowMutableNodeRefList() = 0; 00322 00323 /** 00324 * Return a previously borrowed MutableNodeRefList instance. 00325 * 00326 * @param theList A pointer the to previously borrowed instance. 00327 * @return true if the list was borrowed (at therefore, destroyed), false if not. 00328 */ 00329 virtual bool 00330 returnMutableNodeRefList(MutableNodeRefList* theList) = 0; 00331 00332 class GetCachedNodeList 00333 { 00334 public: 00335 00336 GetCachedNodeList(XPathExecutionContext& executionContext) : 00337 m_xpathExecutionContext(&executionContext), 00338 m_mutableNodeRefList(executionContext.borrowMutableNodeRefList()) 00339 { 00340 assert(m_mutableNodeRefList != 0); 00341 } 00342 00343 // N.B. Non-const copy constructor semantics (like std::auto_ptr) 00344 GetCachedNodeList(const GetCachedNodeList& theSource) : 00345 m_xpathExecutionContext(theSource.m_xpathExecutionContext), 00346 m_mutableNodeRefList(theSource.m_mutableNodeRefList) 00347 { 00348 assert(m_mutableNodeRefList != 0); 00349 00350 ((BorrowReturnMutableNodeRefList&)theSource).m_mutableNodeRefList = 0; 00351 } 00352 00353 ~GetCachedNodeList() 00354 { 00355 release(); 00356 } 00357 00358 MutableNodeRefList& 00359 operator*() const 00360 { 00361 assert(m_mutableNodeRefList != 0); 00362 00363 return *m_mutableNodeRefList; 00364 } 00365 00366 MutableNodeRefList* 00367 get() const 00368 { 00369 return m_mutableNodeRefList; 00370 } 00371 00372 MutableNodeRefList* 00373 operator->() const 00374 { 00375 return get(); 00376 } 00377 00378 void 00379 release() 00380 { 00381 assert(m_xpathExecutionContext != 0); 00382 00383 if (m_mutableNodeRefList != 0) 00384 { 00385 m_xpathExecutionContext->returnMutableNodeRefList(m_mutableNodeRefList); 00386 00387 m_mutableNodeRefList = 0; 00388 } 00389 } 00390 00391 GetCachedNodeList 00392 clone() const 00393 { 00394 assert(m_xpathExecutionContext != 0); 00395 00396 GetCachedNodeList theResult(*m_xpathExecutionContext); 00397 00398 *theResult = *m_mutableNodeRefList; 00399 00400 return theResult; 00401 } 00402 00403 // N.B. Non-const assignment operator semantics. 00404 GetCachedNodeList& 00405 operator=(GetCachedNodeList& theRHS) 00406 { 00407 release(); 00408 00409 m_xpathExecutionContext = theRHS.m_xpathExecutionContext; 00410 00411 m_mutableNodeRefList = theRHS.m_mutableNodeRefList; 00412 00413 theRHS.m_mutableNodeRefList = 0; 00414 00415 return *this; 00416 } 00417 00418 private: 00419 00420 XPathExecutionContext* m_xpathExecutionContext; 00421 00422 MutableNodeRefList* m_mutableNodeRefList; 00423 }; 00424 00425 typedef GetCachedNodeList BorrowReturnMutableNodeRefList; 00426 00427 /** 00428 * Get a cached string for temporary use. 00429 * 00430 * @return A reference to the string 00431 */ 00432 virtual XalanDOMString& 00433 getCachedString() = 0; 00434 00435 /** 00436 * Return a cached string. 00437 * 00438 * @param theString The string to release. 00439 * 00440 * @return true if the string was released successfully. 00441 */ 00442 virtual bool 00443 releaseCachedString(XalanDOMString& theString) = 0; 00444 00445 class GetCachedString 00446 { 00447 public: 00448 00449 GetCachedString(XPathExecutionContext& theExecutionContext) : 00450 m_executionContext(&theExecutionContext), 00451 m_string(&theExecutionContext.getCachedString()) 00452 { 00453 } 00454 00455 // Note non-const copy semantics... 00456 GetCachedString(GetCachedString& theSource) : 00457 m_executionContext(theSource.m_executionContext), 00458 m_string(theSource.m_string) 00459 { 00460 theSource.m_string = 0; 00461 } 00462 00463 ~GetCachedString() 00464 { 00465 if (m_string != 0) 00466 { 00467 m_executionContext->releaseCachedString(*m_string); 00468 } 00469 } 00470 00471 XalanDOMString& 00472 get() const 00473 { 00474 assert(m_string != 0); 00475 00476 return *m_string; 00477 } 00478 00479 XPathExecutionContext& 00480 getExecutionContext() const 00481 { 00482 return *m_executionContext; 00483 } 00484 00485 private: 00486 00487 // Not implemented... 00488 GetCachedString(); 00489 00490 GetCachedString(const GetCachedString&); 00491 00492 GetCachedString& 00493 operator=(const GetCachedString&); 00494 00495 00496 // Data members... 00497 XPathExecutionContext* m_executionContext; 00498 00499 XalanDOMString* m_string; 00500 }; 00501 00502 typedef GetCachedString GetAndReleaseCachedString; 00503 00504 /** 00505 * Create a MutableNodeRefList with the appropriate context. 00506 * 00507 * @return pointer to node list created 00508 */ 00509 virtual MutableNodeRefList* 00510 createMutableNodeRefList(MemoryManager& theManager) const = 0; 00511 00512 /** 00513 * Given a valid element key, return the corresponding node list. 00514 * 00515 * @param context context node 00516 * @param name qname of the key, which must match the 'name' 00517 * attribute on xsl:key 00518 * @param ref value that must match the value found by the 00519 * 'match' attribute on xsl:key 00520 * @param locator The Locator to use for error reporting. Can be 0. 00521 * @param nodelist A node list to contain the nodes found 00522 */ 00523 virtual void 00524 getNodeSetByKey( 00525 XalanNode* context, 00526 const XalanQName& qname, 00527 const XalanDOMString& ref, 00528 const Locator* locator, 00529 MutableNodeRefList& nodelist) = 0; 00530 00531 /** 00532 * Given a valid element key, return the corresponding node list. 00533 * 00534 * @param context context node 00535 * @param name name of the key, which must match the 'name' 00536 * attribute on xsl:key. Will be resolved to a 00537 * qname using the provided resolver. 00538 * @param ref value that must match the value found by the 00539 * 'match' attribute on xsl:key 00540 * @param locator The Locator to use for error reporting. Can be 0. 00541 * @param nodelist A node list to contain the nodes found 00542 */ 00543 virtual void 00544 getNodeSetByKey( 00545 XalanNode* context, 00546 const XalanDOMString& name, 00547 const XalanDOMString& ref, 00548 const Locator* locator, 00549 MutableNodeRefList& nodelist) = 0; 00550 00551 /** 00552 * Given a name, locate a variable in the current context, and return 00553 * a pointer to the object. 00554 * 00555 * @param theName name of variable 00556 * @return An XObjectPtr instance. If the variable is not found, an exception 00557 * is thrown, or the routine returns an instance of XUnknown. 00558 */ 00559 virtual const XObjectPtr 00560 getVariable( 00561 const XalanQName& name, 00562 const Locator* locator = 0) = 0; 00563 00564 /** 00565 * Retrieve the resolver for namespaces. 00566 * 00567 * @return object for namespace resolution 00568 */ 00569 virtual const PrefixResolver* 00570 getPrefixResolver() const = 0; 00571 00572 /** 00573 * Change the resolver for namespaces. 00574 * 00575 * @param thePrefixResolver new object for namespace resolution 00576 */ 00577 virtual void 00578 setPrefixResolver(const PrefixResolver* thePrefixResolver) = 0; 00579 00580 class PrefixResolverSetAndRestore 00581 { 00582 public: 00583 00584 PrefixResolverSetAndRestore( 00585 XPathExecutionContext& theExecutionContext, 00586 const PrefixResolver* theResolver) : 00587 m_executionContext(theExecutionContext), 00588 m_savedResolver(theExecutionContext.getPrefixResolver()) 00589 { 00590 m_executionContext.setPrefixResolver(theResolver); 00591 } 00592 00593 PrefixResolverSetAndRestore( 00594 XPathExecutionContext& theExecutionContext, 00595 const PrefixResolver* theOldResolver, 00596 const PrefixResolver* theNewResolver) : 00597 m_executionContext(theExecutionContext), 00598 m_savedResolver(theOldResolver) 00599 { 00600 m_executionContext.setPrefixResolver(theNewResolver); 00601 } 00602 00603 ~PrefixResolverSetAndRestore() 00604 { 00605 m_executionContext.setPrefixResolver(m_savedResolver); 00606 } 00607 00608 private: 00609 00610 XPathExecutionContext& m_executionContext; 00611 const PrefixResolver* const m_savedResolver; 00612 }; 00613 00614 /** 00615 * Retrieve the URI corresponding to a namespace prefix 00616 * 00617 * @param prefix prefix for a namespace 00618 * @return URI corresponding to namespace 00619 */ 00620 virtual const XalanDOMString* 00621 getNamespaceForPrefix(const XalanDOMString& prefix) const = 0; 00622 00623 /** 00624 * Given a DOM Document, tell what URI was used to parse it. Needed for 00625 * relative resolution. 00626 * 00627 * @param owner source document 00628 * @return document URI 00629 */ 00630 virtual const XalanDOMString& 00631 findURIFromDoc(const XalanDocument* owner) const = 0; 00632 00633 /** 00634 * The getUnparsedEntityURI function returns the URI of the unparsed 00635 * entity with the specified name in the same document as the context 00636 * node (see [3.3 Unparsed Entities]). It returns the empty string if 00637 * there is no such entity. 00638 * 00639 * @param theName name of entity 00640 * @param theDocument document containing entity 00641 * @return URI for the entity 00642 */ 00643 virtual const XalanDOMString& 00644 getUnparsedEntityURI( 00645 const XalanDOMString& theName, 00646 const XalanDocument& theDocument) const = 0; 00647 00648 /** 00649 * Get the document associated with the given URI. 00650 * 00651 * @param theURI document URI 00652 * @return a pointer to the document instance, if any. 00653 */ 00654 virtual XalanDocument* 00655 getSourceDocument(const XalanDOMString& theURI) const = 0; 00656 00657 /** 00658 * Associate a document with a given URI. 00659 * 00660 * @param theURI document URI 00661 * @param theDocument source document 00662 */ 00663 virtual void 00664 setSourceDocument( 00665 const XalanDOMString& theURI, 00666 XalanDocument* theDocument) = 0; 00667 00668 /** 00669 * Formats a number according to the specified pattern. 00670 * 00671 * @param number the number to be formatted 00672 * @param pattern the format pattern 00673 * @param theResult the formatted number 00674 * @param context the source node 00675 * @param locator the locator 00676 */ 00677 virtual void formatNumber( 00678 double number, 00679 const XalanDOMString& pattern, 00680 XalanDOMString& theResult, 00681 const XalanNode* context = 0, 00682 const Locator* locator = 0) = 0; 00683 00684 /** 00685 * Formats a number according to the specified pattern. 00686 * 00687 * @param number the number to be formatted 00688 * @param pattern the format pattern 00689 * @param dfsName the name of decimal format to use 00690 * @param theResult the formatted number 00691 * @param context the source node 00692 * @param locator the locator 00693 * @return a pointer to the functor, 0 if none was found 00694 */ 00695 virtual void formatNumber( 00696 double number, 00697 const XalanDOMString& pattern, 00698 const XalanDOMString& dfsName, 00699 XalanDOMString& theResult, 00700 const XalanNode* context = 0, 00701 const Locator* locator = 0) = 0; 00702 00703 // These interfaces are inherited from ExecutionContext... 00704 00705 virtual void 00706 problem( 00707 eSource source, 00708 eClassification classification, 00709 const XalanDOMString& msg, 00710 const Locator* locator, 00711 const XalanNode* sourceNode) = 0; 00712 00713 virtual void 00714 problem( 00715 eSource source, 00716 eClassification classification, 00717 const XalanDOMString& msg, 00718 const XalanNode* sourceNode) = 0; 00719 00720 virtual bool 00721 shouldStripSourceNode(const XalanText& node) = 0; 00722 00723 protected: 00724 00725 XObjectFactory* m_xobjectFactory; 00726 }; 00727 00728 00729 00730 XALAN_CPP_NAMESPACE_END 00731 00732 00733 00734 #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.11 |
|