1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/log.hxx>
21 #include <osl/diagnose.h>
22 #include <osl/mutex.hxx>
23 #include <cppuhelper/weak.hxx>
24 #include <cppuhelper/component.hxx>
25 #include <cppuhelper/factory.hxx>
26 #include <cppuhelper/implbase.hxx>
27 #include <cppuhelper/queryinterface.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <rtl/unload.h>
31 #include <cppuhelper/propshlp.hxx>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
35 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
36 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/loader/XImplementationLoader.hpp>
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/lang/IllegalArgumentException.hpp>
41 #include <com/sun/star/uno/XUnloadingPreference.hpp>
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
48 using namespace com::sun::star
;
49 using namespace com::sun::star::uno
;
50 using namespace com::sun::star::lang
;
51 using namespace com::sun::star::loader
;
52 using namespace com::sun::star::registry
;
59 class OSingleFactoryHelper
61 , public XSingleServiceFactory
62 , public lang::XSingleComponentFactory
63 , public XUnloadingPreference
67 const Reference
<XMultiServiceFactory
> & rServiceManager
,
68 const OUString
& rImplementationName_
,
69 ComponentInstantiation pCreateFunction_
,
70 ComponentFactoryFunc fptr
,
71 const Sequence
< OUString
> * pServiceNames_
)
72 : xSMgr( rServiceManager
)
73 , pCreateFunction( pCreateFunction_
)
75 , aImplementationName( rImplementationName_
)
78 aServiceNames
= *pServiceNames_
;
81 virtual ~OSingleFactoryHelper();
84 Any SAL_CALL
queryInterface( const Type
& rType
) override
;
86 // XSingleServiceFactory
87 Reference
<XInterface
> SAL_CALL
createInstance() override
;
88 virtual Reference
<XInterface
> SAL_CALL
createInstanceWithArguments(const Sequence
<Any
>& Arguments
) override
;
89 // XSingleComponentFactory
90 virtual Reference
< XInterface
> SAL_CALL
createInstanceWithContext(
91 Reference
< XComponentContext
> const & xContext
) override
;
92 virtual Reference
< XInterface
> SAL_CALL
createInstanceWithArgumentsAndContext(
93 Sequence
< Any
> const & rArguments
,
94 Reference
< XComponentContext
> const & xContext
) override
;
97 OUString SAL_CALL
getImplementationName() override
;
98 sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
99 Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
103 * Create an instance specified by the factory. The one instance logic is implemented
104 * in the createInstance and createInstanceWithArguments methods.
105 * @return the newly created instance. Do not return a previous (one instance) instance.
106 * @throw css::uno::Exception
107 * @throw css::uno::RuntimeException
109 virtual Reference
<XInterface
> createInstanceEveryTime(
110 Reference
< XComponentContext
> const & xContext
);
112 Reference
<XMultiServiceFactory
> xSMgr
;
113 ComponentInstantiation pCreateFunction
;
114 ComponentFactoryFunc m_fptr
;
115 Sequence
< OUString
> aServiceNames
;
116 OUString aImplementationName
;
121 OSingleFactoryHelper::~OSingleFactoryHelper()
126 Any
OSingleFactoryHelper::queryInterface( const Type
& rType
)
128 return ::cppu::queryInterface(
130 static_cast< XSingleComponentFactory
* >( this ),
131 static_cast< XSingleServiceFactory
* >( this ),
132 static_cast< XServiceInfo
* >( this ) ,
133 static_cast< XUnloadingPreference
* >( this ));
136 // OSingleFactoryHelper
137 Reference
<XInterface
> OSingleFactoryHelper::createInstanceEveryTime(
138 Reference
< XComponentContext
> const & xContext
)
142 return (*m_fptr
)( xContext
);
144 if( pCreateFunction
)
148 Reference
< lang::XMultiServiceFactory
> xContextMgr(
149 xContext
->getServiceManager(), UNO_QUERY
);
150 if (xContextMgr
.is())
151 return (*pCreateFunction
)( xContextMgr
);
153 return (*pCreateFunction
)( xSMgr
);
155 return Reference
< XInterface
>();
158 // XSingleServiceFactory
159 Reference
<XInterface
> OSingleFactoryHelper::createInstance()
161 return createInstanceWithContext( Reference
< XComponentContext
>() );
164 // XSingleServiceFactory
165 Reference
<XInterface
> OSingleFactoryHelper::createInstanceWithArguments(
166 const Sequence
<Any
>& Arguments
)
168 return createInstanceWithArgumentsAndContext(
169 Arguments
, Reference
< XComponentContext
>() );
172 // XSingleComponentFactory
174 Reference
< XInterface
> OSingleFactoryHelper::createInstanceWithContext(
175 Reference
< XComponentContext
> const & xContext
)
177 return createInstanceEveryTime( xContext
);
180 Reference
< XInterface
> OSingleFactoryHelper::createInstanceWithArgumentsAndContext(
181 Sequence
< Any
> const & rArguments
,
182 Reference
< XComponentContext
> const & xContext
)
184 Reference
< XInterface
> xRet( createInstanceWithContext( xContext
) );
186 Reference
< lang::XInitialization
> xInit( xRet
, UNO_QUERY
);
187 // always call initialize, even if there are no arguments. #i63511#
190 xInit
->initialize( rArguments
);
194 if ( rArguments
.hasElements() )
196 // dispose the here created UNO object before throwing out exception
197 // to avoid risk of memory leaks #i113722#
198 Reference
<XComponent
> xComp( xRet
, UNO_QUERY
);
202 throw lang::IllegalArgumentException(
203 "cannot pass arguments to component => no XInitialization implemented!",
204 Reference
< XInterface
>(), 0 );
212 OUString
OSingleFactoryHelper::getImplementationName()
214 return aImplementationName
;
218 sal_Bool
OSingleFactoryHelper::supportsService(
219 const OUString
& ServiceName
)
221 return cppu::supportsService(this, ServiceName
);
225 Sequence
< OUString
> OSingleFactoryHelper::getSupportedServiceNames()
227 return aServiceNames
;
232 struct OFactoryComponentHelper_Mutex
237 class OFactoryComponentHelper
238 : public OFactoryComponentHelper_Mutex
239 , public OComponentHelper
240 , public OSingleFactoryHelper
243 OFactoryComponentHelper(
244 const Reference
<XMultiServiceFactory
> & rServiceManager
,
245 const OUString
& rImplementationName_
,
246 ComponentInstantiation pCreateFunction_
,
247 ComponentFactoryFunc fptr
,
248 const Sequence
< OUString
> * pServiceNames_
,
250 : OComponentHelper( aMutex
)
251 , OSingleFactoryHelper( rServiceManager
, rImplementationName_
, pCreateFunction_
, fptr
, pServiceNames_
)
252 , bOneInstance( bOneInstance_
)
257 Any SAL_CALL
queryInterface( const Type
& rType
) override
;
258 void SAL_CALL
acquire() noexcept override
259 { OComponentHelper::acquire(); }
260 void SAL_CALL
release() noexcept override
261 { OComponentHelper::release(); }
263 // XSingleServiceFactory
264 Reference
<XInterface
> SAL_CALL
createInstance() override
;
265 Reference
<XInterface
> SAL_CALL
createInstanceWithArguments( const Sequence
<Any
>& Arguments
) override
;
266 // XSingleComponentFactory
267 virtual Reference
< XInterface
> SAL_CALL
createInstanceWithContext(
268 Reference
< XComponentContext
> const & xContext
) override
;
269 virtual Reference
< XInterface
> SAL_CALL
createInstanceWithArgumentsAndContext(
270 Sequence
< Any
> const & rArguments
,
271 Reference
< XComponentContext
> const & xContext
) override
;
274 virtual Sequence
< Type
> SAL_CALL
getTypes() override
;
275 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
278 Any SAL_CALL
queryAggregation( const Type
& rType
) override
;
280 // XUnloadingPreference
281 virtual sal_Bool SAL_CALL
releaseOnNotification() override
;
284 void SAL_CALL
dispose() override
;
287 Reference
<XInterface
> xTheInstance
;
290 // needed for implementing XUnloadingPreference in inheriting classes
291 bool isOneInstance() const {return bOneInstance
;}
292 bool isInstance() const {return xTheInstance
.is();}
297 Any SAL_CALL
OFactoryComponentHelper::queryInterface( const Type
& rType
)
299 if( rType
== cppu::UnoType
<XUnloadingPreference
>::get() )
302 Reference
< XUnloadingPreference
>(
303 static_cast< XUnloadingPreference
* >(this) ) );
305 return OComponentHelper::queryInterface( rType
);
309 Any
OFactoryComponentHelper::queryAggregation( const Type
& rType
)
311 Any
aRet( OComponentHelper::queryAggregation( rType
) );
312 return (aRet
.hasValue() ? aRet
: OSingleFactoryHelper::queryInterface( rType
));
316 Sequence
< Type
> OFactoryComponentHelper::getTypes()
319 ar
[ 0 ] = cppu::UnoType
<XSingleServiceFactory
>::get();
320 ar
[ 1 ] = cppu::UnoType
<XServiceInfo
>::get();
321 ar
[ 2 ] = cppu::UnoType
<XUnloadingPreference
>::get();
324 ar
[ 3 ] = cppu::UnoType
<XSingleComponentFactory
>::get();
326 return Sequence
< Type
>( ar
, m_fptr
? 4 : 3 );
329 Sequence
< sal_Int8
> OFactoryComponentHelper::getImplementationId()
331 return css::uno::Sequence
<sal_Int8
>();
334 // XSingleServiceFactory
335 Reference
<XInterface
> OFactoryComponentHelper::createInstance()
339 if( !xTheInstance
.is() )
341 MutexGuard
aGuard( aMutex
);
342 if( !xTheInstance
.is() )
343 xTheInstance
= OSingleFactoryHelper::createInstance();
347 return OSingleFactoryHelper::createInstance();
350 Reference
<XInterface
> OFactoryComponentHelper::createInstanceWithArguments(
351 const Sequence
<Any
>& Arguments
)
355 if( !xTheInstance
.is() )
357 MutexGuard
aGuard( aMutex
);
358 // OSL_ENSURE( !xTheInstance.is(), "### arguments will be ignored!" );
359 if( !xTheInstance
.is() )
360 xTheInstance
= OSingleFactoryHelper::createInstanceWithArguments( Arguments
);
364 return OSingleFactoryHelper::createInstanceWithArguments( Arguments
);
367 // XSingleComponentFactory
369 Reference
< XInterface
> OFactoryComponentHelper::createInstanceWithContext(
370 Reference
< XComponentContext
> const & xContext
)
374 if( !xTheInstance
.is() )
376 MutexGuard
aGuard( aMutex
);
377 // OSL_ENSURE( !xTheInstance.is(), "### context will be ignored!" );
378 if( !xTheInstance
.is() )
379 xTheInstance
= OSingleFactoryHelper::createInstanceWithContext( xContext
);
383 return OSingleFactoryHelper::createInstanceWithContext( xContext
);
386 Reference
< XInterface
> OFactoryComponentHelper::createInstanceWithArgumentsAndContext(
387 Sequence
< Any
> const & rArguments
,
388 Reference
< XComponentContext
> const & xContext
)
392 if( !xTheInstance
.is() )
394 MutexGuard
aGuard( aMutex
);
395 // OSL_ENSURE( !xTheInstance.is(), "### context and arguments will be ignored!" );
396 if( !xTheInstance
.is() )
397 xTheInstance
= OSingleFactoryHelper::createInstanceWithArgumentsAndContext( rArguments
, xContext
);
401 return OSingleFactoryHelper::createInstanceWithArgumentsAndContext( rArguments
, xContext
);
406 void OFactoryComponentHelper::dispose()
408 OComponentHelper::dispose();
410 Reference
<XInterface
> x
;
412 // do not delete in the guard section
413 MutexGuard
aGuard( aMutex
);
415 xTheInstance
.clear();
417 // if it is a component call dispose at the component
418 Reference
<XComponent
> xComp( x
, UNO_QUERY
);
423 // XUnloadingPreference
424 // This class is used for single factories, component factories and
425 // one-instance factories. Depending on the usage this function has
426 // to return different values.
427 // one-instance factory: sal_False
428 // single factory: sal_True
429 // component factory: sal_True
430 sal_Bool SAL_CALL
OFactoryComponentHelper::releaseOnNotification()
439 class ORegistryFactoryHelper
: public OFactoryComponentHelper
,
440 public OPropertySetHelper
444 ORegistryFactoryHelper(
445 const Reference
<XMultiServiceFactory
> & rServiceManager
,
446 const OUString
& rImplementationName_
,
447 const Reference
<XRegistryKey
> & xImplementationKey_
,
449 : OFactoryComponentHelper(
450 rServiceManager
, rImplementationName_
, nullptr, nullptr, nullptr, bOneInstance_
),
451 OPropertySetHelper( OComponentHelper::rBHelper
),
452 xImplementationKey( xImplementationKey_
)
456 virtual Any SAL_CALL
queryInterface( Type
const & type
) override
;
457 virtual void SAL_CALL
acquire() noexcept override
;
458 virtual void SAL_CALL
release() noexcept override
;
460 virtual Sequence
< Type
> SAL_CALL
getTypes() override
;
462 virtual Reference
< beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
464 // OPropertySetHelper
465 virtual IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
466 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
467 Any
& rConvertedValue
, Any
& rOldValue
,
468 sal_Int32 nHandle
, Any
const & rValue
) override
;
469 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
470 sal_Int32 nHandle
, Any
const & rValue
) override
;
471 using OPropertySetHelper::getFastPropertyValue
;
472 virtual void SAL_CALL
getFastPropertyValue(
473 Any
& rValue
, sal_Int32 nHandle
) const override
;
475 // OSingleFactoryHelper
476 Reference
<XInterface
> createInstanceEveryTime(
477 Reference
< XComponentContext
> const & xContext
) override
;
479 // XSingleServiceFactory
480 Reference
<XInterface
> SAL_CALL
createInstanceWithArguments(const Sequence
<Any
>& Arguments
) override
;
481 // XSingleComponentFactory
482 Reference
< XInterface
> SAL_CALL
createInstanceWithArgumentsAndContext(
483 Sequence
< Any
> const & rArguments
,
484 Reference
< XComponentContext
> const & xContext
) override
;
487 Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
488 // XUnloadingPreference
489 sal_Bool SAL_CALL
releaseOnNotification() override
;
493 /// @throws css::uno::Exception
494 /// @throws css::uno::RuntimeException
495 Reference
< XInterface
> createModuleFactory();
497 /** The registry key of the implementation section */
498 Reference
<XRegistryKey
> xImplementationKey
;
499 /** The factory created with the loader. */
500 Reference
<XSingleComponentFactory
> xModuleFactory
;
501 Reference
<XSingleServiceFactory
> xModuleFactoryDepr
;
502 Reference
< beans::XPropertySetInfo
> m_xInfo
;
503 std::unique_ptr
< IPropertyArrayHelper
> m_property_array_helper
;
505 using OPropertySetHelper::getTypes
;
512 Any SAL_CALL
ORegistryFactoryHelper::queryInterface(
515 Any
ret( OFactoryComponentHelper::queryInterface( type
) );
518 return OPropertySetHelper::queryInterface( type
);
522 void ORegistryFactoryHelper::acquire() noexcept
524 OFactoryComponentHelper::acquire();
528 void ORegistryFactoryHelper::release() noexcept
530 OFactoryComponentHelper::release();
535 Sequence
< Type
> ORegistryFactoryHelper::getTypes()
537 Sequence
< Type
> types( OFactoryComponentHelper::getTypes() );
538 sal_Int32 pos
= types
.getLength();
539 types
.realloc( pos
+ 3 );
540 Type
* p
= types
.getArray();
541 p
[ pos
++ ] = cppu::UnoType
<beans::XMultiPropertySet
>::get();
542 p
[ pos
++ ] = cppu::UnoType
<beans::XFastPropertySet
>::get();
543 p
[ pos
++ ] = cppu::UnoType
<beans::XPropertySet
>::get();
549 Reference
< beans::XPropertySetInfo
>
550 ORegistryFactoryHelper::getPropertySetInfo()
552 ::osl::MutexGuard
guard( aMutex
);
554 m_xInfo
= createPropertySetInfo( getInfoHelper() );
558 // OPropertySetHelper
560 IPropertyArrayHelper
& ORegistryFactoryHelper::getInfoHelper()
562 ::osl::MutexGuard
guard( aMutex
);
563 if (m_property_array_helper
== nullptr)
565 beans::Property
prop(
566 "ImplementationKey" /* name */,
568 cppu::UnoType
<decltype(xImplementationKey
)>::get(),
569 beans::PropertyAttribute::READONLY
|
570 beans::PropertyAttribute::OPTIONAL
);
571 m_property_array_helper
.reset(
572 new ::cppu::OPropertyArrayHelper( &prop
, 1 ) );
574 return *m_property_array_helper
;
578 sal_Bool
ORegistryFactoryHelper::convertFastPropertyValue(
579 Any
&, Any
&, sal_Int32
, Any
const & )
581 OSL_FAIL( "unexpected!" );
586 void ORegistryFactoryHelper::setFastPropertyValue_NoBroadcast(
587 sal_Int32
, Any
const & )
589 throw beans::PropertyVetoException(
590 "unexpected: only readonly properties!",
591 static_cast< OWeakObject
* >(this) );
595 void ORegistryFactoryHelper::getFastPropertyValue(
596 Any
& rValue
, sal_Int32 nHandle
) const
600 rValue
<<= xImplementationKey
;
605 throw beans::UnknownPropertyException(
606 "unknown property!", static_cast< OWeakObject
* >(
607 const_cast< ORegistryFactoryHelper
* >(this) ) );
611 Reference
<XInterface
> ORegistryFactoryHelper::createInstanceEveryTime(
612 Reference
< XComponentContext
> const & xContext
)
614 if( !xModuleFactory
.is() && !xModuleFactoryDepr
.is() )
616 Reference
< XInterface
> x( createModuleFactory() );
619 MutexGuard
aGuard( aMutex
);
620 if( !xModuleFactory
.is() && !xModuleFactoryDepr
.is() )
622 xModuleFactory
.set( x
, UNO_QUERY
);
623 xModuleFactoryDepr
.set( x
, UNO_QUERY
);
627 if( xModuleFactory
.is() )
629 return xModuleFactory
->createInstanceWithContext( xContext
);
631 if( xModuleFactoryDepr
.is() )
633 return xModuleFactoryDepr
->createInstance();
636 return Reference
<XInterface
>();
639 Reference
<XInterface
> SAL_CALL
ORegistryFactoryHelper::createInstanceWithArguments(
640 const Sequence
<Any
>& Arguments
)
642 if( !xModuleFactory
.is() && !xModuleFactoryDepr
.is() )
644 Reference
< XInterface
> x( createModuleFactory() );
647 MutexGuard
aGuard( aMutex
);
648 if( !xModuleFactory
.is() && !xModuleFactoryDepr
.is() )
650 xModuleFactory
.set( x
, UNO_QUERY
);
651 xModuleFactoryDepr
.set( x
, UNO_QUERY
);
655 if( xModuleFactoryDepr
.is() )
657 return xModuleFactoryDepr
->createInstanceWithArguments( Arguments
);
659 if( xModuleFactory
.is() )
661 SAL_INFO("cppuhelper", "no context ORegistryFactoryHelper::createInstanceWithArgumentsAndContext()!");
662 return xModuleFactory
->createInstanceWithArgumentsAndContext( Arguments
, Reference
< XComponentContext
>() );
665 return Reference
<XInterface
>();
668 Reference
< XInterface
> ORegistryFactoryHelper::createInstanceWithArgumentsAndContext(
669 Sequence
< Any
> const & rArguments
,
670 Reference
< XComponentContext
> const & xContext
)
672 if( !xModuleFactory
.is() && !xModuleFactoryDepr
.is() )
674 Reference
< XInterface
> x( createModuleFactory() );
677 MutexGuard
aGuard( aMutex
);
678 if( !xModuleFactory
.is() && !xModuleFactoryDepr
.is() )
680 xModuleFactory
.set( x
, UNO_QUERY
);
681 xModuleFactoryDepr
.set( x
, UNO_QUERY
);
685 if( xModuleFactory
.is() )
687 return xModuleFactory
->createInstanceWithArgumentsAndContext( rArguments
, xContext
);
689 if( xModuleFactoryDepr
.is() )
691 SAL_INFO_IF(xContext
.is(), "cppuhelper", "ignoring context calling ORegistryFactoryHelper::createInstanceWithArgumentsAndContext()!");
692 return xModuleFactoryDepr
->createInstanceWithArguments( rArguments
);
695 return Reference
<XInterface
>();
699 // OSingleFactoryHelper
700 Reference
< XInterface
> ORegistryFactoryHelper::createModuleFactory()
702 OUString aActivatorUrl
;
703 OUString aActivatorName
;
706 Reference
<XRegistryKey
> xActivatorKey
= xImplementationKey
->openKey(
708 if( xActivatorKey
.is() && xActivatorKey
->getValueType() == RegistryValueType_ASCII
)
710 aActivatorUrl
= xActivatorKey
->getAsciiValue();
712 aActivatorName
= aActivatorUrl
.getToken(0, ':');
714 Reference
<XRegistryKey
> xLocationKey
= xImplementationKey
->openKey(
716 if( xLocationKey
.is() && xLocationKey
->getValueType() == RegistryValueType_ASCII
)
717 aLocation
= xLocationKey
->getAsciiValue();
722 // the location of the program code of the implementation
723 Reference
<XRegistryKey
> xLocationKey
= xImplementationKey
->openKey(
725 // is the key of the right type ?
726 if( xLocationKey
.is() && xLocationKey
->getValueType() == RegistryValueType_ASCII
)
728 // one implementation found -> try to activate
729 aLocation
= xLocationKey
->getAsciiValue();
731 // search protocol delimiter
732 sal_Int32 nPos
= aLocation
.indexOf("://");
735 aActivatorName
= aLocation
.copy( 0, nPos
);
736 if( aActivatorName
== "java" )
737 aActivatorName
= "com.sun.star.loader.Java";
738 else if( aActivatorName
== "module" )
739 aActivatorName
= "com.sun.star.loader.SharedLibrary";
740 aLocation
= aLocation
.copy( nPos
+ 3 );
745 Reference
< XInterface
> xFactory
;
746 if( !aActivatorName
.isEmpty() )
748 Reference
<XInterface
> x
= xSMgr
->createInstance( aActivatorName
);
749 Reference
<XImplementationLoader
> xLoader( x
, UNO_QUERY
);
752 xFactory
= xLoader
->activate( aImplementationName
, aActivatorUrl
, aLocation
, xImplementationKey
);
759 Sequence
< OUString
> ORegistryFactoryHelper::getSupportedServiceNames()
761 MutexGuard
aGuard( aMutex
);
762 if( !aServiceNames
.hasElements() )
767 Reference
<XRegistryKey
> xKey
= xImplementationKey
->openKey( "UNO/SERVICES" );
771 // length of prefix. +1 for the '/' at the end
772 sal_Int32 nPrefixLen
= xKey
->getKeyName().getLength() + 1;
774 // Full qualified names like "IMPLEMENTATIONS/TEST/UNO/SERVICES/com.sun.star..."
775 Sequence
<OUString
> seqKeys
= xKey
->getKeyNames();
776 for( OUString
& key
: seqKeys
)
777 key
= key
.copy(nPrefixLen
);
779 aServiceNames
= seqKeys
;
782 catch (InvalidRegistryException
&)
786 return aServiceNames
;
789 sal_Bool SAL_CALL
ORegistryFactoryHelper::releaseOnNotification()
792 if( isOneInstance() && isInstance())
796 else if( ! isOneInstance())
799 if( xModuleFactory
.is())
801 Reference
<XUnloadingPreference
> xunloading( xModuleFactory
, UNO_QUERY
);
803 retVal
= xunloading
->releaseOnNotification();
805 else if( xModuleFactoryDepr
.is())
807 Reference
<XUnloadingPreference
> xunloading( xModuleFactoryDepr
, UNO_QUERY
);
809 retVal
= xunloading
->releaseOnNotification();
817 class OFactoryProxyHelper
: public WeakImplHelper
< XServiceInfo
, XSingleServiceFactory
,
818 XUnloadingPreference
>
820 Reference
<XSingleServiceFactory
> xFactory
;
824 explicit OFactoryProxyHelper( const Reference
<XSingleServiceFactory
> & rFactory
)
825 : xFactory( rFactory
)
828 // XSingleServiceFactory
829 Reference
<XInterface
> SAL_CALL
createInstance() override
;
830 Reference
<XInterface
> SAL_CALL
createInstanceWithArguments(const Sequence
<Any
>& Arguments
) override
;
833 OUString SAL_CALL
getImplementationName() override
;
834 sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
835 Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
836 //XUnloadingPreference
837 sal_Bool SAL_CALL
releaseOnNotification() override
;
843 // XSingleServiceFactory
844 Reference
<XInterface
> OFactoryProxyHelper::createInstance()
846 return xFactory
->createInstance();
849 // XSingleServiceFactory
850 Reference
<XInterface
> OFactoryProxyHelper::createInstanceWithArguments
852 const Sequence
<Any
>& Arguments
855 return xFactory
->createInstanceWithArguments( Arguments
);
859 OUString
OFactoryProxyHelper::getImplementationName()
861 Reference
<XServiceInfo
> xInfo( xFactory
, UNO_QUERY
);
863 return xInfo
->getImplementationName();
868 sal_Bool
OFactoryProxyHelper::supportsService(const OUString
& ServiceName
)
870 return cppu::supportsService(this, ServiceName
);
874 Sequence
< OUString
> OFactoryProxyHelper::getSupportedServiceNames()
876 Reference
<XServiceInfo
> xInfo( xFactory
, UNO_QUERY
);
878 return xInfo
->getSupportedServiceNames();
879 return Sequence
< OUString
>();
882 sal_Bool SAL_CALL
OFactoryProxyHelper::releaseOnNotification()
885 Reference
<XUnloadingPreference
> pref( xFactory
, UNO_QUERY
);
887 return pref
->releaseOnNotification();
892 Reference
<XSingleServiceFactory
> SAL_CALL
createSingleFactory(
893 const Reference
<XMultiServiceFactory
> & rServiceManager
,
894 const OUString
& rImplementationName
,
895 ComponentInstantiation pCreateFunction
,
896 const Sequence
< OUString
> & rServiceNames
,
899 return new OFactoryComponentHelper(
900 rServiceManager
, rImplementationName
, pCreateFunction
, nullptr, &rServiceNames
, false );
904 Reference
<XSingleServiceFactory
> SAL_CALL
createFactoryProxy(
905 SAL_UNUSED_PARAMETER
const Reference
<XMultiServiceFactory
> &,
906 const Reference
<XSingleServiceFactory
> & rFactory
)
908 return new OFactoryProxyHelper( rFactory
);
912 Reference
<XSingleServiceFactory
> SAL_CALL
createOneInstanceFactory(
913 const Reference
<XMultiServiceFactory
> & rServiceManager
,
914 const OUString
& rImplementationName
,
915 ComponentInstantiation pCreateFunction
,
916 const Sequence
< OUString
> & rServiceNames
,
919 return new OFactoryComponentHelper(
920 rServiceManager
, rImplementationName
, pCreateFunction
, nullptr, &rServiceNames
, true );
924 Reference
<XSingleServiceFactory
> SAL_CALL
createSingleRegistryFactory(
925 const Reference
<XMultiServiceFactory
> & rServiceManager
,
926 const OUString
& rImplementationName
,
927 const Reference
<XRegistryKey
> & rImplementationKey
)
929 return new ORegistryFactoryHelper(
930 rServiceManager
, rImplementationName
, rImplementationKey
, false );
934 Reference
<XSingleServiceFactory
> SAL_CALL
createOneInstanceRegistryFactory(
935 const Reference
<XMultiServiceFactory
> & rServiceManager
,
936 const OUString
& rImplementationName
,
937 const Reference
<XRegistryKey
> & rImplementationKey
)
939 return new ORegistryFactoryHelper(
940 rServiceManager
, rImplementationName
, rImplementationKey
, true );
944 Reference
< lang::XSingleComponentFactory
> SAL_CALL
createSingleComponentFactory(
945 ComponentFactoryFunc fptr
,
946 OUString
const & rImplementationName
,
947 Sequence
< OUString
> const & rServiceNames
,
950 return new OFactoryComponentHelper(
951 Reference
< XMultiServiceFactory
>(), rImplementationName
, nullptr, fptr
, &rServiceNames
, false );
954 Reference
< lang::XSingleComponentFactory
> SAL_CALL
createOneInstanceComponentFactory(
955 ComponentFactoryFunc fptr
,
956 OUString
const & rImplementationName
,
957 Sequence
< OUString
> const & rServiceNames
,
960 return new OFactoryComponentHelper(
961 Reference
< XMultiServiceFactory
>(), rImplementationName
, nullptr, fptr
, &rServiceNames
, true );
967 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */