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 _DYNAMIC_RESULTSET_WRAPPER_HXX
25 #define _DYNAMIC_RESULTSET_WRAPPER_HXX
26 
27 #include <osl/mutex.hxx>
28 #include <osl/conditn.hxx>
29 #include <ucbhelper/macros.hxx>
30 #include <cppuhelper/weak.hxx>
31 #include <com/sun/star/lang/XTypeProvider.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <cppuhelper/interfacecontainer.hxx>
34 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
35 #include <com/sun/star/ucb/XSourceInitialization.hpp>
36 
37 #ifndef __com_sun_star_lang_DisposedException_idl__
38 #include <com/sun/star/lang/DisposedException.hpp>
39 #endif
40 #include <com/sun/star/ucb/XDynamicResultSetListener.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 
43 //#define CACHED_CRS_STUB_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSetStub"
44 //#define CACHED_CRS_STUB_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetStubFactory"
45 
46 //=========================================================================
47 
48 class DynamicResultSetWrapperListener;
49 class DynamicResultSetWrapper
50 				: public cppu::OWeakObject
51 				, public com::sun::star::ucb::XDynamicResultSet
52 				, public com::sun::star::ucb::XSourceInitialization
53 {
54 private:
55 	//management of listeners
56 	sal_Bool				m_bDisposed; ///Dispose call ready.
57 	sal_Bool				m_bInDispose;///In dispose call
58 	osl::Mutex				m_aContainerMutex;
59 	cppu::OInterfaceContainerHelper*
60 							m_pDisposeEventListeners;
61 protected:
62 	com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener >
63 							m_xMyListenerImpl;
64 	DynamicResultSetWrapperListener*
65 							m_pMyListenerImpl;
66 
67 	com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
68 							m_xSMgr;
69 
70 	osl::Mutex				m_aMutex;
71 	sal_Bool				m_bStatic;
72 	sal_Bool				m_bGotWelcome;
73 
74 	//different Interfaces from Origin:
75 	com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSet >
76 							m_xSource;
77 	com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet >
78 							m_xSourceResultOne;
79 	com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet >
80 							m_xSourceResultTwo;
81 	//com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet >
82 	//						m_xSourceResultCurrent;
83 	//sal_Bool				m_bUseOne;
84 	//
85 	com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet >
86 							m_xMyResultOne;
87 	com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet >
88 							m_xMyResultTwo;
89 	//
90 	com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener >
91 							m_xListener;
92 
93 	osl::Condition			m_aSourceSet;
94 	osl::Condition			m_aListenerSet;
95 
96 protected:
97 	void SAL_CALL impl_init();
98 	void SAL_CALL impl_deinit();
99 	void SAL_CALL
100 	impl_EnsureNotDisposed()
101 		throw( com::sun::star::lang::DisposedException,
102 			   com::sun::star::uno::RuntimeException );
103 
104 	virtual void SAL_CALL
105 	impl_InitResultSetOne( const com::sun::star::uno::Reference<
106 				com::sun::star::sdbc::XResultSet >& xResultSet );
107 	virtual void SAL_CALL
108 	impl_InitResultSetTwo( const com::sun::star::uno::Reference<
109 				com::sun::star::sdbc::XResultSet >& xResultSet );
110 
111 public:
112 
113 	DynamicResultSetWrapper(
114 		com::sun::star::uno::Reference<
115 						com::sun::star::ucb::XDynamicResultSet > xOrigin
116 		, const com::sun::star::uno::Reference<
117 						com::sun::star::lang::XMultiServiceFactory > & xSMgr );
118 
119 	virtual ~DynamicResultSetWrapper();
120 
121 	//-----------------------------------------------------------------
122 	// XInterface
123 	virtual com::sun::star::uno::Any SAL_CALL
124 	queryInterface( const com::sun::star::uno::Type & rType )
125 		throw( com::sun::star::uno::RuntimeException );
126 
127 	//-----------------------------------------------------------------
128     // XDynamicResultSet
129 	virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > SAL_CALL
130 	getStaticResultSet()
131 		throw( com::sun::star::ucb::ListenerAlreadySetException
132 		, com::sun::star::uno::RuntimeException );
133 
134 	virtual void SAL_CALL
135 	setListener( const com::sun::star::uno::Reference<
136 		com::sun::star::ucb::XDynamicResultSetListener > & Listener )
137 		throw( com::sun::star::ucb::ListenerAlreadySetException
138 			, com::sun::star::uno::RuntimeException );
139 
140 	virtual void SAL_CALL
141 	connectToCache( const com::sun::star::uno::Reference<
142 		com::sun::star::ucb::XDynamicResultSet > & xCache )
143 		throw( com::sun::star::ucb::ListenerAlreadySetException
144 			, com::sun::star::ucb::AlreadyInitializedException
145 			, com::sun::star::ucb::ServiceNotFoundException
146 			, com::sun::star::uno::RuntimeException );
147 
148 	virtual sal_Int16 SAL_CALL
149 	getCapabilities() throw( com::sun::star::uno::RuntimeException );
150 
151 	//-----------------------------------------------------------------
152 	// XComponent ( base of XDynamicResultSet )
153 	virtual void SAL_CALL
154 	dispose() throw( com::sun::star::uno::RuntimeException );
155 
156     virtual void SAL_CALL
157 	addEventListener( const com::sun::star::uno::Reference<
158 		com::sun::star::lang::XEventListener >& Listener )
159 			throw( com::sun::star::uno::RuntimeException );
160 
161     virtual void SAL_CALL
162 	removeEventListener( const com::sun::star::uno::Reference<
163 		com::sun::star::lang::XEventListener >& Listener )
164 			throw( com::sun::star::uno::RuntimeException );
165 
166 	//-----------------------------------------------------------------
167     // XSourceInitialization
168 
169 	virtual void SAL_CALL
170 	setSource(	const com::sun::star::uno::Reference<
171 		com::sun::star::uno::XInterface > & Source )
172 		 throw( com::sun::star::ucb::AlreadyInitializedException
173 				, com::sun::star::uno::RuntimeException );
174 
175 	//-----------------------------------------------------------------
176 	// own methods:
177     virtual void SAL_CALL
178 	impl_disposing( const com::sun::star::lang::EventObject& Source )
179 		throw( com::sun::star::uno::RuntimeException );
180 
181 	virtual void SAL_CALL
182 	impl_notify( const ::com::sun::star::ucb::ListEvent& Changes )
183 		throw( com::sun::star::uno::RuntimeException );
184 };
185 
186 //=========================================================================
187 
188 class DynamicResultSetWrapperListener
189 				: public cppu::OWeakObject
190 				, public com::sun::star::ucb::XDynamicResultSetListener
191 {
192 protected:
193 	DynamicResultSetWrapper*	m_pOwner;
194 	osl::Mutex					m_aMutex;
195 
196 public:
197 	DynamicResultSetWrapperListener( DynamicResultSetWrapper* pOwner );
198 
199 	virtual ~DynamicResultSetWrapperListener();
200 
201 	//-----------------------------------------------------------------
202 	// XInterface
203 	//-----------------------------------------------------------------
204 	XINTERFACE_DECL()
205 
206 	//-----------------------------------------------------------------
207 	// XEventListener ( base of XDynamicResultSetListener )
208 	//-----------------------------------------------------------------
209     virtual void SAL_CALL
210 	disposing( const com::sun::star::lang::EventObject& Source )
211 		throw( com::sun::star::uno::RuntimeException );
212 	//-----------------------------------------------------------------
213 	// XDynamicResultSetListener
214     virtual void SAL_CALL
215 	notify( const ::com::sun::star::ucb::ListEvent& Changes )
216 		throw( com::sun::star::uno::RuntimeException );
217 
218 	//-----------------------------------------------------------------
219 	// own methods:
220 	void SAL_CALL impl_OwnerDies();
221 };
222 
223 
224 #endif
225 
226