2000-09-18 09:29:57 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 05:33:32 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:33:32 -05:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:33:32 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:33:32 -05:00
|
|
|
* $RCSfile: factory.cxx,v $
|
|
|
|
* $Revision: 1.28 $
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:33:32 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:33:32 -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.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:33:32 -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).
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:33:32 -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.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 06:40:24 -05:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_cppuhelper.hxx"
|
2000-09-18 09:29:57 -05:00
|
|
|
#include <osl/diagnose.h>
|
|
|
|
#include <osl/mutex.hxx>
|
|
|
|
#include <cppuhelper/weak.hxx>
|
|
|
|
#include <cppuhelper/component.hxx>
|
|
|
|
#include <cppuhelper/factory.hxx>
|
2001-06-07 04:56:36 -05:00
|
|
|
#ifndef _CPPUHELPER_IMPLBASE3_HXX
|
|
|
|
#include <cppuhelper/implbase3.hxx>
|
2000-09-18 09:29:57 -05:00
|
|
|
#endif
|
|
|
|
#include <cppuhelper/typeprovider.hxx>
|
2001-06-07 04:56:36 -05:00
|
|
|
#include <rtl/unload.h>
|
|
|
|
|
2004-03-30 07:45:46 -06:00
|
|
|
#include "cppuhelper/propshlp.hxx"
|
2001-06-07 04:56:36 -05:00
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
#include <com/sun/star/lang/XServiceInfo.hpp>
|
|
|
|
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
2001-05-08 09:56:02 -05:00
|
|
|
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
|
2000-09-18 09:29:57 -05:00
|
|
|
#include <com/sun/star/lang/XInitialization.hpp>
|
|
|
|
#include <com/sun/star/loader/XImplementationLoader.hpp>
|
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
|
|
|
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
2001-06-07 04:56:36 -05:00
|
|
|
#include <com/sun/star/uno/XUnloadingPreference.hpp>
|
2004-03-30 07:45:46 -06:00
|
|
|
#include "com/sun/star/beans/PropertyAttribute.hpp"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
using namespace osl;
|
|
|
|
using namespace rtl;
|
2001-05-08 09:56:02 -05:00
|
|
|
using namespace com::sun::star;
|
2000-09-18 09:29:57 -05:00
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::lang;
|
|
|
|
using namespace com::sun::star::loader;
|
|
|
|
using namespace com::sun::star::registry;
|
|
|
|
|
|
|
|
namespace cppu
|
|
|
|
{
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
class OSingleFactoryHelper
|
|
|
|
: public XServiceInfo
|
|
|
|
, public XSingleServiceFactory
|
2001-05-08 09:56:02 -05:00
|
|
|
, public lang::XSingleComponentFactory
|
2001-06-07 04:56:36 -05:00
|
|
|
, public XUnloadingPreference
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
public:
|
2001-03-09 05:15:28 -06:00
|
|
|
OSingleFactoryHelper(
|
|
|
|
const Reference<XMultiServiceFactory > & rServiceManager,
|
|
|
|
const OUString & rImplementationName_,
|
|
|
|
ComponentInstantiation pCreateFunction_,
|
2001-05-08 09:56:02 -05:00
|
|
|
ComponentFactoryFunc fptr,
|
2001-03-09 05:15:28 -06:00
|
|
|
const Sequence< OUString > * pServiceNames_ )
|
|
|
|
SAL_THROW( () )
|
2000-09-18 09:29:57 -05:00
|
|
|
: xSMgr( rServiceManager )
|
|
|
|
, pCreateFunction( pCreateFunction_ )
|
2001-05-08 09:56:02 -05:00
|
|
|
, m_fptr( fptr )
|
2006-06-19 04:33:27 -05:00
|
|
|
, aImplementationName( rImplementationName_ )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
if( pServiceNames_ )
|
|
|
|
aServiceNames = *pServiceNames_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// old function, only for backward compatibility
|
2001-03-09 05:15:28 -06:00
|
|
|
OSingleFactoryHelper(
|
|
|
|
const Reference<XMultiServiceFactory > & rServiceManager,
|
|
|
|
const OUString & rImplementationName_ )
|
|
|
|
SAL_THROW( () )
|
2000-09-18 09:29:57 -05:00
|
|
|
: xSMgr( rServiceManager )
|
|
|
|
, pCreateFunction( NULL )
|
2001-05-08 09:56:02 -05:00
|
|
|
, m_fptr( 0 )
|
2006-06-19 04:33:27 -05:00
|
|
|
, aImplementationName( rImplementationName_ )
|
2001-03-09 05:15:28 -06:00
|
|
|
{}
|
2000-09-18 09:29:57 -05:00
|
|
|
|
2001-10-15 07:37:05 -05:00
|
|
|
virtual ~OSingleFactoryHelper();
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
// XInterface
|
|
|
|
Any SAL_CALL queryInterface( const Type & rType )
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
|
|
|
|
|
|
|
// XSingleServiceFactory
|
2001-03-09 05:15:28 -06:00
|
|
|
Reference<XInterface > SAL_CALL createInstance()
|
2000-09-18 09:29:57 -05:00
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
|
|
|
|
virtual Reference<XInterface > SAL_CALL createInstanceWithArguments(const Sequence<Any>& Arguments)
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
|
2001-05-08 09:56:02 -05:00
|
|
|
// XSingleComponentFactory
|
|
|
|
virtual Reference< XInterface > SAL_CALL createInstanceWithContext(
|
|
|
|
Reference< XComponentContext > const & xContext )
|
|
|
|
throw (Exception, RuntimeException);
|
|
|
|
virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
|
|
|
|
Sequence< Any > const & rArguments,
|
|
|
|
Reference< XComponentContext > const & xContext )
|
|
|
|
throw (Exception, RuntimeException);
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
// XServiceInfo
|
|
|
|
OUString SAL_CALL getImplementationName()
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
|
|
|
sal_Bool SAL_CALL supportsService(const OUString& ServiceName)
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
|
|
|
Sequence< OUString > SAL_CALL getSupportedServiceNames(void)
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Create an instance specified by the factory. The one instance logic is implemented
|
|
|
|
* in the createInstance and createInstanceWithArguments methods.
|
|
|
|
* @return the newly created instance. Do not return a previous (one instance) instance.
|
|
|
|
*/
|
2001-05-08 09:56:02 -05:00
|
|
|
virtual Reference<XInterface > createInstanceEveryTime(
|
|
|
|
Reference< XComponentContext > const & xContext )
|
2000-09-18 09:29:57 -05:00
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
|
|
|
|
|
|
|
|
Reference<XMultiServiceFactory > xSMgr;
|
|
|
|
ComponentInstantiation pCreateFunction;
|
2001-05-08 09:56:02 -05:00
|
|
|
ComponentFactoryFunc m_fptr;
|
2000-09-18 09:29:57 -05:00
|
|
|
Sequence< OUString > aServiceNames;
|
|
|
|
OUString aImplementationName;
|
|
|
|
};
|
2001-10-15 07:37:05 -05:00
|
|
|
OSingleFactoryHelper::~OSingleFactoryHelper()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
Any OSingleFactoryHelper::queryInterface( const Type & rType )
|
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return ::cppu::queryInterface(
|
2001-05-08 09:56:02 -05:00
|
|
|
rType,
|
|
|
|
static_cast< XSingleComponentFactory * >( this ),
|
|
|
|
static_cast< XSingleServiceFactory * >( this ),
|
2001-06-07 04:56:36 -05:00
|
|
|
static_cast< XServiceInfo * >( this ) ,
|
|
|
|
static_cast< XUnloadingPreference * >( this ));
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// OSingleFactoryHelper
|
2001-05-08 09:56:02 -05:00
|
|
|
Reference<XInterface > OSingleFactoryHelper::createInstanceEveryTime(
|
|
|
|
Reference< XComponentContext > const & xContext )
|
2000-09-18 09:29:57 -05:00
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
if (m_fptr)
|
|
|
|
{
|
|
|
|
return (*m_fptr)( xContext );
|
|
|
|
}
|
|
|
|
else if( pCreateFunction )
|
|
|
|
{
|
|
|
|
if (xContext.is())
|
|
|
|
{
|
2004-05-03 07:58:08 -05:00
|
|
|
Reference< lang::XMultiServiceFactory > xContextMgr(
|
|
|
|
xContext->getServiceManager(), UNO_QUERY );
|
|
|
|
if (xContextMgr.is())
|
|
|
|
return (*pCreateFunction)( xContextMgr );
|
2001-05-08 09:56:02 -05:00
|
|
|
}
|
|
|
|
return (*pCreateFunction)( xSMgr );
|
|
|
|
}
|
2000-09-18 09:29:57 -05:00
|
|
|
else
|
2001-05-08 09:56:02 -05:00
|
|
|
{
|
|
|
|
return Reference< XInterface >();
|
|
|
|
}
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// XSingleServiceFactory
|
|
|
|
Reference<XInterface > OSingleFactoryHelper::createInstance()
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
return createInstanceWithContext( Reference< XComponentContext >() );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// XSingleServiceFactory
|
2001-05-08 09:56:02 -05:00
|
|
|
Reference<XInterface > OSingleFactoryHelper::createInstanceWithArguments(
|
|
|
|
const Sequence<Any>& Arguments )
|
2000-09-18 09:29:57 -05:00
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
return createInstanceWithArgumentsAndContext(
|
|
|
|
Arguments, Reference< XComponentContext >() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// XSingleComponentFactory
|
|
|
|
//__________________________________________________________________________________________________
|
|
|
|
Reference< XInterface > OSingleFactoryHelper::createInstanceWithContext(
|
|
|
|
Reference< XComponentContext > const & xContext )
|
|
|
|
throw (Exception, RuntimeException)
|
|
|
|
{
|
|
|
|
return createInstanceEveryTime( xContext );
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
|
|
Reference< XInterface > OSingleFactoryHelper::createInstanceWithArgumentsAndContext(
|
|
|
|
Sequence< Any > const & rArguments,
|
|
|
|
Reference< XComponentContext > const & xContext )
|
|
|
|
throw (Exception, RuntimeException)
|
|
|
|
{
|
|
|
|
Reference< XInterface > xRet( createInstanceWithContext( xContext ) );
|
2000-09-18 09:29:57 -05:00
|
|
|
|
2006-03-31 04:56:18 -06:00
|
|
|
Reference< lang::XInitialization > xInit( xRet, UNO_QUERY );
|
|
|
|
// always call initialize, even if there are no arguments.
|
|
|
|
// #i63511# / 2006-03-27 / frank.schoenheit@sun.com
|
|
|
|
if (xInit.is())
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2006-03-31 04:56:18 -06:00
|
|
|
xInit->initialize( rArguments );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( rArguments.getLength() )
|
2001-05-08 09:56:02 -05:00
|
|
|
throw lang::IllegalArgumentException(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("cannot pass arguments to component => no XInitialization implemented!") ),
|
|
|
|
Reference< XInterface >(), 0 );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
2001-05-08 09:56:02 -05:00
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
return xRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XServiceInfo
|
|
|
|
OUString OSingleFactoryHelper::getImplementationName()
|
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return aImplementationName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XServiceInfo
|
2001-05-08 09:56:02 -05:00
|
|
|
sal_Bool OSingleFactoryHelper::supportsService(
|
|
|
|
const OUString& ServiceName )
|
2000-09-18 09:29:57 -05:00
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
Sequence< OUString > seqServices = getSupportedServiceNames();
|
|
|
|
const OUString * pServices = seqServices.getConstArray();
|
|
|
|
for( sal_Int32 i = 0; i < seqServices.getLength(); i++ )
|
|
|
|
if( pServices[i] == ServiceName )
|
|
|
|
return sal_True;
|
|
|
|
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XServiceInfo
|
|
|
|
Sequence< OUString > OSingleFactoryHelper::getSupportedServiceNames(void)
|
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return aServiceNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
struct OFactoryComponentHelper_Mutex
|
|
|
|
{
|
|
|
|
Mutex aMutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
class OFactoryComponentHelper
|
|
|
|
: public OFactoryComponentHelper_Mutex
|
|
|
|
, public OComponentHelper
|
|
|
|
, public OSingleFactoryHelper
|
|
|
|
{
|
|
|
|
public:
|
2001-03-09 05:15:28 -06:00
|
|
|
OFactoryComponentHelper(
|
|
|
|
const Reference<XMultiServiceFactory > & rServiceManager,
|
|
|
|
const OUString & rImplementationName_,
|
|
|
|
ComponentInstantiation pCreateFunction_,
|
2001-05-08 09:56:02 -05:00
|
|
|
ComponentFactoryFunc fptr,
|
2001-03-09 05:15:28 -06:00
|
|
|
const Sequence< OUString > * pServiceNames_,
|
|
|
|
sal_Bool bOneInstance_ = sal_False )
|
|
|
|
SAL_THROW( () )
|
2000-09-18 09:29:57 -05:00
|
|
|
: OComponentHelper( aMutex )
|
2001-05-08 09:56:02 -05:00
|
|
|
, OSingleFactoryHelper( rServiceManager, rImplementationName_, pCreateFunction_, fptr, pServiceNames_ )
|
2000-09-18 09:29:57 -05:00
|
|
|
, bOneInstance( bOneInstance_ )
|
2001-06-07 04:56:36 -05:00
|
|
|
, pModuleCount(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used by the createXXXFactory functions. The argument pModCount is used to prevent the unloading of the module
|
|
|
|
// which contains pCreateFunction_
|
|
|
|
OFactoryComponentHelper(
|
|
|
|
const Reference<XMultiServiceFactory > & rServiceManager,
|
|
|
|
const OUString & rImplementationName_,
|
|
|
|
ComponentInstantiation pCreateFunction_,
|
|
|
|
ComponentFactoryFunc fptr,
|
|
|
|
const Sequence< OUString > * pServiceNames_,
|
|
|
|
rtl_ModuleCount * pModCount,
|
|
|
|
sal_Bool bOneInstance_ = sal_False )
|
|
|
|
SAL_THROW( () )
|
|
|
|
: OComponentHelper( aMutex )
|
|
|
|
, OSingleFactoryHelper( rServiceManager, rImplementationName_, pCreateFunction_, fptr, pServiceNames_ )
|
|
|
|
, bOneInstance( bOneInstance_ )
|
|
|
|
, pModuleCount(pModCount)
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-06-07 04:56:36 -05:00
|
|
|
if(pModuleCount)
|
|
|
|
pModuleCount->acquire( pModuleCount);
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// old function, only for backward compatibility
|
2001-03-09 05:15:28 -06:00
|
|
|
OFactoryComponentHelper(
|
|
|
|
const Reference<XMultiServiceFactory > & rServiceManager,
|
|
|
|
const OUString & rImplementationName_,
|
|
|
|
sal_Bool bOneInstance_ = sal_False )
|
|
|
|
SAL_THROW( () )
|
2000-09-18 09:29:57 -05:00
|
|
|
: OComponentHelper( aMutex )
|
|
|
|
, OSingleFactoryHelper( rServiceManager, rImplementationName_ )
|
|
|
|
, bOneInstance( bOneInstance_ )
|
2001-06-07 04:56:36 -05:00
|
|
|
, pModuleCount(0)
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-06-07 04:56:36 -05:00
|
|
|
~OFactoryComponentHelper()
|
|
|
|
{
|
|
|
|
if(pModuleCount)
|
|
|
|
pModuleCount->release( pModuleCount);
|
|
|
|
}
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
// XInterface
|
2001-06-07 04:56:36 -05:00
|
|
|
Any SAL_CALL queryInterface( const Type & rType )
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
2001-09-26 09:08:52 -05:00
|
|
|
void SAL_CALL acquire() throw()
|
2000-09-18 09:29:57 -05:00
|
|
|
{ OComponentHelper::acquire(); }
|
2001-09-26 09:08:52 -05:00
|
|
|
void SAL_CALL release() throw()
|
2000-09-18 09:29:57 -05:00
|
|
|
{ OComponentHelper::release(); }
|
|
|
|
|
|
|
|
// XSingleServiceFactory
|
|
|
|
Reference<XInterface > SAL_CALL createInstance()
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
|
|
|
|
Reference<XInterface > SAL_CALL createInstanceWithArguments( const Sequence<Any>& Arguments )
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
|
2001-05-10 08:32:28 -05:00
|
|
|
// XSingleComponentFactory
|
|
|
|
virtual Reference< XInterface > SAL_CALL createInstanceWithContext(
|
|
|
|
Reference< XComponentContext > const & xContext )
|
|
|
|
throw (Exception, RuntimeException);
|
|
|
|
virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
|
|
|
|
Sequence< Any > const & rArguments,
|
|
|
|
Reference< XComponentContext > const & xContext )
|
|
|
|
throw (Exception, RuntimeException);
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
// XTypeProvider
|
|
|
|
virtual Sequence< Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException);
|
|
|
|
virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(::com::sun::star::uno::RuntimeException);
|
|
|
|
|
|
|
|
// XAggregation
|
|
|
|
Any SAL_CALL queryAggregation( const Type & rType )
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
|
|
|
|
2001-06-07 04:56:36 -05:00
|
|
|
// XUnloadingPreference
|
|
|
|
virtual sal_Bool SAL_CALL releaseOnNotification()
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
// OComponentHelper
|
|
|
|
void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Reference<XInterface > xTheInstance;
|
|
|
|
sal_Bool bOneInstance;
|
2001-06-07 04:56:36 -05:00
|
|
|
rtl_ModuleCount * pModuleCount;
|
|
|
|
protected:
|
|
|
|
// needed for implementing XUnloadingPreference in inheriting classes
|
|
|
|
sal_Bool isOneInstance() {return bOneInstance;}
|
|
|
|
sal_Bool isInstance() {return xTheInstance.is();}
|
2000-09-18 09:29:57 -05:00
|
|
|
};
|
|
|
|
|
2001-06-07 04:56:36 -05:00
|
|
|
|
|
|
|
Any SAL_CALL OFactoryComponentHelper::queryInterface( const Type & rType )
|
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
if( rType == ::getCppuType( (Reference<XUnloadingPreference>*)0))
|
|
|
|
{
|
2004-03-30 07:45:46 -06:00
|
|
|
return makeAny(
|
|
|
|
Reference< XUnloadingPreference >(
|
|
|
|
static_cast< XUnloadingPreference * >(this) ) );
|
2001-06-07 04:56:36 -05:00
|
|
|
}
|
|
|
|
return OComponentHelper::queryInterface( rType );
|
|
|
|
}
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
// XAggregation
|
|
|
|
Any OFactoryComponentHelper::queryAggregation( const Type & rType )
|
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
Any aRet( OComponentHelper::queryAggregation( rType ) );
|
|
|
|
return (aRet.hasValue() ? aRet : OSingleFactoryHelper::queryInterface( rType ));
|
|
|
|
}
|
|
|
|
|
|
|
|
// XTypeProvider
|
|
|
|
Sequence< Type > OFactoryComponentHelper::getTypes()
|
|
|
|
throw (::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2001-06-07 04:56:36 -05:00
|
|
|
Type ar[ 4 ];
|
2001-05-08 09:56:02 -05:00
|
|
|
ar[ 0 ] = ::getCppuType( (const Reference< XSingleServiceFactory > *)0 );
|
|
|
|
ar[ 1 ] = ::getCppuType( (const Reference< XServiceInfo > *)0 );
|
2001-06-07 04:56:36 -05:00
|
|
|
ar[ 2 ] = ::getCppuType( (const Reference< XUnloadingPreference > *)0 );
|
2001-05-08 09:56:02 -05:00
|
|
|
|
|
|
|
if (m_fptr)
|
2001-06-07 04:56:36 -05:00
|
|
|
ar[ 3 ] = ::getCppuType( (const Reference< XSingleComponentFactory > *)0 );
|
2001-05-08 09:56:02 -05:00
|
|
|
|
2001-06-07 04:56:36 -05:00
|
|
|
return Sequence< Type >( ar, m_fptr ? 4 : 3 );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
2001-05-08 09:56:02 -05:00
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
Sequence< sal_Int8 > OFactoryComponentHelper::getImplementationId()
|
|
|
|
throw (::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
static OImplementationId * pId = 0;
|
|
|
|
if (! pId)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( Mutex::getGlobalMutex() );
|
|
|
|
if (! pId)
|
|
|
|
{
|
|
|
|
static OImplementationId aId;
|
|
|
|
pId = &aId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pId->getImplementationId();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XSingleServiceFactory
|
|
|
|
Reference<XInterface > OFactoryComponentHelper::createInstance()
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
if( bOneInstance )
|
|
|
|
{
|
|
|
|
if( !xTheInstance.is() )
|
2001-07-04 02:50:23 -05:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( aMutex );
|
|
|
|
if( !xTheInstance.is() )
|
|
|
|
xTheInstance = OSingleFactoryHelper::createInstance();
|
|
|
|
}
|
2000-09-18 09:29:57 -05:00
|
|
|
return xTheInstance;
|
|
|
|
}
|
|
|
|
return OSingleFactoryHelper::createInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference<XInterface > OFactoryComponentHelper::createInstanceWithArguments(
|
|
|
|
const Sequence<Any>& Arguments )
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
if( bOneInstance )
|
|
|
|
{
|
|
|
|
if( !xTheInstance.is() )
|
2001-07-04 02:50:23 -05:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( aMutex );
|
|
|
|
// OSL_ENSURE( !xTheInstance.is(), "### arguments will be ignored!" );
|
|
|
|
if( !xTheInstance.is() )
|
|
|
|
xTheInstance = OSingleFactoryHelper::createInstanceWithArguments( Arguments );
|
|
|
|
}
|
2000-09-18 09:29:57 -05:00
|
|
|
return xTheInstance;
|
|
|
|
}
|
|
|
|
return OSingleFactoryHelper::createInstanceWithArguments( Arguments );
|
|
|
|
}
|
|
|
|
|
2001-05-10 08:32:28 -05:00
|
|
|
// XSingleComponentFactory
|
|
|
|
//__________________________________________________________________________________________________
|
|
|
|
Reference< XInterface > OFactoryComponentHelper::createInstanceWithContext(
|
|
|
|
Reference< XComponentContext > const & xContext )
|
|
|
|
throw (Exception, RuntimeException)
|
|
|
|
{
|
|
|
|
if( bOneInstance )
|
|
|
|
{
|
|
|
|
if( !xTheInstance.is() )
|
2001-07-04 02:50:23 -05:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( aMutex );
|
|
|
|
// OSL_ENSURE( !xTheInstance.is(), "### context will be ignored!" );
|
|
|
|
if( !xTheInstance.is() )
|
|
|
|
xTheInstance = OSingleFactoryHelper::createInstanceWithContext( xContext );
|
|
|
|
}
|
2001-05-10 08:32:28 -05:00
|
|
|
return xTheInstance;
|
|
|
|
}
|
|
|
|
return OSingleFactoryHelper::createInstanceWithContext( xContext );
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
|
|
Reference< XInterface > OFactoryComponentHelper::createInstanceWithArgumentsAndContext(
|
|
|
|
Sequence< Any > const & rArguments,
|
|
|
|
Reference< XComponentContext > const & xContext )
|
|
|
|
throw (Exception, RuntimeException)
|
|
|
|
{
|
|
|
|
if( bOneInstance )
|
|
|
|
{
|
|
|
|
if( !xTheInstance.is() )
|
2001-07-04 02:50:23 -05:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( aMutex );
|
|
|
|
// OSL_ENSURE( !xTheInstance.is(), "### context and arguments will be ignored!" );
|
|
|
|
if( !xTheInstance.is() )
|
|
|
|
xTheInstance = OSingleFactoryHelper::createInstanceWithArgumentsAndContext( rArguments, xContext );
|
|
|
|
}
|
2001-05-10 08:32:28 -05:00
|
|
|
return xTheInstance;
|
|
|
|
}
|
|
|
|
return OSingleFactoryHelper::createInstanceWithArgumentsAndContext( rArguments, xContext );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
// OComponentHelper
|
|
|
|
void OFactoryComponentHelper::dispose()
|
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
OComponentHelper::dispose();
|
|
|
|
|
|
|
|
Reference<XInterface > x;
|
|
|
|
{
|
|
|
|
// do not delete in the guard section
|
|
|
|
MutexGuard aGuard( aMutex );
|
|
|
|
x = xTheInstance;
|
|
|
|
xTheInstance = Reference<XInterface >();
|
|
|
|
}
|
|
|
|
// if it is a component call dispose at the component
|
|
|
|
Reference<XComponent > xComp( x, UNO_QUERY );
|
|
|
|
if( xComp.is() )
|
|
|
|
xComp->dispose();
|
|
|
|
}
|
|
|
|
|
2001-06-07 04:56:36 -05:00
|
|
|
// XUnloadingPreference
|
|
|
|
// This class is used for single factories, component factories and
|
|
|
|
// one-instance factories. Depending on the usage this function has
|
|
|
|
// to return different values.
|
|
|
|
// one-instance factory: sal_False
|
|
|
|
// single factory: sal_True
|
|
|
|
// component factory: sal_True
|
2001-06-12 04:19:10 -05:00
|
|
|
sal_Bool SAL_CALL OFactoryComponentHelper::releaseOnNotification() throw(::com::sun::star::uno::RuntimeException)
|
2001-06-07 04:56:36 -05:00
|
|
|
{
|
|
|
|
if( bOneInstance)
|
|
|
|
return sal_False;
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
2004-03-30 07:45:46 -06:00
|
|
|
class ORegistryFactoryHelper : public OFactoryComponentHelper,
|
|
|
|
public OPropertySetHelper
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
public:
|
2001-03-09 05:15:28 -06:00
|
|
|
ORegistryFactoryHelper(
|
|
|
|
const Reference<XMultiServiceFactory > & rServiceManager,
|
|
|
|
const OUString & rImplementationName_,
|
|
|
|
const Reference<XRegistryKey > & xImplementationKey_,
|
2004-03-30 07:45:46 -06:00
|
|
|
sal_Bool bOneInstance_ = sal_False ) SAL_THROW( () )
|
|
|
|
: OFactoryComponentHelper(
|
|
|
|
rServiceManager, rImplementationName_, 0, 0, 0, bOneInstance_ ),
|
|
|
|
OPropertySetHelper( OComponentHelper::rBHelper ),
|
|
|
|
xImplementationKey( xImplementationKey_ )
|
2000-09-18 09:29:57 -05:00
|
|
|
{}
|
|
|
|
|
2004-03-30 07:45:46 -06:00
|
|
|
// XInterface
|
|
|
|
virtual Any SAL_CALL queryInterface( Type const & type )
|
|
|
|
throw (RuntimeException);
|
|
|
|
virtual void SAL_CALL acquire() throw ();
|
|
|
|
virtual void SAL_CALL release() throw ();
|
|
|
|
// XTypeProvider
|
|
|
|
virtual Sequence< Type > SAL_CALL getTypes()
|
|
|
|
throw (RuntimeException);
|
|
|
|
// XPropertySet
|
|
|
|
virtual Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo()
|
|
|
|
throw (RuntimeException);
|
|
|
|
|
|
|
|
// OPropertySetHelper
|
|
|
|
virtual IPropertyArrayHelper & SAL_CALL getInfoHelper();
|
|
|
|
virtual sal_Bool SAL_CALL convertFastPropertyValue(
|
|
|
|
Any & rConvertedValue, Any & rOldValue,
|
|
|
|
sal_Int32 nHandle, Any const & rValue )
|
|
|
|
throw (lang::IllegalArgumentException);
|
|
|
|
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
|
|
|
|
sal_Int32 nHandle, Any const & rValue )
|
|
|
|
throw (Exception);
|
2006-06-19 04:33:27 -05:00
|
|
|
using OPropertySetHelper::getFastPropertyValue;
|
2004-03-30 07:45:46 -06:00
|
|
|
virtual void SAL_CALL getFastPropertyValue(
|
|
|
|
Any & rValue, sal_Int32 nHandle ) const;
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
// OSingleFactoryHelper
|
2001-05-08 09:56:02 -05:00
|
|
|
Reference<XInterface > createInstanceEveryTime(
|
|
|
|
Reference< XComponentContext > const & xContext )
|
2000-09-18 09:29:57 -05:00
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
|
|
|
|
|
|
|
|
// XSingleServiceFactory
|
|
|
|
Reference<XInterface > SAL_CALL createInstanceWithArguments(const Sequence<Any>& Arguments)
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
|
2001-05-08 09:56:02 -05:00
|
|
|
// XSingleComponentFactory
|
|
|
|
Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
|
|
|
|
Sequence< Any > const & rArguments,
|
|
|
|
Reference< XComponentContext > const & xContext )
|
|
|
|
throw (Exception, RuntimeException);
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
// XServiceInfo
|
|
|
|
Sequence< OUString > SAL_CALL getSupportedServiceNames(void)
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
2001-06-07 04:56:36 -05:00
|
|
|
// XUnloadingPreference
|
|
|
|
sal_Bool SAL_CALL releaseOnNotification()
|
|
|
|
throw( RuntimeException);
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
private:
|
2001-05-08 09:56:02 -05:00
|
|
|
Reference< XInterface > createModuleFactory()
|
2000-09-18 09:29:57 -05:00
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
|
|
|
|
|
|
|
|
/** The registry key of the implementation section */
|
|
|
|
Reference<XRegistryKey > xImplementationKey;
|
|
|
|
/** The factory created with the loader. */
|
2001-05-08 09:56:02 -05:00
|
|
|
Reference<XSingleComponentFactory > xModuleFactory;
|
|
|
|
Reference<XSingleServiceFactory > xModuleFactoryDepr;
|
2004-03-30 07:45:46 -06:00
|
|
|
Reference< beans::XPropertySetInfo > m_xInfo;
|
|
|
|
::std::auto_ptr< IPropertyArrayHelper > m_property_array_helper;
|
2007-05-10 03:45:26 -05:00
|
|
|
protected:
|
|
|
|
using OPropertySetHelper::getTypes;
|
2000-09-18 09:29:57 -05:00
|
|
|
};
|
|
|
|
|
2004-03-30 07:45:46 -06:00
|
|
|
// XInterface
|
|
|
|
//______________________________________________________________________________
|
|
|
|
Any SAL_CALL ORegistryFactoryHelper::queryInterface(
|
|
|
|
Type const & type ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
Any ret( OFactoryComponentHelper::queryInterface( type ) );
|
|
|
|
if (ret.hasValue())
|
|
|
|
return ret;
|
|
|
|
else
|
|
|
|
return OPropertySetHelper::queryInterface( type );
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
|
|
|
void ORegistryFactoryHelper::acquire() throw ()
|
|
|
|
{
|
|
|
|
OFactoryComponentHelper::acquire();
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
|
|
|
void ORegistryFactoryHelper::release() throw ()
|
|
|
|
{
|
|
|
|
OFactoryComponentHelper::release();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XTypeProvider
|
|
|
|
//______________________________________________________________________________
|
|
|
|
Sequence< Type > ORegistryFactoryHelper::getTypes() throw (RuntimeException)
|
|
|
|
{
|
|
|
|
Sequence< Type > types( OFactoryComponentHelper::getTypes() );
|
|
|
|
sal_Int32 pos = types.getLength();
|
|
|
|
types.realloc( pos + 3 );
|
|
|
|
Type * p = types.getArray();
|
|
|
|
p[ pos++ ] = ::getCppuType(
|
|
|
|
reinterpret_cast< Reference< beans::XMultiPropertySet > const * >(0) );
|
|
|
|
p[ pos++ ] = ::getCppuType(
|
|
|
|
reinterpret_cast< Reference< beans::XFastPropertySet > const * >(0) );
|
|
|
|
p[ pos++ ] = ::getCppuType(
|
|
|
|
reinterpret_cast< Reference< beans::XPropertySet > const * >(0) );
|
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XPropertySet
|
|
|
|
//______________________________________________________________________________
|
|
|
|
Reference< beans::XPropertySetInfo >
|
|
|
|
ORegistryFactoryHelper::getPropertySetInfo() throw (RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard guard( aMutex );
|
|
|
|
if (! m_xInfo.is())
|
|
|
|
m_xInfo = createPropertySetInfo( getInfoHelper() );
|
|
|
|
return m_xInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OPropertySetHelper
|
|
|
|
//______________________________________________________________________________
|
|
|
|
IPropertyArrayHelper & ORegistryFactoryHelper::getInfoHelper()
|
|
|
|
{
|
|
|
|
::osl::MutexGuard guard( aMutex );
|
|
|
|
if (m_property_array_helper.get() == 0)
|
|
|
|
{
|
|
|
|
beans::Property prop(
|
|
|
|
OUSTR("ImplementationKey") /* name */,
|
|
|
|
0 /* handle */,
|
|
|
|
::getCppuType( &xImplementationKey ),
|
|
|
|
beans::PropertyAttribute::READONLY |
|
|
|
|
beans::PropertyAttribute::OPTIONAL );
|
|
|
|
m_property_array_helper.reset(
|
|
|
|
new ::cppu::OPropertyArrayHelper( &prop, 1 ) );
|
|
|
|
}
|
|
|
|
return *m_property_array_helper.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
|
|
|
sal_Bool ORegistryFactoryHelper::convertFastPropertyValue(
|
2006-06-19 04:33:27 -05:00
|
|
|
Any &, Any &, sal_Int32, Any const & )
|
2004-03-30 07:45:46 -06:00
|
|
|
throw (lang::IllegalArgumentException)
|
|
|
|
{
|
|
|
|
OSL_ENSURE( 0, "unexpected!" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
|
|
|
void ORegistryFactoryHelper::setFastPropertyValue_NoBroadcast(
|
2006-06-19 04:33:27 -05:00
|
|
|
sal_Int32, Any const & )
|
2004-03-30 07:45:46 -06:00
|
|
|
throw (Exception)
|
|
|
|
{
|
|
|
|
throw beans::PropertyVetoException(
|
|
|
|
OUSTR("unexpected: only readonly properties!"),
|
|
|
|
static_cast< OWeakObject * >(this) );
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
|
|
|
void ORegistryFactoryHelper::getFastPropertyValue(
|
|
|
|
Any & rValue, sal_Int32 nHandle ) const
|
|
|
|
{
|
|
|
|
if (nHandle == 0)
|
|
|
|
{
|
|
|
|
rValue <<= xImplementationKey;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rValue.clear();
|
|
|
|
throw beans::UnknownPropertyException(
|
|
|
|
OUSTR("unknown property!"), static_cast< OWeakObject * >(
|
|
|
|
const_cast< ORegistryFactoryHelper * >(this) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-08 09:56:02 -05:00
|
|
|
Reference<XInterface > ORegistryFactoryHelper::createInstanceEveryTime(
|
|
|
|
Reference< XComponentContext > const & xContext )
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2001-05-17 06:06:19 -05:00
|
|
|
if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
|
2001-05-08 09:56:02 -05:00
|
|
|
{
|
2001-05-17 06:06:19 -05:00
|
|
|
Reference< XInterface > x( createModuleFactory() );
|
|
|
|
if (x.is())
|
2001-05-08 09:56:02 -05:00
|
|
|
{
|
2001-05-17 06:06:19 -05:00
|
|
|
MutexGuard aGuard( aMutex );
|
|
|
|
if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
|
|
|
|
{
|
|
|
|
xModuleFactory.set( x, UNO_QUERY );
|
|
|
|
xModuleFactoryDepr.set( x, UNO_QUERY );
|
|
|
|
}
|
2001-05-08 09:56:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if( xModuleFactory.is() )
|
|
|
|
{
|
|
|
|
return xModuleFactory->createInstanceWithContext( xContext );
|
|
|
|
}
|
|
|
|
else if( xModuleFactoryDepr.is() )
|
|
|
|
{
|
|
|
|
return xModuleFactoryDepr->createInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Reference<XInterface >();
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference<XInterface > SAL_CALL ORegistryFactoryHelper::createInstanceWithArguments(
|
|
|
|
const Sequence<Any>& Arguments )
|
2000-09-18 09:29:57 -05:00
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2001-05-17 06:06:19 -05:00
|
|
|
if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
|
2001-05-08 09:56:02 -05:00
|
|
|
{
|
2001-05-17 06:06:19 -05:00
|
|
|
Reference< XInterface > x( createModuleFactory() );
|
|
|
|
if (x.is())
|
2001-05-08 09:56:02 -05:00
|
|
|
{
|
2001-05-17 06:06:19 -05:00
|
|
|
MutexGuard aGuard( aMutex );
|
|
|
|
if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
|
|
|
|
{
|
|
|
|
xModuleFactory.set( x, UNO_QUERY );
|
|
|
|
xModuleFactoryDepr.set( x, UNO_QUERY );
|
|
|
|
}
|
2001-05-08 09:56:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if( xModuleFactoryDepr.is() )
|
|
|
|
{
|
|
|
|
return xModuleFactoryDepr->createInstanceWithArguments( Arguments );
|
|
|
|
}
|
2001-05-17 06:06:19 -05:00
|
|
|
else if( xModuleFactory.is() )
|
|
|
|
{
|
2003-04-15 10:34:31 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2001-05-17 06:06:19 -05:00
|
|
|
OSL_TRACE( "### no context ORegistryFactoryHelper::createInstanceWithArgumentsAndContext()!\n" );
|
|
|
|
#endif
|
|
|
|
return xModuleFactory->createInstanceWithArgumentsAndContext( Arguments, Reference< XComponentContext >() );
|
|
|
|
}
|
2001-05-08 09:56:02 -05:00
|
|
|
|
|
|
|
return Reference<XInterface >();
|
|
|
|
}
|
2000-09-18 09:29:57 -05:00
|
|
|
|
2001-05-08 09:56:02 -05:00
|
|
|
Reference< XInterface > ORegistryFactoryHelper::createInstanceWithArgumentsAndContext(
|
|
|
|
Sequence< Any > const & rArguments,
|
|
|
|
Reference< XComponentContext > const & xContext )
|
|
|
|
throw (Exception, RuntimeException)
|
|
|
|
{
|
2001-05-17 06:06:19 -05:00
|
|
|
if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
|
2000-10-18 07:20:58 -05:00
|
|
|
{
|
2001-05-17 06:06:19 -05:00
|
|
|
Reference< XInterface > x( createModuleFactory() );
|
|
|
|
if (x.is())
|
2000-12-06 02:36:29 -06:00
|
|
|
{
|
2001-05-17 06:06:19 -05:00
|
|
|
MutexGuard aGuard( aMutex );
|
|
|
|
if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
|
|
|
|
{
|
|
|
|
xModuleFactory.set( x, UNO_QUERY );
|
|
|
|
xModuleFactoryDepr.set( x, UNO_QUERY );
|
|
|
|
}
|
2000-12-06 02:36:29 -06:00
|
|
|
}
|
2000-10-18 07:20:58 -05:00
|
|
|
}
|
2000-09-18 09:29:57 -05:00
|
|
|
if( xModuleFactory.is() )
|
2001-05-08 09:56:02 -05:00
|
|
|
{
|
|
|
|
return xModuleFactory->createInstanceWithArgumentsAndContext( rArguments, xContext );
|
|
|
|
}
|
|
|
|
else if( xModuleFactoryDepr.is() )
|
|
|
|
{
|
2003-04-15 10:34:31 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2001-05-08 09:56:02 -05:00
|
|
|
if (xContext.is())
|
|
|
|
{
|
|
|
|
OSL_TRACE( "### ignoring context calling ORegistryFactoryHelper::createInstanceWithArgumentsAndContext()!\n" );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return xModuleFactoryDepr->createInstanceWithArguments( rArguments );
|
|
|
|
}
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
return Reference<XInterface >();
|
|
|
|
}
|
|
|
|
|
2001-05-08 09:56:02 -05:00
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
// OSingleFactoryHelper
|
2001-05-08 09:56:02 -05:00
|
|
|
Reference< XInterface > ORegistryFactoryHelper::createModuleFactory()
|
2000-09-18 09:29:57 -05:00
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
Reference< XInterface > xFactory;
|
2000-09-18 09:29:57 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
OUString aActivatorUrl;
|
|
|
|
OUString aActivatorName;
|
|
|
|
OUString aLocation;
|
|
|
|
|
|
|
|
Reference<XRegistryKey > xActivatorKey = xImplementationKey->openKey(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/ACTIVATOR") ) );
|
|
|
|
if( xActivatorKey.is() && xActivatorKey->getValueType() == RegistryValueType_ASCII )
|
|
|
|
{
|
|
|
|
aActivatorUrl = xActivatorKey->getAsciiValue();
|
|
|
|
|
|
|
|
OUString tmpActivator(aActivatorUrl.getStr());
|
2001-05-10 14:29:53 -05:00
|
|
|
sal_Int32 nIndex = 0;
|
|
|
|
aActivatorName = tmpActivator.getToken(0, ':', nIndex );
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
Reference<XRegistryKey > xLocationKey = xImplementationKey->openKey(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/LOCATION") ) );
|
|
|
|
if( xLocationKey.is() && xLocationKey->getValueType() == RegistryValueType_ASCII )
|
|
|
|
aLocation = xLocationKey->getAsciiValue();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// old style"url"
|
|
|
|
// the location of the program code of the implementation
|
|
|
|
Reference<XRegistryKey > xLocationKey = xImplementationKey->openKey(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/URL") ) );
|
|
|
|
// is the the key of the right type ?
|
|
|
|
if( xLocationKey.is() && xLocationKey->getValueType() == RegistryValueType_ASCII )
|
|
|
|
{
|
|
|
|
// one implementation found -> try to activate
|
|
|
|
aLocation = xLocationKey->getAsciiValue();
|
|
|
|
|
|
|
|
// search protocol delemitter
|
2001-05-10 14:29:53 -05:00
|
|
|
sal_Int32 nPos = aLocation.indexOf(
|
2000-09-18 09:29:57 -05:00
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("://") ) );
|
|
|
|
if( nPos != -1 )
|
|
|
|
{
|
|
|
|
aActivatorName = aLocation.copy( 0, nPos );
|
|
|
|
if( aActivatorName.compareToAscii( "java" ) == 0 )
|
|
|
|
aActivatorName = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.loader.Java") );
|
|
|
|
else if( aActivatorName.compareToAscii( "module" ) == 0 )
|
|
|
|
aActivatorName = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.loader.SharedLibrary") );
|
|
|
|
aLocation = aLocation.copy( nPos + 3 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-10 14:29:53 -05:00
|
|
|
if( aActivatorName.getLength() != 0 )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
Reference<XInterface > x = xSMgr->createInstance( aActivatorName );
|
|
|
|
Reference<XImplementationLoader > xLoader( x, UNO_QUERY );
|
|
|
|
Reference<XInterface > xMF;
|
|
|
|
if (xLoader.is())
|
|
|
|
{
|
|
|
|
// JSC: This exception must not be catched if a concept for exception handling
|
|
|
|
// is specified, implemented and used.
|
|
|
|
try
|
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
xFactory = xLoader->activate( aImplementationName, aActivatorUrl, aLocation, xImplementationKey );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
catch( CannotActivateFactoryException& e)
|
|
|
|
{
|
|
|
|
OString msg( OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US) );
|
2003-04-23 10:24:33 -05:00
|
|
|
OSL_TRACE(msg.getStr() );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-04-23 10:24:33 -05:00
|
|
|
catch (InvalidRegistryException & e)
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2003-04-23 10:24:33 -05:00
|
|
|
OString msg( OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US) );
|
|
|
|
OSL_TRACE(msg.getStr() );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return xFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XServiceInfo
|
|
|
|
Sequence< OUString > ORegistryFactoryHelper::getSupportedServiceNames(void)
|
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( aMutex );
|
|
|
|
if( aServiceNames.getLength() == 0 )
|
|
|
|
{
|
|
|
|
// not yet loaded
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference<XRegistryKey > xKey = xImplementationKey->openKey(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("UNO/SERVICES") ) );
|
|
|
|
|
|
|
|
if (xKey.is())
|
|
|
|
{
|
|
|
|
// length of prefix. +1 for the '/' at the end
|
2001-05-10 14:29:53 -05:00
|
|
|
sal_Int32 nPrefixLen = xKey->getKeyName().getLength() + 1;
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
// Full qualified names like "IMPLEMENTATIONS/TEST/UNO/SERVICES/com.sun.star..."
|
|
|
|
Sequence<OUString> seqKeys = xKey->getKeyNames();
|
|
|
|
OUString* pKeys = seqKeys.getArray();
|
|
|
|
for( sal_Int32 i = 0; i < seqKeys.getLength(); i++ )
|
|
|
|
pKeys[i] = pKeys[i].copy(nPrefixLen);
|
|
|
|
|
|
|
|
aServiceNames = seqKeys;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (InvalidRegistryException &)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aServiceNames;
|
|
|
|
}
|
|
|
|
|
2001-06-12 04:19:10 -05:00
|
|
|
sal_Bool SAL_CALL ORegistryFactoryHelper::releaseOnNotification() throw(::com::sun::star::uno::RuntimeException)
|
2001-06-07 04:56:36 -05:00
|
|
|
{
|
|
|
|
sal_Bool retVal= sal_True;
|
|
|
|
if( isOneInstance() && isInstance())
|
|
|
|
{
|
|
|
|
retVal= sal_False;
|
|
|
|
}
|
|
|
|
else if( ! isOneInstance())
|
|
|
|
{
|
|
|
|
// try to delegate
|
|
|
|
if( xModuleFactory.is())
|
|
|
|
{
|
|
|
|
Reference<XUnloadingPreference> xunloading( xModuleFactory, UNO_QUERY);
|
|
|
|
if( xunloading.is())
|
|
|
|
retVal= xunloading->releaseOnNotification();
|
|
|
|
}
|
|
|
|
else if( xModuleFactoryDepr.is())
|
|
|
|
{
|
|
|
|
Reference<XUnloadingPreference> xunloading( xModuleFactoryDepr, UNO_QUERY);
|
|
|
|
if( xunloading.is())
|
|
|
|
retVal= xunloading->releaseOnNotification();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retVal;
|
|
|
|
}
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-06-07 04:56:36 -05:00
|
|
|
class OFactoryProxyHelper : public WeakImplHelper3< XServiceInfo, XSingleServiceFactory,
|
|
|
|
XUnloadingPreference >
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
Reference<XSingleServiceFactory > xFactory;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2001-03-09 05:15:28 -06:00
|
|
|
OFactoryProxyHelper(
|
|
|
|
const Reference<XMultiServiceFactory > & /*rServiceManager*/,
|
|
|
|
const Reference<XSingleServiceFactory > & rFactory )
|
|
|
|
SAL_THROW( () )
|
2000-09-18 09:29:57 -05:00
|
|
|
: xFactory( rFactory )
|
|
|
|
{}
|
|
|
|
|
|
|
|
// XSingleServiceFactory
|
|
|
|
Reference<XInterface > SAL_CALL createInstance()
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
|
|
|
|
Reference<XInterface > SAL_CALL createInstanceWithArguments(const Sequence<Any>& Arguments)
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
|
|
|
|
|
|
|
|
// XServiceInfo
|
|
|
|
OUString SAL_CALL getImplementationName()
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
|
|
|
sal_Bool SAL_CALL supportsService(const OUString& ServiceName)
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
|
|
|
Sequence< OUString > SAL_CALL getSupportedServiceNames(void)
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
2001-06-07 04:56:36 -05:00
|
|
|
//XUnloadingPreference
|
|
|
|
sal_Bool SAL_CALL releaseOnNotification()
|
|
|
|
throw(::com::sun::star::uno::RuntimeException);
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// XSingleServiceFactory
|
|
|
|
Reference<XInterface > OFactoryProxyHelper::createInstance()
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return xFactory->createInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XSingleServiceFactory
|
|
|
|
Reference<XInterface > OFactoryProxyHelper::createInstanceWithArguments
|
|
|
|
(
|
|
|
|
const Sequence<Any>& Arguments
|
|
|
|
)
|
|
|
|
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return xFactory->createInstanceWithArguments( Arguments );
|
|
|
|
}
|
|
|
|
|
|
|
|
// XServiceInfo
|
|
|
|
OUString OFactoryProxyHelper::getImplementationName()
|
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
Reference<XServiceInfo > xInfo( xFactory, UNO_QUERY );
|
|
|
|
if( xInfo.is() )
|
|
|
|
return xInfo->getImplementationName();
|
|
|
|
return OUString();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XServiceInfo
|
|
|
|
sal_Bool OFactoryProxyHelper::supportsService(const OUString& ServiceName)
|
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
Reference<XServiceInfo > xInfo( xFactory, UNO_QUERY );
|
|
|
|
if( xInfo.is() )
|
|
|
|
return xInfo->supportsService( ServiceName );
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XServiceInfo
|
|
|
|
Sequence< OUString > OFactoryProxyHelper::getSupportedServiceNames(void)
|
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
Reference<XServiceInfo > xInfo( xFactory, UNO_QUERY );
|
|
|
|
if( xInfo.is() )
|
|
|
|
return xInfo->getSupportedServiceNames();
|
|
|
|
return Sequence< OUString >();
|
|
|
|
}
|
|
|
|
|
2001-06-12 04:19:10 -05:00
|
|
|
sal_Bool SAL_CALL OFactoryProxyHelper::releaseOnNotification() throw(::com::sun::star::uno::RuntimeException)
|
2001-06-07 04:56:36 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
Reference<XUnloadingPreference> pref( xFactory, UNO_QUERY);
|
|
|
|
if( pref.is())
|
|
|
|
return pref->releaseOnNotification();
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// global function
|
2001-03-09 05:15:28 -06:00
|
|
|
Reference<XSingleServiceFactory > SAL_CALL createSingleFactory(
|
2000-09-18 09:29:57 -05:00
|
|
|
const Reference<XMultiServiceFactory > & rServiceManager,
|
|
|
|
const OUString & rImplementationName,
|
|
|
|
ComponentInstantiation pCreateFunction,
|
2001-05-18 09:44:18 -05:00
|
|
|
const Sequence< OUString > & rServiceNames,
|
|
|
|
rtl_ModuleCount *pModCount )
|
2001-03-09 05:15:28 -06:00
|
|
|
SAL_THROW( () )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
return new OFactoryComponentHelper(
|
2001-06-07 04:56:36 -05:00
|
|
|
rServiceManager, rImplementationName, pCreateFunction, 0, &rServiceNames, pModCount, sal_False );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// global function
|
2001-03-09 05:15:28 -06:00
|
|
|
Reference<XSingleServiceFactory > SAL_CALL createFactoryProxy(
|
2000-09-18 09:29:57 -05:00
|
|
|
const Reference<XMultiServiceFactory > & rServiceManager,
|
2001-03-09 05:15:28 -06:00
|
|
|
const Reference<XSingleServiceFactory > & rFactory )
|
|
|
|
SAL_THROW( () )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
return new OFactoryProxyHelper(
|
|
|
|
rServiceManager, rFactory );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// global function
|
2001-03-09 05:15:28 -06:00
|
|
|
Reference<XSingleServiceFactory > SAL_CALL createOneInstanceFactory(
|
2000-09-18 09:29:57 -05:00
|
|
|
const Reference<XMultiServiceFactory > & rServiceManager,
|
|
|
|
const OUString & rImplementationName,
|
|
|
|
ComponentInstantiation pCreateFunction,
|
2001-05-18 09:44:18 -05:00
|
|
|
const Sequence< OUString > & rServiceNames,
|
|
|
|
rtl_ModuleCount *pModCount )
|
2001-03-09 05:15:28 -06:00
|
|
|
SAL_THROW( () )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
return new OFactoryComponentHelper(
|
2001-06-07 04:56:36 -05:00
|
|
|
rServiceManager, rImplementationName, pCreateFunction, 0, &rServiceNames, pModCount, sal_True );
|
|
|
|
// return new OFactoryUnloadableComponentHelper(
|
|
|
|
// rServiceManager, rImplementationName, pCreateFunction, 0, &rServiceNames, pModCount, sal_True );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// global function
|
2001-03-09 05:15:28 -06:00
|
|
|
Reference<XSingleServiceFactory > SAL_CALL createSingleRegistryFactory(
|
2000-09-18 09:29:57 -05:00
|
|
|
const Reference<XMultiServiceFactory > & rServiceManager,
|
|
|
|
const OUString & rImplementationName,
|
2001-03-09 05:15:28 -06:00
|
|
|
const Reference<XRegistryKey > & rImplementationKey )
|
|
|
|
SAL_THROW( () )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
return new ORegistryFactoryHelper(
|
|
|
|
rServiceManager, rImplementationName, rImplementationKey, sal_False );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// global function
|
2001-03-09 05:15:28 -06:00
|
|
|
Reference<XSingleServiceFactory > SAL_CALL createOneInstanceRegistryFactory(
|
2000-09-18 09:29:57 -05:00
|
|
|
const Reference<XMultiServiceFactory > & rServiceManager,
|
|
|
|
const OUString & rImplementationName,
|
2001-03-09 05:15:28 -06:00
|
|
|
const Reference<XRegistryKey > & rImplementationKey )
|
|
|
|
SAL_THROW( () )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
2001-05-08 09:56:02 -05:00
|
|
|
return new ORegistryFactoryHelper(
|
|
|
|
rServiceManager, rImplementationName, rImplementationKey, sal_True );
|
|
|
|
}
|
|
|
|
|
|
|
|
//##################################################################################################
|
|
|
|
Reference< lang::XSingleComponentFactory > SAL_CALL createSingleComponentFactory(
|
|
|
|
ComponentFactoryFunc fptr,
|
|
|
|
OUString const & rImplementationName,
|
2001-05-18 09:44:18 -05:00
|
|
|
Sequence< OUString > const & rServiceNames,
|
|
|
|
rtl_ModuleCount * pModCount)
|
2001-05-08 09:56:02 -05:00
|
|
|
SAL_THROW( () )
|
|
|
|
{
|
|
|
|
return new OFactoryComponentHelper(
|
2001-06-07 04:56:36 -05:00
|
|
|
Reference< XMultiServiceFactory >(), rImplementationName, 0, fptr, &rServiceNames, pModCount, sal_False );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|