Xalan-C++ API Reference 1.12.0
XercesDocumentWrapper.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#if !defined(XERCESDOCUMENTWRAPPER_HEADER_GUARD_1357924680)
19#define XERCESDOCUMENTWRAPPER_HEADER_GUARD_1357924680
20
21
22
24
25
26
28
29
30
32
33
34
35#if defined(XALAN_AUTO_PTR_REQUIRES_DEFINITION)
37#endif
38
39
40
42
43
44
47
48
55
56
58
59
60
61namespace XALAN_CPP_NAMESPACE {
62
63
64
65class XalanDOMStringPool;
66class XercesCommentWrapper;
67class XercesCDATASectionWrapper;
68class XercesDocumentFragmentWrapper;
69class XercesDocumentTypeWrapper;
70class XercesEntityWrapper;
71class XercesEntityReferenceWrapper;
72class XercesProcessingInstructionWrapper;
73class XercesNotationWrapper;
74
75
76
78{
79public:
80
82
83 /**
84 *
85 * Constructor for XercesDocumentWrapper.
86 *
87 * If the document will be shared amongst multiple threads of execution,
88 * the parameter buildWrapper must be true. Otherwise, the bridge
89 * nodes will be built on demand, a process which is not synchronized.
90 * This could cause serious problems if multiple threads tried to visit
91 * an unbuilt node at the same time.
92 *
93 * @param theXercesDocument The Xerces document to bridge
94 * @param threadSafe If true, the tree can safely be shared amongst multiple threads. (Also implies buildWrapper == true)
95 * @param buildWrapper If true, all of the bridge nodes will be built during construction.
96 * @param buildMaps If true, a map of Xerces to Xalan nodes will be built, even if the bridge is built
97 *
98 */
100 MemoryManager& theManager,
102 bool threadSafe = true,
103 bool buildWrapper = true,
104 bool buildMaps = false);
105
108 MemoryManager& theManager,
110 bool threadSafe,
111 bool buildWrapper,
112 bool buildMaps);
113
114 MemoryManager&
116 {
117 return m_nodeMap.getMemoryManager();
118 }
119
120 virtual
122
123 // These interfaces are inherited from XalanNode...
124
125 virtual const XalanDOMString&
126 getNodeName() const;
127
128 virtual const XalanDOMString&
130
131 virtual NodeType
132 getNodeType() const;
133
134 virtual XalanNode*
136
137 virtual const XalanNodeList*
139
140 virtual XalanNode*
142
143 virtual XalanNode*
145
146 virtual XalanNode*
148
149 virtual XalanNode*
151
152 virtual const XalanNamedNodeMap*
154
155 virtual XalanDocument*
157
158 virtual const XalanDOMString&
160
161 virtual const XalanDOMString&
162 getPrefix() const;
163
164 virtual const XalanDOMString&
166
167 virtual bool
168 isIndexed() const;
169
170 virtual IndexType
171 getIndex() const;
172
173 virtual XalanElement*
175
176 virtual XalanElement*
178
179 // These are some special interfaces to manage relationships between
180 // our nodes and Xerces nodes.
181
182 /**
183 * Destroy the entire bridge structure that connects
184 * the Xerces document to this XercesDocumentWrapper
185 * instance. This will invalidate any pointers to
186 * any nodes in the document (except, of course, the
187 * document itself).
188 */
189 void
191
192 /**
193 * Rebuild the entire bridge structure that connects
194 * the Xerces document to this XercesDocumentWrapper
195 * instance. This destroys the bridge before
196 * rebuilding.
197 */
198 void
200
201 /**
202 * Map a Xerces node to the corresponding wrapper node.
203 * If the constructor for the instance was called with
204 * the threadSafe or buildWrapper parameter equal to
205 * true, this call will fail.
206 *
207 * @param theXercesNode The Xerces instance to map
208 *
209 * @return The pointer to the corresponding XalanNode instance, or 0 if the node could not be mapped.
210 */
211 XalanNode*
213
214 /**
215 * Map a Xerces node to the corresponding wrapper node.
216 * If the constructor for the instance was called with
217 * the threadSafe or buildWrapper parameter equal to
218 * true, this call will fail.
219 *
220 * @param theXercesNode The Xerces instance to map
221 *
222 * @return The pointer to the corresponding XalanNode instance, or 0 if the node could not be mapped.
223 */
224 XalanAttr*
226
227 /**
228 * Map a Xerces node to the corresponding wrapper node.
229 * If the constructor for the instance was called with
230 * the threadSafe or buildWrapper parameter equal to
231 * true, this call will fail.
232 *
233 * @param theXercesNode The Xerces instance to map
234 *
235 * @return The pointer to the corresponding XalanNode instance, or 0 if the node could not be mapped.
236 */
239
240 /**
241 * Map a XalanNode to the corresponding Xerces node.
242 * If the node not owned by this document, the
243 * function will throw XalanDOMException with the code
244 * WRONG_DOCUMENT_ERR.
245 *
246 * @param theXalanNode The Xalan instance to map
247 *
248 * @return The pointer to the corresponding XalanNode instance, or 0 if the node could not be mapped.
249 */
250 const DOMNodeType*
252
253 /**
254 *
255 * Get the Xerces DOMDocument that this XercesDocument represents.
256 *
257 * @return the Xerces DOMDocument instance.
258 *
259 */
260 const DOMDocument_Type*
262 {
263 return m_xercesDocument;
264 }
265
266 /**
267 * Build the entire bridge structure. This should be done before any
268 * processing begins, if the tree will be shared amongst multiple
269 * threads.
270 */
271 void
273
275
276 // Helper class to walk the tree and build everything...
278 {
279 public:
280
282
287 bool theBuildMapsFlag);
288
289 virtual
291
306
308
309 protected:
310
311 virtual bool
312 startNode(const DOMNodeType* node);
313
314 virtual bool
315 endNode(const DOMNodeType* node);
316
317 using ParentType::startNode;
318 using ParentType::endNode;
319
320 private:
321
322 XercesDocumentWrapper* m_document;
323
324 IndexType m_currentIndex;
325
326 NavigatorStackType m_parentNavigatorStack;
327
328 NavigatorStackType m_siblingNavigatorStack;
329
330 const bool m_buildMaps;
331 };
332
333
334 /**
335 * Get a pooled string. If the string is not in the pool,
336 * add it.
337 *
338 * @param theString The string to pool.
339 * @return A const reference to the pooled string.
340 */
341 const XalanDOMString&
343
344 /**
345 * Get a pooled string. If the string is not in the pool,
346 * add it.
347 *
348 * @param theString The string to pool.
349 * @param theLength The length of the string. If XalanDOMString::npos, the string is assumed to be null-terminated.
350 * @return A const reference to the pooled string.
351 */
352 const XalanDOMString&
354 const XalanDOMChar* theString,
355 XalanDOMString::size_type theLength = XalanDOMString::npos) const;
356
357 bool
359 {
360 return m_mappingMode;
361 }
362
363private:
364
365 // Destruction API...
366 void
367 destroyWrapperNode(XalanNode* theNode);
368
369 // Not implemented...
371
373 operator=(const XercesDocumentWrapper& theRHS);
374
375 bool
377
378 // Private delete function...
379 void
380 destroyNode(XalanNode* theNode);
381
382 // More internal implementation stuff...
383
384 // Factory methods for our implementation nodes...
385 XalanNode*
386 createWrapperNode(
388 IndexType theIndex,
389 bool mapNode,
391
393 createWrapperNode(
395 IndexType theIndex,
396 bool mapNode,
398
400 createWrapperNode(
402 IndexType theIndex,
403 bool mapNode,
405
407 createWrapperNode(
409 IndexType theIndex,
410 bool mapNode,
412
414 createWrapperNode(
416 IndexType theIndex,
417 bool mapNode,
419
421 createWrapperNode(
423 IndexType theIndex,
424 bool mapNode,
426
428 createWrapperNode(
430 IndexType theIndex,
431 bool mapNode,
433
435 createWrapperNode(
437 IndexType theIndex,
438 bool mapNode,
440
442 createWrapperNode(
444 IndexType theIndex,
445 bool mapNode,
447
449 createWrapperNode(
451 IndexType theIndex,
452 bool mapNode,
454
456 createWrapperNode(
458 IndexType theIndex,
459 bool mapNode,
461
463 createNavigator() const;
464
465 // This is a private helper class for building the tree...
467
468 const DOMDocument_Type* const m_xercesDocument;
469
470 XalanElement* m_documentElement;
471
472 mutable XercesWrapperToXalanNodeMap m_nodeMap;
473
474 mutable XercesWrapperNavigatorAllocator m_navigatorAllocator;
475
476 // Our navigator will be the first entry in m_navigators,
477 // but we'll cache this so access is faster...
478 XercesWrapperNavigator* m_navigator;
479
480 XercesNodeListWrapper m_children;
481
482 mutable NodeVectorType m_nodes;
483
484 mutable XercesDocumentTypeWrapper* m_doctype;
485
486 bool m_mappingMode;
487
488 bool m_indexValid;
489
490 const bool m_buildMaps;
491
492 mutable XercesElementWrapperAllocator m_elementAllocator;
493
494 mutable XercesTextWrapperAllocator m_textAllocator;
495
496 mutable XercesAttrWrapperAllocator m_attributeAllocator;
497
499};
500
501
502
503}
504
505
506
507#endif // !defined(XERCESDOCUMENTWRAPPER_HEADER_GUARD_1357924680)
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
#define XALAN_XERCESPARSERLIAISON_EXPORT
virtual bool endNode(const DOMNodeType *node)
Called when leaving a node.
XalanVector< NavigatorStackEntryType > NavigatorStackType
virtual bool startNode(const DOMNodeType *node)
Called when first walking a node.
BuildWrapperTreeWalker(XercesDocumentWrapper *theDocument, XercesWrapperNavigator *theDocumentNavigator, IndexType theStartIndex, bool theBuildMapsFlag)
const DOMNodeType * mapNode(XalanNode *theXalanNode) const
Map a XalanNode to the corresponding Xerces node.
virtual const XalanDOMString & getNamespaceURI() const
Get the namespace URI of this node, or null if it is unspecified.
static XercesDocumentWrapper * create(MemoryManager &theManager, const DOMDocument_Type *theXercesDocument, bool threadSafe, bool buildWrapper, bool buildMaps)
virtual XalanElement * getDocumentElement() const
Return a reference to the root element of the document.
virtual XalanNode * getParentNode() const
Gets the parent of this node.
virtual NodeType getNodeType() const
An enum value representing the type of the underlying object.
virtual XalanNode * getFirstChild() const
Gets the first child of this node.
const XalanDOMString & getPooledString(const XalanDOMString &theString) const
Get a pooled string.
virtual const XalanDOMString & getLocalName() const
Returns the local part of the qualified name of this node.
virtual const XalanNodeList * getChildNodes() const
Gets a NodeList that contains all children of this node.
virtual const XalanDOMString & getPrefix() const
Get the namespace prefix of this node, or null if it is unspecified.
const XalanDOMString & getPooledString(const XalanDOMChar *theString, XalanDOMString::size_type theLength=XalanDOMString::npos) const
Get a pooled string.
virtual XalanElement * getElementById(const XalanDOMString &elementId) const
Returns the Element whose ID is given by elementId.
virtual const XalanNamedNodeMap * getAttributes() const
Gets a NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
virtual const XalanDOMString & getNodeValue() const
Gets the value of this node, depending on its type.
virtual bool isIndexed() const
Determine if the document is node-order indexed.
XalanAttr * mapNode(const DOMAttrType *theXercesNode) const
Map a Xerces node to the corresponding wrapper node.
virtual const XalanDOMString & getNodeName() const
Gets the name of this node, depending on its type.
virtual XalanNode * getPreviousSibling() const
Gets the node immediately preceding this node.
virtual XalanNode * getNextSibling() const
Gets the node immediately following this node.
XalanElement * mapNode(const DOMElementType *theXercesNode) const
Map a Xerces node to the corresponding wrapper node.
virtual XalanDocument * getOwnerDocument() const
Gets the Document object associated with this node.
MemoryManager & getMemoryManager() const
void destroyWrapper()
Destroy the entire bridge structure that connects the Xerces document to this XercesDocumentWrapper i...
virtual XalanNode * getLastChild() const
Gets the last child of this node.
XalanVector< XalanNode * > NodeVectorType
void buildWrapperNodes()
Build the entire bridge structure.
XalanNode * mapNode(const DOMNodeType *theXercesNode) const
Map a Xerces node to the corresponding wrapper node.
void rebuildWrapper()
Rebuild the entire bridge structure that connects the Xerces document to this XercesDocumentWrapper i...
virtual IndexType getIndex() const
Get the node's index.
const DOMDocument_Type * getXercesDocument() const
Get the Xerces DOMDocument that this XercesDocument represents.
XercesDocumentWrapper(MemoryManager &theManager, const DOMDocument_Type *theXercesDocument, bool threadSafe=true, bool buildWrapper=true, bool buildMaps=false)
Constructor for XercesDocumentWrapper.
xercesc::DOMDocument DOMDocument_Type
xercesc::DOMElement DOMElementType
xercesc::DOMEntityReference DOMEntityReferenceType
xercesc::DOMDocumentType DOMDocumentType_Type
xercesc::DOMProcessingInstruction DOMProcessingInstructionType
xercesc::DOMAttr DOMAttrType
xercesc::DOMNode DOMNodeType
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
xercesc::DOMNotation DOMNotationType
xercesc::DOMText DOMTextType
xercesc::DOMComment DOMCommentType
xercesc::DOMCDATASection DOMCDATASectionType
xercesc::DOMEntity DOMEntityType
NavigatorStackEntryType(XercesWrapperNavigator *theNavigator=0, XalanNode *theNode=0)