1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski #ifndef _BUFFERNODE_HXX
25*b1cdbd2cSJim Jagielski #define _BUFFERNODE_HXX
26*b1cdbd2cSJim Jagielski 
27*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XServiceInfo.hpp>
28*b1cdbd2cSJim Jagielski #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
29*b1cdbd2cSJim Jagielski 
30*b1cdbd2cSJim Jagielski #ifndef INCLUDED_VECTOR
31*b1cdbd2cSJim Jagielski #include <vector>
32*b1cdbd2cSJim Jagielski #define INCLUDED_VECTOR
33*b1cdbd2cSJim Jagielski #endif
34*b1cdbd2cSJim Jagielski 
35*b1cdbd2cSJim Jagielski class ElementMark;
36*b1cdbd2cSJim Jagielski class ElementCollector;
37*b1cdbd2cSJim Jagielski 
38*b1cdbd2cSJim Jagielski class BufferNode
39*b1cdbd2cSJim Jagielski /****** buffernode.hxx/CLASS BufferNode ***************************************
40*b1cdbd2cSJim Jagielski  *
41*b1cdbd2cSJim Jagielski  *   NAME
42*b1cdbd2cSJim Jagielski  *	BufferNode -- Class to maintain the tree of bufferred elements
43*b1cdbd2cSJim Jagielski  *
44*b1cdbd2cSJim Jagielski  *   FUNCTION
45*b1cdbd2cSJim Jagielski  *	One BufferNode object represents a bufferred element in the document
46*b1cdbd2cSJim Jagielski  *	wrapper component.
47*b1cdbd2cSJim Jagielski  *	All BufferNode objects construct a tree which has the same structure
48*b1cdbd2cSJim Jagielski  *	of all bufferred elements. That is to say, if one bufferred element is
49*b1cdbd2cSJim Jagielski  *	an ancestor of another bufferred element, then the corresponding
50*b1cdbd2cSJim Jagielski  *	BufferNode objects are also in ancestor/descendant relationship.
51*b1cdbd2cSJim Jagielski  *	This class is used to manipulate the tree of bufferred elements.
52*b1cdbd2cSJim Jagielski  *
53*b1cdbd2cSJim Jagielski  *   HISTORY
54*b1cdbd2cSJim Jagielski  *	05.01.2004 -	implemented
55*b1cdbd2cSJim Jagielski  *
56*b1cdbd2cSJim Jagielski  *   AUTHOR
57*b1cdbd2cSJim Jagielski  *	Michael Mi
58*b1cdbd2cSJim Jagielski  *	Email: michael.mi@sun.com
59*b1cdbd2cSJim Jagielski  ******************************************************************************/
60*b1cdbd2cSJim Jagielski {
61*b1cdbd2cSJim Jagielski private:
62*b1cdbd2cSJim Jagielski 	/* the parent BufferNode */
63*b1cdbd2cSJim Jagielski 	BufferNode* m_pParent;
64*b1cdbd2cSJim Jagielski 
65*b1cdbd2cSJim Jagielski 	/* all child BufferNodes */
66*b1cdbd2cSJim Jagielski 	std::vector< const BufferNode* > m_vChildren;
67*b1cdbd2cSJim Jagielski 
68*b1cdbd2cSJim Jagielski 	/* all ElementCollector holding this BufferNode */
69*b1cdbd2cSJim Jagielski 	std::vector< const ElementCollector* > m_vElementCollectors;
70*b1cdbd2cSJim Jagielski 
71*b1cdbd2cSJim Jagielski 	/*
72*b1cdbd2cSJim Jagielski 	 * the blocker holding this BufferNode, one BufferNode can have one
73*b1cdbd2cSJim Jagielski 	 * blocker at most
74*b1cdbd2cSJim Jagielski 	 */
75*b1cdbd2cSJim Jagielski 	ElementMark* m_pBlocker;
76*b1cdbd2cSJim Jagielski 
77*b1cdbd2cSJim Jagielski 	/*
78*b1cdbd2cSJim Jagielski 	 * whether the element has completely bufferred by the document wrapper
79*b1cdbd2cSJim Jagielski 	 * component
80*b1cdbd2cSJim Jagielski 	 */
81*b1cdbd2cSJim Jagielski 	bool m_bAllReceived;
82*b1cdbd2cSJim Jagielski 
83*b1cdbd2cSJim Jagielski 	/* the XMLElementWrapper of the bufferred element */
84*b1cdbd2cSJim Jagielski 	com::sun::star::uno::Reference<
85*b1cdbd2cSJim Jagielski 		com::sun::star::xml::wrapper::XXMLElementWrapper > m_xXMLElement;
86*b1cdbd2cSJim Jagielski 
87*b1cdbd2cSJim Jagielski private:
88*b1cdbd2cSJim Jagielski 	bool isECInSubTreeIncluded(sal_Int32 nIgnoredSecurityId) const;
89*b1cdbd2cSJim Jagielski 	bool isECOfBeforeModifyInAncestorIncluded(sal_Int32 nIgnoredSecurityId) const;
90*b1cdbd2cSJim Jagielski 	bool isBlockerInSubTreeIncluded(sal_Int32 nIgnoredSecurityId) const;
91*b1cdbd2cSJim Jagielski 	const BufferNode* getNextChild(const BufferNode* pChild) const;
92*b1cdbd2cSJim Jagielski 
93*b1cdbd2cSJim Jagielski public:
94*b1cdbd2cSJim Jagielski 	explicit BufferNode(
95*b1cdbd2cSJim Jagielski 		const com::sun::star::uno::Reference<
96*b1cdbd2cSJim Jagielski 			com::sun::star::xml::wrapper::XXMLElementWrapper >& xXMLElement);
~BufferNode()97*b1cdbd2cSJim Jagielski 	virtual ~BufferNode() {};
98*b1cdbd2cSJim Jagielski 
99*b1cdbd2cSJim Jagielski 	bool isECOfBeforeModifyIncluded(sal_Int32 nIgnoredSecurityId) const;
100*b1cdbd2cSJim Jagielski         void setReceivedAll();
101*b1cdbd2cSJim Jagielski         bool isAllReceived() const;
102*b1cdbd2cSJim Jagielski 	void addElementCollector(const ElementCollector* pElementCollector);
103*b1cdbd2cSJim Jagielski 	void removeElementCollector(const ElementCollector* pElementCollector);
104*b1cdbd2cSJim Jagielski 	ElementMark* getBlocker() const;
105*b1cdbd2cSJim Jagielski 	void setBlocker(const ElementMark* pBlocker);
106*b1cdbd2cSJim Jagielski 	rtl::OUString printChildren() const;
107*b1cdbd2cSJim Jagielski 	bool hasAnything() const;
108*b1cdbd2cSJim Jagielski 	bool hasChildren() const;
109*b1cdbd2cSJim Jagielski 	std::vector< const BufferNode* >* getChildren() const;
110*b1cdbd2cSJim Jagielski 	const BufferNode* getFirstChild() const;
111*b1cdbd2cSJim Jagielski 	void addChild(const BufferNode* pChild, sal_Int32 nPosition);
112*b1cdbd2cSJim Jagielski 	void addChild(const BufferNode* pChild);
113*b1cdbd2cSJim Jagielski 	void removeChild(const BufferNode* pChild);
114*b1cdbd2cSJim Jagielski 	sal_Int32 indexOfChild(const BufferNode* pChild) const;
115*b1cdbd2cSJim Jagielski 	const BufferNode* childAt(sal_Int32 nIndex) const;
116*b1cdbd2cSJim Jagielski 	const BufferNode* getParent() const;
117*b1cdbd2cSJim Jagielski 	void setParent(const BufferNode* pParent);
118*b1cdbd2cSJim Jagielski 	const BufferNode* getNextSibling() const;
119*b1cdbd2cSJim Jagielski 	const BufferNode* isAncestor(const BufferNode* pDescendant) const;
120*b1cdbd2cSJim Jagielski 	bool isPrevious(const BufferNode* pFollowing) const;
121*b1cdbd2cSJim Jagielski 	const BufferNode* getNextNodeByTreeOrder() const;
122*b1cdbd2cSJim Jagielski 	com::sun::star::uno::Reference<
123*b1cdbd2cSJim Jagielski 		com::sun::star::xml::wrapper::XXMLElementWrapper > getXMLElement() const;
124*b1cdbd2cSJim Jagielski 	void setXMLElement(const com::sun::star::uno::Reference<
125*b1cdbd2cSJim Jagielski 		com::sun::star::xml::wrapper::XXMLElementWrapper >& xXMLElement);
126*b1cdbd2cSJim Jagielski 	void notifyBranch();
127*b1cdbd2cSJim Jagielski 	void notifyAncestor();
128*b1cdbd2cSJim Jagielski 	void elementCollectorNotify();
129*b1cdbd2cSJim Jagielski 	void freeAllChildren();
130*b1cdbd2cSJim Jagielski };
131*b1cdbd2cSJim Jagielski 
132*b1cdbd2cSJim Jagielski #endif
133*b1cdbd2cSJim Jagielski 
134