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_ucb.hxx" 30*cdf0e10cSrcweir #include <osl/diagnose.h> 31*cdf0e10cSrcweir #include "provprox.hxx" 32*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir using namespace rtl; 35*cdf0e10cSrcweir using namespace com::sun::star::lang; 36*cdf0e10cSrcweir using namespace com::sun::star::ucb; 37*cdf0e10cSrcweir using namespace com::sun::star::uno; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir //========================================================================= 40*cdf0e10cSrcweir //========================================================================= 41*cdf0e10cSrcweir // 42*cdf0e10cSrcweir // UcbContentProviderProxyFactory Implementation. 43*cdf0e10cSrcweir // 44*cdf0e10cSrcweir //========================================================================= 45*cdf0e10cSrcweir //========================================================================= 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir UcbContentProviderProxyFactory::UcbContentProviderProxyFactory( 48*cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rxSMgr ) 49*cdf0e10cSrcweir : m_xSMgr( rxSMgr ) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //========================================================================= 54*cdf0e10cSrcweir // virtual 55*cdf0e10cSrcweir UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory() 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir //========================================================================= 60*cdf0e10cSrcweir // 61*cdf0e10cSrcweir // XInterface methods. 62*cdf0e10cSrcweir // 63*cdf0e10cSrcweir //========================================================================= 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir XINTERFACE_IMPL_3( UcbContentProviderProxyFactory, 66*cdf0e10cSrcweir XTypeProvider, 67*cdf0e10cSrcweir XServiceInfo, 68*cdf0e10cSrcweir XContentProviderFactory ); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //========================================================================= 71*cdf0e10cSrcweir // 72*cdf0e10cSrcweir // XTypeProvider methods. 73*cdf0e10cSrcweir // 74*cdf0e10cSrcweir //========================================================================= 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( UcbContentProviderProxyFactory, 77*cdf0e10cSrcweir XTypeProvider, 78*cdf0e10cSrcweir XServiceInfo, 79*cdf0e10cSrcweir XContentProviderFactory ); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir //========================================================================= 82*cdf0e10cSrcweir // 83*cdf0e10cSrcweir // XServiceInfo methods. 84*cdf0e10cSrcweir // 85*cdf0e10cSrcweir //========================================================================= 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir XSERVICEINFO_IMPL_1( UcbContentProviderProxyFactory, 88*cdf0e10cSrcweir OUString::createFromAscii( 89*cdf0e10cSrcweir "com.sun.star.comp.ucb.UcbContentProviderProxyFactory" ), 90*cdf0e10cSrcweir OUString::createFromAscii( 91*cdf0e10cSrcweir PROVIDER_FACTORY_SERVICE_NAME ) ); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir //========================================================================= 94*cdf0e10cSrcweir // 95*cdf0e10cSrcweir // Service factory implementation. 96*cdf0e10cSrcweir // 97*cdf0e10cSrcweir //========================================================================= 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbContentProviderProxyFactory ); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir //========================================================================= 102*cdf0e10cSrcweir // 103*cdf0e10cSrcweir // XContentProviderFactory methods. 104*cdf0e10cSrcweir // 105*cdf0e10cSrcweir //========================================================================= 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // virtual 108*cdf0e10cSrcweir Reference< XContentProvider > SAL_CALL 109*cdf0e10cSrcweir UcbContentProviderProxyFactory::createContentProvider( 110*cdf0e10cSrcweir const OUString& Service ) 111*cdf0e10cSrcweir throw( RuntimeException ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir return Reference< XContentProvider >( 114*cdf0e10cSrcweir new UcbContentProviderProxy( m_xSMgr, Service ) ); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir //========================================================================= 118*cdf0e10cSrcweir //========================================================================= 119*cdf0e10cSrcweir // 120*cdf0e10cSrcweir // UcbContentProviderProxy Implementation. 121*cdf0e10cSrcweir // 122*cdf0e10cSrcweir //========================================================================= 123*cdf0e10cSrcweir //========================================================================= 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir UcbContentProviderProxy::UcbContentProviderProxy( 126*cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rxSMgr, 127*cdf0e10cSrcweir const OUString& Service ) 128*cdf0e10cSrcweir : m_aService( Service ), 129*cdf0e10cSrcweir m_bReplace( sal_False ), 130*cdf0e10cSrcweir m_bRegister( sal_False ), 131*cdf0e10cSrcweir m_xSMgr( rxSMgr ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir //========================================================================= 136*cdf0e10cSrcweir // virtual 137*cdf0e10cSrcweir UcbContentProviderProxy::~UcbContentProviderProxy() 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir //========================================================================= 142*cdf0e10cSrcweir // 143*cdf0e10cSrcweir // XInterface methods. 144*cdf0e10cSrcweir // 145*cdf0e10cSrcweir //========================================================================= 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir XINTERFACE_COMMON_IMPL( UcbContentProviderProxy ); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir //============================================================================ 150*cdf0e10cSrcweir // virtual 151*cdf0e10cSrcweir Any SAL_CALL 152*cdf0e10cSrcweir UcbContentProviderProxy::queryInterface( const Type & rType ) 153*cdf0e10cSrcweir throw ( RuntimeException ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir Any aRet = cppu::queryInterface( rType, 156*cdf0e10cSrcweir static_cast< XTypeProvider * >( this ), 157*cdf0e10cSrcweir static_cast< XServiceInfo * >( this ), 158*cdf0e10cSrcweir static_cast< XContentProvider * >( this ), 159*cdf0e10cSrcweir static_cast< XParameterizedContentProvider * >( this ), 160*cdf0e10cSrcweir static_cast< XContentProviderSupplier * >( this ) ); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir if ( !aRet.hasValue() ) 163*cdf0e10cSrcweir aRet = OWeakObject::queryInterface( rType ); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir if ( !aRet.hasValue() ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir // Get original provider an forward the call... 168*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 169*cdf0e10cSrcweir Reference< XContentProvider > xProvider = getContentProvider(); 170*cdf0e10cSrcweir if ( xProvider.is() ) 171*cdf0e10cSrcweir aRet = xProvider->queryInterface( rType ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir return aRet; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir //========================================================================= 178*cdf0e10cSrcweir // 179*cdf0e10cSrcweir // XTypeProvider methods. 180*cdf0e10cSrcweir // 181*cdf0e10cSrcweir //========================================================================= 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy ); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir //========================================================================= 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir Sequence< Type > SAL_CALL UcbContentProviderProxy::getTypes() \ 188*cdf0e10cSrcweir throw( RuntimeException ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir // Get original provider an forward the call... 191*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 192*cdf0e10cSrcweir Reference< XTypeProvider > xProvider( getContentProvider(), UNO_QUERY ); 193*cdf0e10cSrcweir if ( xProvider.is() ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir return xProvider->getTypes(); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir else 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir static cppu::OTypeCollection collection( 200*cdf0e10cSrcweir CPPU_TYPE_REF( XTypeProvider ), 201*cdf0e10cSrcweir CPPU_TYPE_REF( XServiceInfo ), 202*cdf0e10cSrcweir CPPU_TYPE_REF( XContentProvider ), 203*cdf0e10cSrcweir CPPU_TYPE_REF( XParameterizedContentProvider ), 204*cdf0e10cSrcweir CPPU_TYPE_REF( XContentProviderSupplier ) ); 205*cdf0e10cSrcweir return collection.getTypes(); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir //========================================================================= 210*cdf0e10cSrcweir // 211*cdf0e10cSrcweir // XServiceInfo methods. 212*cdf0e10cSrcweir // 213*cdf0e10cSrcweir //========================================================================= 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir XSERVICEINFO_NOFACTORY_IMPL_1( UcbContentProviderProxy, 216*cdf0e10cSrcweir OUString::createFromAscii( 217*cdf0e10cSrcweir "com.sun.star.comp.ucb.UcbContentProviderProxy" ), 218*cdf0e10cSrcweir OUString::createFromAscii( 219*cdf0e10cSrcweir PROVIDER_PROXY_SERVICE_NAME ) ); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir //========================================================================= 222*cdf0e10cSrcweir // 223*cdf0e10cSrcweir // XContentProvider methods. 224*cdf0e10cSrcweir // 225*cdf0e10cSrcweir //========================================================================= 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir // virtual 228*cdf0e10cSrcweir Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent( 229*cdf0e10cSrcweir const Reference< XContentIdentifier >& Identifier ) 230*cdf0e10cSrcweir throw( IllegalIdentifierException, 231*cdf0e10cSrcweir RuntimeException ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir // Get original provider an forward the call... 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir Reference< XContentProvider > xProvider = getContentProvider(); 238*cdf0e10cSrcweir if ( xProvider.is() ) 239*cdf0e10cSrcweir return xProvider->queryContent( Identifier ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir return Reference< XContent >(); 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir //========================================================================= 245*cdf0e10cSrcweir // virtual 246*cdf0e10cSrcweir sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds( 247*cdf0e10cSrcweir const Reference< XContentIdentifier >& Id1, 248*cdf0e10cSrcweir const Reference< XContentIdentifier >& Id2 ) 249*cdf0e10cSrcweir throw( RuntimeException ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir // Get original provider an forward the call... 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 254*cdf0e10cSrcweir Reference< XContentProvider > xProvider = getContentProvider(); 255*cdf0e10cSrcweir if ( xProvider.is() ) 256*cdf0e10cSrcweir return xProvider->compareContentIds( Id1, Id2 ); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir // OSL_ENSURE( sal_False, 259*cdf0e10cSrcweir // "UcbContentProviderProxy::compareContentIds - No provider!" ); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir // @@@ What else? 262*cdf0e10cSrcweir return 0; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir //========================================================================= 266*cdf0e10cSrcweir // 267*cdf0e10cSrcweir // XParameterizedContentProvider methods. 268*cdf0e10cSrcweir // 269*cdf0e10cSrcweir //========================================================================= 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir // virtual 272*cdf0e10cSrcweir Reference< XContentProvider > SAL_CALL 273*cdf0e10cSrcweir UcbContentProviderProxy::registerInstance( const OUString& Template, 274*cdf0e10cSrcweir const OUString& Arguments, 275*cdf0e10cSrcweir sal_Bool ReplaceExisting ) 276*cdf0e10cSrcweir throw( IllegalArgumentException, 277*cdf0e10cSrcweir RuntimeException ) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir // Just remember that this method was called ( and the params ). 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir if ( !m_bRegister ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir // m_xTargetProvider = 0; 286*cdf0e10cSrcweir m_aTemplate = Template; 287*cdf0e10cSrcweir m_aArguments = Arguments; 288*cdf0e10cSrcweir m_bReplace = ReplaceExisting; 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir m_bRegister = sal_True; 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir return this; 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir //========================================================================= 296*cdf0e10cSrcweir // virtual 297*cdf0e10cSrcweir Reference< XContentProvider > SAL_CALL 298*cdf0e10cSrcweir UcbContentProviderProxy::deregisterInstance( const OUString& Template, 299*cdf0e10cSrcweir const OUString& Arguments ) 300*cdf0e10cSrcweir throw( IllegalArgumentException, 301*cdf0e10cSrcweir RuntimeException ) 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir // registerInstance called at proxy and at original? 306*cdf0e10cSrcweir if ( m_bRegister && m_xTargetProvider.is() ) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir m_bRegister = sal_False; 309*cdf0e10cSrcweir m_xTargetProvider = 0; 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir Reference< XParameterizedContentProvider > 312*cdf0e10cSrcweir xParamProvider( m_xProvider, UNO_QUERY ); 313*cdf0e10cSrcweir if ( xParamProvider.is() ) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir try 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir xParamProvider->deregisterInstance( Template, Arguments ); 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir catch ( IllegalIdentifierException const & ) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir OSL_ENSURE( sal_False, 322*cdf0e10cSrcweir "UcbContentProviderProxy::deregisterInstance - " 323*cdf0e10cSrcweir "Caught IllegalIdentifierException!" ); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir return this; 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir //========================================================================= 332*cdf0e10cSrcweir // 333*cdf0e10cSrcweir // XContentProviderSupplier methods. 334*cdf0e10cSrcweir // 335*cdf0e10cSrcweir //========================================================================= 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir // virtual 338*cdf0e10cSrcweir Reference< XContentProvider > SAL_CALL 339*cdf0e10cSrcweir UcbContentProviderProxy::getContentProvider() 340*cdf0e10cSrcweir throw( RuntimeException ) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 343*cdf0e10cSrcweir if ( !m_xProvider.is() ) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir try 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir m_xProvider 348*cdf0e10cSrcweir = Reference< XContentProvider >( 349*cdf0e10cSrcweir m_xSMgr->createInstance( m_aService ), UNO_QUERY ); 350*cdf0e10cSrcweir if(m_aArguments.compareToAscii("NoConfig") == 0) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir Reference<XInitialization> xInit(m_xProvider,UNO_QUERY); 353*cdf0e10cSrcweir if(xInit.is()) { 354*cdf0e10cSrcweir Sequence<Any> aArgs(1); 355*cdf0e10cSrcweir aArgs[0] <<= m_aArguments; 356*cdf0e10cSrcweir xInit->initialize(aArgs); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir catch ( RuntimeException const & ) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir throw; 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir catch ( Exception const & ) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir // registerInstance called at proxy, but not yet at original? 369*cdf0e10cSrcweir if ( m_xProvider.is() && m_bRegister ) 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir Reference< XParameterizedContentProvider > 372*cdf0e10cSrcweir xParamProvider( m_xProvider, UNO_QUERY ); 373*cdf0e10cSrcweir if ( xParamProvider.is() ) 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir try 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir m_xTargetProvider 378*cdf0e10cSrcweir = xParamProvider->registerInstance( m_aTemplate, 379*cdf0e10cSrcweir m_aArguments, 380*cdf0e10cSrcweir m_bReplace ); 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir catch ( IllegalIdentifierException const & ) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir OSL_ENSURE( sal_False, 385*cdf0e10cSrcweir "UcbContentProviderProxy::getContentProvider - " 386*cdf0e10cSrcweir "Caught IllegalIdentifierException!" ); 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir OSL_ENSURE( m_xTargetProvider.is(), 390*cdf0e10cSrcweir "UcbContentProviderProxy::getContentProvider - " 391*cdf0e10cSrcweir "No provider!" ); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir if ( !m_xTargetProvider.is() ) 395*cdf0e10cSrcweir m_xTargetProvider = m_xProvider; 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir OSL_ENSURE( m_xProvider.is(), 399*cdf0e10cSrcweir "UcbContentProviderProxy::getContentProvider - No provider!" ); 400*cdf0e10cSrcweir return m_xTargetProvider; 401*cdf0e10cSrcweir } 402