1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _DYNAMIC_RESULTSET_WRAPPER_HXX 29 #define _DYNAMIC_RESULTSET_WRAPPER_HXX 30 31 #include <osl/mutex.hxx> 32 #include <osl/conditn.hxx> 33 #include <ucbhelper/macros.hxx> 34 #include <cppuhelper/weak.hxx> 35 #include <com/sun/star/lang/XTypeProvider.hpp> 36 #include <com/sun/star/lang/XServiceInfo.hpp> 37 #include <cppuhelper/interfacecontainer.hxx> 38 #include <com/sun/star/ucb/XDynamicResultSet.hpp> 39 #include <com/sun/star/ucb/XSourceInitialization.hpp> 40 41 #ifndef __com_sun_star_lang_DisposedException_idl__ 42 #include <com/sun/star/lang/DisposedException.hpp> 43 #endif 44 #include <com/sun/star/ucb/XDynamicResultSetListener.hpp> 45 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 46 47 //#define CACHED_CRS_STUB_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSetStub" 48 //#define CACHED_CRS_STUB_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetStubFactory" 49 50 //========================================================================= 51 52 class DynamicResultSetWrapperListener; 53 class DynamicResultSetWrapper 54 : public cppu::OWeakObject 55 , public com::sun::star::ucb::XDynamicResultSet 56 , public com::sun::star::ucb::XSourceInitialization 57 { 58 private: 59 //management of listeners 60 sal_Bool m_bDisposed; ///Dispose call ready. 61 sal_Bool m_bInDispose;///In dispose call 62 osl::Mutex m_aContainerMutex; 63 cppu::OInterfaceContainerHelper* 64 m_pDisposeEventListeners; 65 protected: 66 com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener > 67 m_xMyListenerImpl; 68 DynamicResultSetWrapperListener* 69 m_pMyListenerImpl; 70 71 com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > 72 m_xSMgr; 73 74 osl::Mutex m_aMutex; 75 sal_Bool m_bStatic; 76 sal_Bool m_bGotWelcome; 77 78 //different Interfaces from Origin: 79 com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSet > 80 m_xSource; 81 com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > 82 m_xSourceResultOne; 83 com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > 84 m_xSourceResultTwo; 85 //com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > 86 // m_xSourceResultCurrent; 87 //sal_Bool m_bUseOne; 88 // 89 com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > 90 m_xMyResultOne; 91 com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > 92 m_xMyResultTwo; 93 // 94 com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener > 95 m_xListener; 96 97 osl::Condition m_aSourceSet; 98 osl::Condition m_aListenerSet; 99 100 protected: 101 void SAL_CALL impl_init(); 102 void SAL_CALL impl_deinit(); 103 void SAL_CALL 104 impl_EnsureNotDisposed() 105 throw( com::sun::star::lang::DisposedException, 106 com::sun::star::uno::RuntimeException ); 107 108 virtual void SAL_CALL 109 impl_InitResultSetOne( const com::sun::star::uno::Reference< 110 com::sun::star::sdbc::XResultSet >& xResultSet ); 111 virtual void SAL_CALL 112 impl_InitResultSetTwo( const com::sun::star::uno::Reference< 113 com::sun::star::sdbc::XResultSet >& xResultSet ); 114 115 public: 116 117 DynamicResultSetWrapper( 118 com::sun::star::uno::Reference< 119 com::sun::star::ucb::XDynamicResultSet > xOrigin 120 , const com::sun::star::uno::Reference< 121 com::sun::star::lang::XMultiServiceFactory > & xSMgr ); 122 123 virtual ~DynamicResultSetWrapper(); 124 125 //----------------------------------------------------------------- 126 // XInterface 127 virtual com::sun::star::uno::Any SAL_CALL 128 queryInterface( const com::sun::star::uno::Type & rType ) 129 throw( com::sun::star::uno::RuntimeException ); 130 131 //----------------------------------------------------------------- 132 // XDynamicResultSet 133 virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > SAL_CALL 134 getStaticResultSet() 135 throw( com::sun::star::ucb::ListenerAlreadySetException 136 , com::sun::star::uno::RuntimeException ); 137 138 virtual void SAL_CALL 139 setListener( const com::sun::star::uno::Reference< 140 com::sun::star::ucb::XDynamicResultSetListener > & Listener ) 141 throw( com::sun::star::ucb::ListenerAlreadySetException 142 , com::sun::star::uno::RuntimeException ); 143 144 virtual void SAL_CALL 145 connectToCache( const com::sun::star::uno::Reference< 146 com::sun::star::ucb::XDynamicResultSet > & xCache ) 147 throw( com::sun::star::ucb::ListenerAlreadySetException 148 , com::sun::star::ucb::AlreadyInitializedException 149 , com::sun::star::ucb::ServiceNotFoundException 150 , com::sun::star::uno::RuntimeException ); 151 152 virtual sal_Int16 SAL_CALL 153 getCapabilities() throw( com::sun::star::uno::RuntimeException ); 154 155 //----------------------------------------------------------------- 156 // XComponent ( base of XDynamicResultSet ) 157 virtual void SAL_CALL 158 dispose() throw( com::sun::star::uno::RuntimeException ); 159 160 virtual void SAL_CALL 161 addEventListener( const com::sun::star::uno::Reference< 162 com::sun::star::lang::XEventListener >& Listener ) 163 throw( com::sun::star::uno::RuntimeException ); 164 165 virtual void SAL_CALL 166 removeEventListener( const com::sun::star::uno::Reference< 167 com::sun::star::lang::XEventListener >& Listener ) 168 throw( com::sun::star::uno::RuntimeException ); 169 170 //----------------------------------------------------------------- 171 // XSourceInitialization 172 173 virtual void SAL_CALL 174 setSource( const com::sun::star::uno::Reference< 175 com::sun::star::uno::XInterface > & Source ) 176 throw( com::sun::star::ucb::AlreadyInitializedException 177 , com::sun::star::uno::RuntimeException ); 178 179 //----------------------------------------------------------------- 180 // own methods: 181 virtual void SAL_CALL 182 impl_disposing( const com::sun::star::lang::EventObject& Source ) 183 throw( com::sun::star::uno::RuntimeException ); 184 185 virtual void SAL_CALL 186 impl_notify( const ::com::sun::star::ucb::ListEvent& Changes ) 187 throw( com::sun::star::uno::RuntimeException ); 188 }; 189 190 //========================================================================= 191 192 class DynamicResultSetWrapperListener 193 : public cppu::OWeakObject 194 , public com::sun::star::ucb::XDynamicResultSetListener 195 { 196 protected: 197 DynamicResultSetWrapper* m_pOwner; 198 osl::Mutex m_aMutex; 199 200 public: 201 DynamicResultSetWrapperListener( DynamicResultSetWrapper* pOwner ); 202 203 virtual ~DynamicResultSetWrapperListener(); 204 205 //----------------------------------------------------------------- 206 // XInterface 207 //----------------------------------------------------------------- 208 XINTERFACE_DECL() 209 210 //----------------------------------------------------------------- 211 // XEventListener ( base of XDynamicResultSetListener ) 212 //----------------------------------------------------------------- 213 virtual void SAL_CALL 214 disposing( const com::sun::star::lang::EventObject& Source ) 215 throw( com::sun::star::uno::RuntimeException ); 216 //----------------------------------------------------------------- 217 // XDynamicResultSetListener 218 virtual void SAL_CALL 219 notify( const ::com::sun::star::ucb::ListEvent& Changes ) 220 throw( com::sun::star::uno::RuntimeException ); 221 222 //----------------------------------------------------------------- 223 // own methods: 224 void SAL_CALL impl_OwnerDies(); 225 }; 226 227 228 #endif 229 230