Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.4

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

XercesDocumentBridge.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 #if !defined(XERCESDOCUMENTBRIDGE_HEADER_GUARD_1357924680)
00058 #define XERCESDOCUMENTBRIDGE_HEADER_GUARD_1357924680
00059 
00060 
00061 
00062 #include <XercesParserLiaison/XercesParserLiaisonDefinitions.hpp>
00063 
00064 
00065 
00066 #include <deque>
00067 #include <set>
00068 #include <vector>
00069 
00070 
00071 
00072 #if XERCES_VERSION_MAJOR >= 2
00073 #include <xercesc/dom/deprecated/DOM_Document.hpp>
00074 #else
00075 #include <xercesc/dom/DOM_Document.hpp>
00076 #endif
00077 
00078 
00079 
00080 #include <XalanDOM/XalanDocument.hpp>
00081 
00082 
00083 
00084 #if defined(XALAN_AUTO_PTR_REQUIRES_DEFINITION)
00085 #include <XalanDOM/XalanDOMImplementation.hpp>
00086 #include <PlatformSupport/XalanDOMStringPool.hpp>
00087 #endif
00088 
00089 
00090 
00091 #include <Include/XalanAutoPtr.hpp>
00092 
00093 
00094 
00095 #include <DOMSupport/TreeWalker.hpp>
00096 
00097 
00098 
00099 #include <XercesParserLiaison/XercesToXalanNodeMap.hpp>
00100 #include <XercesParserLiaison/XercesBridgeNavigator.hpp>
00101 #include <XercesParserLiaison/XercesNodeListBridge.hpp>
00102 #include <XercesParserLiaison/XercesTreeWalker.hpp>
00103 #include <XercesParserLiaison/XercesElementBridgeAllocator.hpp>
00104 #include <XercesParserLiaison/XercesTextBridgeAllocator.hpp>
00105 #include <XercesParserLiaison/XercesAttributeBridgeAllocator.hpp>
00106 
00107 
00108 
00109 class XalanDOMStringPool;
00110 class XercesAttrBridge;
00111 class XercesCommentBridge;
00112 class XercesCDATASectionBridge;
00113 class XercesDocumentFragmentBridge;
00114 class XercesDocumentTypeBridge;
00115 class XercesElementBridge;
00116 class XercesEntityBridge;
00117 class XercesEntityReferenceBridge;
00118 class XercesProcessingInstructionBridge;
00119 class XercesNotationBridge;
00120 class XercesTextBridge;
00121 
00122 
00123 
00124 class XALAN_XERCESPARSERLIAISON_EXPORT XercesDocumentBridge : public XalanDocument
00125 {
00126 public:
00127 
00128     friend class XercesBridgeNavigator;
00129 
00145     XercesDocumentBridge(
00146             const DOM_Document&     theXercesDocument,
00147             bool                    threadSafe = true,
00148             bool                    buildBridge = true);
00149 
00150     virtual
00151     ~XercesDocumentBridge();
00152 
00153     // These interfaces are inherited from XalanNode...
00154 
00155     virtual const XalanDOMString&
00156     getNodeName() const;
00157 
00158     virtual const XalanDOMString&
00159     getNodeValue() const;
00160 
00161     virtual NodeType
00162     getNodeType() const;
00163 
00164     virtual XalanNode*
00165     getParentNode() const;
00166 
00167     virtual const XalanNodeList*
00168     getChildNodes() const;
00169 
00170     virtual XalanNode*
00171     getFirstChild() const;
00172 
00173     virtual XalanNode*
00174     getLastChild() const;
00175 
00176     virtual XalanNode*
00177     getPreviousSibling() const;
00178 
00179     virtual XalanNode*
00180     getNextSibling() const;
00181 
00182     virtual const XalanNamedNodeMap*
00183     getAttributes() const;
00184 
00185     virtual XalanDocument*
00186     getOwnerDocument() const;
00187 
00188 #if defined(XALAN_NO_COVARIANT_RETURN_TYPE)
00189     virtual XalanNode*
00190 #else
00191     virtual XercesDocumentBridge*
00192 #endif
00193     cloneNode(bool deep) const;
00194 
00195     virtual XalanNode*
00196     insertBefore(
00197             XalanNode*  newChild,
00198             XalanNode*  refChild);
00199 
00200     virtual XalanNode*
00201     replaceChild(
00202             XalanNode*  newChild,
00203             XalanNode*  oldChild);
00204 
00205     virtual XalanNode*
00206     removeChild(XalanNode*  oldChild);
00207 
00208     virtual XalanNode*
00209     appendChild(XalanNode*  newChild);
00210 
00211     virtual bool
00212     hasChildNodes() const;
00213 
00214     virtual void
00215     setNodeValue(const XalanDOMString&      nodeValue);
00216 
00217     virtual void
00218     normalize();
00219 
00220     virtual bool
00221     isSupported(
00222             const XalanDOMString&   feature,
00223             const XalanDOMString&   version) const;
00224 
00225     virtual const XalanDOMString&
00226     getNamespaceURI() const;
00227 
00228     virtual const XalanDOMString&
00229     getPrefix() const;
00230 
00231     virtual const XalanDOMString&
00232     getLocalName() const;
00233 
00234     virtual void
00235     setPrefix(const XalanDOMString& prefix);
00236 
00237     virtual bool
00238     isIndexed() const;
00239 
00240     virtual unsigned long
00241     getIndex() const;
00242 
00243     virtual XalanElement*
00244     createElement(const XalanDOMString& tagName);
00245 
00246     virtual XalanDocumentFragment*
00247     createDocumentFragment();
00248 
00249     virtual XalanText*
00250     createTextNode(const XalanDOMString&    data);
00251 
00252     virtual XalanComment*
00253     createComment(const XalanDOMString& data);
00254 
00255     virtual XalanCDATASection*
00256     createCDATASection(const XalanDOMString&    data);
00257 
00258     virtual XalanProcessingInstruction*
00259     createProcessingInstruction(
00260             const XalanDOMString&   target,
00261             const XalanDOMString&   data);
00262 
00263     virtual XalanAttr*
00264     createAttribute(const XalanDOMString&   name);
00265 
00266     virtual XalanEntityReference*
00267     createEntityReference(const XalanDOMString& name);
00268 
00269     virtual XalanDocumentType*
00270     getDoctype() const;
00271 
00272     virtual XalanDOMImplementation*
00273     getImplementation() const;
00274 
00275     virtual XalanElement*
00276     getDocumentElement() const;
00277 
00278     virtual XalanNodeList*
00279     getElementsByTagName(const XalanDOMString&      tagname) const;
00280 
00281     virtual XalanNode*
00282     importNode(
00283             XalanNode*  importedNode,
00284             bool        deep);
00285 
00286     virtual XalanElement*
00287     createElementNS(
00288             const XalanDOMString&   namespaceURI,
00289             const XalanDOMString&   qualifiedName);
00290 
00291     virtual XalanAttr*
00292     createAttributeNS(
00293             const XalanDOMString& namespaceURI,
00294             const XalanDOMString& qualifiedName);
00295 
00296     virtual XalanNodeList*
00297     getElementsByTagNameNS(
00298             const XalanDOMString&   namespaceURI,
00299             const XalanDOMString&   localName) const;
00300 
00301     virtual XalanElement*
00302     getElementById(const XalanDOMString&    elementId) const;
00303 
00304     // These are some special interfaces to manage relationships between
00305     // our nodes and Xerces nodes.
00306 
00314     void
00315     destroyBridge();
00316 
00323     void
00324     rebuildBridge();
00325 
00326     XalanNode*
00327     mapNode(const DOM_Node&     theXercesNode) const;
00328 
00329     XalanAttr*
00330     mapNode(const DOM_Attr&     theXercesNode) const;
00331 
00332     XalanElement*
00333     mapNode(const DOM_Element&  theXercesNode) const;
00334 
00335     DOM_Node
00336     mapNode(const XalanNode*    theXalanNode) const;
00337 
00338     DOM_Attr
00339     mapNode(const XalanAttr*    theXalanNode) const;
00340 
00341     NodeImpl*
00342     mapNodeToImpl(const XalanNode*  theXalanNode) const;
00343 
00351     DOM_Document
00352     getXercesDocument() const
00353     {
00354         return m_xercesDocument;
00355     }
00356 
00362     void
00363     buildBridgeNodes();
00364 
00365 #if defined(XALAN_NO_NAMESPACES)
00366     typedef deque<XercesBridgeNavigator>    NavigatorBridgeVectorType;
00367 
00368     typedef deque<XalanNode*>               NodeVectorType;
00369 #else
00370     typedef std::deque<XercesBridgeNavigator>   NavigatorBridgeVectorType;
00371 
00372     typedef std::deque<XalanNode*>              NodeVectorType;
00373 #endif
00374 
00375     // Helper class to walk the tree and build everything...
00376     class BuildBridgeTreeWalker : public XercesTreeWalker
00377     {
00378     public:
00379 
00380         typedef NavigatorBridgeVectorType   NavigatorBridgeVectorInnerType;
00381 
00382         BuildBridgeTreeWalker(
00383                 XercesDocumentBridge*           theDocument,
00384                 XercesBridgeNavigator*          theDocumentNavigator,
00385                 NavigatorBridgeVectorInnerType& theNavigators,
00386                 unsigned long                   theStartIndex);
00387 
00388         virtual
00389         ~BuildBridgeTreeWalker();
00390 
00391         struct NavigatorStackEntryType
00392         {
00393             NavigatorStackEntryType(
00394                         XercesBridgeNavigator*  theNavigator = 0,
00395                         XalanNode*              theNode = 0) :
00396                 m_navigator(theNavigator),
00397                 m_node(theNode)
00398             {
00399             }
00400 
00401             XercesBridgeNavigator*  m_navigator;
00402 
00403             XalanNode*              m_node;
00404         };
00405 
00406     #if defined(XALAN_NO_NAMESPACES)
00407         typedef vector<NavigatorStackEntryType>         NavigatorStackType;
00408     #else
00409         typedef std::vector<NavigatorStackEntryType>    NavigatorStackType;
00410     #endif
00411 
00412     protected:
00413 
00414         virtual void
00415         startNode(const DOM_Node&   node);
00416 
00417         virtual void
00418         endNode(const DOM_Node& node);
00419 
00420     private:
00421 
00422         XercesDocumentBridge*           m_document;
00423 
00424         NavigatorBridgeVectorInnerType& m_navigators;
00425 
00426         unsigned long                   m_currentIndex;
00427 
00428         NavigatorStackType              m_parentNavigatorStack;
00429 
00430         NavigatorStackType              m_siblingNavigatorStack;
00431     };
00432 
00433 
00441     const XalanDOMString&
00442     getPooledString(const XalanDOMString&   theString) const;
00443 
00452     const XalanDOMString&
00453     getPooledString(
00454             const XalanDOMChar*         theString,
00455             XalanDOMString::size_type   theLength /* = XalanDOMString::npos */) const;
00456 
00457 private:
00458 
00459     XalanNode*
00460     mapNode(NodeImpl*   theXercesNodeImpl) const;
00461 
00462     // Destruction API...
00463     void
00464     destroyBridgeNode(XalanNode*    theNode);
00465 
00466     // Not implemented...
00467     XercesDocumentBridge(const XercesDocumentBridge&    theSource);
00468 
00469     XercesDocumentBridge&
00470     operator=(const XercesDocumentBridge&   theRHS);
00471 
00472     bool
00473     operator==(const XercesDocumentBridge&  theRHS) const;
00474 
00475     // Private delete function...
00476     void
00477     destroyNode(XalanNode*  theNode);
00478 
00479     // More internal implementation stuff...
00480     XalanNode*
00481     internalCloneNode(
00482             const XalanNode*    theXalanNode,
00483             const DOM_Node&     theXercesNode,
00484             bool                deep);
00485 
00486     // Factory methods for our implementation nodes...
00487     XalanNode*
00488     createBridgeNode(
00489             const DOM_Node& theXercesNode,
00490             unsigned long   theIndex,
00491             bool            mapNode) const;
00492 
00493     XercesDocumentTypeBridge*
00494     createBridgeNode(
00495             const DOM_DocumentType&     theDoctype,
00496             unsigned long               theIndex,
00497             bool                        mapNode) const;
00498 
00499     XercesElementBridge*
00500     createBridgeNode(
00501             const DOM_Element&  theXercesNode,
00502             unsigned long       theIndex,
00503             bool                mapNode) const;
00504 
00505     XercesDocumentFragmentBridge*
00506     createBridgeNode(
00507             const DOM_DocumentFragment&     theXercesNode,
00508             unsigned long                   theIndex,
00509             bool                            mapNode) const;
00510 
00511     XercesTextBridge*
00512     createBridgeNode(
00513             const DOM_Text&     theXercesNode,
00514             unsigned long       theIndex,
00515             bool                mapNode) const;
00516 
00517     XercesCommentBridge*
00518     createBridgeNode(
00519             const DOM_Comment&  theXercesNode,
00520             unsigned long       theIndex,
00521             bool                mapNode) const;
00522 
00523     XercesCDATASectionBridge*
00524     createBridgeNode(
00525             const DOM_CDATASection&     theXercesNode,
00526             unsigned long               theIndex,
00527             bool                        mapNode) const;
00528 
00529     XercesProcessingInstructionBridge*
00530     createBridgeNode(
00531             const DOM_ProcessingInstruction&    theXercesNode,
00532             unsigned long                       theIndex,
00533             bool                                mapNode) const;
00534 
00535     XercesAttrBridge*
00536     createBridgeNode(
00537             const DOM_Attr&     theXercesNode,
00538             unsigned long       theIndex,
00539             bool                mapNode) const;
00540 
00541     XercesEntityBridge*
00542     createBridgeNode(
00543             const DOM_Entity&   theXercesNode,
00544             unsigned long       theIndex,
00545             bool                mapNode) const;
00546 
00547     XercesEntityReferenceBridge*
00548     createBridgeNode(
00549             const DOM_EntityReference&  theXercesNode,
00550             unsigned long               theIndex,
00551             bool                        mapNode) const;
00552 
00553     XercesNotationBridge*
00554     createBridgeNode(
00555             const DOM_Notation&     theXercesNode,
00556             unsigned long           theIndex,
00557             bool                    mapNode) const;
00558 
00559     XercesBridgeNavigator&
00560     pushNavigator(bool  mappingMode) const;
00561 
00562     // This is a private helper class for building the tree...
00563     friend class BuildBridgeTreeWalker;
00564 
00565     // $$$ ToDo: This is because DOM_Document::getElementById() is not
00566     // const...
00567     mutable DOM_Document                    m_xercesDocument;
00568 
00569     XalanElement*                           m_documentElement;
00570 
00571     mutable XercesToXalanNodeMap            m_nodeMap;
00572 
00573     XalanAutoPtr<XalanDOMImplementation>    m_domImplementation;
00574 
00575     mutable NavigatorBridgeVectorType       m_navigators;
00576 
00577     // Our navigator will be the first entry in m_navigators,
00578     // but we'll cache this so access is faster...
00579     XercesBridgeNavigator*                  m_navigator;
00580 
00581     XercesNodeListBridge                    m_children;
00582 
00583     mutable NodeVectorType                  m_nodes;
00584 
00585     mutable XercesDocumentTypeBridge*       m_doctype;
00586 
00587     bool                                    m_mappingMode;
00588 
00589     bool                                    m_indexValid;
00590 
00591     mutable XercesElementBridgeAllocator    m_elementAllocator;
00592 
00593     mutable XercesTextBridgeAllocator       m_textAllocator;
00594 
00595     mutable XercesAttributeBridgeAllocator  m_attributeAllocator;
00596 
00597     const XalanAutoPtr<XalanDOMStringPool>  m_stringPool;
00598 };
00599 
00600 
00601 
00602 #endif  // !defined(XERCESDOCUMENTBRIDGE_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.4
Copyright © 2000, 2001, 2002 The Apache Software Foundation. All Rights Reserved.