Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.6

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

XPathExecutionContext.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  *
00005  * Copyright (c) 1999-2002 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 <xalanc/XPath/XPathDefinitions.hpp>
00066 
00067 
00068 
00069 #include <cassert>
00070 #include <vector>
00071 
00072 
00073 
00074 #include <xalanc/XalanDOM/XalanDOMString.hpp>
00075 
00076 
00077 
00078 // Base class header file...
00079 #include <xalanc/PlatformSupport/ExecutionContext.hpp>
00080 
00081 
00082 
00083 #include <xalanc/XPath/MutableNodeRefList.hpp>
00084 #include <xalanc/XPath/ResultTreeFragBase.hpp>
00085 
00086 
00087 
00088 XALAN_CPP_NAMESPACE_BEGIN
00089 
00090 
00091 
00092 class XalanDecimalFormatSymbols;
00093 class PrefixResolver;
00094 class XalanQName;
00095 class XObject;
00096 class XObjectPtr;
00097 class XObjectFactory;
00098 class XalanDocument;
00099 class XalanElement;
00100 class XalanNode;
00101 class XalanText;
00102 
00103 
00104 
00105 //
00106 // An abstract class which provides support for executing XPath functions
00107 // and extension functions.
00108 //
00109 
00110 class XALAN_XPATH_EXPORT XPathExecutionContext : public ExecutionContext
00111 {
00112 public:
00113 
00114 #if defined(XALAN_NO_STD_NAMESPACE)
00115     typedef vector<XObjectPtr>          XObjectArgVectorType;
00116 #else
00117     typedef std::vector<XObjectPtr>     XObjectArgVectorType;
00118 #endif
00119 
00120     typedef NodeRefListBase::size_type  size_type;
00121 
00122     explicit
00123     XPathExecutionContext(XObjectFactory*   theXObjectFactory = 0);
00124 
00125     virtual
00126     ~XPathExecutionContext();
00127 
00132     virtual void
00133     reset() = 0;
00134 
00140     virtual XalanNode*
00141     getCurrentNode() const = 0;
00142 
00148     virtual void
00149     setCurrentNode(XalanNode*   theCurrentNode) = 0;
00150 
00151     class CurrentNodeSetAndRestore
00152     {
00153     public:
00154 
00155         CurrentNodeSetAndRestore(
00156                 XPathExecutionContext&  theExecutionContext,
00157                 XalanNode*              theNewNode) :
00158             m_executionContext(theExecutionContext),
00159             m_savedNode(theExecutionContext.getCurrentNode())
00160         {
00161             theExecutionContext.setCurrentNode(theNewNode);
00162         }
00163 
00164         CurrentNodeSetAndRestore(
00165                 XPathExecutionContext&  theExecutionContext,
00166                 XalanNode*              theOldNode,
00167                 XalanNode*              theNewNode) :
00168             m_executionContext(theExecutionContext),
00169             m_savedNode(theOldNode)
00170         {
00171             assert(theExecutionContext.getCurrentNode() == theOldNode);
00172 
00173             theExecutionContext.setCurrentNode(theNewNode);
00174         }
00175 
00176         ~CurrentNodeSetAndRestore()
00177         {
00178             m_executionContext.setCurrentNode(m_savedNode);
00179         }
00180 
00181     private:
00182 
00183         XPathExecutionContext&  m_executionContext;
00184         XalanNode* const        m_savedNode;
00185     };
00186 
00192     XObjectFactory&
00193     getXObjectFactory() const
00194     {
00195         assert(m_xobjectFactory != 0);
00196 
00197         return *m_xobjectFactory;
00198     }
00199 
00207     virtual bool
00208     isNodeAfter(
00209             const XalanNode&    node1,
00210             const XalanNode&    node2) const = 0;
00211 
00217     virtual const NodeRefListBase&
00218     getContextNodeList() const = 0;
00219 
00225     virtual void    
00226     setContextNodeList(const NodeRefListBase&   theList) = 0;
00227 
00228     class ContextNodeListSetAndRestore
00229     {
00230     public:
00231 
00232         ContextNodeListSetAndRestore(
00233                 XPathExecutionContext&      theExecutionContext,
00234                 const NodeRefListBase&      theNodeList) :
00235             m_executionContext(theExecutionContext),
00236             m_savedNodeList(theExecutionContext.getContextNodeList())
00237         {
00238             m_executionContext.setContextNodeList(theNodeList);
00239         }
00240 
00241         ~ContextNodeListSetAndRestore()
00242         {
00243             m_executionContext.setContextNodeList(m_savedNodeList);
00244         }
00245 
00246     private:
00247 
00248         XPathExecutionContext&  m_executionContext;
00249         const NodeRefListBase&  m_savedNodeList;
00250     };
00251 
00252     /*
00253      * Get the count of nodes in the current context node list.
00254      *
00255      * @return length of list
00256      */
00257     virtual size_type
00258     getContextNodeListLength() const = 0;
00259 
00260     /*
00261      * Get the position of the node in the current context node list.
00262      * Note that this is 1-based indexing (XPath/XSLT-style), not 0-based.
00263      * Thus, 0 will be returned if the node was not found.
00264      *
00265      * @return position in list
00266      */
00267     virtual size_type
00268     getContextNodeListPosition(const XalanNode&     contextNode) const = 0;
00269 
00277     virtual bool
00278     elementAvailable(const XalanQName&  theQName) const = 0;
00279 
00289     virtual bool
00290     elementAvailable(
00291             const XalanDOMString&   theName,
00292             const LocatorType*      locator) const = 0;
00293 
00301     virtual bool
00302     functionAvailable(const XalanQName&     theQName) const = 0;
00303 
00312     virtual bool
00313     functionAvailable(
00314             const XalanDOMString&   theName,
00315             const LocatorType*      locator) const = 0;
00316 
00327     virtual const XObjectPtr
00328     extFunction(
00329             const XalanDOMString&           theNamespace,
00330             const XalanDOMString&           functionName,
00331             XalanNode*                      context,
00332             const XObjectArgVectorType&     argVec,
00333             const LocatorType*              locator) = 0;
00334 
00342     virtual XalanDocument*
00343     parseXML(
00344             const XalanDOMString&   urlString,
00345             const XalanDOMString&   base) const = 0;
00346 
00352     virtual MutableNodeRefList*
00353     borrowMutableNodeRefList() = 0;
00354 
00361     virtual bool
00362     returnMutableNodeRefList(MutableNodeRefList*    theList) = 0;
00363 
00364     class BorrowReturnMutableNodeRefList
00365     {
00366     public:
00367 
00368         BorrowReturnMutableNodeRefList(XPathExecutionContext&   executionContext) :
00369             m_xpathExecutionContext(&executionContext),
00370             m_mutableNodeRefList(executionContext.borrowMutableNodeRefList())
00371         {
00372             assert(m_mutableNodeRefList != 0);
00373         }
00374 
00375         // N.B. Non-const copy constructor semantics (like std::auto_ptr)
00376         BorrowReturnMutableNodeRefList(const BorrowReturnMutableNodeRefList&    theSource) :
00377             m_xpathExecutionContext(theSource.m_xpathExecutionContext),
00378             m_mutableNodeRefList(theSource.m_mutableNodeRefList)
00379         {
00380             assert(m_mutableNodeRefList != 0);
00381 
00382             ((BorrowReturnMutableNodeRefList&)theSource).m_mutableNodeRefList = 0;
00383         }
00384 
00385         ~BorrowReturnMutableNodeRefList()
00386         {
00387             release();
00388         }
00389 
00390         MutableNodeRefList&
00391         operator*() const
00392         {
00393             assert(m_mutableNodeRefList != 0);
00394 
00395             return *m_mutableNodeRefList;
00396         }
00397 
00398         MutableNodeRefList*
00399         get() const
00400         {
00401             return m_mutableNodeRefList;
00402         }
00403 
00404         MutableNodeRefList*
00405         operator->() const
00406         {
00407             return get();
00408         }
00409 
00410         void
00411         release()
00412         {
00413             assert(m_xpathExecutionContext != 0);
00414 
00415             if (m_mutableNodeRefList != 0)
00416             {
00417                 m_xpathExecutionContext->returnMutableNodeRefList(m_mutableNodeRefList);
00418 
00419                 m_mutableNodeRefList = 0;
00420             }
00421         }
00422 
00423         BorrowReturnMutableNodeRefList
00424         clone() const
00425         {
00426             assert(m_xpathExecutionContext != 0);
00427 
00428             BorrowReturnMutableNodeRefList  theResult(*m_xpathExecutionContext);
00429 
00430             *theResult = *m_mutableNodeRefList;
00431 
00432             return theResult;
00433         }
00434 
00435         // N.B. Non-const assignment operator semantics.
00436         BorrowReturnMutableNodeRefList&
00437         operator=(BorrowReturnMutableNodeRefList&   theRHS)
00438         {
00439             release();
00440 
00441             m_xpathExecutionContext = theRHS.m_xpathExecutionContext;
00442 
00443             m_mutableNodeRefList = theRHS.m_mutableNodeRefList;
00444 
00445             theRHS.m_mutableNodeRefList = 0;
00446 
00447             return *this;
00448         }
00449 
00450     private:
00451 
00452         XPathExecutionContext*  m_xpathExecutionContext;
00453 
00454         MutableNodeRefList*     m_mutableNodeRefList;
00455     };
00456 
00462     virtual XalanDOMString&
00463     getCachedString() = 0;
00464 
00472     virtual bool
00473     releaseCachedString(XalanDOMString&     theString) = 0;
00474 
00475     class GetAndReleaseCachedString
00476     {
00477     public:
00478 
00479         GetAndReleaseCachedString(XPathExecutionContext&    theExecutionContext) :
00480             m_executionContext(&theExecutionContext),
00481             m_string(&theExecutionContext.getCachedString())
00482         {
00483         }
00484 
00485         // Note non-const copy semantics...
00486         GetAndReleaseCachedString(GetAndReleaseCachedString&    theSource) :
00487             m_executionContext(theSource.m_executionContext),
00488             m_string(theSource.m_string)
00489         {
00490             theSource.m_string = 0;
00491         }
00492 
00493         ~GetAndReleaseCachedString()
00494         {
00495             if (m_string != 0)
00496             {
00497                 m_executionContext->releaseCachedString(*m_string);
00498             }
00499         }
00500 
00501         XalanDOMString&
00502         get() const
00503         {
00504             assert(m_string != 0);
00505 
00506             return *m_string;
00507         }
00508 
00509         XPathExecutionContext&
00510         getExecutionContext() const
00511         {
00512             return *m_executionContext;
00513         }
00514 
00515     private:
00516 
00517         // Not implemented...
00518         GetAndReleaseCachedString&
00519         operator=(const GetAndReleaseCachedString&);
00520 
00521 
00522         // Data members...
00523         XPathExecutionContext*  m_executionContext;
00524 
00525         XalanDOMString*         m_string;
00526     };
00527 
00533     virtual MutableNodeRefList*
00534     createMutableNodeRefList() const = 0;
00535 
00546     virtual void
00547     getNodeSetByKey(
00548             XalanDocument*          doc,
00549             const XalanQName&       qname,
00550             const XalanDOMString&   ref,
00551             MutableNodeRefList&     nodelist) = 0;
00552 
00565     virtual void
00566     getNodeSetByKey(
00567             XalanDocument*          doc,
00568             const XalanDOMString&   name,
00569             const XalanDOMString&   ref,
00570             const LocatorType*      locator,
00571             MutableNodeRefList&     nodelist) = 0;
00572 
00580     virtual const XObjectPtr
00581     getVariable(
00582             const XalanQName&   name,
00583             const LocatorType*  locator = 0) = 0;
00584 
00590     virtual const PrefixResolver*
00591     getPrefixResolver() const = 0;
00592 
00598     virtual void
00599     setPrefixResolver(const PrefixResolver*     thePrefixResolver) = 0;
00600 
00601     class PrefixResolverSetAndRestore
00602     {
00603     public:
00604 
00605         PrefixResolverSetAndRestore(
00606                 XPathExecutionContext&  theExecutionContext,
00607                 const PrefixResolver*   theResolver) :
00608             m_executionContext(theExecutionContext),
00609             m_savedResolver(theExecutionContext.getPrefixResolver())
00610         {
00611             m_executionContext.setPrefixResolver(theResolver);
00612         }
00613 
00614         PrefixResolverSetAndRestore(
00615                 XPathExecutionContext&  theExecutionContext,
00616                 const PrefixResolver*   theOldResolver,
00617                 const PrefixResolver*   theNewResolver) :
00618             m_executionContext(theExecutionContext),
00619             m_savedResolver(theOldResolver)
00620         {
00621             m_executionContext.setPrefixResolver(theNewResolver);
00622         }
00623 
00624         ~PrefixResolverSetAndRestore()
00625         {
00626             m_executionContext.setPrefixResolver(m_savedResolver);
00627         }
00628 
00629     private:
00630 
00631         XPathExecutionContext&          m_executionContext;
00632         const PrefixResolver* const     m_savedResolver;
00633     };
00634 
00641     virtual const XalanDOMString*
00642     getNamespaceForPrefix(const XalanDOMString&     prefix) const = 0;
00643 
00651     virtual XalanDOMString
00652     findURIFromDoc(const XalanDocument*     owner) const = 0;
00653 
00664     virtual const XalanDOMString&
00665     getUnparsedEntityURI(
00666             const XalanDOMString&   theName,
00667             const XalanDocument&    theDocument) const = 0;
00668 
00679     virtual bool
00680     shouldStripSourceNode(const XalanNode&  node) = 0;
00681 
00689     virtual bool
00690     getThrowFoundIndex() const = 0;
00691 
00699     virtual void
00700     setThrowFoundIndex(bool     fThrow) = 0;
00701 
00702     virtual XalanDocument*
00703     getSourceDocument(const XalanDOMString&     theURI) const = 0;
00704 
00711     virtual void
00712     setSourceDocument(
00713             const XalanDOMString&   theURI,
00714             XalanDocument*          theDocument) = 0;
00715 
00716 
00724     virtual const XalanDecimalFormatSymbols*
00725     getDecimalFormatSymbols(const XalanQName&   qname) = 0;
00726 
00727     // These interfaces are inherited from ExecutionContext...
00728 
00729     virtual void
00730     error(
00731             const XalanDOMString&   msg,
00732             const XalanNode*        sourceNode = 0,
00733             const LocatorType*      locator = 0) const = 0;
00734 
00735     virtual void
00736     error(
00737             const char*         msg,
00738             const XalanNode*    sourceNode = 0,
00739             const LocatorType*  locator = 0) const = 0;
00740 
00741     virtual void
00742     warn(
00743             const XalanDOMString&   msg,
00744             const XalanNode*        sourceNode = 0,
00745             const LocatorType*      locator = 0) const = 0;
00746 
00747     virtual void
00748     warn(
00749             const char*         msg,
00750             const XalanNode*    sourceNode = 0,
00751             const LocatorType*  locator = 0) const = 0;
00752 
00753     virtual void
00754     message(
00755             const XalanDOMString&   msg,
00756             const XalanNode*        sourceNode = 0,
00757             const LocatorType*      locator = 0) const = 0;
00758 
00759     virtual void
00760     message(
00761             const char*         msg,
00762             const XalanNode*    sourceNode = 0,
00763             const LocatorType*  locator = 0) const = 0;
00764 
00765 protected:
00766 
00767     XObjectFactory*     m_xobjectFactory;
00768 };
00769 
00770 
00771 
00772 XALAN_CPP_NAMESPACE_END
00773 
00774 
00775 
00776 #endif  // XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680

Interpreting class diagrams

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

Xalan-C++ XSLT Processor Version 1.6
Copyright © 2000, 2001, 2002, 2003 The Apache Software Foundation. All Rights Reserved.