2000-09-18 09:29:57 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: servicefactory.cxx,v $
|
|
|
|
*
|
2002-01-11 03:06:02 -06:00
|
|
|
* $Revision: 1.28 $
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2002-01-11 03:06:02 -06:00
|
|
|
* last change: $Author: dbo $ $Date: 2002-01-11 10:06:02 $
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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 for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
#include <vector>
|
|
|
|
|
2001-05-29 08:02:08 -05:00
|
|
|
#include <rtl/process.h>
|
2000-09-18 09:29:57 -05:00
|
|
|
#include <rtl/string.hxx>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
2002-01-11 03:06:02 -06:00
|
|
|
#include <rtl/bootstrap.hxx>
|
|
|
|
|
|
|
|
#include <osl/diagnose.h>
|
|
|
|
#include <osl/file.hxx>
|
|
|
|
#include <osl/module.h>
|
|
|
|
#include <osl/thread.h>
|
2000-09-18 09:29:57 -05:00
|
|
|
|
2000-12-19 08:01:51 -06:00
|
|
|
#include <cppuhelper/shlib.hxx>
|
2001-05-08 09:56:02 -05:00
|
|
|
#include <cppuhelper/factory.hxx>
|
|
|
|
#include <cppuhelper/component_context.hxx>
|
2001-05-09 07:28:58 -05:00
|
|
|
#include <cppuhelper/servicefactory.hxx>
|
2001-10-11 08:40:44 -05:00
|
|
|
#include <cppuhelper/bootstrap.hxx>
|
2002-01-11 03:06:02 -06:00
|
|
|
#include <cppuhelper/access_control.hxx>
|
2000-09-18 09:29:57 -05:00
|
|
|
|
2001-05-08 09:56:02 -05:00
|
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
2000-09-18 09:29:57 -05:00
|
|
|
#include <com/sun/star/lang/XInitialization.hpp>
|
|
|
|
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
2001-05-08 09:56:02 -05:00
|
|
|
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
|
|
|
|
#include <com/sun/star/container/XSet.hpp>
|
2001-10-11 08:40:44 -05:00
|
|
|
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
|
2001-05-29 08:02:08 -05:00
|
|
|
#include <com/sun/star/registry/XSimpleRegistry.hpp>
|
2000-09-18 09:29:57 -05:00
|
|
|
#include <com/sun/star/registry/XImplementationRegistration.hpp>
|
2002-01-11 03:06:02 -06:00
|
|
|
#include <com/sun/star/security/XAccessController.hpp>
|
2000-09-18 09:29:57 -05:00
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
|
|
|
|
|
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
using namespace ::rtl;
|
|
|
|
using namespace ::osl;
|
|
|
|
using namespace ::com::sun::star;
|
2001-05-29 08:02:08 -05:00
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::registry;
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
namespace cppu
|
|
|
|
{
|
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
// private forward decl
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void addFactories(
|
|
|
|
char const * const * ppNames /* lib, implname, ..., 0 */,
|
|
|
|
OUString const & bootstrapPath,
|
|
|
|
Reference< lang::XMultiComponentFactory > const & xMgr,
|
|
|
|
Reference< registry::XRegistryKey > const & xKey )
|
|
|
|
SAL_THROW( (Exception) );
|
2001-12-14 06:19:51 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2002-01-11 03:06:02 -06:00
|
|
|
Reference< security::XAccessController > createDefaultAccessController() SAL_THROW( () );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void * SAL_CALL parentThreadCallback(void) SAL_THROW_EXTERN_C();
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void SAL_CALL childThreadCallback( void * xParentContext ) SAL_THROW_EXTERN_C();
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
//==================================================================================================
|
2001-05-08 09:56:02 -05:00
|
|
|
static Reference< XInterface > SAL_CALL createInstance(
|
|
|
|
Reference< XInterface > const & xFactory,
|
|
|
|
Reference< XComponentContext > const & xContext = Reference< XComponentContext >() )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-09 07:28:58 -05:00
|
|
|
Reference< lang::XSingleComponentFactory > xFac( xFactory, UNO_QUERY );
|
2001-05-08 09:56:02 -05:00
|
|
|
if (xFac.is())
|
|
|
|
{
|
|
|
|
return xFac->createInstanceWithContext( xContext );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-09 07:28:58 -05:00
|
|
|
Reference< lang::XSingleServiceFactory > xFac( xFactory, UNO_QUERY );
|
2001-05-08 09:56:02 -05:00
|
|
|
if (xFac.is())
|
|
|
|
{
|
|
|
|
OSL_ENSURE( !xContext.is(), "### ignoring context!" );
|
|
|
|
return xFac->createInstance();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw Exception(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("no factory object given!") ),
|
|
|
|
Reference< XInterface >() );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
//==================================================================================================
|
2001-05-09 07:28:58 -05:00
|
|
|
Reference< registry::XSimpleRegistry > SAL_CALL createSimpleRegistry(
|
|
|
|
OUString const & rBootstrapPath )
|
|
|
|
SAL_THROW( () )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-09 07:28:58 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return Reference< registry::XSimpleRegistry >(
|
|
|
|
createInstance( loadSharedLibComponentFactory(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("simreg") ), rBootstrapPath,
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.SimpleRegistry") ),
|
|
|
|
Reference< lang::XMultiServiceFactory >(), Reference< registry::XRegistryKey >() ) ), UNO_QUERY );
|
|
|
|
}
|
|
|
|
catch (Exception &)
|
|
|
|
{
|
|
|
|
}
|
2000-09-18 09:29:57 -05:00
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
OSL_ENSURE( 0, "### cannot instanciate simple registry!" );
|
|
|
|
return Reference< registry::XSimpleRegistry >();
|
|
|
|
}
|
|
|
|
//==================================================================================================
|
|
|
|
Reference< registry::XSimpleRegistry > SAL_CALL createNestedRegistry(
|
|
|
|
OUString const & rBootstrapPath )
|
|
|
|
SAL_THROW( () )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return Reference< registry::XSimpleRegistry >(
|
|
|
|
createInstance( loadSharedLibComponentFactory(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("defreg") ), rBootstrapPath,
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.NestedRegistry") ),
|
|
|
|
Reference< lang::XMultiServiceFactory >(), Reference< registry::XRegistryKey >() ) ), UNO_QUERY );
|
|
|
|
}
|
|
|
|
catch (Exception &)
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
OSL_ENSURE( 0, "### cannot instanciate simple registry!" );
|
|
|
|
return Reference< registry::XSimpleRegistry >();
|
|
|
|
}
|
2001-05-08 09:56:02 -05:00
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2001-10-11 08:40:44 -05:00
|
|
|
Reference< lang::XMultiComponentFactory > bootstrapInitialSF(
|
2001-05-09 07:28:58 -05:00
|
|
|
OUString const & rBootstrapPath )
|
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
2001-10-11 08:40:44 -05:00
|
|
|
Reference< lang::XMultiComponentFactory > xMgr( createInstance( loadSharedLibComponentFactory(
|
2001-05-09 07:28:58 -05:00
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("smgr") ), rBootstrapPath,
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.ORegistryServiceManager") ),
|
|
|
|
Reference< lang::XMultiServiceFactory >(), Reference< registry::XRegistryKey >() ) ), UNO_QUERY );
|
2001-05-08 09:56:02 -05:00
|
|
|
|
|
|
|
// write initial shared lib loader, simple registry, default registry, impl reg
|
2001-10-11 08:40:44 -05:00
|
|
|
static char const * ar[] = {
|
|
|
|
"cpld", "com.sun.star.comp.stoc.DLLComponentLoader",
|
|
|
|
"simreg", "com.sun.star.comp.stoc.SimpleRegistry",
|
|
|
|
"defreg", "com.sun.star.comp.stoc.NestedRegistry",
|
|
|
|
"tdmgr", "com.sun.star.comp.stoc.TypeDescriptionManager",
|
|
|
|
"impreg", "com.sun.star.comp.stoc.ImplementationRegistration",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
addFactories(
|
|
|
|
ar, rBootstrapPath,
|
|
|
|
xMgr, Reference< registry::XRegistryKey >() );
|
|
|
|
|
|
|
|
return xMgr;
|
2001-05-09 07:28:58 -05:00
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2001-10-11 08:40:44 -05:00
|
|
|
// returns context with UNinitialized smgr
|
|
|
|
Reference< XComponentContext > bootstrapInitialContext(
|
2001-05-09 07:28:58 -05:00
|
|
|
Reference< lang::XMultiComponentFactory > const & xSF,
|
2001-05-29 08:02:08 -05:00
|
|
|
Reference< registry::XSimpleRegistry > const & types_xRegistry,
|
|
|
|
Reference< registry::XSimpleRegistry > const & services_xRegistry,
|
2002-01-11 03:06:02 -06:00
|
|
|
OUString const & rBootstrapPath,
|
|
|
|
Bootstrap const & bootstrap )
|
2001-05-09 07:28:58 -05:00
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
|
|
|
Reference< lang::XInitialization > xSFInit( xSF, UNO_QUERY );
|
|
|
|
if (! xSFInit.is())
|
|
|
|
{
|
2001-10-11 08:40:44 -05:00
|
|
|
throw RuntimeException(
|
|
|
|
OUSTR("servicemanager does not support XInitialization!"),
|
2001-05-09 07:28:58 -05:00
|
|
|
Reference< XInterface >() );
|
|
|
|
}
|
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
// basic context values
|
|
|
|
ContextEntry_Init entry;
|
|
|
|
::std::vector< ContextEntry_Init > context_values;
|
2001-12-14 06:19:51 -06:00
|
|
|
context_values.reserve( 6 );
|
2001-10-11 08:40:44 -05:00
|
|
|
|
|
|
|
// read out singleton infos from registry
|
|
|
|
if (services_xRegistry.is())
|
|
|
|
{
|
|
|
|
Reference< registry::XRegistryKey > xKey( services_xRegistry->getRootKey() );
|
|
|
|
if (xKey.is())
|
|
|
|
{
|
|
|
|
xKey = xKey->openKey( OUString( RTL_CONSTASCII_USTRINGPARAM("/SINGLETONS") ) );
|
|
|
|
if (xKey.is())
|
|
|
|
{
|
|
|
|
entry.bLateInitService = true;
|
|
|
|
|
|
|
|
Sequence< Reference< registry::XRegistryKey > > keys( xKey->openKeys() );
|
|
|
|
Reference< registry::XRegistryKey > const * pKeys = keys.getConstArray();
|
|
|
|
for ( sal_Int32 nPos = keys.getLength(); nPos--; )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference< registry::XRegistryKey > const & xKey = pKeys[ nPos ];
|
|
|
|
|
|
|
|
OUStringBuffer buf( 32 );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("/singletons/") );
|
|
|
|
buf.append( xKey->getKeyName().copy( sizeof("/SINGLETONS") /* -\0 +'/' */ ) );
|
|
|
|
entry.name = buf.makeStringAndClear();
|
|
|
|
entry.value <<= xKey->getStringValue();
|
|
|
|
context_values.push_back( entry );
|
|
|
|
}
|
|
|
|
catch (Exception & rExc)
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
OString aStr( OUStringToOString(
|
|
|
|
xKey->getKeyName().copy( 11 ), RTL_TEXTENCODING_ASCII_US ) );
|
|
|
|
OString aStr2( OUStringToOString(
|
|
|
|
rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
|
|
|
|
::fprintf( stderr, "### failed reading singleton [%s] service name from registry: %s\n", aStr.getStr(), aStr2.getStr() );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
// smgr
|
2001-10-11 08:40:44 -05:00
|
|
|
entry.bLateInitService = false;
|
|
|
|
entry.name = OUSTR("/singletons/com.sun.star.lang.theServiceManager");
|
|
|
|
entry.value <<= xSF;
|
|
|
|
context_values.push_back( entry );
|
|
|
|
|
2001-12-14 06:19:51 -06:00
|
|
|
// ac
|
2002-01-11 03:06:02 -06:00
|
|
|
entry.bLateInitService = false;
|
|
|
|
entry.name = OUSTR(AC_SINGLETON);
|
2001-12-14 06:19:51 -06:00
|
|
|
entry.value <<= createDefaultAccessController();
|
|
|
|
context_values.push_back( entry );
|
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
// tdmgr
|
2001-10-11 08:40:44 -05:00
|
|
|
entry.bLateInitService = true;
|
|
|
|
entry.name = OUSTR("/singletons/com.sun.star.reflection.theTypeDescriptionManager");
|
|
|
|
entry.value <<= OUSTR("com.sun.star.reflection.TypeDescriptionManager");
|
|
|
|
context_values.push_back( entry );
|
|
|
|
|
2001-05-09 10:36:42 -05:00
|
|
|
// tdmgr: cache size
|
2001-10-11 08:40:44 -05:00
|
|
|
entry.bLateInitService = false;
|
|
|
|
entry.name = OUSTR("/implementations/com.sun.star.comp.stoc.TypeDescriptionManager/CacheSize");
|
|
|
|
entry.value <<= (sal_Int32)512;
|
|
|
|
context_values.push_back( entry );
|
2001-05-09 07:28:58 -05:00
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
Reference< XComponentContext > xContext;
|
|
|
|
Reference< container::XHierarchicalNameAccess > xTDMgr;
|
2001-05-11 04:15:01 -05:00
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
// bootstrap type system
|
|
|
|
if (types_xRegistry.is()) // use type registry?
|
|
|
|
{
|
2001-05-09 07:28:58 -05:00
|
|
|
// rdbtdp: registries to be used
|
2001-10-11 08:40:44 -05:00
|
|
|
entry.bLateInitService = false;
|
|
|
|
entry.name = OUSTR("/implementations/com.sun.star.comp.stoc.RegistryTypeDescriptionProvider/Registries");
|
|
|
|
entry.value <<= Sequence< Reference< registry::XSimpleRegistry > >( &types_xRegistry, 1 );
|
|
|
|
context_values.push_back( entry );
|
2001-05-09 07:28:58 -05:00
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
xContext = createComponentContext(
|
|
|
|
&context_values[ 0 ], context_values.size(),
|
|
|
|
Reference< XComponentContext >() );
|
2001-05-09 07:28:58 -05:00
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
if (xContext->getValueByName(
|
|
|
|
OUSTR("/singletons/com.sun.star.reflection.theTypeDescriptionManager") ) >>= xTDMgr)
|
|
|
|
{
|
|
|
|
// add registry td provider factory to smgr and instance to tdmgr
|
|
|
|
Reference< lang::XSingleComponentFactory > xFac( loadSharedLibComponentFactory(
|
|
|
|
OUSTR("rdbtdp"), rBootstrapPath,
|
|
|
|
OUSTR("com.sun.star.comp.stoc.RegistryTypeDescriptionProvider"),
|
|
|
|
Reference< lang::XMultiServiceFactory >( xSF, UNO_QUERY ),
|
|
|
|
Reference< registry::XRegistryKey >() ), UNO_QUERY );
|
|
|
|
OSL_ASSERT( xFac.is() );
|
|
|
|
// smgr
|
|
|
|
Reference< container::XSet > xSet( xSF, UNO_QUERY );
|
|
|
|
xSet->insert( makeAny( xFac ) );
|
|
|
|
OSL_ENSURE( xSet->has( makeAny( xFac ) ), "### failed registering registry td provider!" );
|
|
|
|
// tdmgr
|
|
|
|
xSet.set( xTDMgr, UNO_QUERY );
|
|
|
|
OSL_ASSERT( xSet.is() );
|
|
|
|
Any types_RDB( makeAny( types_xRegistry ) );
|
|
|
|
Any rdbtdp( makeAny( xFac->createInstanceWithArgumentsAndContext(
|
|
|
|
Sequence< Any >( &types_RDB, 1 ), xContext ) ) );
|
|
|
|
xSet->insert( rdbtdp );
|
|
|
|
OSL_ENSURE( xSet->has( rdbtdp ), "### failed inserting registry td provider to tdmgr!" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // no type registry
|
|
|
|
{
|
|
|
|
xContext = createComponentContext(
|
|
|
|
&context_values[ 0 ], context_values.size(),
|
|
|
|
Reference< XComponentContext >() );
|
|
|
|
xContext->getValueByName(
|
|
|
|
OUSTR("/singletons/com.sun.star.reflection.theTypeDescriptionManager") ) >>= xTDMgr;
|
|
|
|
}
|
2001-05-09 07:28:58 -05:00
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
if (xTDMgr.is())
|
2001-05-09 07:28:58 -05:00
|
|
|
{
|
2001-10-11 08:40:44 -05:00
|
|
|
// install callback
|
2001-05-09 07:28:58 -05:00
|
|
|
installTypeDescriptionManager( xTDMgr );
|
|
|
|
}
|
|
|
|
|
2002-01-11 03:06:02 -06:00
|
|
|
// wrap ac for subsequent services
|
|
|
|
OUString ac_service;
|
|
|
|
if (bootstrap.getFrom( OUSTR("UNO_AC"), ac_service ) && ac_service.getLength())
|
|
|
|
{
|
|
|
|
// wrap ac
|
|
|
|
ContextEntry_Init entry;
|
|
|
|
entry.bLateInitService = true;
|
|
|
|
entry.name = OUSTR(AC_SINGLETON);
|
|
|
|
entry.value <<= ac_service;
|
|
|
|
xContext = createComponentContext( &entry, 1, xContext );
|
|
|
|
}
|
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
return xContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
static Reference< lang::XMultiComponentFactory > createImplServiceFactory(
|
|
|
|
const OUString & rWriteRegistry,
|
|
|
|
const OUString & rReadRegistry,
|
|
|
|
sal_Bool bReadOnly,
|
|
|
|
const OUString & rBootstrapPath )
|
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
2002-01-11 03:06:02 -06:00
|
|
|
// osl_registerThreadCallbacks( parentThreadCallback, childThreadCallback );
|
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
Reference< lang::XMultiComponentFactory > xSF( bootstrapInitialSF( rBootstrapPath ) );
|
|
|
|
|
|
|
|
Reference< registry::XSimpleRegistry > xRegistry;
|
2000-09-18 09:29:57 -05:00
|
|
|
|
2001-05-08 09:56:02 -05:00
|
|
|
// open a registry
|
|
|
|
sal_Bool bRegistryShouldBeValid = sal_False;
|
|
|
|
if (rWriteRegistry.getLength() && !rReadRegistry.getLength())
|
|
|
|
{
|
|
|
|
bRegistryShouldBeValid = sal_True;
|
2001-05-09 07:28:58 -05:00
|
|
|
xRegistry.set( createSimpleRegistry( rBootstrapPath ) );
|
2001-05-08 09:56:02 -05:00
|
|
|
if (xRegistry.is())
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
if (bReadOnly)
|
|
|
|
{
|
|
|
|
xRegistry->open( rWriteRegistry, sal_True, sal_False );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xRegistry->open( rWriteRegistry, sal_False, sal_True );
|
|
|
|
}
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
2001-05-08 09:56:02 -05:00
|
|
|
}
|
|
|
|
else if (rWriteRegistry.getLength() && rReadRegistry.getLength()) // default registry
|
|
|
|
{
|
|
|
|
bRegistryShouldBeValid = sal_True;
|
2001-05-09 07:28:58 -05:00
|
|
|
xRegistry.set( createNestedRegistry( rBootstrapPath ) );
|
2000-09-18 09:29:57 -05:00
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
Reference< registry::XSimpleRegistry > xWriteReg( createSimpleRegistry( rBootstrapPath ) );
|
2001-05-08 09:56:02 -05:00
|
|
|
if (xWriteReg.is())
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
if (bReadOnly)
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
try
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
xWriteReg->open( rWriteRegistry, sal_True, sal_False );
|
|
|
|
}
|
2001-05-09 07:28:58 -05:00
|
|
|
catch (registry::InvalidRegistryException &)
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
if (! xWriteReg->isValid())
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
throw Exception(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("specified first registry could not be open readonly!") ),
|
|
|
|
Reference< XInterface >() );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
}
|
2001-05-08 09:56:02 -05:00
|
|
|
else
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
xWriteReg->open( rWriteRegistry, sal_False, sal_True );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
Reference< registry::XSimpleRegistry > xReadReg( createSimpleRegistry( rBootstrapPath ) );
|
2001-05-08 09:56:02 -05:00
|
|
|
if (xReadReg.is())
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
xReadReg->open( rReadRegistry, sal_True, sal_False );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
Reference< lang::XInitialization > xInit( xRegistry, UNO_QUERY );
|
2001-05-08 09:56:02 -05:00
|
|
|
Sequence< Any > aInitSeq( 2 );
|
|
|
|
aInitSeq[ 0 ] <<= xWriteReg;
|
|
|
|
aInitSeq[ 1 ] <<= xReadReg;
|
|
|
|
xInit->initialize( aInitSeq );
|
|
|
|
}
|
2000-09-18 09:29:57 -05:00
|
|
|
|
2001-05-08 09:56:02 -05:00
|
|
|
if (bRegistryShouldBeValid && (!xRegistry.is() || !xRegistry->isValid()))
|
|
|
|
{
|
|
|
|
throw Exception(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("specified registry could not be initialized") ),
|
|
|
|
Reference< XInterface >() );
|
|
|
|
}
|
|
|
|
|
2002-01-11 03:06:02 -06:00
|
|
|
Bootstrap bootstrap;
|
2001-10-11 08:40:44 -05:00
|
|
|
Reference< XComponentContext > xContext(
|
2002-01-11 03:06:02 -06:00
|
|
|
bootstrapInitialContext( xSF, xRegistry, xRegistry, rBootstrapPath, bootstrap ) );
|
2001-10-11 08:40:44 -05:00
|
|
|
|
|
|
|
// initialize sf
|
|
|
|
Reference< lang::XInitialization > xInit( xSF, UNO_QUERY );
|
|
|
|
OSL_ASSERT( xInit.is() );
|
|
|
|
Sequence< Any > aSFInit( 2 );
|
|
|
|
aSFInit[ 0 ] <<= xRegistry;
|
|
|
|
aSFInit[ 1 ] <<= xContext; // default context
|
|
|
|
xInit->initialize( aSFInit );
|
2001-05-08 09:56:02 -05:00
|
|
|
|
|
|
|
return xSF;
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//==================================================================================================
|
2001-05-09 07:28:58 -05:00
|
|
|
Reference< lang::XMultiServiceFactory > SAL_CALL createRegistryServiceFactory(
|
2001-02-15 04:46:17 -06:00
|
|
|
const OUString & rWriteRegistry,
|
|
|
|
const OUString & rReadRegistry,
|
|
|
|
sal_Bool bReadOnly,
|
|
|
|
const OUString & rBootstrapPath )
|
2002-01-11 03:06:02 -06:00
|
|
|
SAL_THROW( (Exception) )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-09 07:28:58 -05:00
|
|
|
return Reference< lang::XMultiServiceFactory >( createImplServiceFactory(
|
|
|
|
rWriteRegistry, rReadRegistry, bReadOnly, rBootstrapPath ), UNO_QUERY );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
//==================================================================================================
|
|
|
|
Reference< XComponentContext > SAL_CALL bootstrap_InitialComponentContext(
|
|
|
|
Reference< registry::XSimpleRegistry > const & xRegistry,
|
|
|
|
OUString const & rBootstrapPath )
|
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
2002-01-11 03:06:02 -06:00
|
|
|
Bootstrap bootstrap;
|
|
|
|
|
|
|
|
// osl_registerThreadCallbacks( parentThreadCallback, childThreadCallback );
|
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
Reference< lang::XMultiComponentFactory > xSF(
|
|
|
|
bootstrapInitialSF( rBootstrapPath ) );
|
|
|
|
Reference< XComponentContext > xContext(
|
2002-01-11 03:06:02 -06:00
|
|
|
bootstrapInitialContext( xSF, xRegistry, xRegistry, rBootstrapPath, bootstrap ) );
|
2001-10-11 08:40:44 -05:00
|
|
|
|
|
|
|
// initialize sf
|
|
|
|
Reference< lang::XInitialization > xInit( xSF, UNO_QUERY );
|
|
|
|
OSL_ASSERT( xInit.is() );
|
|
|
|
Sequence< Any > aSFInit( 2 );
|
|
|
|
aSFInit[ 0 ] <<= xRegistry;
|
|
|
|
aSFInit[ 1 ] <<= xContext; // default context
|
|
|
|
xInit->initialize( aSFInit );
|
2001-05-29 08:02:08 -05:00
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
return xContext;
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
2001-05-09 07:28:58 -05:00
|
|
|
}
|