2010-10-12 15:53:47 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-10-16 13:56:13 +00:00
/*************************************************************************
*
2008-04-10 13:38:15 +00:00
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
2000-10-16 13:56:13 +00:00
*
2010-02-12 15:01:35 +01:00
* Copyright 2000 , 2010 Oracle and / or its affiliates .
2000-10-16 13:56:13 +00:00
*
2008-04-10 13:38:15 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2000-10-16 13:56:13 +00:00
*
2008-04-10 13:38:15 +00:00
* This file is part of OpenOffice . org .
2000-10-16 13:56:13 +00:00
*
2008-04-10 13:38:15 +00:00
* OpenOffice . org is free software : you can redistribute it and / or modify
* it under the terms of the GNU Lesser General Public License version 3
* only , as published by the Free Software Foundation .
2000-10-16 13:56:13 +00:00
*
2008-04-10 13:38:15 +00:00
* OpenOffice . org is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Lesser General Public License version 3 for more details
* ( a copy is included in the LICENSE file that accompanied this code ) .
2000-10-16 13:56:13 +00:00
*
2008-04-10 13:38:15 +00:00
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice . org . If not , see
* < http : //www.openoffice.org/license.html>
* for a copy of the LGPLv3 License .
2000-10-16 13:56:13 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <osl/diagnose.h>
2011-10-06 23:30:09 +01:00
# include <osl/thread.h>
# include <rtl/strbuf.hxx>
2000-10-16 13:56:13 +00:00
# include "provprox.hxx"
2006-09-15 13:33:50 +00:00
# include <com/sun/star/lang/XInitialization.hpp>
2000-10-16 13:56:13 +00:00
using namespace com : : sun : : star : : lang ;
using namespace com : : sun : : star : : ucb ;
using namespace com : : sun : : star : : uno ;
2011-02-21 15:48:08 +02:00
using : : rtl : : OUString ;
2000-10-16 13:56:13 +00:00
//=========================================================================
//=========================================================================
//
// UcbContentProviderProxyFactory Implementation.
//
//=========================================================================
//=========================================================================
UcbContentProviderProxyFactory : : UcbContentProviderProxyFactory (
const Reference < XMultiServiceFactory > & rxSMgr )
: m_xSMgr ( rxSMgr )
{
}
//=========================================================================
// virtual
UcbContentProviderProxyFactory : : ~ UcbContentProviderProxyFactory ( )
{
}
//=========================================================================
//
// XInterface methods.
//
//=========================================================================
XINTERFACE_IMPL_3 ( UcbContentProviderProxyFactory ,
XTypeProvider ,
XServiceInfo ,
XContentProviderFactory ) ;
//=========================================================================
//
// XTypeProvider methods.
//
//=========================================================================
XTYPEPROVIDER_IMPL_3 ( UcbContentProviderProxyFactory ,
XTypeProvider ,
XServiceInfo ,
XContentProviderFactory ) ;
//=========================================================================
//
// XServiceInfo methods.
//
//=========================================================================
XSERVICEINFO_IMPL_1 ( UcbContentProviderProxyFactory ,
2012-03-28 11:22:52 +03:00
OUString ( RTL_CONSTASCII_USTRINGPARAM (
" com.sun.star.comp.ucb.UcbContentProviderProxyFactory " ) ) ,
OUString ( RTL_CONSTASCII_USTRINGPARAM (
PROVIDER_FACTORY_SERVICE_NAME ) ) ) ;
2000-10-16 13:56:13 +00:00
//=========================================================================
//
// Service factory implementation.
//
//=========================================================================
ONE_INSTANCE_SERVICE_FACTORY_IMPL ( UcbContentProviderProxyFactory ) ;
//=========================================================================
//
// XContentProviderFactory methods.
//
//=========================================================================
// virtual
Reference < XContentProvider > SAL_CALL
UcbContentProviderProxyFactory : : createContentProvider (
const OUString & Service )
throw ( RuntimeException )
{
return Reference < XContentProvider > (
new UcbContentProviderProxy ( m_xSMgr , Service ) ) ;
}
//=========================================================================
//=========================================================================
//
// UcbContentProviderProxy Implementation.
//
//=========================================================================
//=========================================================================
UcbContentProviderProxy : : UcbContentProviderProxy (
const Reference < XMultiServiceFactory > & rxSMgr ,
const OUString & Service )
: m_aService ( Service ) ,
m_bReplace ( sal_False ) ,
m_bRegister ( sal_False ) ,
m_xSMgr ( rxSMgr )
{
}
//=========================================================================
// virtual
UcbContentProviderProxy : : ~ UcbContentProviderProxy ( )
{
}
//=========================================================================
//
// XInterface methods.
//
//=========================================================================
XINTERFACE_COMMON_IMPL ( UcbContentProviderProxy ) ;
//============================================================================
// virtual
Any SAL_CALL
UcbContentProviderProxy : : queryInterface ( const Type & rType )
throw ( RuntimeException )
{
Any aRet = cppu : : queryInterface ( rType ,
static_cast < XTypeProvider * > ( this ) ,
static_cast < XServiceInfo * > ( this ) ,
static_cast < XContentProvider * > ( this ) ,
static_cast < XParameterizedContentProvider * > ( this ) ,
static_cast < XContentProviderSupplier * > ( this ) ) ;
if ( ! aRet . hasValue ( ) )
aRet = OWeakObject : : queryInterface ( rType ) ;
if ( ! aRet . hasValue ( ) )
{
// Get original provider an forward the call...
osl : : Guard < osl : : Mutex > aGuard ( m_aMutex ) ;
2006-06-20 04:16:23 +00:00
Reference < XContentProvider > xProvider = getContentProvider ( ) ;
2000-10-16 13:56:13 +00:00
if ( xProvider . is ( ) )
aRet = xProvider - > queryInterface ( rType ) ;
}
return aRet ;
}
//=========================================================================
//
// XTypeProvider methods.
//
//=========================================================================
2004-04-14 12:37:48 +00:00
XTYPEPROVIDER_COMMON_IMPL ( UcbContentProviderProxy ) ;
//=========================================================================
Sequence < Type > SAL_CALL UcbContentProviderProxy : : getTypes ( ) \
throw ( RuntimeException )
{
// Get original provider an forward the call...
osl : : Guard < osl : : Mutex > aGuard ( m_aMutex ) ;
Reference < XTypeProvider > xProvider ( getContentProvider ( ) , UNO_QUERY ) ;
if ( xProvider . is ( ) )
{
return xProvider - > getTypes ( ) ;
}
else
{
2006-06-20 04:16:23 +00:00
static cppu : : OTypeCollection collection (
CPPU_TYPE_REF ( XTypeProvider ) ,
CPPU_TYPE_REF ( XServiceInfo ) ,
CPPU_TYPE_REF ( XContentProvider ) ,
CPPU_TYPE_REF ( XParameterizedContentProvider ) ,
CPPU_TYPE_REF ( XContentProviderSupplier ) ) ;
return collection . getTypes ( ) ;
2004-04-14 12:37:48 +00:00
}
}
2000-10-16 13:56:13 +00:00
//=========================================================================
//
// XServiceInfo methods.
//
//=========================================================================
XSERVICEINFO_NOFACTORY_IMPL_1 ( UcbContentProviderProxy ,
2010-11-13 09:00:53 +01:00
OUString ( RTL_CONSTASCII_USTRINGPARAM (
" com.sun.star.comp.ucb.UcbContentProviderProxy " ) ) ,
OUString ( RTL_CONSTASCII_USTRINGPARAM (
PROVIDER_PROXY_SERVICE_NAME ) ) ) ;
2000-10-16 13:56:13 +00:00
//=========================================================================
//
// XContentProvider methods.
//
//=========================================================================
// virtual
Reference < XContent > SAL_CALL UcbContentProviderProxy : : queryContent (
const Reference < XContentIdentifier > & Identifier )
throw ( IllegalIdentifierException ,
RuntimeException )
{
// Get original provider an forward the call...
osl : : Guard < osl : : Mutex > aGuard ( m_aMutex ) ;
Reference < XContentProvider > xProvider = getContentProvider ( ) ;
if ( xProvider . is ( ) )
return xProvider - > queryContent ( Identifier ) ;
return Reference < XContent > ( ) ;
}
//=========================================================================
// virtual
sal_Int32 SAL_CALL UcbContentProviderProxy : : compareContentIds (
const Reference < XContentIdentifier > & Id1 ,
const Reference < XContentIdentifier > & Id2 )
throw ( RuntimeException )
{
// Get original provider an forward the call...
osl : : Guard < osl : : Mutex > aGuard ( m_aMutex ) ;
Reference < XContentProvider > xProvider = getContentProvider ( ) ;
if ( xProvider . is ( ) )
return xProvider - > compareContentIds ( Id1 , Id2 ) ;
2011-03-19 14:09:49 +01:00
// OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
2000-10-16 13:56:13 +00:00
// @@@ What else?
return 0 ;
}
//=========================================================================
//
// XParameterizedContentProvider methods.
//
//=========================================================================
// virtual
Reference < XContentProvider > SAL_CALL
UcbContentProviderProxy : : registerInstance ( const OUString & Template ,
const OUString & Arguments ,
sal_Bool ReplaceExisting )
throw ( IllegalArgumentException ,
RuntimeException )
{
// Just remember that this method was called ( and the params ).
osl : : Guard < osl : : Mutex > aGuard ( m_aMutex ) ;
if ( ! m_bRegister )
{
// m_xTargetProvider = 0;
m_aTemplate = Template ;
m_aArguments = Arguments ;
m_bReplace = ReplaceExisting ;
m_bRegister = sal_True ;
}
return this ;
}
//=========================================================================
// virtual
Reference < XContentProvider > SAL_CALL
UcbContentProviderProxy : : deregisterInstance ( const OUString & Template ,
const OUString & Arguments )
throw ( IllegalArgumentException ,
RuntimeException )
{
osl : : Guard < osl : : Mutex > aGuard ( m_aMutex ) ;
// registerInstance called at proxy and at original?
if ( m_bRegister & & m_xTargetProvider . is ( ) )
{
m_bRegister = sal_False ;
m_xTargetProvider = 0 ;
Reference < XParameterizedContentProvider >
xParamProvider ( m_xProvider , UNO_QUERY ) ;
if ( xParamProvider . is ( ) )
{
try
{
2001-04-26 08:03:25 +00:00
xParamProvider - > deregisterInstance ( Template , Arguments ) ;
2000-10-16 13:56:13 +00:00
}
catch ( IllegalIdentifierException const & )
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " UcbContentProviderProxy::deregisterInstance - "
2000-10-16 13:56:13 +00:00
" Caught IllegalIdentifierException! " ) ;
}
}
}
return this ;
}
//=========================================================================
//
// XContentProviderSupplier methods.
//
//=========================================================================
// virtual
Reference < XContentProvider > SAL_CALL
UcbContentProviderProxy : : getContentProvider ( )
throw ( RuntimeException )
{
osl : : Guard < osl : : Mutex > aGuard ( m_aMutex ) ;
if ( ! m_xProvider . is ( ) )
{
try
{
m_xProvider
= Reference < XContentProvider > (
m_xSMgr - > createInstance ( m_aService ) , UNO_QUERY ) ;
2012-04-06 15:05:52 +02:00
if ( m_aArguments = = " NoConfig " )
2006-09-15 13:33:50 +00:00
{
Reference < XInitialization > xInit ( m_xProvider , UNO_QUERY ) ;
if ( xInit . is ( ) ) {
Sequence < Any > aArgs ( 1 ) ;
aArgs [ 0 ] < < = m_aArguments ;
xInit - > initialize ( aArgs ) ;
}
}
2000-10-16 13:56:13 +00:00
}
catch ( RuntimeException const & )
{
throw ;
}
catch ( Exception const & )
{
}
// registerInstance called at proxy, but not yet at original?
if ( m_xProvider . is ( ) & & m_bRegister )
{
Reference < XParameterizedContentProvider >
xParamProvider ( m_xProvider , UNO_QUERY ) ;
if ( xParamProvider . is ( ) )
{
try
{
m_xTargetProvider
= xParamProvider - > registerInstance ( m_aTemplate ,
m_aArguments ,
m_bReplace ) ;
}
catch ( IllegalIdentifierException const & )
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " UcbContentProviderProxy::getContentProvider - "
2000-10-16 13:56:13 +00:00
" Caught IllegalIdentifierException! " ) ;
}
OSL_ENSURE ( m_xTargetProvider . is ( ) ,
" UcbContentProviderProxy::getContentProvider - "
" No provider! " ) ;
}
}
if ( ! m_xTargetProvider . is ( ) )
m_xTargetProvider = m_xProvider ;
}
OSL_ENSURE ( m_xProvider . is ( ) ,
2011-10-06 23:30:09 +01:00
rtl : : OStringBuffer ( " UcbContentProviderProxy::getContentProvider - No provider for ' " ) . append ( rtl : : OUStringToOString ( m_aService , osl_getThreadTextEncoding ( ) ) ) . append ( " . " ) . getStr ( ) ) ;
2000-10-16 13:56:13 +00:00
return m_xTargetProvider ;
}
2010-10-12 15:53:47 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */