use insert function instead of for loop
[LibreOffice.git] / stoc / source / loader / dllcomponentloader.cxx
blobaf7e0b752290eac5067cac1eaa9c6c9cee68f5a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <osl/diagnose.h>
22 #include <rtl/ustring.hxx>
23 #include <cppuhelper/weak.hxx>
24 #include <cppuhelper/shlib.hxx>
25 #include <cppuhelper/implbase.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <cppuhelper/bootstrap.hxx>
29 #include <com/sun/star/loader/XImplementationLoader.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/lang/XInitialization.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
35 namespace com::sun::star::registry { class XRegistryKey; }
37 using namespace com::sun::star;
38 using namespace css::uno;
39 using namespace css::loader;
40 using namespace css::lang;
41 using namespace css::registry;
42 using namespace cppu;
44 namespace {
46 class DllComponentLoader
47 : public WeakImplHelper< XImplementationLoader,
48 XInitialization,
49 XServiceInfo >
51 public:
52 explicit DllComponentLoader( const Reference<XComponentContext> & xCtx );
54 // XServiceInfo
55 virtual OUString SAL_CALL getImplementationName( ) override;
56 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
57 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
59 // XInitialization
60 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
62 // XImplementationLoader
63 virtual Reference<XInterface> SAL_CALL activate( const OUString& implementationName, const OUString& implementationLoaderUrl, const OUString& locationUrl, const Reference<XRegistryKey>& xKey ) override;
64 virtual sal_Bool SAL_CALL writeRegistryInfo( const Reference<XRegistryKey>& xKey, const OUString& implementationLoaderUrl, const OUString& locationUrl ) override;
66 private:
67 Reference<XMultiServiceFactory> m_xSMgr;
71 DllComponentLoader::DllComponentLoader( const Reference<XComponentContext> & xCtx )
73 m_xSMgr.set( xCtx->getServiceManager(), UNO_QUERY );
76 OUString SAL_CALL DllComponentLoader::getImplementationName( )
78 return u"com.sun.star.comp.stoc.DLLComponentLoader"_ustr;
81 sal_Bool SAL_CALL DllComponentLoader::supportsService( const OUString& ServiceName )
83 return cppu::supportsService(this, ServiceName);
86 Sequence<OUString> SAL_CALL DllComponentLoader::getSupportedServiceNames( )
88 return { u"com.sun.star.loader.SharedLibrary"_ustr };
92 void DllComponentLoader::initialize( const css::uno::Sequence< css::uno::Any >& )
94 OSL_FAIL( "dllcomponentloader::initialize should not be called !" );
95 // if( aArgs.getLength() != 1 )
96 // {
97 // throw IllegalArgumentException();
98 // }
100 // Reference< XMultiServiceFactory > rServiceManager;
102 // if( aArgs.getConstArray()[0].getValueTypeClass() == TypeClass_INTERFACE )
103 // {
104 // aArgs.getConstArray()[0] >>= rServiceManager;
105 // }
107 // if( !rServiceManager.is() )
108 // {
109 // throw IllegalArgumentException();
110 // }
112 // m_xSMgr = rServiceManager;
116 Reference<XInterface> SAL_CALL DllComponentLoader::activate(
117 const OUString & rImplName, const OUString &, const OUString & rLibName,
118 const Reference< XRegistryKey > & )
120 return loadSharedLibComponentFactory(
121 cppu::bootstrap_expandUri(rLibName), OUString(), rImplName, m_xSMgr,
122 css::uno::Reference<css::registry::XRegistryKey>());
126 sal_Bool SAL_CALL DllComponentLoader::writeRegistryInfo(
127 const Reference< XRegistryKey > & xKey, const OUString &, const OUString & rLibName )
129 #ifdef DISABLE_DYNLOADING
130 (void) xKey;
131 (void) rLibName;
132 OSL_FAIL( "DllComponentLoader::writeRegistryInfo() should not be called I think?" );
133 return sal_False;
134 #else
135 writeSharedLibComponentInfo(
136 cppu::bootstrap_expandUri(rLibName), OUString(), m_xSMgr, xKey );
137 return true;
138 #endif
143 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
144 com_sun_star_comp_stoc_DLLComponentLoader_get_implementation(
145 css::uno::XComponentContext *context,
146 css::uno::Sequence<css::uno::Any> const &)
148 return cppu::acquire(new DllComponentLoader(context));
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */