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 .
24 #include <osl/mutex.hxx>
25 #include <osl/diagnose.h>
26 #include <osl/module.h>
27 #include <rtl/ref.hxx>
28 #include <rtl/ustring.hxx>
29 #include <uno/environment.h>
30 #include <uno/mapping.hxx>
31 #include <cppuhelper/queryinterface.hxx>
32 #include <cppuhelper/weak.hxx>
33 #include <cppuhelper/shlib.hxx>
34 #include <cppuhelper/implbase3.hxx>
35 #include <cppuhelper/implementationentry.hxx>
36 #include <cppuhelper/supportsservice.hxx>
37 #include <cppuhelper/bootstrap.hxx>
39 #include <com/sun/star/loader/XImplementationLoader.hpp>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/lang/XInitialization.hpp>
43 #include <com/sun/star/registry/XRegistryKey.hpp>
45 using namespace com::sun::star
;
46 using namespace css::uno
;
47 using namespace css::loader
;
48 using namespace css::lang
;
49 using namespace css::registry
;
55 class DllComponentLoader
56 : public WeakImplHelper3
< XImplementationLoader
,
61 DllComponentLoader( const Reference
<XComponentContext
> & xCtx
);
62 virtual ~DllComponentLoader();
65 virtual OUString SAL_CALL
getImplementationName( ) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
66 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
67 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
70 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) throw(css::uno::Exception
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
72 // XImplementationLoader
73 virtual Reference
<XInterface
> SAL_CALL
activate( const OUString
& implementationName
, const OUString
& implementationLoaderUrl
, const OUString
& locationUrl
, const Reference
<XRegistryKey
>& xKey
) throw(CannotActivateFactoryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
74 virtual sal_Bool SAL_CALL
writeRegistryInfo( const Reference
<XRegistryKey
>& xKey
, const OUString
& implementationLoaderUrl
, const OUString
& locationUrl
) throw(CannotRegisterImplementationException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
77 Reference
<XMultiServiceFactory
> m_xSMgr
;
81 DllComponentLoader::DllComponentLoader( const Reference
<XComponentContext
> & xCtx
)
83 m_xSMgr
.set( xCtx
->getServiceManager(), UNO_QUERY
);
87 DllComponentLoader::~DllComponentLoader() {}
90 OUString SAL_CALL
DllComponentLoader::getImplementationName( )
91 throw(css::uno::RuntimeException
, std::exception
)
93 return OUString("com.sun.star.comp.stoc.DLLComponentLoader");
96 sal_Bool SAL_CALL
DllComponentLoader::supportsService( const OUString
& ServiceName
)
97 throw(css::uno::RuntimeException
, std::exception
)
99 return cppu::supportsService(this, ServiceName
);
102 Sequence
<OUString
> SAL_CALL
DllComponentLoader::getSupportedServiceNames( )
103 throw(css::uno::RuntimeException
, std::exception
)
105 Sequence
< OUString
> seqNames(1);
106 seqNames
[0] = "com.sun.star.loader.SharedLibrary";
111 void DllComponentLoader::initialize( const css::uno::Sequence
< css::uno::Any
>& )
112 throw(css::uno::Exception
, css::uno::RuntimeException
, std::exception
)
114 OSL_FAIL( "dllcomponentloader::initialize should not be called !" );
115 // if( aArgs.getLength() != 1 )
117 // throw IllegalArgumentException();
120 // Reference< XMultiServiceFactory > rServiceManager;
122 // if( aArgs.getConstArray()[0].getValueType().getTypeClass() == TypeClass_INTERFACE )
124 // aArgs.getConstArray()[0] >>= rServiceManager;
127 // if( !rServiceManager.is() )
129 // throw IllegalArgumentException();
132 // m_xSMgr = rServiceManager;
136 Reference
<XInterface
> SAL_CALL
DllComponentLoader::activate(
137 const OUString
& rImplName
, const OUString
&, const OUString
& rLibName
,
138 const Reference
< XRegistryKey
> & )
140 throw(CannotActivateFactoryException
, RuntimeException
, std::exception
)
142 return loadSharedLibComponentFactory(
143 cppu::bootstrap_expandUri(rLibName
), OUString(), rImplName
, m_xSMgr
,
144 css::uno::Reference
<css::registry::XRegistryKey
>());
149 sal_Bool SAL_CALL
DllComponentLoader::writeRegistryInfo(
150 const Reference
< XRegistryKey
> & xKey
, const OUString
&, const OUString
& rLibName
)
152 throw(CannotRegisterImplementationException
, RuntimeException
, std::exception
)
154 #ifdef DISABLE_DYNLOADING
157 OSL_FAIL( "DllComponentLoader::writeRegistryInfo() should not be called I think?" );
160 writeSharedLibComponentInfo(
161 cppu::bootstrap_expandUri(rLibName
), OUString(), m_xSMgr
, xKey
);
168 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
169 com_sun_star_comp_stoc_DLLComponentLoader_get_implementation(
170 css::uno::XComponentContext
*context
,
171 css::uno::Sequence
<css::uno::Any
> const &)
173 return cppu::acquire(new DllComponentLoader(context
));
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */