Xalan-C++ API Documentation

The Xalan C++ XSL Transformer Version 1.1

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 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 QName;
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     explicit
00119     XPathExecutionContext();
00120 
00121     virtual
00122     ~XPathExecutionContext();
00123 
00128     virtual void
00129     reset() = 0;
00130 
00136     virtual XalanNode*
00137     getCurrentNode() const = 0;
00138 
00144     virtual void
00145     setCurrentNode(XalanNode*   theCurrentNode) = 0;
00146 
00147     class CurrentNodeSetAndRestore
00148     {
00149     public:
00150 
00151         CurrentNodeSetAndRestore(
00152                 XPathExecutionContext&  theExecutionContext,
00153                 XalanNode*              theNode) :
00154             m_executionContext(theExecutionContext),
00155             m_savedNode(theExecutionContext.getCurrentNode())
00156         {
00157             m_executionContext.setCurrentNode(theNode);
00158         }
00159 
00160         ~CurrentNodeSetAndRestore()
00161         {
00162             m_executionContext.setCurrentNode(m_savedNode);
00163         }
00164 
00165     private:
00166 
00167         XPathExecutionContext&  m_executionContext;
00168         XalanNode* const        m_savedNode;
00169     };
00170 
00176     virtual XObjectFactory&
00177     getXObjectFactory() const = 0;
00178 
00186     virtual XObjectPtr
00187     createNodeSet(XalanNode&    theNode) = 0;
00188 
00196     virtual bool
00197     isNodeAfter(
00198             const XalanNode&    node1,
00199             const XalanNode&    node2) const = 0;
00200 
00206     virtual const NodeRefListBase&
00207     getContextNodeList() const = 0;
00208 
00214     virtual void    
00215     setContextNodeList(const NodeRefListBase&   theList) = 0;
00216 
00217     class ContextNodeListSetAndRestore
00218     {
00219     public:
00220 
00221         ContextNodeListSetAndRestore(
00222                 XPathExecutionContext&      theExecutionContext,
00223                 const NodeRefListBase&      theNodeList) :
00224             m_executionContext(theExecutionContext),
00225             m_savedNodeList(theExecutionContext.getContextNodeList())
00226         {
00227             m_executionContext.setContextNodeList(theNodeList);
00228         }
00229 
00230         ~ContextNodeListSetAndRestore()
00231         {
00232             m_executionContext.setContextNodeList(m_savedNodeList);
00233         }
00234 
00235     private:
00236 
00237         XPathExecutionContext&  m_executionContext;
00238         const NodeRefListBase&  m_savedNodeList;
00239     };
00240 
00241     /*
00242      * Get the count of nodes in the current context node list.
00243      *
00244      * @return length of list
00245      */
00246     virtual unsigned int
00247     getContextNodeListLength() const = 0;
00248 
00249     /*
00250      * Get the position of the node in the current context node list.
00251      * Note that this is 1-based indexing (XPath/XSLT-style), not 0-based.
00252      * Thus, 0 will be returned if the node was not found.
00253      *
00254      * @return position in list
00255      */
00256     virtual unsigned int
00257     getContextNodeListPosition(const XalanNode&     contextNode) const = 0;
00258 
00266     virtual bool
00267     elementAvailable(
00268             const XalanDOMString&   theNamespace, 
00269             const XalanDOMString&   elementName) const = 0;
00270 
00280     virtual bool
00281     functionAvailable(
00282             const XalanDOMString&   theNamespace, 
00283             const XalanDOMString&   functionName) const = 0;
00284 
00293     virtual const XObjectPtr
00294     extFunction(
00295             const XalanDOMString&           theNamespace,
00296             const XalanDOMString&           functionName,
00297             XalanNode*                      context,
00298             const XObjectArgVectorType&     argVec) = 0;
00299 
00307     virtual XLocator*
00308     getXLocatorFromNode(const XalanNode*    node) const = 0;
00309 
00317     virtual void
00318     associateXLocatorToNode(
00319             const XalanNode*    node,
00320             XLocator*           xlocator) = 0;
00321 
00329     virtual XalanDocument*
00330     parseXML(
00331             const XalanDOMString&   urlString,
00332             const XalanDOMString&   base) const = 0;
00333 
00339     virtual MutableNodeRefList*
00340     borrowMutableNodeRefList() = 0;
00341 
00348     virtual bool
00349     returnMutableNodeRefList(MutableNodeRefList*    theList) = 0;
00350 
00351     class BorrowReturnMutableNodeRefList
00352     {
00353     public:
00354 
00355         BorrowReturnMutableNodeRefList(XPathExecutionContext&   executionContext) :
00356             m_xpathExecutionContext(&executionContext),
00357             m_mutableNodeRefList(executionContext.borrowMutableNodeRefList())
00358         {
00359             assert(m_mutableNodeRefList != 0);
00360         }
00361 
00362         // N.B. Non-const copy constructor semantics (like std::auto_ptr)
00363         BorrowReturnMutableNodeRefList(const BorrowReturnMutableNodeRefList&    theSource) :
00364             m_xpathExecutionContext(theSource.m_xpathExecutionContext),
00365             m_mutableNodeRefList(theSource.m_mutableNodeRefList)
00366         {
00367             assert(m_mutableNodeRefList != 0);
00368 
00369             ((BorrowReturnMutableNodeRefList&)theSource).m_mutableNodeRefList = 0;
00370         }
00371 
00372         ~BorrowReturnMutableNodeRefList()
00373         {
00374             release();
00375         }
00376 
00377         MutableNodeRefList&
00378         operator*() const
00379         {
00380             assert(m_mutableNodeRefList != 0);
00381 
00382             return *m_mutableNodeRefList;
00383         }
00384 
00385         MutableNodeRefList*
00386         get() const
00387         {
00388             return m_mutableNodeRefList;
00389         }
00390 
00391         MutableNodeRefList*
00392         operator->() const
00393         {
00394             return get();
00395         }
00396 
00397         void
00398         release()
00399         {
00400             assert(m_xpathExecutionContext != 0);
00401 
00402             if (m_mutableNodeRefList != 0)
00403             {
00404                 m_xpathExecutionContext->returnMutableNodeRefList(m_mutableNodeRefList);
00405 
00406                 m_mutableNodeRefList = 0;
00407             }
00408         }
00409 
00410         BorrowReturnMutableNodeRefList
00411         clone() const
00412         {
00413             assert(m_xpathExecutionContext != 0);
00414 
00415             BorrowReturnMutableNodeRefList  theResult(*m_xpathExecutionContext);
00416 
00417             *theResult = *m_mutableNodeRefList;
00418 
00419             return theResult;
00420         }
00421 
00422         // N.B. Non-const assignment operator semantics.
00423         BorrowReturnMutableNodeRefList&
00424         operator=(BorrowReturnMutableNodeRefList&   theRHS)
00425         {
00426             release();
00427 
00428             m_xpathExecutionContext = theRHS.m_xpathExecutionContext;
00429 
00430             m_mutableNodeRefList = theRHS.m_mutableNodeRefList;
00431 
00432             theRHS.m_mutableNodeRefList = 0;
00433 
00434             return *this;
00435         }
00436 
00437     private:
00438 
00439         XPathExecutionContext*  m_xpathExecutionContext;
00440 
00441         MutableNodeRefList*     m_mutableNodeRefList;
00442     };
00443 
00444     virtual XalanDOMString&
00445     getCachedString() = 0;
00446 
00447     virtual bool
00448     releaseCachedString(XalanDOMString&     theString) = 0;
00449 
00450     class GetAndReleaseCachedString
00451     {
00452     public:
00453 
00454         GetAndReleaseCachedString(XPathExecutionContext&    theExecutionContext) :
00455             m_executionContext(&theExecutionContext),
00456             m_string(&theExecutionContext.getCachedString())
00457         {
00458         }
00459 
00460         // Note non-const copy semantics...
00461         GetAndReleaseCachedString(GetAndReleaseCachedString&    theSource) :
00462             m_executionContext(theSource.m_executionContext),
00463             m_string(theSource.m_string)
00464         {
00465             theSource.m_string = 0;
00466         }
00467 
00468         ~GetAndReleaseCachedString()
00469         {
00470             if (m_string != 0)
00471             {
00472                 m_executionContext->releaseCachedString(*m_string);
00473             }
00474         }
00475 
00476         XalanDOMString&
00477         get() const
00478         {
00479             assert(m_string != 0);
00480 
00481             return *m_string;
00482         }
00483 
00484         XPathExecutionContext&
00485         getExecutionContext() const
00486         {
00487             return *m_executionContext;
00488         }
00489 
00490     private:
00491 
00492         // Not implemented...
00493         GetAndReleaseCachedString&
00494         operator=(const GetAndReleaseCachedString&);
00495 
00496 
00497         // Data members...
00498         XPathExecutionContext*  m_executionContext;
00499 
00500         XalanDOMString*         m_string;
00501     };
00502 
00508     virtual ResultTreeFragBase*
00509     borrowResultTreeFrag() = 0;
00510 
00517     virtual bool
00518     returnResultTreeFrag(ResultTreeFragBase*    theResultTreeFragBase) = 0;
00519 
00520 
00521     class BorrowReturnResultTreeFrag
00522     {
00523     public:
00524 
00525         BorrowReturnResultTreeFrag(XPathExecutionContext&   executionContext) :
00526             m_xpathExecutionContext(executionContext),
00527             m_resultTreeFrag(executionContext.borrowResultTreeFrag())
00528         {
00529             assert(m_resultTreeFrag != 0);
00530         }
00531 
00532         // N.B. Non-const copy constructor semantics (like std::auto_ptr)
00533         BorrowReturnResultTreeFrag(const BorrowReturnResultTreeFrag&    theSource) :
00534             m_xpathExecutionContext(theSource.m_xpathExecutionContext),
00535             m_resultTreeFrag(theSource.m_resultTreeFrag)
00536         {
00537             assert(m_resultTreeFrag != 0);
00538 
00539             ((BorrowReturnResultTreeFrag&)theSource).m_resultTreeFrag = 0;
00540         }
00541 
00542         ~BorrowReturnResultTreeFrag()
00543         {
00544             if (m_resultTreeFrag != 0)
00545             {
00546                 if (m_xpathExecutionContext.returnResultTreeFrag(m_resultTreeFrag) == false)
00547                 {
00548                     delete m_resultTreeFrag;
00549                 }
00550             }
00551         }
00552 
00553         ResultTreeFragBase&
00554         operator*() const
00555         {
00556             return *m_resultTreeFrag;
00557         }
00558 
00559         ResultTreeFragBase*
00560         get() const
00561         {
00562             return m_resultTreeFrag;
00563         }
00564 
00565         ResultTreeFragBase*
00566         operator->() const
00567         {
00568             return get();
00569         }
00570 
00571         BorrowReturnResultTreeFrag
00572         clone(bool  deep = false) const
00573         {
00574             BorrowReturnResultTreeFrag  theResult(
00575                         m_xpathExecutionContext,
00576                         m_resultTreeFrag->clone(deep));
00577 
00578             return theResult;
00579         }
00580 
00581     private:
00582 
00583         BorrowReturnResultTreeFrag(
00584                 XPathExecutionContext&  executionContext,
00585                 ResultTreeFragBase*     resultTreeFrag) :
00586             m_xpathExecutionContext(executionContext),
00587             m_resultTreeFrag(resultTreeFrag)
00588         {
00589             assert(m_resultTreeFrag != 0);
00590         }
00591 
00592         // Data members...
00593         XPathExecutionContext&  m_xpathExecutionContext;
00594 
00595         ResultTreeFragBase*     m_resultTreeFrag;
00596     };
00597 
00598     friend class BorrowReturnResultTreeFrag;
00599 
00605     virtual MutableNodeRefList*
00606     createMutableNodeRefList() const = 0;
00607 
00619     virtual void
00620     getNodeSetByKey(
00621             XalanNode*              doc,
00622             const XalanDOMString&   name,
00623             const XalanDOMString&   ref,
00624             const PrefixResolver&   resolver,
00625             MutableNodeRefList&     nodelist) = 0;
00626 
00634     virtual const XObjectPtr
00635     getVariable(const QName&    name) = 0;
00636 
00642     virtual const PrefixResolver*
00643     getPrefixResolver() const = 0;
00644 
00650     virtual void
00651     setPrefixResolver(const PrefixResolver*     thePrefixResolver) = 0;
00652 
00653     class PrefixResolverSetAndRestore
00654     {
00655     public:
00656 
00657         PrefixResolverSetAndRestore(
00658                 XPathExecutionContext&  theExecutionContext,
00659                 const PrefixResolver*   theResolver) :
00660             m_executionContext(theExecutionContext),
00661             m_savedResolver(theExecutionContext.getPrefixResolver())
00662         {
00663             m_executionContext.setPrefixResolver(theResolver);
00664         }
00665 
00666         ~PrefixResolverSetAndRestore()
00667         {
00668             m_executionContext.setPrefixResolver(m_savedResolver);
00669         }
00670 
00671     private:
00672 
00673         XPathExecutionContext&          m_executionContext;
00674         const PrefixResolver* const     m_savedResolver;
00675     };
00676 
00683     virtual const XalanDOMString&
00684     getNamespaceForPrefix(const XalanDOMString&     prefix) const = 0;
00685 
00693     virtual XalanDOMString
00694     findURIFromDoc(const XalanDocument*     owner) const = 0;
00695 
00701     virtual XalanDocument*
00702     getDOMFactory() const = 0;
00703 
00714     virtual const XalanDOMString&
00715     getUnparsedEntityURI(
00716             const XalanDOMString&   theName,
00717             const XalanDocument&    theDocument) const = 0;
00718 
00729     virtual bool
00730     shouldStripSourceNode(const XalanNode&  node) = 0;
00731 
00739     virtual bool
00740     getThrowFoundIndex() const = 0;
00741 
00749     virtual void
00750     setThrowFoundIndex(bool     fThrow) = 0;
00751 
00752     virtual XalanDocument*
00753     getSourceDocument(const XalanDOMString&     theURI) const = 0;
00754 
00761     virtual void
00762     setSourceDocument(
00763             const XalanDOMString&   theURI,
00764             XalanDocument*          theDocument) = 0;
00765 
00766 
00774     virtual const XalanDecimalFormatSymbols*
00775     getDecimalFormatSymbols(const XalanDOMString&   name) = 0;
00776 
00777     // These interfaces are inherited from ExecutionContext...
00778 
00779     virtual void
00780     error(
00781             const XalanDOMString&   msg,
00782             const XalanNode*        sourceNode = 0,
00783             const XalanNode*        styleNode = 0) const = 0;
00784 
00785     virtual void
00786     error(
00787             const char*         msg,
00788             const XalanNode*    sourceNode = 0,
00789             const XalanNode*    styleNode = 0) const = 0;
00790 
00791     virtual void
00792     warn(
00793             const XalanDOMString&   msg,
00794             const XalanNode*        sourceNode = 0,
00795             const XalanNode*        styleNode = 0) const = 0;
00796 
00797     virtual void
00798     warn(
00799             const char*         msg,
00800             const XalanNode*    sourceNode = 0,
00801             const XalanNode*    styleNode = 0) const = 0;
00802 
00803     virtual void
00804     message(
00805             const XalanDOMString&   msg,
00806             const XalanNode*        sourceNode = 0,
00807             const XalanNode*        styleNode = 0) const = 0;
00808 
00809     virtual void
00810     message(
00811             const char*         msg,
00812             const XalanNode*    sourceNode = 0,
00813             const XalanNode*    styleNode = 0) const = 0;
00814 };
00815 
00816 
00817 
00818 #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++ XSL Transformer Version 1.1
Copyright © 2000, 2001 The Apache Software Foundation. All Rights Reserved.