Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.7

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-2004 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 
00085 
00086 
00087 XALAN_CPP_NAMESPACE_BEGIN
00088 
00089 
00090 
00091 class XalanDecimalFormatSymbols;
00092 class PrefixResolver;
00093 class XalanQName;
00094 class XObject;
00095 class XObjectPtr;
00096 class XObjectFactory;
00097 class XalanDocument;
00098 class XalanElement;
00099 class XalanNode;
00100 class XalanText;
00101 
00102 
00103 
00104 //
00105 // An abstract class which provides support for executing XPath functions
00106 // and extension functions.
00107 //
00108 
00109 class XALAN_XPATH_EXPORT XPathExecutionContext : public ExecutionContext
00110 {
00111 public:
00112 
00113 #if defined(XALAN_NO_STD_NAMESPACE)
00114     typedef vector<XObjectPtr>          XObjectArgVectorType;
00115 #else
00116     typedef std::vector<XObjectPtr>     XObjectArgVectorType;
00117 #endif
00118 
00119     typedef NodeRefListBase::size_type  size_type;
00120 
00121     explicit
00122     XPathExecutionContext(XObjectFactory*   theXObjectFactory = 0);
00123 
00124     virtual
00125     ~XPathExecutionContext();
00126 
00131     virtual void
00132     reset() = 0;
00133 
00139     virtual XalanNode*
00140     getCurrentNode() const = 0;
00141 
00147     virtual void
00148     pushCurrentNode(XalanNode*  theCurrentNode) = 0;
00149 
00153     virtual void
00154     popCurrentNode() = 0;
00155 
00156     class CurrentNodePushAndPop
00157     {
00158     public:
00159 
00160         CurrentNodePushAndPop(
00161                 XPathExecutionContext&  theExecutionContext,
00162                 XalanNode*              theNewNode) :
00163             m_executionContext(theExecutionContext)
00164         {
00165             theExecutionContext.pushCurrentNode(theNewNode);
00166         }
00167 
00168         ~CurrentNodePushAndPop()
00169         {
00170             m_executionContext.popCurrentNode();
00171         }
00172 
00173     private:
00174 
00175         XPathExecutionContext&  m_executionContext;
00176     };
00177 
00183     XObjectFactory&
00184     getXObjectFactory() const
00185     {
00186         assert(m_xobjectFactory != 0);
00187 
00188         return *m_xobjectFactory;
00189     }
00190 
00198     virtual bool
00199     isNodeAfter(
00200             const XalanNode&    node1,
00201             const XalanNode&    node2) const = 0;
00202 
00208     virtual void
00209     pushContextNodeList(const NodeRefListBase&  theList) = 0;
00210 
00214     virtual void    
00215     popContextNodeList() = 0;
00216 
00217     class ContextNodeListPushAndPop
00218     {
00219     public:
00220 
00221         ContextNodeListPushAndPop(
00222                 XPathExecutionContext&      theExecutionContext,
00223                 const NodeRefListBase&      theNodeList) :
00224             m_executionContext(theExecutionContext)
00225         {
00226             m_executionContext.pushContextNodeList(theNodeList);
00227         }
00228 
00229         ~ContextNodeListPushAndPop()
00230         {
00231             m_executionContext.popContextNodeList();
00232         }
00233 
00234     private:
00235 
00236         XPathExecutionContext&  m_executionContext;
00237     };
00238 
00244     virtual const NodeRefListBase&
00245     getContextNodeList() const = 0;
00246 
00247     /*
00248      * Get the count of nodes in the current context node list.
00249      *
00250      * @return length of list
00251      */
00252     virtual size_type
00253     getContextNodeListLength() const = 0;
00254 
00255     /*
00256      * Get the position of the node in the current context node list.
00257      * Note that this is 1-based indexing (XPath/XSLT-style), not 0-based.
00258      * Thus, 0 will be returned if the node was not found.
00259      *
00260      * @return position in list
00261      */
00262     virtual size_type
00263     getContextNodeListPosition(const XalanNode&     contextNode) const = 0;
00264 
00272     virtual bool
00273     elementAvailable(const XalanQName&  theQName) const = 0;
00274 
00284     virtual bool
00285     elementAvailable(
00286             const XalanDOMString&   theName,
00287             const LocatorType*      locator) const = 0;
00288 
00296     virtual bool
00297     functionAvailable(const XalanQName&     theQName) const = 0;
00298 
00307     virtual bool
00308     functionAvailable(
00309             const XalanDOMString&   theName,
00310             const LocatorType*      locator) const = 0;
00311 
00322     virtual const XObjectPtr
00323     extFunction(
00324             const XalanDOMString&           theNamespace,
00325             const XalanDOMString&           functionName,
00326             XalanNode*                      context,
00327             const XObjectArgVectorType&     argVec,
00328             const LocatorType*              locator) = 0;
00329 
00337     virtual XalanDocument*
00338     parseXML(
00339             const XalanDOMString&   urlString,
00340             const XalanDOMString&   base) const = 0;
00341 
00347     virtual MutableNodeRefList*
00348     borrowMutableNodeRefList() = 0;
00349 
00356     virtual bool
00357     returnMutableNodeRefList(MutableNodeRefList*    theList) = 0;
00358 
00359     class BorrowReturnMutableNodeRefList
00360     {
00361     public:
00362 
00363         BorrowReturnMutableNodeRefList(XPathExecutionContext&   executionContext) :
00364             m_xpathExecutionContext(&executionContext),
00365             m_mutableNodeRefList(executionContext.borrowMutableNodeRefList())
00366         {
00367             assert(m_mutableNodeRefList != 0);
00368         }
00369 
00370         // N.B. Non-const copy constructor semantics (like std::auto_ptr)
00371         BorrowReturnMutableNodeRefList(const BorrowReturnMutableNodeRefList&    theSource) :
00372             m_xpathExecutionContext(theSource.m_xpathExecutionContext),
00373             m_mutableNodeRefList(theSource.m_mutableNodeRefList)
00374         {
00375             assert(m_mutableNodeRefList != 0);
00376 
00377             ((BorrowReturnMutableNodeRefList&)theSource).m_mutableNodeRefList = 0;
00378         }
00379 
00380         ~BorrowReturnMutableNodeRefList()
00381         {
00382             release();
00383         }
00384 
00385         MutableNodeRefList&
00386         operator*() const
00387         {
00388             assert(m_mutableNodeRefList != 0);
00389 
00390             return *m_mutableNodeRefList;
00391         }
00392 
00393         MutableNodeRefList*
00394         get() const
00395         {
00396             return m_mutableNodeRefList;
00397         }
00398 
00399         MutableNodeRefList*
00400         operator->() const
00401         {
00402             return get();
00403         }
00404 
00405         void
00406         release()
00407         {
00408             assert(m_xpathExecutionContext != 0);
00409 
00410             if (m_mutableNodeRefList != 0)
00411             {
00412                 m_xpathExecutionContext->returnMutableNodeRefList(m_mutableNodeRefList);
00413 
00414                 m_mutableNodeRefList = 0;
00415             }
00416         }
00417 
00418         BorrowReturnMutableNodeRefList
00419         clone() const
00420         {
00421             assert(m_xpathExecutionContext != 0);
00422 
00423             BorrowReturnMutableNodeRefList  theResult(*m_xpathExecutionContext);
00424 
00425             *theResult = *m_mutableNodeRefList;
00426 
00427             return theResult;
00428         }
00429 
00430         // N.B. Non-const assignment operator semantics.
00431         BorrowReturnMutableNodeRefList&
00432         operator=(BorrowReturnMutableNodeRefList&   theRHS)
00433         {
00434             release();
00435 
00436             m_xpathExecutionContext = theRHS.m_xpathExecutionContext;
00437 
00438             m_mutableNodeRefList = theRHS.m_mutableNodeRefList;
00439 
00440             theRHS.m_mutableNodeRefList = 0;
00441 
00442             return *this;
00443         }
00444 
00445     private:
00446 
00447         XPathExecutionContext*  m_xpathExecutionContext;
00448 
00449         MutableNodeRefList*     m_mutableNodeRefList;
00450     };
00451 
00457     virtual XalanDOMString&
00458     getCachedString() = 0;
00459 
00467     virtual bool
00468     releaseCachedString(XalanDOMString&     theString) = 0;
00469 
00470     class GetAndReleaseCachedString
00471     {
00472     public:
00473 
00474         GetAndReleaseCachedString(XPathExecutionContext&    theExecutionContext) :
00475             m_executionContext(&theExecutionContext),
00476             m_string(&theExecutionContext.getCachedString())
00477         {
00478         }
00479 
00480         // Note non-const copy semantics...
00481         GetAndReleaseCachedString(GetAndReleaseCachedString&    theSource) :
00482             m_executionContext(theSource.m_executionContext),
00483             m_string(theSource.m_string)
00484         {
00485             theSource.m_string = 0;
00486         }
00487 
00488         ~GetAndReleaseCachedString()
00489         {
00490             if (m_string != 0)
00491             {
00492                 m_executionContext->releaseCachedString(*m_string);
00493             }
00494         }
00495 
00496         XalanDOMString&
00497         get() const
00498         {
00499             assert(m_string != 0);
00500 
00501             return *m_string;
00502         }
00503 
00504         XPathExecutionContext&
00505         getExecutionContext() const
00506         {
00507             return *m_executionContext;
00508         }
00509 
00510     private:
00511 
00512         // Not implemented...
00513         GetAndReleaseCachedString&
00514         operator=(const GetAndReleaseCachedString&);
00515 
00516 
00517         // Data members...
00518         XPathExecutionContext*  m_executionContext;
00519 
00520         XalanDOMString*         m_string;
00521     };
00522 
00528     virtual MutableNodeRefList*
00529     createMutableNodeRefList() const = 0;
00530 
00541     virtual void
00542     getNodeSetByKey(
00543             XalanDocument*          doc,
00544             const XalanQName&       qname,
00545             const XalanDOMString&   ref,
00546             MutableNodeRefList&     nodelist) = 0;
00547 
00560     virtual void
00561     getNodeSetByKey(
00562             XalanDocument*          doc,
00563             const XalanDOMString&   name,
00564             const XalanDOMString&   ref,
00565             const LocatorType*      locator,
00566             MutableNodeRefList&     nodelist) = 0;
00567 
00575     virtual const XObjectPtr
00576     getVariable(
00577             const XalanQName&   name,
00578             const LocatorType*  locator = 0) = 0;
00579 
00585     virtual const PrefixResolver*
00586     getPrefixResolver() const = 0;
00587 
00593     virtual void
00594     setPrefixResolver(const PrefixResolver*     thePrefixResolver) = 0;
00595 
00596     class PrefixResolverSetAndRestore
00597     {
00598     public:
00599 
00600         PrefixResolverSetAndRestore(
00601                 XPathExecutionContext&  theExecutionContext,
00602                 const PrefixResolver*   theResolver) :
00603             m_executionContext(theExecutionContext),
00604             m_savedResolver(theExecutionContext.getPrefixResolver())
00605         {
00606             m_executionContext.setPrefixResolver(theResolver);
00607         }
00608 
00609         PrefixResolverSetAndRestore(
00610                 XPathExecutionContext&  theExecutionContext,
00611                 const PrefixResolver*   theOldResolver,
00612                 const PrefixResolver*   theNewResolver) :
00613             m_executionContext(theExecutionContext),
00614             m_savedResolver(theOldResolver)
00615         {
00616             m_executionContext.setPrefixResolver(theNewResolver);
00617         }
00618 
00619         ~PrefixResolverSetAndRestore()
00620         {
00621             m_executionContext.setPrefixResolver(m_savedResolver);
00622         }
00623 
00624     private:
00625 
00626         XPathExecutionContext&          m_executionContext;
00627         const PrefixResolver* const     m_savedResolver;
00628     };
00629 
00636     virtual const XalanDOMString*
00637     getNamespaceForPrefix(const XalanDOMString&     prefix) const = 0;
00638 
00646     virtual XalanDOMString
00647     findURIFromDoc(const XalanDocument*     owner) const = 0;
00648 
00659     virtual const XalanDOMString&
00660     getUnparsedEntityURI(
00661             const XalanDOMString&   theName,
00662             const XalanDocument&    theDocument) const = 0;
00663 
00674     virtual bool
00675     shouldStripSourceNode(const XalanNode&  node) = 0;
00676 
00683     virtual XalanDocument*
00684     getSourceDocument(const XalanDOMString&     theURI) const = 0;
00685 
00692     virtual void
00693     setSourceDocument(
00694             const XalanDOMString&   theURI,
00695             XalanDocument*          theDocument) = 0;
00696 
00697 
00705     virtual const XalanDecimalFormatSymbols*
00706     getDecimalFormatSymbols(const XalanQName&   qname) = 0;
00707 
00708     // These interfaces are inherited from ExecutionContext...
00709 
00710     virtual void
00711     error(
00712             const XalanDOMString&   msg,
00713             const XalanNode*        sourceNode = 0,
00714             const LocatorType*      locator = 0) const = 0;
00715 
00716     virtual void
00717     error(
00718             const char*         msg,
00719             const XalanNode*    sourceNode = 0,
00720             const LocatorType*  locator = 0) const = 0;
00721 
00722     virtual void
00723     warn(
00724             const XalanDOMString&   msg,
00725             const XalanNode*        sourceNode = 0,
00726             const LocatorType*      locator = 0) const = 0;
00727 
00728     virtual void
00729     warn(
00730             const char*         msg,
00731             const XalanNode*    sourceNode = 0,
00732             const LocatorType*  locator = 0) const = 0;
00733 
00734     virtual void
00735     message(
00736             const XalanDOMString&   msg,
00737             const XalanNode*        sourceNode = 0,
00738             const LocatorType*      locator = 0) const = 0;
00739 
00740     virtual void
00741     message(
00742             const char*         msg,
00743             const XalanNode*    sourceNode = 0,
00744             const LocatorType*  locator = 0) const = 0;
00745 
00746 protected:
00747 
00748     XObjectFactory*     m_xobjectFactory;
00749 };
00750 
00751 
00752 
00753 XALAN_CPP_NAMESPACE_END
00754 
00755 
00756 
00757 #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.7
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.