21#include <osl/diagnose.h>
22#include <osl/mutex.hxx>
30#include <rtl/unload.h>
35#include <com/sun/star/lang/XServiceInfo.hpp>
36#include <com/sun/star/lang/XSingleServiceFactory.hpp>
37#include <com/sun/star/lang/XSingleComponentFactory.hpp>
38#include <com/sun/star/lang/XInitialization.hpp>
39#include <com/sun/star/lang/XMultiServiceFactory.hpp>
40#include <com/sun/star/loader/XImplementationLoader.hpp>
41#include <com/sun/star/lang/XComponent.hpp>
42#include <com/sun/star/lang/IllegalArgumentException.hpp>
43#include <com/sun/star/uno/XUnloadingPreference.hpp>
44#include <com/sun/star/beans/PropertyAttribute.hpp>
54using namespace com::sun::star::loader;
62class OFactoryComponentHelper
64 ,
public WeakComponentImplHelper<
66 XSingleServiceFactory,
67 lang::XSingleComponentFactory,
71 OFactoryComponentHelper(
73 OUString aImplementationName_,
74 ComponentInstantiation pCreateFunction_,
75 ComponentFactoryFunc fptr,
78 : WeakComponentImplHelper(
m_aMutex )
80 ,
xSMgr( rServiceManager )
108 virtual sal_Bool SAL_CALL releaseOnNotification()
override;
111 void SAL_CALL disposing()
override;
114 css::uno::Reference<css::uno::XInterface> createInstanceWithArgumentsEveryTime(
115 css::uno::Sequence<css::uno::Any>
const & rArguments,
116 css::uno::Reference<css::uno::XComponentContext>
const & xContext);
164 return (*
m_fptr)( xContext );
171 xContext->getServiceManager(), UNO_QUERY );
172 if (xContextMgr.is())
187 MutexGuard aGuard( m_aMutex );
203 MutexGuard aGuard( m_aMutex );
223 MutexGuard aGuard( m_aMutex );
230 return createInstanceEveryTime( xContext );
241 MutexGuard aGuard( m_aMutex );
244 xTheInstance = createInstanceWithArgumentsEveryTime( rArguments, xContext );
248 return createInstanceWithArgumentsEveryTime( rArguments, xContext );
251css::uno::Reference<css::uno::XInterface>
252OFactoryComponentHelper::createInstanceWithArgumentsEveryTime(
253 css::uno::Sequence<css::uno::Any>
const & rArguments,
254 css::uno::Reference<css::uno::XComponentContext>
const & xContext)
262 xInit->initialize( rArguments );
266 if ( rArguments.hasElements() )
274 throw lang::IllegalArgumentException(
275 "cannot pass arguments to component => no XInitialization implemented!",
285void OFactoryComponentHelper::disposing()
290 MutexGuard aGuard( m_aMutex );
301OUString OFactoryComponentHelper::getImplementationName()
308 const OUString& ServiceName )
326sal_Bool SAL_CALL OFactoryComponentHelper::releaseOnNotification()
335class ORegistryFactoryHelper :
public OFactoryComponentHelper,
336 public OPropertySetHelper
340 ORegistryFactoryHelper(
342 const OUString & rImplementationName_,
345 : OFactoryComponentHelper(
346 rServiceManager, rImplementationName_, nullptr, nullptr, nullptr, bOneInstance_ ),
347 OPropertySetHelper( WeakComponentImplHelper::rBHelper ),
353 virtual void SAL_CALL acquire() noexcept override;
354 virtual
void SAL_CALL release() noexcept override;
358 virtual
Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override;
361 virtual IPropertyArrayHelper & SAL_CALL getInfoHelper() override;
362 virtual
sal_Bool SAL_CALL convertFastPropertyValue(
363 Any & rConvertedValue, Any & rOldValue,
364 sal_Int32 nHandle, Any const & rValue ) override;
365 virtual
void SAL_CALL setFastPropertyValue_NoBroadcast(
366 sal_Int32 nHandle, Any const & rValue ) override;
367 using OPropertySetHelper::getFastPropertyValue;
368 virtual
void SAL_CALL getFastPropertyValue(
369 Any & rValue, sal_Int32 nHandle ) const override;
373 Reference< XComponentContext > const & xContext ) override;
380 Reference< XComponentContext > const & xContext ) override;
383 Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
385 sal_Bool SAL_CALL releaseOnNotification() override;
401 using OPropertySetHelper::getTypes;
418void ORegistryFactoryHelper::acquire() noexcept
420 OFactoryComponentHelper::acquire();
424void ORegistryFactoryHelper::release() noexcept
426 OFactoryComponentHelper::release();
434 sal_Int32
pos = types.getLength();
435 types.realloc( pos + 3 );
436 Type *
p = types.getArray();
446ORegistryFactoryHelper::getPropertySetInfo()
448 ::osl::MutexGuard guard( m_aMutex );
450 m_xInfo = createPropertySetInfo( getInfoHelper() );
456IPropertyArrayHelper & ORegistryFactoryHelper::getInfoHelper()
458 ::osl::MutexGuard guard( m_aMutex );
461 beans::Property prop(
462 "ImplementationKey" ,
465 beans::PropertyAttribute::READONLY |
466 beans::PropertyAttribute::OPTIONAL );
468 new ::cppu::OPropertyArrayHelper( &prop, 1 ) );
474sal_Bool ORegistryFactoryHelper::convertFastPropertyValue(
475 Any &, Any &, sal_Int32, Any
const & )
477 OSL_FAIL(
"unexpected!" );
482void ORegistryFactoryHelper::setFastPropertyValue_NoBroadcast(
483 sal_Int32, Any
const & )
485 throw beans::PropertyVetoException(
486 "unexpected: only readonly properties!",
487 static_cast< OWeakObject *
>(
this) );
491void ORegistryFactoryHelper::getFastPropertyValue(
492 Any & rValue, sal_Int32 nHandle )
const
501 throw beans::UnknownPropertyException(
502 "unknown property!",
static_cast< OWeakObject *
>(
503 const_cast< ORegistryFactoryHelper *
>(
this) ) );
515 MutexGuard aGuard( m_aMutex );
543 MutexGuard aGuard( m_aMutex );
557 SAL_INFO(
"cppuhelper",
"no context ORegistryFactoryHelper::createInstanceWithArgumentsAndContext()!");
573 MutexGuard aGuard( m_aMutex );
583 return xModuleFactory->createInstanceWithArgumentsAndContext( rArguments, xContext );
587 SAL_INFO_IF(xContext.is(),
"cppuhelper",
"ignoring context calling ORegistryFactoryHelper::createInstanceWithArgumentsAndContext()!");
597 OUString aActivatorUrl;
598 OUString aActivatorName;
603 if( xActivatorKey.is() && xActivatorKey->getValueType() == RegistryValueType_ASCII )
605 aActivatorUrl = xActivatorKey->getAsciiValue();
611 if( xLocationKey.is() && xLocationKey->getValueType() == RegistryValueType_ASCII )
612 aLocation = xLocationKey->getAsciiValue();
621 if( xLocationKey.is() && xLocationKey->getValueType() == RegistryValueType_ASCII )
624 aLocation = xLocationKey->getAsciiValue();
627 sal_Int32
nPos = aLocation.indexOf(
"://");
630 aActivatorName = aLocation.subView( 0, nPos );
631 if( aActivatorName == u
"java" )
632 aActivatorName =
u"com.sun.star.loader.Java";
633 else if( aActivatorName == u
"module" )
634 aActivatorName =
u"com.sun.star.loader.SharedLibrary";
635 aLocation = aLocation.copy( nPos + 3 );
641 if( !aActivatorName.isEmpty() )
656 MutexGuard aGuard( m_aMutex );
667 sal_Int32 nPrefixLen = xKey->getKeyName().getLength() + 1;
671 for( OUString & key : asNonConstRange(seqKeys) )
672 key = key.copy(nPrefixLen);
677 catch (InvalidRegistryException &)
684sal_Bool SAL_CALL ORegistryFactoryHelper::releaseOnNotification()
687 if( isOneInstance() && isInstance())
691 else if( ! isOneInstance())
698 retVal= xunloading->releaseOnNotification();
704 retVal= xunloading->releaseOnNotification();
712class OFactoryProxyHelper :
public WeakImplHelper< XServiceInfo, XSingleServiceFactory,
713 XUnloadingPreference >
732 sal_Bool SAL_CALL releaseOnNotification()
override;
750 return xFactory->createInstanceWithArguments( Arguments );
754OUString OFactoryProxyHelper::getImplementationName()
758 return xInfo->getImplementationName();
773 return xInfo->getSupportedServiceNames();
777sal_Bool SAL_CALL OFactoryProxyHelper::releaseOnNotification()
782 return pref->releaseOnNotification();
789 const OUString & rImplementationName,
794 return new OFactoryComponentHelper(
795 rServiceManager, rImplementationName,
pCreateFunction,
nullptr, &rServiceNames,
false );
803 return new OFactoryProxyHelper( rFactory );
809 const OUString & rImplementationName,
814 return new OFactoryComponentHelper(
815 rServiceManager, rImplementationName,
pCreateFunction,
nullptr, &rServiceNames,
true );
821 const OUString & rImplementationName,
824 return new ORegistryFactoryHelper(
825 rServiceManager, rImplementationName, rImplementationKey,
false );
831 const OUString & rImplementationName,
834 return new ORegistryFactoryHelper(
835 rServiceManager, rImplementationName, rImplementationKey,
true );
840 ComponentFactoryFunc fptr,
841 OUString
const & rImplementationName,
845 return new OFactoryComponentHelper(
850 ComponentFactoryFunc fptr,
851 OUString
const & rImplementationName,
855 return new OFactoryComponentHelper(
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
base class for all classes who want derive from cppu::WeakComponentImplHelperXX.
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) SAL_OVERRIDE
Only returns a reference to XMultiPropertySet, XFastPropertySet, XPropertySet and XEventListener.
css::uno::Type const & get()
Reference< XInterface > xTheInstance
Reference< XMultiServiceFactory > xSMgr
std::unique_ptr< IPropertyArrayHelper > m_property_array_helper
Reference< XSingleServiceFactory > xFactory
Reference< XRegistryKey > xImplementationKey
The registry key of the implementation section.
Sequence< OUString > aServiceNames
ComponentInstantiation pCreateFunction
Reference< beans::XPropertySetInfo > m_xInfo
Reference< XSingleComponentFactory > xModuleFactory
The factory created with the loader.
OUString aImplementationName
ComponentFactoryFunc m_fptr
Reference< XSingleServiceFactory > xModuleFactoryDepr
#define SAL_INFO_IF(condition, area, stream)
#define SAL_INFO(area, stream)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
Reference< XSingleServiceFactory > SAL_CALL createOneInstanceRegistryFactory(const Reference< XMultiServiceFactory > &rServiceManager, const OUString &rImplementationName, const Reference< XRegistryKey > &rImplementationKey)
css::uno::Reference< css::uno::XInterface >(SAL_CALL *ComponentFactoryFunc)(css CPPUHELPER_DLLPUBLIC css::uno::Reference< css::lang::XSingleComponentFactory > SAL_CALL createSingleComponentFactory(ComponentFactoryFunc fptr, ::rtl::OUString const &rImplementationName, css::uno::Sequence< ::rtl::OUString > const &rServiceNames, rtl_ModuleCount *pModCount=NULL)
Function pointer declaration.
Reference< XSingleServiceFactory > SAL_CALL createSingleRegistryFactory(const Reference< XMultiServiceFactory > &rServiceManager, const OUString &rImplementationName, const Reference< XRegistryKey > &rImplementationKey)
Reference< XSingleServiceFactory > SAL_CALL createOneInstanceFactory(const Reference< XMultiServiceFactory > &rServiceManager, const OUString &rImplementationName, ComponentInstantiation pCreateFunction, const Sequence< OUString > &rServiceNames, rtl_ModuleCount *)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
Compares demanded type to given template argument types.
Reference< lang::XSingleComponentFactory > SAL_CALL createOneInstanceComponentFactory(ComponentFactoryFunc fptr, OUString const &rImplementationName, Sequence< OUString > const &rServiceNames, rtl_ModuleCount *)
css::uno::Reference< css::uno::XInterface >(SAL_CALL *ComponentInstantiation)(const css CPPUHELPER_DLLPUBLIC css::uno::Reference< css::lang::XSingleServiceFactory > SAL_CALL createSingleFactory(const css::uno::Reference< css::lang::XMultiServiceFactory > &rServiceManager, const ::rtl::OUString &rImplementationName, ComponentInstantiation pCreateFunction, const css::uno::Sequence< ::rtl::OUString > &rServiceNames, rtl_ModuleCount *pModCount=NULL)
Deprecated.
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
A helper for implementations of com.sun.star.lang.XServiceInfo.
Reference< XSingleServiceFactory > SAL_CALL createFactoryProxy(SAL_UNUSED_PARAMETER const Reference< XMultiServiceFactory > &, const Reference< XSingleServiceFactory > &rFactory)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)