00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(XERCESDOCUMENTBRIDGE_HEADER_GUARD_1357924680) 00019 #define XERCESDOCUMENTBRIDGE_HEADER_GUARD_1357924680 00020 00021 00022 00023 #include <xalanc/XercesParserLiaison/XercesParserLiaisonDefinitions.hpp> 00024 00025 00026 00027 #include <xalanc/Include/XalanVector.hpp> 00028 #include <xalanc/Include/XalanDeque.hpp> 00029 00030 00031 00032 #if XERCES_VERSION_MAJOR >= 2 00033 #include <xercesc/dom/deprecated/DOM_Document.hpp> 00034 #else 00035 #include <xercesc/dom/DOM_Document.hpp> 00036 #endif 00037 00038 00039 00040 #include <xalanc/XalanDOM/XalanDocument.hpp> 00041 00042 00043 00044 #if defined(XALAN_AUTO_PTR_REQUIRES_DEFINITION) 00045 #include <xalanc/XalanDOM/XalanDOMImplementation.hpp> 00046 #include <xalanc/PlatformSupport/XalanDOMStringPool.hpp> 00047 #endif 00048 00049 00050 00051 #include <xalanc/Include/XalanAutoPtr.hpp> 00052 00053 00054 00055 #include <xalanc/DOMSupport/TreeWalker.hpp> 00056 00057 00058 00059 #include <xalanc/XercesParserLiaison/Deprecated/XercesToXalanNodeMap.hpp> 00060 #include <xalanc/XercesParserLiaison/Deprecated/XercesBridgeNavigator.hpp> 00061 #include <xalanc/XercesParserLiaison/Deprecated/XercesNodeListBridge.hpp> 00062 #include <xalanc/XercesParserLiaison/Deprecated/XercesTreeWalker.hpp> 00063 #include <xalanc/XercesParserLiaison/Deprecated/XercesElementBridgeAllocator.hpp> 00064 #include <xalanc/XercesParserLiaison/Deprecated/XercesTextBridgeAllocator.hpp> 00065 #include <xalanc/XercesParserLiaison/Deprecated/XercesAttributeBridgeAllocator.hpp> 00066 00067 00068 00069 XALAN_CPP_NAMESPACE_BEGIN 00070 00071 00072 00073 class XalanDOMStringPool; 00074 class XercesAttrBridge; 00075 class XercesCommentBridge; 00076 class XercesCDATASectionBridge; 00077 class XercesDocumentFragmentBridge; 00078 class XercesDocumentTypeBridge; 00079 class XercesElementBridge; 00080 class XercesEntityBridge; 00081 class XercesEntityReferenceBridge; 00082 class XercesProcessingInstructionBridge; 00083 class XercesNotationBridge; 00084 class XercesTextBridge; 00085 00086 00087 /** 00088 * This class is deprecated. 00089 * 00090 * @deprecated This class is part of the deprecated Xerces DOM bridge. 00091 */ 00092 class XALAN_XERCESPARSERLIAISON_EXPORT XercesDocumentBridge : public XalanDocument 00093 { 00094 public: 00095 00096 friend class XercesBridgeNavigator; 00097 00098 /** 00099 * 00100 * Constructor for XercesDocumentBridge. 00101 * 00102 * If the document will be shared amongst multiple threads of execution, 00103 * the parameter buildBridge must be true. Otherwise, the bridge 00104 * nodes will be built on demand, a process which is not synchronized. 00105 * This could cause serious problems if multiple threads tried to visit 00106 * an unbuilt node at the same time. 00107 * 00108 * @param theXercesDocument The Xerces document to bridge 00109 * @param threadSafe If true, the tree can safely be shared amongst multiple threads. (Also implies buildBridge == true) 00110 * @param buildBridge If true, all of the bridge nodes will be built during construction. 00111 * 00112 */ 00113 XercesDocumentBridge( 00114 const DOM_Document_Type& theXercesDocument, 00115 bool threadSafe = true, 00116 bool buildBridge = true); 00117 00118 virtual 00119 ~XercesDocumentBridge(); 00120 00121 // These interfaces are inherited from XalanNode... 00122 00123 virtual const XalanDOMString& 00124 getNodeName() const; 00125 00126 virtual const XalanDOMString& 00127 getNodeValue() const; 00128 00129 virtual NodeType 00130 getNodeType() const; 00131 00132 virtual XalanNode* 00133 getParentNode() const; 00134 00135 virtual const XalanNodeList* 00136 getChildNodes() const; 00137 00138 virtual XalanNode* 00139 getFirstChild() const; 00140 00141 virtual XalanNode* 00142 getLastChild() const; 00143 00144 virtual XalanNode* 00145 getPreviousSibling() const; 00146 00147 virtual XalanNode* 00148 getNextSibling() const; 00149 00150 virtual const XalanNamedNodeMap* 00151 getAttributes() const; 00152 00153 virtual XalanDocument* 00154 getOwnerDocument() const; 00155 00156 #if defined(XALAN_NO_COVARIANT_RETURN_TYPE) 00157 virtual XalanNode* 00158 #else 00159 virtual XercesDocumentBridge* 00160 #endif 00161 cloneNode(bool deep) const; 00162 00163 virtual XalanNode* 00164 insertBefore( 00165 XalanNode* newChild, 00166 XalanNode* refChild); 00167 00168 virtual XalanNode* 00169 replaceChild( 00170 XalanNode* newChild, 00171 XalanNode* oldChild); 00172 00173 virtual XalanNode* 00174 removeChild(XalanNode* oldChild); 00175 00176 virtual XalanNode* 00177 appendChild(XalanNode* newChild); 00178 00179 virtual bool 00180 hasChildNodes() const; 00181 00182 virtual void 00183 setNodeValue(const XalanDOMString& nodeValue); 00184 00185 virtual void 00186 normalize(); 00187 00188 virtual bool 00189 isSupported( 00190 const XalanDOMString& feature, 00191 const XalanDOMString& version) const; 00192 00193 virtual const XalanDOMString& 00194 getNamespaceURI() const; 00195 00196 virtual const XalanDOMString& 00197 getPrefix() const; 00198 00199 virtual const XalanDOMString& 00200 getLocalName() const; 00201 00202 virtual void 00203 setPrefix(const XalanDOMString& prefix); 00204 00205 virtual bool 00206 isIndexed() const; 00207 00208 virtual IndexType 00209 getIndex() const; 00210 00211 virtual XalanElement* 00212 createElement(const XalanDOMString& tagName); 00213 00214 virtual XalanDocumentFragment* 00215 createDocumentFragment(); 00216 00217 virtual XalanText* 00218 createTextNode(const XalanDOMString& data); 00219 00220 virtual XalanComment* 00221 createComment(const XalanDOMString& data); 00222 00223 virtual XalanCDATASection* 00224 createCDATASection(const XalanDOMString& data); 00225 00226 virtual XalanProcessingInstruction* 00227 createProcessingInstruction( 00228 const XalanDOMString& target, 00229 const XalanDOMString& data); 00230 00231 virtual XalanAttr* 00232 createAttribute(const XalanDOMString& name); 00233 00234 virtual XalanEntityReference* 00235 createEntityReference(const XalanDOMString& name); 00236 00237 virtual XalanDocumentType* 00238 getDoctype() const; 00239 00240 virtual XalanDOMImplementation* 00241 getImplementation() const; 00242 00243 virtual XalanElement* 00244 getDocumentElement() const; 00245 00246 virtual XalanNodeList* 00247 getElementsByTagName(const XalanDOMString& tagname) const; 00248 00249 virtual XalanNode* 00250 importNode( 00251 XalanNode* importedNode, 00252 bool deep); 00253 00254 virtual XalanElement* 00255 createElementNS( 00256 const XalanDOMString& namespaceURI, 00257 const XalanDOMString& qualifiedName); 00258 00259 virtual XalanAttr* 00260 createAttributeNS( 00261 const XalanDOMString& namespaceURI, 00262 const XalanDOMString& qualifiedName); 00263 00264 virtual XalanNodeList* 00265 getElementsByTagNameNS( 00266 const XalanDOMString& namespaceURI, 00267 const XalanDOMString& localName) const; 00268 00269 virtual XalanElement* 00270 getElementById(const XalanDOMString& elementId) const; 00271 00272 // These are some special interfaces to manage relationships between 00273 // our nodes and Xerces nodes. 00274 00275 /** 00276 * Destroy the entire bridge structure that connects 00277 * the Xerces document to this XercesDocumentBridge 00278 * instance. This will invalidate any pointers to 00279 * any nodes in the document (except, of course, the 00280 * document itself). 00281 */ 00282 void 00283 destroyBridge(); 00284 00285 /** 00286 * Rebuild the entire bridge structure that connects 00287 * the Xerces document to this XercesDocumentBridge 00288 * instance. This destroys the bridge before 00289 * rebuilding. 00290 */ 00291 void 00292 rebuildBridge(); 00293 00294 XalanNode* 00295 mapNode(const DOM_NodeType& theXercesNode) const; 00296 00297 XalanAttr* 00298 mapNode(const DOM_AttrType& theXercesNode) const; 00299 00300 XalanElement* 00301 mapNode(const DOM_ElementType& theXercesNode) const; 00302 00303 DOM_NodeType 00304 mapNode(const XalanNode* theXalanNode) const; 00305 00306 DOM_AttrType 00307 mapNode(const XalanAttr* theXalanNode) const; 00308 00309 NodeImplType* 00310 mapNodeToImpl(const XalanNode* theXalanNode) const; 00311 00312 /** 00313 * 00314 * Get the Xerces DOM_Document that this XercesDocument represents. 00315 * 00316 * @return the Xerces DOM_Document instance. 00317 * 00318 */ 00319 DOM_Document_Type 00320 getXercesDocument() const 00321 { 00322 return m_xercesDocument; 00323 } 00324 00325 /** 00326 * Build the entire bridge structure. This should be done before any 00327 * processing begins, if the tree will be shared amongst multiple 00328 * threads. 00329 */ 00330 void 00331 buildBridgeNodes(); 00332 00333 00334 typedef XalanDeque<XercesBridgeNavigator> NavigatorBridgeVectorType; 00335 typedef XalanDeque<XalanNode*> NodeVectorType; 00336 00337 00338 // Helper class to walk the tree and build everything... 00339 class BuildBridgeTreeWalker : public XercesTreeWalker 00340 { 00341 public: 00342 00343 typedef NavigatorBridgeVectorType NavigatorBridgeVectorInnerType; 00344 00345 BuildBridgeTreeWalker( 00346 XercesDocumentBridge* theDocument, 00347 XercesBridgeNavigator* theDocumentNavigator, 00348 NavigatorBridgeVectorInnerType& theNavigators, 00349 IndexType theStartIndex); 00350 00351 virtual 00352 ~BuildBridgeTreeWalker(); 00353 00354 struct NavigatorStackEntryType 00355 { 00356 NavigatorStackEntryType( 00357 XercesBridgeNavigator* theNavigator = 0, 00358 XalanNode* theNode = 0) : 00359 m_navigator(theNavigator), 00360 m_node(theNode) 00361 { 00362 } 00363 00364 XercesBridgeNavigator* m_navigator; 00365 00366 XalanNode* m_node; 00367 }; 00368 00369 00370 typedef XalanVector<NavigatorStackEntryType> NavigatorStackType; 00371 00372 protected: 00373 00374 virtual void 00375 startNode(const DOM_NodeType& node); 00376 00377 virtual void 00378 endNode(const DOM_NodeType& node); 00379 00380 private: 00381 00382 XercesDocumentBridge* m_document; 00383 00384 NavigatorBridgeVectorInnerType& m_navigators; 00385 00386 IndexType m_currentIndex; 00387 00388 NavigatorStackType m_parentNavigatorStack; 00389 00390 NavigatorStackType m_siblingNavigatorStack; 00391 }; 00392 00393 00394 /** 00395 * Get a pooled string. If the string is not in the pool, 00396 * add it. 00397 * 00398 * @param theString The string to pool. 00399 * @return A const reference to the pooled string. 00400 */ 00401 const XalanDOMString& 00402 getPooledString(const XalanDOMString& theString) const; 00403 00404 /** 00405 * Get a pooled string. If the string is not in the pool, 00406 * add it. 00407 * 00408 * @param theString The string to pool. 00409 * @param theLength The length of the string. If XalanDOMString::npos, the string is assumed to be null-terminated. 00410 * @return A const reference to the pooled string. 00411 */ 00412 const XalanDOMString& 00413 getPooledString( 00414 const XalanDOMChar* theString, 00415 XalanDOMString::size_type theLength /* = XalanDOMString::npos */) const; 00416 00417 private: 00418 00419 XalanNode* 00420 mapNode(NodeImplType* theXercesNodeImpl) const; 00421 00422 // Destruction API... 00423 void 00424 destroyBridgeNode(XalanNode* theNode); 00425 00426 // Not implemented... 00427 XercesDocumentBridge(const XercesDocumentBridge& theSource); 00428 00429 XercesDocumentBridge& 00430 operator=(const XercesDocumentBridge& theRHS); 00431 00432 bool 00433 operator==(const XercesDocumentBridge& theRHS) const; 00434 00435 // Private delete function... 00436 void 00437 destroyNode(XalanNode* theNode); 00438 00439 // More internal implementation stuff... 00440 XalanNode* 00441 internalCloneNode( 00442 const XalanNode* theXalanNode, 00443 const DOM_NodeType& theXercesNode, 00444 bool deep); 00445 00446 // Factory methods for our implementation nodes... 00447 XalanNode* 00448 createBridgeNode( 00449 const DOM_NodeType& theXercesNode, 00450 IndexType theIndex, 00451 bool mapNode) const; 00452 00453 XercesDocumentTypeBridge* 00454 createBridgeNode( 00455 const DOM_DocumentType_Type& theDoctype, 00456 IndexType theIndex, 00457 bool mapNode) const; 00458 00459 XercesElementBridge* 00460 createBridgeNode( 00461 const DOM_ElementType& theXercesNode, 00462 IndexType theIndex, 00463 bool mapNode) const; 00464 00465 XercesDocumentFragmentBridge* 00466 createBridgeNode( 00467 const DOM_DocumentFragmentType& theXercesNode, 00468 IndexType theIndex, 00469 bool mapNode) const; 00470 00471 XercesTextBridge* 00472 createBridgeNode( 00473 const DOM_TextType& theXercesNode, 00474 IndexType theIndex, 00475 bool mapNode) const; 00476 00477 XercesCommentBridge* 00478 createBridgeNode( 00479 const DOM_CommentType& theXercesNode, 00480 IndexType theIndex, 00481 bool mapNode) const; 00482 00483 XercesCDATASectionBridge* 00484 createBridgeNode( 00485 const DOM_CDATASectionType& theXercesNode, 00486 IndexType theIndex, 00487 bool mapNode) const; 00488 00489 XercesProcessingInstructionBridge* 00490 createBridgeNode( 00491 const DOM_ProcessingInstructionType& theXercesNode, 00492 IndexType theIndex, 00493 bool mapNode) const; 00494 00495 XercesAttrBridge* 00496 createBridgeNode( 00497 const DOM_AttrType& theXercesNode, 00498 IndexType theIndex, 00499 bool mapNode) const; 00500 00501 XercesEntityBridge* 00502 createBridgeNode( 00503 const DOM_EntityType& theXercesNode, 00504 IndexType theIndex, 00505 bool mapNode) const; 00506 00507 XercesEntityReferenceBridge* 00508 createBridgeNode( 00509 const DOM_EntityReferenceType& theXercesNode, 00510 IndexType theIndex, 00511 bool mapNode) const; 00512 00513 XercesNotationBridge* 00514 createBridgeNode( 00515 const DOM_NotationType& theXercesNode, 00516 IndexType theIndex, 00517 bool mapNode) const; 00518 00519 XercesBridgeNavigator& 00520 pushNavigator(bool mappingMode) const; 00521 00522 // This is a private helper class for building the tree... 00523 friend class BuildBridgeTreeWalker; 00524 00525 // $$$ ToDo: This is because DOM_Document::getElementById() is not 00526 // const... 00527 mutable DOM_Document_Type m_xercesDocument; 00528 00529 XalanElement* m_documentElement; 00530 00531 mutable XercesToXalanNodeMap m_nodeMap; 00532 00533 XalanAutoPtr<XalanDOMImplementation> m_domImplementation; 00534 00535 mutable NavigatorBridgeVectorType m_navigators; 00536 00537 // Our navigator will be the first entry in m_navigators, 00538 // but we'll cache this so access is faster... 00539 XercesBridgeNavigator* m_navigator; 00540 00541 XercesNodeListBridge m_children; 00542 00543 mutable NodeVectorType m_nodes; 00544 00545 mutable XercesDocumentTypeBridge* m_doctype; 00546 00547 bool m_mappingMode; 00548 00549 bool m_indexValid; 00550 00551 mutable XercesElementBridgeAllocator m_elementAllocator; 00552 00553 mutable XercesTextBridgeAllocator m_textAllocator; 00554 00555 mutable XercesAttributeBridgeAllocator m_attributeAllocator; 00556 00557 const XalanAutoPtr<XalanDOMStringPool> m_stringPool; 00558 }; 00559 00560 00561 00562 XALAN_CPP_NAMESPACE_END 00563 00564 00565 00566 #endif // !defined(XERCESDOCUMENTBRIDGE_HEADER_GUARD_1357924680)
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|