1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_ucbhelper.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir /************************************************************************** 32*cdf0e10cSrcweir TODO 33*cdf0e10cSrcweir ************************************************************************** 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir - This implementation is far away from completion. It has no interface 36*cdf0e10cSrcweir for changes notifications etc. 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir *************************************************************************/ 39*cdf0e10cSrcweir #include <com/sun/star/ucb/ListActionType.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/ucb/XSourceInitialization.hpp> 43*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 44*cdf0e10cSrcweir #include <ucbhelper/resultsethelper.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include "osl/diagnose.h" 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir using namespace com::sun::star; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //========================================================================= 51*cdf0e10cSrcweir //========================================================================= 52*cdf0e10cSrcweir // 53*cdf0e10cSrcweir // ResultSetImplHelper Implementation. 54*cdf0e10cSrcweir // 55*cdf0e10cSrcweir //========================================================================= 56*cdf0e10cSrcweir //========================================================================= 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir namespace ucbhelper { 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir //========================================================================= 61*cdf0e10cSrcweir ResultSetImplHelper::ResultSetImplHelper( 62*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr ) 63*cdf0e10cSrcweir : m_pDisposeEventListeners( 0 ), 64*cdf0e10cSrcweir m_bStatic( sal_False ), 65*cdf0e10cSrcweir m_bInitDone( sal_False ), 66*cdf0e10cSrcweir m_xSMgr( rxSMgr ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //========================================================================= 71*cdf0e10cSrcweir ResultSetImplHelper::ResultSetImplHelper( 72*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr, 73*cdf0e10cSrcweir const com::sun::star::ucb::OpenCommandArgument2& rCommand ) 74*cdf0e10cSrcweir : m_pDisposeEventListeners( 0 ), 75*cdf0e10cSrcweir m_bStatic( sal_False ), 76*cdf0e10cSrcweir m_bInitDone( sal_False ), 77*cdf0e10cSrcweir m_aCommand( rCommand ), 78*cdf0e10cSrcweir m_xSMgr( rxSMgr ) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir //========================================================================= 83*cdf0e10cSrcweir // virtual 84*cdf0e10cSrcweir ResultSetImplHelper::~ResultSetImplHelper() 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir delete m_pDisposeEventListeners; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir //========================================================================= 90*cdf0e10cSrcweir // 91*cdf0e10cSrcweir // XInterface methods. 92*cdf0e10cSrcweir // 93*cdf0e10cSrcweir //========================================================================= 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir XINTERFACE_IMPL_4( ResultSetImplHelper, 96*cdf0e10cSrcweir lang::XTypeProvider, 97*cdf0e10cSrcweir lang::XServiceInfo, 98*cdf0e10cSrcweir lang::XComponent, /* base of XDynamicResultSet */ 99*cdf0e10cSrcweir com::sun::star::ucb::XDynamicResultSet ); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir //========================================================================= 102*cdf0e10cSrcweir // 103*cdf0e10cSrcweir // XTypeProvider methods. 104*cdf0e10cSrcweir // 105*cdf0e10cSrcweir //========================================================================= 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( ResultSetImplHelper, 108*cdf0e10cSrcweir lang::XTypeProvider, 109*cdf0e10cSrcweir lang::XServiceInfo, 110*cdf0e10cSrcweir com::sun::star::ucb::XDynamicResultSet ); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir //========================================================================= 113*cdf0e10cSrcweir // 114*cdf0e10cSrcweir // XServiceInfo methods. 115*cdf0e10cSrcweir // 116*cdf0e10cSrcweir //========================================================================= 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir XSERVICEINFO_NOFACTORY_IMPL_1( ResultSetImplHelper, 119*cdf0e10cSrcweir rtl::OUString::createFromAscii( 120*cdf0e10cSrcweir "ResultSetImplHelper" ), 121*cdf0e10cSrcweir rtl::OUString::createFromAscii( 122*cdf0e10cSrcweir DYNAMICRESULTSET_SERVICE_NAME ) ); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir //========================================================================= 125*cdf0e10cSrcweir // 126*cdf0e10cSrcweir // XComponent methods. 127*cdf0e10cSrcweir // 128*cdf0e10cSrcweir //========================================================================= 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir // virtual 131*cdf0e10cSrcweir void SAL_CALL ResultSetImplHelper::dispose() 132*cdf0e10cSrcweir throw( uno::RuntimeException ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir lang::EventObject aEvt; 139*cdf0e10cSrcweir aEvt.Source = static_cast< lang::XComponent * >( this ); 140*cdf0e10cSrcweir m_pDisposeEventListeners->disposeAndClear( aEvt ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir //========================================================================= 145*cdf0e10cSrcweir // virtual 146*cdf0e10cSrcweir void SAL_CALL ResultSetImplHelper::addEventListener( 147*cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& Listener ) 148*cdf0e10cSrcweir throw( uno::RuntimeException ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir if ( !m_pDisposeEventListeners ) 153*cdf0e10cSrcweir m_pDisposeEventListeners 154*cdf0e10cSrcweir = new cppu::OInterfaceContainerHelper( m_aMutex ); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir m_pDisposeEventListeners->addInterface( Listener ); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir //========================================================================= 160*cdf0e10cSrcweir // virtual 161*cdf0e10cSrcweir void SAL_CALL ResultSetImplHelper::removeEventListener( 162*cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& Listener ) 163*cdf0e10cSrcweir throw( uno::RuntimeException ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir if ( m_pDisposeEventListeners ) 168*cdf0e10cSrcweir m_pDisposeEventListeners->removeInterface( Listener ); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir //========================================================================= 172*cdf0e10cSrcweir // 173*cdf0e10cSrcweir // XDynamicResultSet methods. 174*cdf0e10cSrcweir // 175*cdf0e10cSrcweir //========================================================================= 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir // virtual 178*cdf0e10cSrcweir uno::Reference< sdbc::XResultSet > SAL_CALL 179*cdf0e10cSrcweir ResultSetImplHelper::getStaticResultSet() 180*cdf0e10cSrcweir throw( com::sun::star::ucb::ListenerAlreadySetException, 181*cdf0e10cSrcweir uno::RuntimeException ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir if ( m_xListener.is() ) 186*cdf0e10cSrcweir throw com::sun::star::ucb::ListenerAlreadySetException(); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir init( sal_True ); 189*cdf0e10cSrcweir return m_xResultSet1; 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir //========================================================================= 193*cdf0e10cSrcweir // virtual 194*cdf0e10cSrcweir void SAL_CALL ResultSetImplHelper::setListener( 195*cdf0e10cSrcweir const uno::Reference< com::sun::star::ucb::XDynamicResultSetListener >& 196*cdf0e10cSrcweir Listener ) 197*cdf0e10cSrcweir throw( com::sun::star::ucb::ListenerAlreadySetException, 198*cdf0e10cSrcweir uno::RuntimeException ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir osl::ClearableMutexGuard aGuard( m_aMutex ); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir if ( m_bStatic || m_xListener.is() ) 203*cdf0e10cSrcweir throw com::sun::star::ucb::ListenerAlreadySetException(); 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir m_xListener = Listener; 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 208*cdf0e10cSrcweir // Create "welcome event" and send it to listener. 209*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir // Note: We only have the implementation for a static result set at the 212*cdf0e10cSrcweir // moment (src590). The dynamic result sets passed to the listener 213*cdf0e10cSrcweir // are a fake. This implementation will never call "notify" at the 214*cdf0e10cSrcweir // listener to propagate any changes!!! 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir init( sal_False ); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir uno::Any aInfo; 219*cdf0e10cSrcweir aInfo <<= com::sun::star::ucb::WelcomeDynamicResultSetStruct( 220*cdf0e10cSrcweir m_xResultSet1 /* "old" */, 221*cdf0e10cSrcweir m_xResultSet2 /* "new" */ ); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir uno::Sequence< com::sun::star::ucb::ListAction > aActions( 1 ); 224*cdf0e10cSrcweir aActions.getArray()[ 0 ] 225*cdf0e10cSrcweir = com::sun::star::ucb::ListAction( 226*cdf0e10cSrcweir 0, // Position; not used 227*cdf0e10cSrcweir 0, // Count; not used 228*cdf0e10cSrcweir com::sun::star::ucb::ListActionType::WELCOME, 229*cdf0e10cSrcweir aInfo ); 230*cdf0e10cSrcweir aGuard.clear(); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir Listener->notify( 233*cdf0e10cSrcweir com::sun::star::ucb::ListEvent( 234*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), aActions ) ); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir //========================================================================= 238*cdf0e10cSrcweir // virtual 239*cdf0e10cSrcweir sal_Int16 SAL_CALL ResultSetImplHelper::getCapabilities() 240*cdf0e10cSrcweir throw( uno::RuntimeException ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir // ! com::sun::star::ucb::ContentResultSetCapability::SORTED 243*cdf0e10cSrcweir return 0; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir //========================================================================= 247*cdf0e10cSrcweir // virtual 248*cdf0e10cSrcweir void SAL_CALL ResultSetImplHelper::connectToCache( 249*cdf0e10cSrcweir const uno::Reference< com::sun::star::ucb::XDynamicResultSet > & 250*cdf0e10cSrcweir xCache ) 251*cdf0e10cSrcweir throw( com::sun::star::ucb::ListenerAlreadySetException, 252*cdf0e10cSrcweir com::sun::star::ucb::AlreadyInitializedException, 253*cdf0e10cSrcweir com::sun::star::ucb::ServiceNotFoundException, 254*cdf0e10cSrcweir uno::RuntimeException ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir if ( m_xListener.is() ) 257*cdf0e10cSrcweir throw com::sun::star::ucb::ListenerAlreadySetException(); 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir if ( m_bStatic ) 260*cdf0e10cSrcweir throw com::sun::star::ucb::ListenerAlreadySetException(); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XSourceInitialization > 263*cdf0e10cSrcweir xTarget( xCache, uno::UNO_QUERY ); 264*cdf0e10cSrcweir if ( xTarget.is() ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir uno::Reference< 267*cdf0e10cSrcweir com::sun::star::ucb::XCachedDynamicResultSetStubFactory > 268*cdf0e10cSrcweir xStubFactory; 269*cdf0e10cSrcweir try 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir xStubFactory 272*cdf0e10cSrcweir = uno::Reference< 273*cdf0e10cSrcweir com::sun::star::ucb::XCachedDynamicResultSetStubFactory >( 274*cdf0e10cSrcweir m_xSMgr->createInstance( 275*cdf0e10cSrcweir rtl::OUString::createFromAscii( 276*cdf0e10cSrcweir "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ) ), 277*cdf0e10cSrcweir uno::UNO_QUERY ); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir catch ( uno::Exception const & ) 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir if ( xStubFactory.is() ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir xStubFactory->connectToCache( 286*cdf0e10cSrcweir this, xCache, m_aCommand.SortingInfo, 0 ); 287*cdf0e10cSrcweir return; 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir throw com::sun::star::ucb::ServiceNotFoundException(); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir //========================================================================= 294*cdf0e10cSrcweir // 295*cdf0e10cSrcweir // Non-interface methods. 296*cdf0e10cSrcweir // 297*cdf0e10cSrcweir //========================================================================= 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir void ResultSetImplHelper::init( sal_Bool bStatic ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir if ( !m_bInitDone ) 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir if ( bStatic ) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir // virtual... derived class fills m_xResultSet1 308*cdf0e10cSrcweir initStatic(); 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir OSL_ENSURE( m_xResultSet1.is(), 311*cdf0e10cSrcweir "ResultSetImplHelper::init - No 1st result set!" ); 312*cdf0e10cSrcweir m_bStatic = sal_True; 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir else 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir // virtual... derived class fills m_xResultSet1 and m_xResultSet2 317*cdf0e10cSrcweir initDynamic(); 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir OSL_ENSURE( m_xResultSet1.is(), 320*cdf0e10cSrcweir "ResultSetImplHelper::init - No 1st result set!" ); 321*cdf0e10cSrcweir OSL_ENSURE( m_xResultSet2.is(), 322*cdf0e10cSrcweir "ResultSetImplHelper::init - No 2nd result set!" ); 323*cdf0e10cSrcweir m_bStatic = sal_False; 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir m_bInitDone = sal_True; 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir } // namespace ucbhelper 330