Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


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 
61 XALAN_CPP_NAMESPACE_BEGIN
62 
63 
64 
65 class XalanDOMStringPool;
68 class XercesDocumentFragmentWrapper;
74 
75 
76 
78 {
79 public:
80 
81  friend class XercesWrapperNavigator;
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,
101  const DOMDocument_Type* theXercesDocument,
102  bool threadSafe = true,
103  bool buildWrapper = true,
104  bool buildMaps = false);
105 
106  static XercesDocumentWrapper*
107  create(
108  MemoryManager& theManager,
109  const DOMDocument_Type* theXercesDocument,
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&
129  getNodeValue() const;
130 
131  virtual NodeType
132  getNodeType() const;
133 
134  virtual XalanNode*
135  getParentNode() const;
136 
137  virtual const XalanNodeList*
138  getChildNodes() const;
139 
140  virtual XalanNode*
141  getFirstChild() const;
142 
143  virtual XalanNode*
144  getLastChild() const;
145 
146  virtual XalanNode*
147  getPreviousSibling() const;
148 
149  virtual XalanNode*
150  getNextSibling() const;
151 
152  virtual const XalanNamedNodeMap*
153  getAttributes() const;
154 
155  virtual XalanDocument*
156  getOwnerDocument() const;
157 
158  virtual const XalanDOMString&
159  getNamespaceURI() const;
160 
161  virtual const XalanDOMString&
162  getPrefix() const;
163 
164  virtual const XalanDOMString&
165  getLocalName() const;
166 
167  virtual bool
168  isIndexed() const;
169 
170  virtual IndexType
171  getIndex() const;
172 
173  virtual XalanElement*
174  getDocumentElement() const;
175 
176  virtual XalanElement*
177  getElementById(const XalanDOMString& elementId) const;
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
190  destroyWrapper();
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
199  rebuildWrapper();
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*
212  mapNode(const DOMNodeType* theXercesNode) const;
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*
225  mapNode(const DOMAttrType* theXercesNode) const;
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  */
237  XalanElement*
238  mapNode(const DOMElementType* theXercesNode) const;
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*
251  mapNode(XalanNode* theXalanNode) const;
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
272  buildWrapperNodes();
273 
275 
276  // Helper class to walk the tree and build everything...
278  {
279  public:
280 
282 
284  XercesDocumentWrapper* theDocument,
285  XercesWrapperNavigator* theDocumentNavigator,
286  IndexType theStartIndex,
287  bool theBuildMapsFlag);
288 
289  virtual
291 
293  {
295  XercesWrapperNavigator* theNavigator = 0,
296  XalanNode* theNode = 0) :
297  m_navigator(theNavigator),
298  m_node(theNode)
299  {
300  }
301 
303 
305  };
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&
342  getPooledString(const XalanDOMString& theString) const;
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&
353  getPooledString(
354  const XalanDOMChar* theString,
356 
357  bool
359  {
360  return m_mappingMode;
361  }
362 
363 private:
364 
365  // Destruction API...
366  void
367  destroyWrapperNode(XalanNode* theNode);
368 
369  // Not implemented...
371 
373  operator=(const XercesDocumentWrapper& theRHS);
374 
375  bool
376  operator==(const XercesDocumentWrapper& theRHS) const;
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(
387  const DOMNodeType* theXercesNode,
388  IndexType theIndex,
389  bool mapNode,
390  XercesWrapperNavigator** theWrapperNodeNavigator = 0) const;
391 
393  createWrapperNode(
394  const DOMDocumentType_Type* theDoctype,
395  IndexType theIndex,
396  bool mapNode,
397  XercesWrapperNavigator** theWrapperNodeNavigator = 0) const;
398 
400  createWrapperNode(
401  const DOMElementType* theXercesNode,
402  IndexType theIndex,
403  bool mapNode,
404  XercesWrapperNavigator** theWrapperNodeNavigator = 0) const;
405 
407  createWrapperNode(
408  const DOMTextType* theXercesNode,
409  IndexType theIndex,
410  bool mapNode,
411  XercesWrapperNavigator** theWrapperNodeNavigator = 0) const;
412 
414  createWrapperNode(
415  const DOMCommentType* theXercesNode,
416  IndexType theIndex,
417  bool mapNode,
418  XercesWrapperNavigator** theWrapperNodeNavigator = 0) const;
419 
421  createWrapperNode(
422  const DOMCDATASectionType* theXercesNode,
423  IndexType theIndex,
424  bool mapNode,
425  XercesWrapperNavigator** theWrapperNodeNavigator = 0) const;
426 
428  createWrapperNode(
429  const DOMProcessingInstructionType* theXercesNode,
430  IndexType theIndex,
431  bool mapNode,
432  XercesWrapperNavigator** theWrapperNodeNavigator = 0) const;
433 
435  createWrapperNode(
436  const DOMAttrType* theXercesNode,
437  IndexType theIndex,
438  bool mapNode,
439  XercesWrapperNavigator** theWrapperNodeNavigator = 0) const;
440 
442  createWrapperNode(
443  const DOMEntityType* theXercesNode,
444  IndexType theIndex,
445  bool mapNode,
446  XercesWrapperNavigator** theWrapperNodeNavigator = 0) const;
447 
449  createWrapperNode(
450  const DOMEntityReferenceType* theXercesNode,
451  IndexType theIndex,
452  bool mapNode,
453  XercesWrapperNavigator** theWrapperNodeNavigator = 0) const;
454 
456  createWrapperNode(
457  const DOMNotationType* theXercesNode,
458  IndexType theIndex,
459  bool mapNode,
460  XercesWrapperNavigator** theWrapperNodeNavigator = 0) const;
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 
498  const XalanMemMgrAutoPtr<XalanDOMStringPool> m_stringPool;
499 };
500 
501 
502 
503 XALAN_CPP_NAMESPACE_END
504 
505 
506 
507 #endif // !defined(XERCESDOCUMENTWRAPPER_HEADER_GUARD_1357924680)
virtual XalanElement * getDocumentElement() const =0
Return a reference to the root element of the document.
virtual IndexType getIndex() const =0
Get the node&#39;s index.
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocumentType DOMDocumentType_Type
virtual const XalanNodeList * getChildNodes() const =0
Gets a NodeList that contains all children of this node.
virtual XalanNode * getParentNode() const =0
Gets the parent of this node.
NavigatorStackEntryType(XercesWrapperNavigator *theNavigator=0, XalanNode *theNode=0)
virtual XalanElement * getElementById(const XalanDOMString &elementId) const =0
Returns the Element whose ID is given by elementId.
#define XALAN_XERCESPARSERLIAISON_EXPORT
XERCES_CPP_NAMESPACE_QUALIFIER DOMText DOMTextType
virtual XalanDocument * getOwnerDocument() const =0
Gets the Document object associated with this node.
virtual const XalanDOMString & getLocalName() const =0
Returns the local part of the qualified name of this node.
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument DOMDocument_Type
XalanSize_t size_type
XALAN_CPP_NAMESPACE_BEGIN typedef XERCES_CPP_NAMESPACE_QUALIFIER DOMAttr DOMAttrType
XalanNode * mapNode(const DOMNodeType *theXercesNode) const
virtual const XalanDOMString & getNamespaceURI() const =0
Get the namespace URI of this node, or null if it is unspecified.
virtual XalanNode * getLastChild() const =0
Gets the last child of this node.
virtual const XalanDOMString & getNodeValue() const =0
Gets the value of this node, depending on its type.
virtual XalanNode * getFirstChild() const =0
Gets the first child of this node.
virtual bool isIndexed() const =0
Determine if the document is node-order indexed.
XERCES_CPP_NAMESPACE_QUALIFIER DOMEntity DOMEntityType
XERCES_CPP_NAMESPACE_QUALIFIER DOMNode DOMNodeType
virtual const XalanDOMString & getPrefix() const =0
Get the namespace prefix of this node, or null if it is unspecified.
virtual XalanNode * getNextSibling() const =0
Gets the node immediately following this node.
virtual const XalanNamedNodeMap * getAttributes() const =0
Gets a NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise...
XalanVector< NavigatorStackEntryType > NavigatorStackType
bool operator==(const ElemAttributeSet &theLHS, const ElemAttributeSet &theRHS)
XalanVector< XalanNode * > NodeVectorType
virtual XalanNode * getPreviousSibling() const =0
Gets the node immediately preceding this node.
MemoryManager & getMemoryManager() const
const DOMDocument_Type * getXercesDocument() const
Get the Xerces DOMDocument that this XercesDocument represents.
unsigned long IndexType
Definition: XalanNode.hpp:64
virtual const XalanDOMString & getNodeName() const =0
Gets the name of this node, depending on its type.
XERCES_CPP_NAMESPACE_QUALIFIER DOMNotation DOMNotationType
XERCES_CPP_NAMESPACE_QUALIFIER DOMEntityReference DOMEntityReferenceType
XERCES_CPP_NAMESPACE_QUALIFIER DOMProcessingInstruction DOMProcessingInstructionType
XERCES_CPP_NAMESPACE_QUALIFIER DOMComment DOMCommentType
XERCES_CPP_NAMESPACE_QUALIFIER DOMCDATASection DOMCDATASectionType
virtual NodeType getNodeType() const =0
An enum value representing the type of the underlying object.
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement DOMElementType

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.11
Copyright © 1999-2012 The Apache Software Foundation.
All Rights Reserved.

Apache Logo