xref: /AOO41X/main/package/source/xstor/ohierarchyholder.hxx (revision f319bb99b6b251a37b98027a84e8048ce3778b1f)
1*f319bb99SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f319bb99SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f319bb99SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f319bb99SAndrew Rist  * distributed with this work for additional information
6*f319bb99SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f319bb99SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f319bb99SAndrew Rist  * "License"); you may not use this file except in compliance
9*f319bb99SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f319bb99SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f319bb99SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f319bb99SAndrew Rist  * software distributed under the License is distributed on an
15*f319bb99SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f319bb99SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f319bb99SAndrew Rist  * specific language governing permissions and limitations
18*f319bb99SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f319bb99SAndrew Rist  *************************************************************/
21*f319bb99SAndrew Rist 
22*f319bb99SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _OHIERARCHYHOLDER_HXX_
25cdf0e10cSrcweir #define _OHIERARCHYHOLDER_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp>
28cdf0e10cSrcweir #include <com/sun/star/embed/XTransactionListener.hpp>
29cdf0e10cSrcweir #include <com/sun/star/embed/XExtendedStorageStream.hpp>
30cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <rtl/ref.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <hash_map>
37cdf0e10cSrcweir #include <list>
38cdf0e10cSrcweir #include <vector>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir struct OHierarchyElement_Impl;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir struct eqFunc
43cdf0e10cSrcweir {
operator ()eqFunc44cdf0e10cSrcweir 	sal_Bool operator()( const rtl::OUString &r1,
45cdf0e10cSrcweir 				    	 const rtl::OUString &r2) const
46cdf0e10cSrcweir 	{
47cdf0e10cSrcweir 		return r1 == r2;
48cdf0e10cSrcweir 	}
49cdf0e10cSrcweir };
50cdf0e10cSrcweir typedef ::std::hash_map< ::rtl::OUString,
51cdf0e10cSrcweir 						 ::rtl::Reference< OHierarchyElement_Impl >,
52cdf0e10cSrcweir 						 ::rtl::OUStringHash,
53cdf0e10cSrcweir 						 eqFunc > OHierarchyElementList_Impl;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir typedef ::std::vector< ::rtl::OUString > OStringList_Impl;
56cdf0e10cSrcweir typedef ::std::list< ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XExtendedStorageStream > >
57cdf0e10cSrcweir 						OWeakStorRefList_Impl;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir struct OHierarchyElement_Impl : public cppu::WeakImplHelper1< ::com::sun::star::embed::XTransactionListener >
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	::osl::Mutex m_aMutex;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	::rtl::Reference< OHierarchyElement_Impl > m_rParent;
64cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xOwnStorage;
65cdf0e10cSrcweir 	::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakOwnStorage;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	OHierarchyElementList_Impl m_aChildren;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	OWeakStorRefList_Impl m_aOpenStreams;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir public:
OHierarchyElement_ImplOHierarchyElement_Impl72cdf0e10cSrcweir 	OHierarchyElement_Impl( OHierarchyElement_Impl* pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
73cdf0e10cSrcweir 	: m_rParent( pParent )
74cdf0e10cSrcweir 	, m_xOwnStorage( xStorage )
75cdf0e10cSrcweir 	{}
76cdf0e10cSrcweir 
OHierarchyElement_ImplOHierarchyElement_Impl77cdf0e10cSrcweir 	OHierarchyElement_Impl( const ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage >& xWeakStorage )
78cdf0e10cSrcweir 	: m_rParent( NULL )
79cdf0e10cSrcweir 	, m_xWeakOwnStorage( xWeakStorage )
80cdf0e10cSrcweir 	{}
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	void Commit();
83cdf0e10cSrcweir 
SetParentOHierarchyElement_Impl84cdf0e10cSrcweir 	void SetParent( const ::rtl::Reference< OHierarchyElement_Impl >& rParent ) { m_rParent = rParent; }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	void TestForClosing();
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	void RemoveElement( const ::rtl::Reference< OHierarchyElement_Impl >& aRef );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream >
91cdf0e10cSrcweir         GetStreamHierarchically( sal_Int32 nStorageMode,
92cdf0e10cSrcweir                                 OStringList_Impl& aPath,
93cdf0e10cSrcweir                                 sal_Int32 nStreamMode,
94cdf0e10cSrcweir                                 const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	void RemoveStreamHierarchically( OStringList_Impl& aListPath );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	// XEventListener
99cdf0e10cSrcweir     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source )
100cdf0e10cSrcweir 		throw (::com::sun::star::uno::RuntimeException);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	// XTransactionListener
104cdf0e10cSrcweir     virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent )
105cdf0e10cSrcweir 		throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
106cdf0e10cSrcweir     virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent )
107cdf0e10cSrcweir 		throw (::com::sun::star::uno::RuntimeException);
108cdf0e10cSrcweir     virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent )
109cdf0e10cSrcweir 		throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
110cdf0e10cSrcweir     virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent )
111cdf0e10cSrcweir 		throw (::com::sun::star::uno::RuntimeException);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir };
114cdf0e10cSrcweir 
115cdf0e10cSrcweir class OHierarchyHolder_Impl : public ::cppu::OWeakObject
116cdf0e10cSrcweir {
117cdf0e10cSrcweir 	::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakOwnStorage;
118cdf0e10cSrcweir 	::rtl::Reference< OHierarchyElement_Impl > m_xChild;
119cdf0e10cSrcweir public:
OHierarchyHolder_Impl(const::com::sun::star::uno::Reference<::com::sun::star::embed::XStorage> & xOwnStorage)120cdf0e10cSrcweir 	OHierarchyHolder_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xOwnStorage )
121cdf0e10cSrcweir 	: m_xWeakOwnStorage( xOwnStorage )
122cdf0e10cSrcweir 	, m_xChild( new OHierarchyElement_Impl( ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage >( xOwnStorage ) ) )
123cdf0e10cSrcweir 	{}
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	static OStringList_Impl GetListPathFromString( const ::rtl::OUString& aPath );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream >
128cdf0e10cSrcweir         GetStreamHierarchically( sal_Int32 nStorageMode,
129cdf0e10cSrcweir                                 OStringList_Impl& aListPath,
130cdf0e10cSrcweir                                 sal_Int32 nStreamMode,
131cdf0e10cSrcweir                                 const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	void RemoveStreamHierarchically( OStringList_Impl& aListPath );
134cdf0e10cSrcweir };
135cdf0e10cSrcweir 
136cdf0e10cSrcweir #endif // _OHIERARCHYHOLDER
137cdf0e10cSrcweir 
138