2002-06-12 10:43:30 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 06:15:39 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2002-06-12 10:43:30 -05:00
|
|
|
*
|
2008-04-11 06:15:39 -05:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2002-06-12 10:43:30 -05:00
|
|
|
*
|
2008-04-11 06:15:39 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2002-06-12 10:43:30 -05:00
|
|
|
*
|
2008-04-11 06:15:39 -05:00
|
|
|
* $RCSfile: backendfactory.cxx,v $
|
|
|
|
* $Revision: 1.12 $
|
2002-06-12 10:43:30 -05:00
|
|
|
*
|
2008-04-11 06:15:39 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2002-06-12 10:43:30 -05:00
|
|
|
*
|
2008-04-11 06:15:39 -05: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.
|
2002-06-12 10:43:30 -05:00
|
|
|
*
|
2008-04-11 06:15:39 -05: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).
|
2002-06-12 10:43:30 -05:00
|
|
|
*
|
2008-04-11 06:15:39 -05: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.
|
2002-06-12 10:43:30 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 09:01:29 -05:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_configmgr.hxx"
|
|
|
|
|
2002-06-12 10:43:30 -05:00
|
|
|
#include "backendfactory.hxx"
|
|
|
|
|
2003-03-19 09:20:19 -06:00
|
|
|
#ifndef CONFIGMGR_API_FACTORY_HXX_
|
|
|
|
#include "confapifactory.hxx"
|
|
|
|
#endif
|
2002-06-12 10:43:30 -05:00
|
|
|
#include "bootstrapcontext.hxx"
|
|
|
|
#include "bootstrap.hxx"
|
|
|
|
#include "backendaccess.hxx"
|
2003-03-19 09:20:19 -06:00
|
|
|
#include "serviceinfohelper.hxx"
|
|
|
|
#include "wrapexception.hxx"
|
2002-12-13 03:14:47 -06:00
|
|
|
|
2002-06-12 10:43:30 -05:00
|
|
|
|
2002-09-02 11:23:43 -05:00
|
|
|
#include <com/sun/star/configuration/CannotLoadConfigurationException.hpp>
|
2003-04-17 07:13:26 -05:00
|
|
|
#include <com/sun/star/configuration/backend/XBackend.hpp>
|
|
|
|
#include <com/sun/star/configuration/backend/XMultiLayerStratum.hpp>
|
2002-06-12 10:43:30 -05:00
|
|
|
|
|
|
|
namespace configmgr
|
|
|
|
{
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
namespace backend
|
|
|
|
{
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
namespace uno = ::com::sun::star::uno;
|
|
|
|
namespace lang = ::com::sun::star::lang;
|
2003-04-17 07:13:26 -05:00
|
|
|
namespace backenduno = ::com::sun::star::configuration::backend;
|
2002-06-12 10:43:30 -05:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
const sal_Char k_DefaultBackendWrapper[] = "com.sun.star.comp.configuration.backend.SingleBackendAdapter";
|
2002-09-02 11:23:43 -05:00
|
|
|
const sal_Char k_DefaultBackendService[] = "com.sun.star.comp.configuration.backend.LocalSingleBackend";
|
2003-03-19 09:20:19 -06:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
const sal_Char k_DefaultBackendServiceAndImplName[] = K_DefaultBackendServiceAndImplName ;
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
const sal_Char k_GenericBackendServiceAndImplName[] = "com.sun.star.configuration.backend.Backend" ;
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
static AsciiServiceName const k_BackendServiceNames [] =
|
|
|
|
{
|
|
|
|
k_DefaultBackendServiceAndImplName,
|
|
|
|
k_GenericBackendServiceAndImplName,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
static const ServiceRegistrationInfo k_DefaultBackendServiceInfo =
|
|
|
|
{
|
|
|
|
k_DefaultBackendServiceAndImplName,
|
|
|
|
k_BackendServiceNames
|
|
|
|
};
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
static const ServiceRegistrationInfo k_GenericBackendServiceInfo =
|
|
|
|
{
|
|
|
|
k_GenericBackendServiceAndImplName,
|
|
|
|
k_BackendServiceNames + 1
|
|
|
|
};
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
static const SingletonRegistrationInfo k_DefaultBackendSingletonInfo =
|
|
|
|
{
|
|
|
|
K_DefaultBackendSingletonName,
|
|
|
|
k_DefaultBackendServiceAndImplName,
|
|
|
|
k_DefaultBackendServiceAndImplName,
|
|
|
|
& k_GenericBackendServiceInfo
|
|
|
|
};
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
const SingletonRegistrationInfo * getDefaultBackendSingletonInfo()
|
|
|
|
{
|
|
|
|
return & k_DefaultBackendSingletonInfo;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const ServiceRegistrationInfo * getDefaultBackendServiceInfo()
|
|
|
|
{
|
|
|
|
return & k_DefaultBackendServiceInfo;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
uno::Reference<uno::XInterface> SAL_CALL
|
|
|
|
getDefaultBackendSingleton( CreationContext const& xContext )
|
|
|
|
{
|
|
|
|
OSL_ENSURE( xContext.is(), "ERROR: NULL context has no singletons" );
|
|
|
|
|
|
|
|
UnoContextTunnel aTunnel;
|
|
|
|
aTunnel.passthru( xContext );
|
|
|
|
|
|
|
|
uno::Reference<uno::XInterface> xResult;
|
|
|
|
|
|
|
|
if (xContext.is())
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xContext->getValueByName(SINGLETON(K_DefaultBackendSingletonName))
|
|
|
|
>>= xResult;
|
|
|
|
}
|
|
|
|
catch (uno::Exception & )
|
|
|
|
{
|
|
|
|
// to do: really use the tunneled failure when that is set properly
|
|
|
|
if ( aTunnel.recoverFailure(true).hasValue() )
|
|
|
|
{
|
|
|
|
// have a failure, but can't recover it
|
|
|
|
// -> try to regenerate
|
|
|
|
instantiateDefaultBackend(xContext);
|
|
|
|
|
|
|
|
OSL_ENSURE(false, "Cannot recreate configuration backend instantiation failure - using generic error");
|
|
|
|
}
|
|
|
|
// cannot recover any failure
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return xResult;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef BackendFactory::CreationContext CreationContext;
|
|
|
|
typedef uno::Sequence< uno::Any > UnoInitArgs;
|
2002-06-12 10:43:30 -05:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static
|
2003-03-19 09:20:19 -06:00
|
|
|
UnoInitArgs createInitArgs(ContextReader const & _aContext)
|
2002-06-12 10:43:30 -05:00
|
|
|
{
|
2003-03-19 09:20:19 -06:00
|
|
|
OSL_ASSERT(_aContext.hasBootstrapContext());
|
2002-06-12 10:43:30 -05:00
|
|
|
uno::Sequence< uno::Any > aResult( 1 );
|
2003-03-19 09:20:19 -06:00
|
|
|
aResult[0] <<= _aContext.getBootstrapContext();
|
2002-06-12 10:43:30 -05:00
|
|
|
return aResult;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
2003-03-19 09:20:19 -06:00
|
|
|
uno::Reference< uno::XInterface > createService(ContextReader const & _aCtx, UnoInitArgs const & _aInitArgs, OUString const & _aSvc)
|
2002-06-12 10:43:30 -05:00
|
|
|
{
|
2003-03-19 09:20:19 -06:00
|
|
|
uno::Reference< lang::XMultiComponentFactory > xFactory = _aCtx.getServiceManager();
|
|
|
|
OSL_ENSURE(xFactory.is(),"ERROR: ComponentContext has no service manager\n");
|
|
|
|
if (!xFactory.is()) throw uno::RuntimeException( OUString::createFromAscii("ERROR: ComponentContext has no service manager\n"), NULL );
|
|
|
|
return xFactory->createInstanceWithArgumentsAndContext( _aSvc, _aInitArgs, _aCtx.getBaseContext());
|
2002-06-12 10:43:30 -05:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
2003-04-17 07:13:26 -05:00
|
|
|
typedef uno::Reference< backenduno::XMultiLayerStratum > UnoSingleBackend;
|
|
|
|
typedef uno::Reference< backenduno::XBackend > UnoBackend;
|
2002-06-12 10:43:30 -05:00
|
|
|
|
|
|
|
static
|
2003-03-19 09:20:19 -06:00
|
|
|
UnoBackend wrapSingleBackend(ContextReader const & _aSettings, UnoInitArgs const & _aInitArgs, UnoSingleBackend const & _xWrappedBackend)
|
2002-06-12 10:43:30 -05:00
|
|
|
{
|
2003-03-19 09:20:19 -06:00
|
|
|
OSL_ASSERT(_aSettings.hasUnoBackendWrapper() || _aSettings.hasBootstrapContext());
|
|
|
|
|
2002-06-12 10:43:30 -05:00
|
|
|
OUString aWrapperSvc = _aSettings.hasUnoBackendWrapper() ?
|
|
|
|
_aSettings.getUnoBackendWrapper() :
|
|
|
|
OUString::createFromAscii(k_DefaultBackendWrapper);
|
|
|
|
|
|
|
|
OSL_ENSURE (aWrapperSvc.getLength(), "ERROR: No wrapper service for wrapped configuration");
|
|
|
|
OSL_ENSURE (_xWrappedBackend.is(), "ERROR: No backend to wrap for wrapped configuration");
|
|
|
|
|
|
|
|
sal_Int32 const nBaseArgsCount = _aInitArgs.getLength();
|
|
|
|
UnoInitArgs aExtendedArgs( _aInitArgs );
|
|
|
|
aExtendedArgs.realloc( nBaseArgsCount + 1 );
|
|
|
|
aExtendedArgs[nBaseArgsCount] <<= _xWrappedBackend;
|
|
|
|
|
2003-03-19 09:20:19 -06:00
|
|
|
return UnoBackend::query( createService(_aSettings,aExtendedArgs,aWrapperSvc) );
|
2002-06-12 10:43:30 -05:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static
|
2003-03-19 09:20:19 -06:00
|
|
|
UnoBackend createOfflineBackend(ContextReader const & _aSettings, UnoInitArgs const & _aInitArgs)
|
2002-06-12 10:43:30 -05:00
|
|
|
{
|
2003-03-19 09:20:19 -06:00
|
|
|
OSL_ASSERT(_aSettings.hasUnoBackendWrapper() || _aSettings.hasBootstrapContext());
|
|
|
|
|
2002-06-12 10:43:30 -05:00
|
|
|
UnoBackend xResult;
|
2002-09-02 11:23:43 -05:00
|
|
|
if ( _aSettings.hasUnoBackendWrapper() )
|
2002-06-12 10:43:30 -05:00
|
|
|
{
|
2002-09-02 11:23:43 -05:00
|
|
|
OUString const aWrapperSvc = _aSettings.getUnoBackendWrapper();
|
2002-06-12 10:43:30 -05:00
|
|
|
|
2003-03-19 09:20:19 -06:00
|
|
|
xResult = UnoBackend::query( createService(_aSettings,_aInitArgs,aWrapperSvc) );
|
2002-06-12 10:43:30 -05:00
|
|
|
}
|
2002-09-02 11:23:43 -05:00
|
|
|
|
|
|
|
return xResult;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static
|
2003-03-19 09:20:19 -06:00
|
|
|
uno::Reference< uno::XInterface > createRealBackend(ContextReader const & _aSettings, UnoInitArgs const & _aInitArgs)
|
2002-09-02 11:23:43 -05:00
|
|
|
{
|
2003-03-19 09:20:19 -06:00
|
|
|
OSL_ASSERT(_aSettings.hasUnoBackendService() || _aSettings.hasBootstrapContext());
|
|
|
|
|
2002-09-02 11:23:43 -05:00
|
|
|
OUString const aBackendServiceName = _aSettings.hasUnoBackendService() ?
|
|
|
|
_aSettings.getUnoBackendService() :
|
|
|
|
OUString::createFromAscii(k_DefaultBackendService);
|
|
|
|
|
|
|
|
uno::Reference< uno::XInterface > xResult =
|
2003-03-19 09:20:19 -06:00
|
|
|
createService(_aSettings,_aInitArgs,aBackendServiceName);
|
2002-09-02 11:23:43 -05:00
|
|
|
|
2002-06-12 10:43:30 -05:00
|
|
|
return xResult;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static
|
2003-03-19 09:20:19 -06:00
|
|
|
UnoBackend createOnlineBackend(ContextReader const & _aSettings, UnoInitArgs const & _aInitArgs)
|
2002-06-12 10:43:30 -05:00
|
|
|
{
|
|
|
|
OSL_ENSURE( _aSettings.isUnoBackend(), "ERROR - BackendFactory: For legacy backends use createSessionBackend()");
|
|
|
|
|
|
|
|
UnoBackend xResult;
|
|
|
|
|
2003-03-19 09:20:19 -06:00
|
|
|
uno::Reference< uno::XInterface > xRealBackend = createRealBackend(_aSettings,_aInitArgs);
|
2002-09-02 11:23:43 -05:00
|
|
|
|
|
|
|
if (_aSettings.hasUnoBackendWrapper())
|
2002-06-12 10:43:30 -05:00
|
|
|
{
|
2002-09-02 11:23:43 -05:00
|
|
|
// try wrapping a single backend
|
|
|
|
UnoSingleBackend xSingleRealBackend( xRealBackend, uno::UNO_QUERY);
|
|
|
|
if (xSingleRealBackend.is())
|
2003-03-19 09:20:19 -06:00
|
|
|
xResult = wrapSingleBackend(_aSettings,_aInitArgs,xSingleRealBackend);
|
2002-06-12 10:43:30 -05:00
|
|
|
|
2002-09-02 11:23:43 -05:00
|
|
|
// if we don't have one, try using it as unwrapped backend
|
|
|
|
else
|
|
|
|
xResult.set(xRealBackend, uno::UNO_QUERY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// look for a direct implementation of XBackend
|
|
|
|
xResult.set(xRealBackend, uno::UNO_QUERY);
|
2002-06-12 10:43:30 -05:00
|
|
|
if (!xResult.is())
|
|
|
|
{
|
2002-09-02 11:23:43 -05:00
|
|
|
// try the default wrapper if we only have a single backend
|
2002-06-12 10:43:30 -05:00
|
|
|
UnoSingleBackend xSingleRealBackend( xRealBackend, uno::UNO_QUERY);
|
|
|
|
if (xSingleRealBackend.is())
|
2003-03-19 09:20:19 -06:00
|
|
|
xResult = wrapSingleBackend(_aSettings,_aInitArgs,xSingleRealBackend);
|
2002-06-12 10:43:30 -05:00
|
|
|
|
|
|
|
else
|
2002-09-19 04:53:21 -05:00
|
|
|
OSL_ENSURE( !xRealBackend.is(), "Configuration Backend implements no known backend interface" );
|
2002-06-12 10:43:30 -05:00
|
|
|
}
|
|
|
|
}
|
2002-09-02 11:23:43 -05:00
|
|
|
|
2002-06-12 10:43:30 -05:00
|
|
|
return xResult;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
2003-03-19 09:20:19 -06:00
|
|
|
static UnoBackend createUnoBackend(CreationContext const& _xCtx)
|
2002-10-24 09:33:07 -05:00
|
|
|
{
|
2003-03-19 09:20:19 -06:00
|
|
|
ContextReader aSettings(_xCtx);
|
|
|
|
OSL_ENSURE( aSettings.isUnoBackend(), "ERROR - BackendFactory: Legacy backends are not supported any more");
|
2002-10-24 09:33:07 -05:00
|
|
|
|
2003-03-19 09:20:19 -06:00
|
|
|
UnoInitArgs aArguments = createInitArgs(aSettings);
|
2002-06-12 10:43:30 -05:00
|
|
|
|
2003-03-19 09:20:19 -06:00
|
|
|
sal_Bool bOffline = aSettings.hasOfflineSetting() ? aSettings.getOfflineSetting() : !aSettings.hasUnoBackendService();
|
2002-09-19 04:53:21 -05:00
|
|
|
|
2002-09-02 11:23:43 -05:00
|
|
|
UnoBackend xResult;
|
|
|
|
|
2002-09-19 04:53:21 -05:00
|
|
|
if (!bOffline)
|
2003-03-19 09:20:19 -06:00
|
|
|
xResult = createOnlineBackend (aSettings,aArguments);
|
2002-06-12 10:43:30 -05:00
|
|
|
|
|
|
|
if (!xResult.is())
|
2003-03-19 09:20:19 -06:00
|
|
|
xResult = createOfflineBackend(aSettings,aArguments);
|
2002-06-12 10:43:30 -05:00
|
|
|
|
|
|
|
return xResult;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2003-03-19 09:20:19 -06:00
|
|
|
// to do: tunnel and raise fully typed exception information (and use it in the get..Singleton wrappers)
|
|
|
|
#define TUNNEL_ALL_EXCEPTIONS() \
|
|
|
|
WRAP_CONFIGBACKEND_CREATION_EXCEPTIONS1( UnoContextTunnel::tunnelFailure, true )
|
2002-06-12 10:43:30 -05:00
|
|
|
|
2003-03-19 09:20:19 -06:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
uno::Reference<uno::XInterface> SAL_CALL instantiateDefaultBackend( CreationContext const& xTargetContext )
|
2002-06-12 10:43:30 -05:00
|
|
|
{
|
2003-03-19 09:20:19 -06:00
|
|
|
CreationContext xContext = UnoContextTunnel::recoverContext(xTargetContext);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2006-06-19 17:17:33 -05:00
|
|
|
return uno::Reference< uno::XInterface >( createUnoBackend(xContext), uno::UNO_QUERY );
|
2003-03-19 09:20:19 -06:00
|
|
|
}
|
|
|
|
TUNNEL_ALL_EXCEPTIONS()
|
2002-06-12 10:43:30 -05:00
|
|
|
|
2003-04-17 07:13:26 -05:00
|
|
|
OSL_ASSERT(!"unreached");
|
|
|
|
return NULL;
|
2003-03-19 09:20:19 -06:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
UnoBackend BackendFactory::getUnoBackend()
|
|
|
|
{
|
|
|
|
return UnoBackend::query( getDefaultBackendSingleton(m_xCtx) );
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
rtl::Reference<IMergedDataProvider> BackendFactory::createBackend()
|
|
|
|
{
|
2002-06-12 10:43:30 -05:00
|
|
|
rtl::Reference< IMergedDataProvider > xBackend;
|
|
|
|
|
2003-03-19 09:20:19 -06:00
|
|
|
UnoBackend xBackendService = this->getUnoBackend();
|
2002-06-12 10:43:30 -05:00
|
|
|
|
|
|
|
if (xBackendService.is())
|
2003-03-19 09:20:19 -06:00
|
|
|
xBackend = new BackendAccess(xBackendService, m_xCtx);
|
2002-06-12 10:43:30 -05:00
|
|
|
|
|
|
|
return xBackend;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
2003-03-19 09:20:19 -06:00
|
|
|
BackendFactory BackendFactory::instance(CreationContext const & _xCtx)
|
2002-06-12 10:43:30 -05:00
|
|
|
{
|
2003-03-19 09:20:19 -06:00
|
|
|
return BackendFactory(_xCtx);
|
2002-06-12 10:43:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
} // namespace
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
} // namespace
|