Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.3

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 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();
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     virtual XObjectFactory&
00179     getXObjectFactory() const = 0;
00180 
00188     virtual XObjectPtr
00189     createNodeSet(XalanNode&    theNode) = 0;
00190 
00198     virtual bool
00199     isNodeAfter(
00200             const XalanNode&    node1,
00201             const XalanNode&    node2) const = 0;
00202 
00208     virtual const NodeRefListBase&
00209     getContextNodeList() const = 0;
00210 
00216     virtual void    
00217     setContextNodeList(const NodeRefListBase&   theList) = 0;
00218 
00219     class ContextNodeListSetAndRestore
00220     {
00221     public:
00222 
00223         ContextNodeListSetAndRestore(
00224                 XPathExecutionContext&      theExecutionContext,
00225                 const NodeRefListBase&      theNodeList) :
00226             m_executionContext(theExecutionContext),
00227             m_savedNodeList(theExecutionContext.getContextNodeList())
00228         {
00229             m_executionContext.setContextNodeList(theNodeList);
00230         }
00231 
00232         ~ContextNodeListSetAndRestore()
00233         {
00234             m_executionContext.setContextNodeList(m_savedNodeList);
00235         }
00236 
00237     private:
00238 
00239         XPathExecutionContext&  m_executionContext;
00240         const NodeRefListBase&  m_savedNodeList;
00241     };
00242 
00243     /*
00244      * Get the count of nodes in the current context node list.
00245      *
00246      * @return length of list
00247      */
00248     virtual size_type
00249     getContextNodeListLength() const = 0;
00250 
00251     /*
00252      * Get the position of the node in the current context node list.
00253      * Note that this is 1-based indexing (XPath/XSLT-style), not 0-based.
00254      * Thus, 0 will be returned if the node was not found.
00255      *
00256      * @return position in list
00257      */
00258     virtual size_type
00259     getContextNodeListPosition(const XalanNode&     contextNode) const = 0;
00260 
00268     virtual bool
00269     elementAvailable(
00270             const XalanDOMString&   theNamespace, 
00271             const XalanDOMString&   elementName) const = 0;
00272 
00282     virtual bool
00283     functionAvailable(
00284             const XalanDOMString&   theNamespace, 
00285             const XalanDOMString&   functionName) const = 0;
00286 
00297     virtual const XObjectPtr
00298     extFunction(
00299             const XalanDOMString&           theNamespace,
00300             const XalanDOMString&           functionName,
00301             XalanNode*                      context,
00302             const XObjectArgVectorType&     argVec,
00303             const Locator*                  locator) = 0;
00304 
00312     virtual XalanDocument*
00313     parseXML(
00314             const XalanDOMString&   urlString,
00315             const XalanDOMString&   base) const = 0;
00316 
00322     virtual MutableNodeRefList*
00323     borrowMutableNodeRefList() = 0;
00324 
00331     virtual bool
00332     returnMutableNodeRefList(MutableNodeRefList*    theList) = 0;
00333 
00334     class BorrowReturnMutableNodeRefList
00335     {
00336     public:
00337 
00338         BorrowReturnMutableNodeRefList(XPathExecutionContext&   executionContext) :
00339             m_xpathExecutionContext(&executionContext),
00340             m_mutableNodeRefList(executionContext.borrowMutableNodeRefList())
00341         {
00342             assert(m_mutableNodeRefList != 0);
00343         }
00344 
00345         // N.B. Non-const copy constructor semantics (like std::auto_ptr)
00346         BorrowReturnMutableNodeRefList(const BorrowReturnMutableNodeRefList&    theSource) :
00347             m_xpathExecutionContext(theSource.m_xpathExecutionContext),
00348             m_mutableNodeRefList(theSource.m_mutableNodeRefList)
00349         {
00350             assert(m_mutableNodeRefList != 0);
00351 
00352             ((BorrowReturnMutableNodeRefList&)theSource).m_mutableNodeRefList = 0;
00353         }
00354 
00355         ~BorrowReturnMutableNodeRefList()
00356         {
00357             release();
00358         }
00359 
00360         MutableNodeRefList&
00361         operator*() const
00362         {
00363             assert(m_mutableNodeRefList != 0);
00364 
00365             return *m_mutableNodeRefList;
00366         }
00367 
00368         MutableNodeRefList*
00369         get() const
00370         {
00371             return m_mutableNodeRefList;
00372         }
00373 
00374         MutableNodeRefList*
00375         operator->() const
00376         {
00377             return get();
00378         }
00379 
00380         void
00381         release()
00382         {
00383             assert(m_xpathExecutionContext != 0);
00384 
00385             if (m_mutableNodeRefList != 0)
00386             {
00387                 m_xpathExecutionContext->returnMutableNodeRefList(m_mutableNodeRefList);
00388 
00389                 m_mutableNodeRefList = 0;
00390             }
00391         }
00392 
00393         BorrowReturnMutableNodeRefList
00394         clone() const
00395         {
00396             assert(m_xpathExecutionContext != 0);
00397 
00398             BorrowReturnMutableNodeRefList  theResult(*m_xpathExecutionContext);
00399 
00400             *theResult = *m_mutableNodeRefList;
00401 
00402             return theResult;
00403         }
00404 
00405         // N.B. Non-const assignment operator semantics.
00406         BorrowReturnMutableNodeRefList&
00407         operator=(BorrowReturnMutableNodeRefList&   theRHS)
00408         {
00409             release();
00410 
00411             m_xpathExecutionContext = theRHS.m_xpathExecutionContext;
00412 
00413             m_mutableNodeRefList = theRHS.m_mutableNodeRefList;
00414 
00415             theRHS.m_mutableNodeRefList = 0;
00416 
00417             return *this;
00418         }
00419 
00420     private:
00421 
00422         XPathExecutionContext*  m_xpathExecutionContext;
00423 
00424         MutableNodeRefList*     m_mutableNodeRefList;
00425     };
00426 
00427     virtual XalanDOMString&
00428     getCachedString() = 0;
00429 
00430     virtual bool
00431     releaseCachedString(XalanDOMString&     theString) = 0;
00432 
00433     class GetAndReleaseCachedString
00434     {
00435     public:
00436 
00437         GetAndReleaseCachedString(XPathExecutionContext&    theExecutionContext) :
00438             m_executionContext(&theExecutionContext),
00439             m_string(&theExecutionContext.getCachedString())
00440         {
00441         }
00442 
00443         // Note non-const copy semantics...
00444         GetAndReleaseCachedString(GetAndReleaseCachedString&    theSource) :
00445             m_executionContext(theSource.m_executionContext),
00446             m_string(theSource.m_string)
00447         {
00448             theSource.m_string = 0;
00449         }
00450 
00451         ~GetAndReleaseCachedString()
00452         {
00453             if (m_string != 0)
00454             {
00455                 m_executionContext->releaseCachedString(*m_string);
00456             }
00457         }
00458 
00459         XalanDOMString&
00460         get() const
00461         {
00462             assert(m_string != 0);
00463 
00464             return *m_string;
00465         }
00466 
00467         XPathExecutionContext&
00468         getExecutionContext() const
00469         {
00470             return *m_executionContext;
00471         }
00472 
00473     private:
00474 
00475         // Not implemented...
00476         GetAndReleaseCachedString&
00477         operator=(const GetAndReleaseCachedString&);
00478 
00479 
00480         // Data members...
00481         XPathExecutionContext*  m_executionContext;
00482 
00483         XalanDOMString*         m_string;
00484     };
00485 
00491     virtual MutableNodeRefList*
00492     createMutableNodeRefList() const = 0;
00493 
00505     virtual void
00506     getNodeSetByKey(
00507             XalanNode*              doc,
00508             const XalanDOMString&   name,
00509             const XalanDOMString&   ref,
00510             const PrefixResolver&   resolver,
00511             MutableNodeRefList&     nodelist) = 0;
00512 
00520     virtual const XObjectPtr
00521     getVariable(
00522             const XalanQName&   name,
00523             const Locator*      locator = 0) = 0;
00524 
00530     virtual const PrefixResolver*
00531     getPrefixResolver() const = 0;
00532 
00538     virtual void
00539     setPrefixResolver(const PrefixResolver*     thePrefixResolver) = 0;
00540 
00541     class PrefixResolverSetAndRestore
00542     {
00543     public:
00544 
00545         PrefixResolverSetAndRestore(
00546                 XPathExecutionContext&  theExecutionContext,
00547                 const PrefixResolver*   theResolver) :
00548             m_executionContext(theExecutionContext),
00549             m_savedResolver(theExecutionContext.getPrefixResolver())
00550         {
00551             m_executionContext.setPrefixResolver(theResolver);
00552         }
00553 
00554         PrefixResolverSetAndRestore(
00555                 XPathExecutionContext&  theExecutionContext,
00556                 const PrefixResolver*   theOldResolver,
00557                 const PrefixResolver*   theNewResolver) :
00558             m_executionContext(theExecutionContext),
00559             m_savedResolver(theOldResolver)
00560         {
00561             m_executionContext.setPrefixResolver(theNewResolver);
00562         }
00563 
00564         ~PrefixResolverSetAndRestore()
00565         {
00566             m_executionContext.setPrefixResolver(m_savedResolver);
00567         }
00568 
00569     private:
00570 
00571         XPathExecutionContext&          m_executionContext;
00572         const PrefixResolver* const     m_savedResolver;
00573     };
00574 
00581     virtual const XalanDOMString*
00582     getNamespaceForPrefix(const XalanDOMString&     prefix) const = 0;
00583 
00591     virtual XalanDOMString
00592     findURIFromDoc(const XalanDocument*     owner) const = 0;
00593 
00604     virtual const XalanDOMString&
00605     getUnparsedEntityURI(
00606             const XalanDOMString&   theName,
00607             const XalanDocument&    theDocument) const = 0;
00608 
00619     virtual bool
00620     shouldStripSourceNode(const XalanNode&  node) = 0;
00621 
00629     virtual bool
00630     getThrowFoundIndex() const = 0;
00631 
00639     virtual void
00640     setThrowFoundIndex(bool     fThrow) = 0;
00641 
00642     virtual XalanDocument*
00643     getSourceDocument(const XalanDOMString&     theURI) const = 0;
00644 
00651     virtual void
00652     setSourceDocument(
00653             const XalanDOMString&   theURI,
00654             XalanDocument*          theDocument) = 0;
00655 
00656 
00664     virtual const XalanDecimalFormatSymbols*
00665     getDecimalFormatSymbols(const XalanQName&   qname) = 0;
00666 
00667     // These interfaces are inherited from ExecutionContext...
00668 
00669     virtual void
00670     error(
00671             const XalanDOMString&   msg,
00672             const XalanNode*        sourceNode = 0,
00673             const XalanNode*        styleNode = 0) const = 0;
00674 
00675     virtual void
00676     error(
00677             const XalanDOMString&   msg,
00678             const XalanNode*        sourceNode,
00679             const Locator*          locator) const = 0;
00680 
00681     virtual void
00682     error(
00683             const char*         msg,
00684             const XalanNode*    sourceNode = 0,
00685             const XalanNode*    styleNode = 0) const = 0;
00686 
00687     virtual void
00688     error(
00689             const char*         msg,
00690             const XalanNode*    sourceNode,
00691             const Locator*      locator) const = 0;
00692 
00693     virtual void
00694     warn(
00695             const XalanDOMString&   msg,
00696             const XalanNode*        sourceNode = 0,
00697             const XalanNode*        styleNode = 0) const = 0;
00698 
00699     virtual void
00700     warn(
00701             const XalanDOMString&   msg,
00702             const XalanNode*        sourceNode,
00703             const Locator*          locator) const = 0;
00704 
00705     virtual void
00706     warn(
00707             const char*         msg,
00708             const XalanNode*    sourceNode = 0,
00709             const XalanNode*    styleNode = 0) const = 0;
00710 
00711     virtual void
00712     warn(
00713             const char*         msg,
00714             const XalanNode*    sourceNode,
00715             const Locator*      locator) const = 0;
00716 
00717     virtual void
00718     message(
00719             const XalanDOMString&   msg,
00720             const XalanNode*        sourceNode = 0,
00721             const XalanNode*        styleNode = 0) const = 0;
00722 
00723     virtual void
00724     message(
00725             const XalanDOMString&   msg,
00726             const XalanNode*    sourceNode,
00727             const Locator*      locator) const = 0;
00728 
00729     virtual void
00730     message(
00731             const char*         msg,
00732             const XalanNode*    sourceNode = 0,
00733             const XalanNode*    styleNode = 0) const = 0;
00734 
00735     virtual void
00736     message(
00737             const char*         msg,
00738             const XalanNode*    sourceNode,
00739             const Locator*      locator) const = 0;
00740 };
00741 
00742 
00743 
00744 #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.3
Copyright © 2000, 2001 The Apache Software Foundation. All Rights Reserved.