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  

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