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(XERCESDOCUMENTWRAPPER_HEADER_GUARD_1357924680) 00019 #define XERCESDOCUMENTWRAPPER_HEADER_GUARD_1357924680 00020 00021 00022 00023 #include <xalanc/XercesParserLiaison/XercesParserLiaisonDefinitions.hpp> 00024 00025 00026 00027 #include <xalanc/Include/XalanVector.hpp> 00028 00029 00030 00031 #include <xalanc/XalanDOM/XalanDocument.hpp> 00032 00033 00034 00035 #if defined(XALAN_AUTO_PTR_REQUIRES_DEFINITION) 00036 #include <xalanc/PlatformSupport/XalanDOMStringPool.hpp> 00037 #endif 00038 00039 00040 00041 #include <xalanc/Include/XalanMemMgrAutoPtr.hpp> 00042 00043 00044 00045 #include <xalanc/XercesParserLiaison/XercesDOMWalker.hpp> 00046 #include <xalanc/XercesParserLiaison/XercesWrapperNavigator.hpp> 00047 00048 00049 #include <xalanc/XercesParserLiaison/XercesWrapperToXalanNodeMap.hpp> 00050 #include <xalanc/XercesParserLiaison/XercesNodeListWrapper.hpp> 00051 #include <xalanc/XercesParserLiaison/XercesAttrWrapperAllocator.hpp> 00052 #include <xalanc/XercesParserLiaison/XercesElementWrapperAllocator.hpp> 00053 #include <xalanc/XercesParserLiaison/XercesTextWrapperAllocator.hpp> 00054 #include <xalanc/XercesParserLiaison/XercesWrapperNavigatorAllocator.hpp> 00055 00056 00057 #include <xalanc/XercesParserLiaison/XercesWrapperTypes.hpp> 00058 00059 00060 00061 XALAN_CPP_NAMESPACE_BEGIN 00062 00063 00064 00065 class XalanDOMStringPool; 00066 class XercesCommentWrapper; 00067 class XercesCDATASectionWrapper; 00068 class XercesDocumentFragmentWrapper; 00069 class XercesDocumentTypeWrapper; 00070 class XercesEntityWrapper; 00071 class XercesEntityReferenceWrapper; 00072 class XercesProcessingInstructionWrapper; 00073 class XercesNotationWrapper; 00074 00075 00076 00077 class XALAN_XERCESPARSERLIAISON_EXPORT XercesDocumentWrapper : public XalanDocument 00078 { 00079 public: 00080 00081 friend class XercesWrapperNavigator; 00082 00083 /** 00084 * 00085 * Constructor for XercesDocumentWrapper. 00086 * 00087 * If the document will be shared amongst multiple threads of execution, 00088 * the parameter buildWrapper must be true. Otherwise, the bridge 00089 * nodes will be built on demand, a process which is not synchronized. 00090 * This could cause serious problems if multiple threads tried to visit 00091 * an unbuilt node at the same time. 00092 * 00093 * @param theXercesDocument The Xerces document to bridge 00094 * @param threadSafe If true, the tree can safely be shared amongst multiple threads. (Also implies buildWrapper == true) 00095 * @param buildWrapper If true, all of the bridge nodes will be built during construction. 00096 * @param buildMaps If true, a map of Xerces to Xalan nodes will be built, even if the bridge is built 00097 * 00098 */ 00099 XercesDocumentWrapper( 00100 MemoryManager& theManager, 00101 const DOMDocument_Type* theXercesDocument, 00102 bool threadSafe = true, 00103 bool buildWrapper = true, 00104 bool buildMaps = false); 00105 00106 static XercesDocumentWrapper* 00107 create( 00108 MemoryManager& theManager, 00109 const DOMDocument_Type* theXercesDocument, 00110 bool threadSafe, 00111 bool buildWrapper, 00112 bool buildMaps); 00113 00114 MemoryManager& 00115 getMemoryManager() const 00116 { 00117 return m_nodeMap.getMemoryManager(); 00118 } 00119 00120 virtual 00121 ~XercesDocumentWrapper(); 00122 00123 // These interfaces are inherited from XalanNode... 00124 00125 virtual const XalanDOMString& 00126 getNodeName() const; 00127 00128 virtual const XalanDOMString& 00129 getNodeValue() const; 00130 00131 virtual NodeType 00132 getNodeType() const; 00133 00134 virtual XalanNode* 00135 getParentNode() const; 00136 00137 virtual const XalanNodeList* 00138 getChildNodes() const; 00139 00140 virtual XalanNode* 00141 getFirstChild() const; 00142 00143 virtual XalanNode* 00144 getLastChild() const; 00145 00146 virtual XalanNode* 00147 getPreviousSibling() const; 00148 00149 virtual XalanNode* 00150 getNextSibling() const; 00151 00152 virtual const XalanNamedNodeMap* 00153 getAttributes() const; 00154 00155 virtual XalanDocument* 00156 getOwnerDocument() const; 00157 00158 virtual const XalanDOMString& 00159 getNamespaceURI() const; 00160 00161 virtual const XalanDOMString& 00162 getPrefix() const; 00163 00164 virtual const XalanDOMString& 00165 getLocalName() const; 00166 00167 virtual bool 00168 isIndexed() const; 00169 00170 virtual IndexType 00171 getIndex() const; 00172 00173 virtual XalanElement* 00174 getDocumentElement() const; 00175 00176 virtual XalanElement* 00177 getElementById(const XalanDOMString& elementId) const; 00178 00179 // These are some special interfaces to manage relationships between 00180 // our nodes and Xerces nodes. 00181 00182 /** 00183 * Destroy the entire bridge structure that connects 00184 * the Xerces document to this XercesDocumentWrapper 00185 * instance. This will invalidate any pointers to 00186 * any nodes in the document (except, of course, the 00187 * document itself). 00188 */ 00189 void 00190 destroyWrapper(); 00191 00192 /** 00193 * Rebuild the entire bridge structure that connects 00194 * the Xerces document to this XercesDocumentWrapper 00195 * instance. This destroys the bridge before 00196 * rebuilding. 00197 */ 00198 void 00199 rebuildWrapper(); 00200 00201 /** 00202 * Map a Xerces node to the corresponding wrapper node. 00203 * If the constructor for the instance was called with 00204 * the threadSafe or buildWrapper parameter equal to 00205 * true, this call will fail. 00206 * 00207 * @param theXercesNode The Xerces instance to map 00208 * 00209 * @return The pointer to the corresponding XalanNode instance, or 0 if the node could not be mapped. 00210 */ 00211 XalanNode* 00212 mapNode(const DOMNodeType* theXercesNode) const; 00213 00214 /** 00215 * Map a Xerces node to the corresponding wrapper node. 00216 * If the constructor for the instance was called with 00217 * the threadSafe or buildWrapper parameter equal to 00218 * true, this call will fail. 00219 * 00220 * @param theXercesNode The Xerces instance to map 00221 * 00222 * @return The pointer to the corresponding XalanNode instance, or 0 if the node could not be mapped. 00223 */ 00224 XalanAttr* 00225 mapNode(const DOMAttrType* theXercesNode) const; 00226 00227 /** 00228 * Map a Xerces node to the corresponding wrapper node. 00229 * If the constructor for the instance was called with 00230 * the threadSafe or buildWrapper parameter equal to 00231 * true, this call will fail. 00232 * 00233 * @param theXercesNode The Xerces instance to map 00234 * 00235 * @return The pointer to the corresponding XalanNode instance, or 0 if the node could not be mapped. 00236 */ 00237 XalanElement* 00238 mapNode(const DOMElementType* theXercesNode) const; 00239 00240 /** 00241 * Map a XalanNode to the corresponding Xerces node. 00242 * If the node not owned by this document, the 00243 * function will throw XalanDOMException with the code 00244 * WRONG_DOCUMENT_ERR. 00245 * 00246 * @param theXalanNode The Xalan instance to map 00247 * 00248 * @return The pointer to the corresponding XalanNode instance, or 0 if the node could not be mapped. 00249 */ 00250 const DOMNodeType* 00251 mapNode(XalanNode* theXalanNode) const; 00252 00253 /** 00254 * 00255 * Get the Xerces DOMDocument that this XercesDocument represents. 00256 * 00257 * @return the Xerces DOMDocument instance. 00258 * 00259 */ 00260 const DOMDocument_Type* 00261 getXercesDocument() const 00262 { 00263 return m_xercesDocument; 00264 } 00265 00266 /** 00267 * Build the entire bridge structure. This should be done before any 00268 * processing begins, if the tree will be shared amongst multiple 00269 * threads. 00270 */ 00271 void 00272 buildWrapperNodes(); 00273 00274 typedef XalanVector<XalanNode*> NodeVectorType; 00275 00276 // Helper class to walk the tree and build everything... 00277 class BuildWrapperTreeWalker : public XercesDOMWalker 00278 { 00279 public: 00280 00281 typedef XercesDOMWalker ParentType; 00282 00283 BuildWrapperTreeWalker( 00284 XercesDocumentWrapper* theDocument, 00285 XercesWrapperNavigator* theDocumentNavigator, 00286 IndexType theStartIndex, 00287 bool theBuildMapsFlag); 00288 00289 virtual 00290 ~BuildWrapperTreeWalker(); 00291 00292 struct NavigatorStackEntryType 00293 { 00294 NavigatorStackEntryType( 00295 XercesWrapperNavigator* theNavigator = 0, 00296 XalanNode* theNode = 0) : 00297 m_navigator(theNavigator), 00298 m_node(theNode) 00299 { 00300 } 00301 00302 XercesWrapperNavigator* m_navigator; 00303 00304 XalanNode* m_node; 00305 }; 00306 00307 typedef XalanVector<NavigatorStackEntryType> NavigatorStackType; 00308 00309 protected: 00310 00311 virtual bool 00312 startNode(const DOMNodeType* node); 00313 00314 virtual bool 00315 endNode(const DOMNodeType* node); 00316 00317 using ParentType::startNode; 00318 using ParentType::endNode; 00319 00320 private: 00321 00322 XercesDocumentWrapper* m_document; 00323 00324 IndexType m_currentIndex; 00325 00326 NavigatorStackType m_parentNavigatorStack; 00327 00328 NavigatorStackType m_siblingNavigatorStack; 00329 00330 const bool m_buildMaps; 00331 }; 00332 00333 00334 /** 00335 * Get a pooled string. If the string is not in the pool, 00336 * add it. 00337 * 00338 * @param theString The string to pool. 00339 * @return A const reference to the pooled string. 00340 */ 00341 const XalanDOMString& 00342 getPooledString(const XalanDOMString& theString) const; 00343 00344 /** 00345 * Get a pooled string. If the string is not in the pool, 00346 * add it. 00347 * 00348 * @param theString The string to pool. 00349 * @param theLength The length of the string. If XalanDOMString::npos, the string is assumed to be null-terminated. 00350 * @return A const reference to the pooled string. 00351 */ 00352 const XalanDOMString& 00353 getPooledString( 00354 const XalanDOMChar* theString, 00355 XalanDOMString::size_type theLength = XalanDOMString::npos) const; 00356 00357 bool 00358 getMappingMode() const 00359 { 00360 return m_mappingMode; 00361 } 00362 00363 private: 00364 00365 // Destruction API... 00366 void 00367 destroyWrapperNode(XalanNode* theNode); 00368 00369 // Not implemented... 00370 XercesDocumentWrapper(const XercesDocumentWrapper& theSource); 00371 00372 XercesDocumentWrapper& 00373 operator=(const XercesDocumentWrapper& theRHS); 00374 00375 bool 00376 operator==(const XercesDocumentWrapper& theRHS) const; 00377 00378 // Private delete function... 00379 void 00380 destroyNode(XalanNode* theNode); 00381 00382 // More internal implementation stuff... 00383 00384 // Factory methods for our implementation nodes... 00385 XalanNode* 00386 createWrapperNode( 00387 const DOMNodeType* theXercesNode, 00388 IndexType theIndex, 00389 bool mapNode, 00390 XercesWrapperNavigator** theWrapperNodeNavigator = 0) const; 00391 00392 XercesDocumentTypeWrapper* 00393 createWrapperNode( 00394 const DOMDocumentType_Type* theDoctype, 00395 IndexType theIndex, 00396 bool mapNode, 00397 XercesWrapperNavigator** theWrapperNodeNavigator = 0) const; 00398 00399 XercesElementWrapper* 00400 createWrapperNode( 00401 const DOMElementType* theXercesNode, 00402 IndexType theIndex, 00403 bool mapNode, 00404 XercesWrapperNavigator** theWrapperNodeNavigator = 0) const; 00405 00406 XercesTextWrapper* 00407 createWrapperNode( 00408 const DOMTextType* theXercesNode, 00409 IndexType theIndex, 00410 bool mapNode, 00411 XercesWrapperNavigator** theWrapperNodeNavigator = 0) const; 00412 00413 XercesCommentWrapper* 00414 createWrapperNode( 00415 const DOMCommentType* theXercesNode, 00416 IndexType theIndex, 00417 bool mapNode, 00418 XercesWrapperNavigator** theWrapperNodeNavigator = 0) const; 00419 00420 XercesCDATASectionWrapper* 00421 createWrapperNode( 00422 const DOMCDATASectionType* theXercesNode, 00423 IndexType theIndex, 00424 bool mapNode, 00425 XercesWrapperNavigator** theWrapperNodeNavigator = 0) const; 00426 00427 XercesProcessingInstructionWrapper* 00428 createWrapperNode( 00429 const DOMProcessingInstructionType* theXercesNode, 00430 IndexType theIndex, 00431 bool mapNode, 00432 XercesWrapperNavigator** theWrapperNodeNavigator = 0) const; 00433 00434 XercesAttrWrapper* 00435 createWrapperNode( 00436 const DOMAttrType* theXercesNode, 00437 IndexType theIndex, 00438 bool mapNode, 00439 XercesWrapperNavigator** theWrapperNodeNavigator = 0) const; 00440 00441 XercesEntityWrapper* 00442 createWrapperNode( 00443 const DOMEntityType* theXercesNode, 00444 IndexType theIndex, 00445 bool mapNode, 00446 XercesWrapperNavigator** theWrapperNodeNavigator = 0) const; 00447 00448 XercesEntityReferenceWrapper* 00449 createWrapperNode( 00450 const DOMEntityReferenceType* theXercesNode, 00451 IndexType theIndex, 00452 bool mapNode, 00453 XercesWrapperNavigator** theWrapperNodeNavigator = 0) const; 00454 00455 XercesNotationWrapper* 00456 createWrapperNode( 00457 const DOMNotationType* theXercesNode, 00458 IndexType theIndex, 00459 bool mapNode, 00460 XercesWrapperNavigator** theWrapperNodeNavigator = 0) const; 00461 00462 XercesWrapperNavigator& 00463 createNavigator() const; 00464 00465 // This is a private helper class for building the tree... 00466 friend class BuildWrapperTreeWalker; 00467 00468 const DOMDocument_Type* const m_xercesDocument; 00469 00470 XalanElement* m_documentElement; 00471 00472 mutable XercesWrapperToXalanNodeMap m_nodeMap; 00473 00474 mutable XercesWrapperNavigatorAllocator m_navigatorAllocator; 00475 00476 // Our navigator will be the first entry in m_navigators, 00477 // but we'll cache this so access is faster... 00478 XercesWrapperNavigator* m_navigator; 00479 00480 XercesNodeListWrapper m_children; 00481 00482 mutable NodeVectorType m_nodes; 00483 00484 mutable XercesDocumentTypeWrapper* m_doctype; 00485 00486 bool m_mappingMode; 00487 00488 bool m_indexValid; 00489 00490 const bool m_buildMaps; 00491 00492 mutable XercesElementWrapperAllocator m_elementAllocator; 00493 00494 mutable XercesTextWrapperAllocator m_textAllocator; 00495 00496 mutable XercesAttrWrapperAllocator m_attributeAllocator; 00497 00498 const XalanMemMgrAutoPtr<XalanDOMStringPool> m_stringPool; 00499 }; 00500 00501 00502 00503 XALAN_CPP_NAMESPACE_END 00504 00505 00506 00507 #endif // !defined(XERCESDOCUMENTWRAPPER_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 |
|