2000-09-18 14:29:57 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: servicefactory.cxx,v $
|
|
|
|
*
|
2001-09-27 14:34:32 +00:00
|
|
|
* $Revision: 1.25 $
|
2000-09-18 14:29:57 +00:00
|
|
|
*
|
2001-09-27 14:34:32 +00:00
|
|
|
* last change: $Author: jbu $ $Date: 2001-09-27 15:34:32 $
|
2000-09-18 14:29:57 +00: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): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _OSL_DIAGNOSE_H_
|
|
|
|
#include <osl/diagnose.h>
|
|
|
|
#endif
|
2001-05-29 13:02:08 +00:00
|
|
|
#ifndef _OSL_FILE_HXX_
|
|
|
|
#include <osl/file.hxx>
|
|
|
|
#endif
|
2000-09-18 14:29:57 +00:00
|
|
|
#ifndef _OSL_MODULE_H_
|
|
|
|
#include <osl/module.h>
|
|
|
|
#endif
|
2001-05-29 13:02:08 +00:00
|
|
|
#ifndef _RTL_PROCESS_H
|
|
|
|
#include <rtl/process.h>
|
|
|
|
#endif
|
|
|
|
#ifndef _RTL_BOOTSTRAP_H
|
|
|
|
#include <rtl/bootstrap.h>
|
|
|
|
#endif
|
2000-09-18 14:29:57 +00:00
|
|
|
#ifndef _RTL_STRING_HXX_
|
|
|
|
#include <rtl/string.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _RTL_USTRBUF_HXX_
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
#endif
|
|
|
|
|
2001-09-03 13:28:17 +00:00
|
|
|
#include <string.h>
|
2001-06-15 13:20:13 +00:00
|
|
|
#include <osl/security.hxx>
|
|
|
|
|
2001-09-03 13:28:17 +00:00
|
|
|
#include <rtl/bootstrap.hxx>
|
|
|
|
|
2000-12-19 14:01:51 +00:00
|
|
|
#include <cppuhelper/shlib.hxx>
|
2001-05-08 14:56:02 +00:00
|
|
|
#include <cppuhelper/factory.hxx>
|
|
|
|
#include <cppuhelper/component_context.hxx>
|
2001-05-09 12:28:58 +00:00
|
|
|
#include <cppuhelper/bootstrap.hxx>
|
|
|
|
#include <cppuhelper/servicefactory.hxx>
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2001-05-08 14:56:02 +00:00
|
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
2000-09-18 14:29:57 +00:00
|
|
|
#include <com/sun/star/lang/XInitialization.hpp>
|
|
|
|
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
2001-05-08 14:56:02 +00:00
|
|
|
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
|
|
|
|
#include <com/sun/star/container/XSet.hpp>
|
2001-05-29 13:02:08 +00:00
|
|
|
#include <com/sun/star/registry/XSimpleRegistry.hpp>
|
2000-09-18 14:29:57 +00:00
|
|
|
#include <com/sun/star/registry/XImplementationRegistration.hpp>
|
|
|
|
|
2001-05-09 12:28:58 +00:00
|
|
|
using namespace ::rtl;
|
|
|
|
using namespace ::osl;
|
|
|
|
using namespace ::com::sun::star;
|
2001-05-29 13:02:08 +00: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 14:29:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace cppu
|
|
|
|
{
|
|
|
|
|
|
|
|
//==================================================================================================
|
2001-05-08 14:56:02 +00:00
|
|
|
static Reference< XInterface > SAL_CALL createInstance(
|
|
|
|
Reference< XInterface > const & xFactory,
|
|
|
|
Reference< XComponentContext > const & xContext = Reference< XComponentContext >() )
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-09 12:28:58 +00:00
|
|
|
Reference< lang::XSingleComponentFactory > xFac( xFactory, UNO_QUERY );
|
2001-05-08 14:56:02 +00:00
|
|
|
if (xFac.is())
|
|
|
|
{
|
|
|
|
return xFac->createInstanceWithContext( xContext );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-09 12:28:58 +00:00
|
|
|
Reference< lang::XSingleServiceFactory > xFac( xFactory, UNO_QUERY );
|
2001-05-08 14:56:02 +00: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 14:29:57 +00:00
|
|
|
}
|
|
|
|
//==================================================================================================
|
2001-05-09 12:28:58 +00:00
|
|
|
Reference< registry::XSimpleRegistry > SAL_CALL createSimpleRegistry(
|
|
|
|
OUString const & rBootstrapPath )
|
|
|
|
SAL_THROW( () )
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-09 12:28:58 +00: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 14:29:57 +00:00
|
|
|
|
2001-05-09 12:28:58 +00: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 14:29:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-05-09 12:28:58 +00:00
|
|
|
OSL_ENSURE( 0, "### cannot instanciate simple registry!" );
|
|
|
|
return Reference< registry::XSimpleRegistry >();
|
|
|
|
}
|
2001-05-08 14:56:02 +00:00
|
|
|
|
2001-05-09 12:28:58 +00:00
|
|
|
// private forward decl
|
|
|
|
Reference< XComponentContext > SAL_CALL createInitialComponentContext(
|
|
|
|
ContextEntry_Init const * pEntries, sal_Int32 nEntries,
|
|
|
|
Reference< registry::XSimpleRegistry > const & xRegistry )
|
|
|
|
SAL_THROW( () );
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
static Reference< lang::XMultiComponentFactory > bootstrapInitialSF(
|
|
|
|
OUString const & rBootstrapPath )
|
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
|
|
|
Reference< lang::XMultiServiceFactory > xSF( createInstance( loadSharedLibComponentFactory(
|
|
|
|
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 14:56:02 +00:00
|
|
|
|
|
|
|
// write initial shared lib loader, simple registry, default registry, impl reg
|
2001-05-09 12:28:58 +00:00
|
|
|
Reference< container::XSet > xSet( xSF, UNO_QUERY );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2001-05-08 14:56:02 +00:00
|
|
|
// loader
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-08 14:56:02 +00:00
|
|
|
Any aFac( makeAny( loadSharedLibComponentFactory(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("cpld") ), rBootstrapPath,
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.DLLComponentLoader") ),
|
2001-05-09 12:28:58 +00:00
|
|
|
xSF, Reference< registry::XRegistryKey >() ) ) );
|
2001-05-08 14:56:02 +00:00
|
|
|
xSet->insert( aFac );
|
|
|
|
OSL_ENSURE( xSet->has( aFac ), "### failed registering loader!" );
|
|
|
|
}
|
|
|
|
// simple registry
|
2001-05-09 12:28:58 +00:00
|
|
|
{
|
|
|
|
Any aFac( makeAny( loadSharedLibComponentFactory(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("simreg") ), rBootstrapPath,
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.SimpleRegistry") ),
|
|
|
|
xSF, Reference< registry::XRegistryKey >() ) ) );
|
|
|
|
xSet->insert( aFac );
|
|
|
|
OSL_ENSURE( xSet->has( aFac ), "### failed registering simple registry!" );
|
|
|
|
}
|
2001-05-08 14:56:02 +00:00
|
|
|
// nested registry
|
2001-05-09 12:28:58 +00:00
|
|
|
{
|
|
|
|
Any aFac( makeAny( loadSharedLibComponentFactory(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("defreg") ), rBootstrapPath,
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.NestedRegistry") ),
|
|
|
|
xSF, Reference< registry::XRegistryKey >() ) ) );
|
|
|
|
xSet->insert( aFac );
|
|
|
|
OSL_ENSURE( xSet->has( aFac ), "### failed registering default registry!" );
|
|
|
|
}
|
|
|
|
// td manager
|
|
|
|
{
|
|
|
|
Any aFac( makeAny( loadSharedLibComponentFactory(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("tdmgr") ), rBootstrapPath,
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.TypeDescriptionManager") ),
|
|
|
|
xSF, Reference< registry::XRegistryKey >() ) ) );
|
|
|
|
xSet->insert( aFac );
|
|
|
|
OSL_ENSURE( xSet->has( aFac ), "### failed registering registry td provider!" );
|
|
|
|
}
|
2001-05-08 14:56:02 +00:00
|
|
|
// implementation registration
|
|
|
|
{
|
|
|
|
Any aFac( makeAny( loadSharedLibComponentFactory(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("impreg") ), rBootstrapPath,
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.ImplementationRegistration") ),
|
2001-05-09 12:28:58 +00:00
|
|
|
xSF, Reference< registry::XRegistryKey >() ) ) );
|
2001-05-08 14:56:02 +00:00
|
|
|
xSet->insert( aFac );
|
|
|
|
OSL_ENSURE( xSet->has( aFac ), "### failed registering impl reg!" );
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2001-05-09 12:28:58 +00:00
|
|
|
return Reference< lang::XMultiComponentFactory >( xSF, UNO_QUERY );
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
static Reference< XComponentContext > initializeSF(
|
|
|
|
Reference< lang::XMultiComponentFactory > const & xSF,
|
2001-05-29 13:02:08 +00:00
|
|
|
Reference< registry::XSimpleRegistry > const & types_xRegistry,
|
|
|
|
Reference< registry::XSimpleRegistry > const & services_xRegistry,
|
2001-05-09 12:28:58 +00:00
|
|
|
OUString const & rBootstrapPath )
|
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
|
|
|
Reference< lang::XInitialization > xSFInit( xSF, UNO_QUERY );
|
|
|
|
if (! xSFInit.is())
|
|
|
|
{
|
|
|
|
throw Exception(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("servicemanager does not support XInitialization!") ),
|
|
|
|
Reference< XInterface >() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// default initial context
|
|
|
|
ContextEntry_Init context_values[ 4 ];
|
|
|
|
// smgr
|
|
|
|
context_values[ 0 ].bLateInitService = false;
|
2001-06-25 13:15:02 +00:00
|
|
|
context_values[ 0 ].name = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.theServiceManager") );
|
|
|
|
context_values[ 0 ].value <<= xSF;
|
2001-05-09 12:28:58 +00:00
|
|
|
// tdmgr
|
|
|
|
context_values[ 1 ].bLateInitService = true;
|
2001-06-25 13:15:02 +00:00
|
|
|
context_values[ 1 ].name = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.theTypeDescriptionManager") );
|
|
|
|
context_values[ 1 ].value <<= OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.TypeDescriptionManager") );
|
2001-05-09 15:36:42 +00:00
|
|
|
// tdmgr: cache size
|
|
|
|
context_values[ 2 ].bLateInitService = false;
|
|
|
|
context_values[ 2 ].name = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.TypeDescriptionManager.CacheSize") );
|
2001-06-25 13:15:02 +00:00
|
|
|
context_values[ 2 ].value <<= (sal_Int32)512;
|
2001-05-09 15:36:42 +00:00
|
|
|
sal_Int32 nEntries = 3;
|
2001-05-09 12:28:58 +00:00
|
|
|
|
2001-05-29 13:02:08 +00:00
|
|
|
if (types_xRegistry.is())
|
2001-05-09 12:28:58 +00:00
|
|
|
{
|
2001-05-11 09:15:01 +00:00
|
|
|
// add registry td provider
|
|
|
|
Reference< container::XSet > xSet( xSF, UNO_QUERY );
|
|
|
|
Any aFac( makeAny( loadSharedLibComponentFactory(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("rdbtdp") ), rBootstrapPath,
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.RegistryTypeDescriptionProvider") ),
|
|
|
|
Reference< lang::XMultiServiceFactory >( xSF, UNO_QUERY ), Reference< registry::XRegistryKey >() ) ) );
|
|
|
|
xSet->insert( aFac );
|
|
|
|
OSL_ENSURE( xSet->has( aFac ), "### failed registering registry td provider!" );
|
|
|
|
|
2001-05-09 12:28:58 +00:00
|
|
|
// rdbtdp: registries to be used
|
2001-05-10 11:30:59 +00:00
|
|
|
context_values[ 3 ].bLateInitService = false;
|
|
|
|
context_values[ 3 ].name = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.RegistryTypeDescriptionProvider.Registries") );
|
2001-05-29 13:02:08 +00:00
|
|
|
context_values[ 3 ].value = makeAny( Sequence< Reference< registry::XSimpleRegistry > >( &types_xRegistry, 1 ) );
|
2001-05-09 12:28:58 +00:00
|
|
|
nEntries = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference< XComponentContext > xContext( createInitialComponentContext(
|
2001-05-29 13:02:08 +00:00
|
|
|
context_values, nEntries, services_xRegistry ) );
|
2001-05-09 12:28:58 +00:00
|
|
|
|
|
|
|
Sequence< Any > aSFInit( 2 );
|
2001-05-29 13:02:08 +00:00
|
|
|
aSFInit[ 0 ] <<= services_xRegistry;
|
2001-05-09 12:28:58 +00:00
|
|
|
aSFInit[ 1 ] <<= xContext; // default context
|
|
|
|
xSFInit->initialize( aSFInit );
|
|
|
|
|
|
|
|
Reference< container::XHierarchicalNameAccess > xTDMgr;
|
|
|
|
if (xContext->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM(
|
2001-06-25 13:15:02 +00:00
|
|
|
"com.sun.star.reflection.theTypeDescriptionManager") ) ) >>= xTDMgr)
|
2001-05-09 12:28:58 +00:00
|
|
|
{
|
|
|
|
installTypeDescriptionManager( xTDMgr );
|
|
|
|
}
|
|
|
|
|
|
|
|
return xContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
static Reference< lang::XMultiComponentFactory > createImplServiceFactory(
|
|
|
|
const OUString & rWriteRegistry,
|
|
|
|
const OUString & rReadRegistry,
|
|
|
|
sal_Bool bReadOnly,
|
|
|
|
const OUString & rBootstrapPath )
|
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
|
|
|
Reference< lang::XMultiComponentFactory > xSF( bootstrapInitialSF( rBootstrapPath ) );
|
|
|
|
|
|
|
|
Reference< registry::XSimpleRegistry > xRegistry;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2001-05-08 14:56:02 +00:00
|
|
|
// open a registry
|
|
|
|
sal_Bool bRegistryShouldBeValid = sal_False;
|
|
|
|
if (rWriteRegistry.getLength() && !rReadRegistry.getLength())
|
|
|
|
{
|
|
|
|
bRegistryShouldBeValid = sal_True;
|
2001-05-09 12:28:58 +00:00
|
|
|
xRegistry.set( createSimpleRegistry( rBootstrapPath ) );
|
2001-05-08 14:56:02 +00:00
|
|
|
if (xRegistry.is())
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-08 14:56:02 +00:00
|
|
|
if (bReadOnly)
|
|
|
|
{
|
|
|
|
xRegistry->open( rWriteRegistry, sal_True, sal_False );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xRegistry->open( rWriteRegistry, sal_False, sal_True );
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2001-05-08 14:56:02 +00:00
|
|
|
}
|
|
|
|
else if (rWriteRegistry.getLength() && rReadRegistry.getLength()) // default registry
|
|
|
|
{
|
|
|
|
bRegistryShouldBeValid = sal_True;
|
2001-05-09 12:28:58 +00:00
|
|
|
xRegistry.set( createNestedRegistry( rBootstrapPath ) );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2001-05-09 12:28:58 +00:00
|
|
|
Reference< registry::XSimpleRegistry > xWriteReg( createSimpleRegistry( rBootstrapPath ) );
|
2001-05-08 14:56:02 +00:00
|
|
|
if (xWriteReg.is())
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-08 14:56:02 +00:00
|
|
|
if (bReadOnly)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-08 14:56:02 +00:00
|
|
|
try
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-08 14:56:02 +00:00
|
|
|
xWriteReg->open( rWriteRegistry, sal_True, sal_False );
|
|
|
|
}
|
2001-05-09 12:28:58 +00:00
|
|
|
catch (registry::InvalidRegistryException &)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-05-09 12:28:58 +00:00
|
|
|
if (! xWriteReg->isValid())
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-08 14:56:02 +00:00
|
|
|
throw Exception(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("specified first registry could not be open readonly!") ),
|
|
|
|
Reference< XInterface >() );
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-08 14:56:02 +00:00
|
|
|
else
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-08 14:56:02 +00:00
|
|
|
xWriteReg->open( rWriteRegistry, sal_False, sal_True );
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-09 12:28:58 +00:00
|
|
|
Reference< registry::XSimpleRegistry > xReadReg( createSimpleRegistry( rBootstrapPath ) );
|
2001-05-08 14:56:02 +00:00
|
|
|
if (xReadReg.is())
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-08 14:56:02 +00:00
|
|
|
xReadReg->open( rReadRegistry, sal_True, sal_False );
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2001-05-09 12:28:58 +00:00
|
|
|
Reference< lang::XInitialization > xInit( xRegistry, UNO_QUERY );
|
2001-05-08 14:56:02 +00:00
|
|
|
Sequence< Any > aInitSeq( 2 );
|
|
|
|
aInitSeq[ 0 ] <<= xWriteReg;
|
|
|
|
aInitSeq[ 1 ] <<= xReadReg;
|
|
|
|
xInit->initialize( aInitSeq );
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2001-05-08 14:56:02 +00:00
|
|
|
if (bRegistryShouldBeValid && (!xRegistry.is() || !xRegistry->isValid()))
|
|
|
|
{
|
|
|
|
throw Exception(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("specified registry could not be initialized") ),
|
|
|
|
Reference< XInterface >() );
|
|
|
|
}
|
|
|
|
|
2001-05-29 13:02:08 +00:00
|
|
|
initializeSF( xSF, xRegistry, xRegistry, rBootstrapPath );
|
2001-05-08 14:56:02 +00:00
|
|
|
|
|
|
|
return xSF;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==================================================================================================
|
2001-05-09 12:28:58 +00:00
|
|
|
Reference< lang::XMultiServiceFactory > SAL_CALL createRegistryServiceFactory(
|
2001-02-15 10:46:17 +00:00
|
|
|
const OUString & rWriteRegistry,
|
|
|
|
const OUString & rReadRegistry,
|
|
|
|
sal_Bool bReadOnly,
|
|
|
|
const OUString & rBootstrapPath )
|
2001-03-09 11:15:28 +00:00
|
|
|
SAL_THROW( (::com::sun::star::uno::Exception) )
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-09 12:28:58 +00:00
|
|
|
return Reference< lang::XMultiServiceFactory >( createImplServiceFactory(
|
|
|
|
rWriteRegistry, rReadRegistry, bReadOnly, rBootstrapPath ), UNO_QUERY );
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2001-05-09 12:28:58 +00:00
|
|
|
//==================================================================================================
|
|
|
|
Reference< XComponentContext > SAL_CALL bootstrap_InitialComponentContext(
|
|
|
|
Reference< registry::XSimpleRegistry > const & xRegistry,
|
|
|
|
OUString const & rBootstrapPath )
|
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
|
|
|
Reference< lang::XMultiComponentFactory > xSF( bootstrapInitialSF( rBootstrapPath ) );
|
2001-05-29 13:02:08 +00:00
|
|
|
return initializeSF( xSF, xRegistry, xRegistry, rBootstrapPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
|
|
|
|
|
2001-09-03 13:28:17 +00:00
|
|
|
static OUString findBoostrapArgument(const Bootstrap & bootstrap, const OUString & arg_name, sal_Bool * pFallenBack) SAL_THROW(()) {
|
2001-05-29 13:02:08 +00:00
|
|
|
OUString result;
|
|
|
|
|
|
|
|
OUString prefixed_arg_name = OUString(RTL_CONSTASCII_USTRINGPARAM("UNO_"));
|
|
|
|
prefixed_arg_name += arg_name.toAsciiUpperCase();
|
|
|
|
|
2001-09-03 13:28:17 +00:00
|
|
|
if(!bootstrap.getFrom(prefixed_arg_name, result)) // environment not set -> try relative to executable
|
2001-05-29 13:02:08 +00:00
|
|
|
{
|
2001-06-15 13:20:13 +00:00
|
|
|
if(pFallenBack)
|
|
|
|
*pFallenBack = sal_True;
|
|
|
|
|
2001-05-29 13:02:08 +00:00
|
|
|
OUString fileName;
|
2001-09-03 13:28:17 +00:00
|
|
|
bootstrap.getIniName(fileName);
|
2001-07-09 11:31:47 +00:00
|
|
|
|
2001-09-03 13:28:17 +00:00
|
|
|
result = fileName.copy(0, fileName.getLength() - strlen(SAL_CONFIGFILE(""))); // cut the rc extension
|
2001-05-29 13:02:08 +00:00
|
|
|
result += OUString(RTL_CONSTASCII_USTRINGPARAM("_"));
|
|
|
|
result += arg_name.toAsciiLowerCase();
|
|
|
|
result += OUString(RTL_CONSTASCII_USTRINGPARAM(".rdb"));
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
OString result_dbg = OUStringToOString(result, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
OString arg_name_dbg = OUStringToOString(arg_name, RTL_TEXTENCODING_ASCII_US);
|
2001-09-03 13:28:17 +00:00
|
|
|
OSL_TRACE("cppuhelper::findBoostrapArgument - setting %s relative to executable: %s\n",
|
2001-05-29 13:02:08 +00:00
|
|
|
arg_name_dbg.getStr(),
|
|
|
|
result_dbg.getStr());
|
2001-06-15 13:20:13 +00:00
|
|
|
#endif
|
2001-05-29 13:02:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-23 09:10:46 +00:00
|
|
|
if(pFallenBack)
|
|
|
|
*pFallenBack = sal_False;
|
2001-06-15 13:20:13 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-05-29 13:02:08 +00:00
|
|
|
OString prefixed_arg_name_dbg = OUStringToOString(prefixed_arg_name, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
OString result_dbg = OUStringToOString(result, RTL_TEXTENCODING_ASCII_US);
|
2001-09-03 13:28:17 +00:00
|
|
|
OSL_TRACE("cppuhelper::findBoostrapArgument - found %s in env: %s",
|
2001-05-29 13:02:08 +00:00
|
|
|
prefixed_arg_name_dbg.getStr(),
|
|
|
|
result_dbg.getStr());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-03 13:28:17 +00:00
|
|
|
static Reference<XSimpleRegistry> nestRegistries(const OUString baseDir,
|
|
|
|
const Reference<XSingleServiceFactory> & xSimRegFac,
|
2001-05-29 13:02:08 +00:00
|
|
|
const Reference<XSingleServiceFactory> & xNesRegFac,
|
2001-06-15 13:20:13 +00:00
|
|
|
OUString csl_rdbs,
|
|
|
|
const OUString & write_rdb,
|
2001-09-27 14:34:32 +00:00
|
|
|
sal_Bool forceWrite_rdb,
|
|
|
|
sal_Bool bFallenBack)
|
2001-05-29 13:02:08 +00:00
|
|
|
SAL_THROW((Exception))
|
|
|
|
{
|
|
|
|
sal_Int32 index;
|
|
|
|
Reference<XSimpleRegistry> lastRegistry;
|
|
|
|
|
2001-06-15 13:20:13 +00:00
|
|
|
if(write_rdb.getLength()) // is there a write registry given?
|
|
|
|
{
|
|
|
|
lastRegistry = Reference<XSimpleRegistry>::query(xSimRegFac->createInstance());
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2001-09-03 13:28:17 +00:00
|
|
|
OSL_TRACE("opening xxxxx");
|
|
|
|
lastRegistry->open(write_rdb, sal_False, forceWrite_rdb);
|
|
|
|
OSL_TRACE("opening yyyy");
|
|
|
|
|
2001-06-15 13:20:13 +00:00
|
|
|
}
|
|
|
|
catch (InvalidRegistryException & invalidRegistryException)
|
|
|
|
{
|
2001-09-27 14:34:32 +00:00
|
|
|
// be tolerant for write registries ...
|
2001-06-15 13:20:13 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
OString rdb_name_tmp = OUStringToOString(write_rdb, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
OString message_dbg = OUStringToOString(invalidRegistryException.Message, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
OSL_TRACE("warning: couldn't open %s cause of %s", rdb_name_tmp.getStr(), message_dbg.getStr());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!lastRegistry->isValid())
|
|
|
|
lastRegistry = Reference<XSimpleRegistry>();
|
|
|
|
}
|
|
|
|
|
2001-05-29 13:02:08 +00:00
|
|
|
do
|
|
|
|
{
|
2001-07-23 09:10:46 +00:00
|
|
|
index = csl_rdbs.indexOf((sal_Unicode)' ');
|
2001-05-29 13:02:08 +00:00
|
|
|
OUString rdb_name = (index == -1) ? csl_rdbs : csl_rdbs.copy(0, index);
|
|
|
|
csl_rdbs = (index == -1) ? OUString() : csl_rdbs.copy(index + 1);
|
|
|
|
|
2001-09-27 14:34:32 +00:00
|
|
|
Reference<XSimpleRegistry> simpleRegistry = Reference<XSimpleRegistry>::query(xSimRegFac->createInstance());
|
|
|
|
|
|
|
|
osl::FileBase::getAbsoluteFileURL(baseDir, rdb_name, rdb_name);
|
|
|
|
|
2001-05-29 13:02:08 +00:00
|
|
|
try
|
|
|
|
{
|
2001-07-23 09:10:46 +00:00
|
|
|
simpleRegistry->open(rdb_name, sal_True, sal_False);
|
2001-05-29 13:02:08 +00:00
|
|
|
|
|
|
|
if(lastRegistry.is())
|
|
|
|
{
|
|
|
|
Reference<XSimpleRegistry> nestedRegistry = Reference<XSimpleRegistry>::query(xNesRegFac->createInstance());
|
|
|
|
Reference<XInitialization> nestedRegistry_xInit(nestedRegistry, UNO_QUERY);
|
|
|
|
|
|
|
|
Sequence<Any> aArgs(2);
|
|
|
|
aArgs[0] = makeAny(lastRegistry);
|
|
|
|
aArgs[1] = makeAny(simpleRegistry);
|
|
|
|
|
|
|
|
nestedRegistry_xInit->initialize(aArgs);
|
|
|
|
|
|
|
|
lastRegistry = nestedRegistry;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
lastRegistry = simpleRegistry;
|
|
|
|
}
|
2001-09-27 14:34:32 +00:00
|
|
|
catch ( InvalidRegistryException & e )
|
2001-05-29 13:02:08 +00:00
|
|
|
{
|
2001-09-27 14:34:32 +00:00
|
|
|
// if a registry was explicitly given, the exception shall fly
|
|
|
|
if( ! bFallenBack )
|
|
|
|
throw;
|
|
|
|
|
|
|
|
// otherwise just a warning in debug case is sufficient ( e.g. tools, that
|
|
|
|
// don't need types/services registry)
|
2001-05-29 13:02:08 +00:00
|
|
|
#ifdef DEBUG
|
2001-09-27 14:34:32 +00:00
|
|
|
OString rdb_name_tmp = OUStringToOString(write_rdb, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
OString message_dbg = OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
|
2001-05-29 13:02:08 +00:00
|
|
|
OSL_TRACE("warning: couldn't open %s cause of %s", rdb_name_tmp.getStr(), message_dbg.getStr());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2001-07-23 09:10:46 +00:00
|
|
|
while(index != -1 && csl_rdbs.getLength()); // are there more rdbs in list?
|
2001-05-29 13:02:08 +00:00
|
|
|
|
|
|
|
return lastRegistry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bootstrap an <code>InitialContext</code>, try to find the
|
|
|
|
* neccessarey types and services rdbs.
|
|
|
|
*
|
|
|
|
* @return the XComponentContext
|
|
|
|
*/
|
2001-09-03 13:28:17 +00:00
|
|
|
Reference<XComponentContext> SAL_CALL defaultBootstrap_InitialComponentContext(const OUString & iniFile) SAL_THROW((Exception))
|
2001-05-29 13:02:08 +00:00
|
|
|
{
|
2001-09-03 13:28:17 +00:00
|
|
|
Bootstrap bootstrap(iniFile);
|
|
|
|
|
2001-09-27 14:34:32 +00:00
|
|
|
sal_Bool bFallenBackTypes = sal_False;
|
|
|
|
sal_Bool bFallenBackServices = sal_False;
|
|
|
|
OUString cls_uno_types = findBoostrapArgument(bootstrap, OUString(RTL_CONSTASCII_USTRINGPARAM("TYPES")), &bFallenBackTypes);
|
|
|
|
OUString cls_uno_services = findBoostrapArgument(bootstrap, OUString(RTL_CONSTASCII_USTRINGPARAM("SERVICES")),&bFallenBackServices);
|
2001-06-15 13:20:13 +00:00
|
|
|
|
2001-09-27 14:34:32 +00:00
|
|
|
sal_Bool fallenBackWriteRegistry;
|
|
|
|
OUString write_rdb = findBoostrapArgument(bootstrap, OUString(RTL_CONSTASCII_USTRINGPARAM("WRITERDB")), &fallenBackWriteRegistry);
|
2001-05-29 13:02:08 +00:00
|
|
|
|
|
|
|
OUString bootstrapPath;
|
|
|
|
|
|
|
|
Reference<XMultiComponentFactory> smgr_XMultiComponentFactory(bootstrapInitialSF(bootstrapPath));
|
|
|
|
Reference<XMultiServiceFactory> smgr_XMultiServiceFactory(smgr_XMultiComponentFactory, UNO_QUERY);
|
|
|
|
|
|
|
|
Reference<XRegistryKey> xEmptyKey;
|
|
|
|
|
|
|
|
Reference<XSingleServiceFactory> xSimRegFac(
|
|
|
|
loadSharedLibComponentFactory(
|
|
|
|
OUString(RTL_CONSTASCII_USTRINGPARAM("simreg")),
|
|
|
|
bootstrapPath,
|
|
|
|
OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.SimpleRegistry")),
|
|
|
|
smgr_XMultiServiceFactory,
|
|
|
|
xEmptyKey),
|
|
|
|
UNO_QUERY);
|
|
|
|
|
|
|
|
Reference<XSingleServiceFactory> xNesRegFac(
|
|
|
|
loadSharedLibComponentFactory(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("defreg")),
|
|
|
|
bootstrapPath,
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.NestedRegistry")),
|
|
|
|
smgr_XMultiServiceFactory,
|
|
|
|
xEmptyKey),
|
|
|
|
UNO_QUERY);
|
|
|
|
|
2001-09-03 13:28:17 +00:00
|
|
|
OUString iniDir;
|
|
|
|
bootstrap.getIniName(iniDir);
|
|
|
|
iniDir = iniDir.copy(0, iniDir.lastIndexOf('/'));
|
|
|
|
|
2001-09-27 14:34:32 +00:00
|
|
|
Reference<XSimpleRegistry> types_xRegistry =
|
|
|
|
nestRegistries(iniDir, xSimRegFac, xNesRegFac, cls_uno_types,
|
|
|
|
OUString(), sal_False , bFallenBackTypes);
|
|
|
|
Reference<XSimpleRegistry> services_xRegistry =
|
|
|
|
nestRegistries( iniDir, xSimRegFac, xNesRegFac, cls_uno_services,
|
|
|
|
write_rdb, !fallenBackWriteRegistry, bFallenBackServices);
|
2001-05-29 13:02:08 +00:00
|
|
|
|
|
|
|
return initializeSF(smgr_XMultiComponentFactory, types_xRegistry, services_xRegistry, bootstrapPath);
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2001-09-03 13:28:17 +00:00
|
|
|
Reference<XComponentContext> SAL_CALL defaultBootstrap_InitialComponentContext() SAL_THROW((Exception))
|
|
|
|
{
|
|
|
|
return defaultBootstrap_InitialComponentContext(OUString());
|
|
|
|
}
|
2001-05-09 12:28:58 +00:00
|
|
|
}
|