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