1 // -*- Mode: Java; 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 .
19 package com
.sun
.star
.comp
.helper
;
21 import com
.sun
.star
.uno
.UnoRuntime
;
22 import com
.sun
.star
.lang
.XMultiServiceFactory
;
23 import com
.sun
.star
.lang
.XSingleServiceFactory
;
24 import com
.sun
.star
.registry
.XRegistryKey
;
27 * @deprecated use class Bootstrap bootstrapping a native UNO installation
28 * and use the shared library loader service.
30 * The <code>SharedLibraryLoader</code> class provides the functionality of the <code>com.sun.star.loader.SharedLibrary</code>
33 * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code>.
35 * @see com.sun.star.loader.SharedLibrary
38 public class SharedLibraryLoader
{
40 * The default library which contains the SharedLibraryLoader component
42 public static final String DEFAULT_LIBRARY
= "shlibloader.uno";
45 * The default implementation name
47 public static final String DEFAULT_IMPLEMENTATION
= "com.sun.star.comp.stoc.DLLComponentLoader";
50 if ("The Android Project".equals(System
.getProperty("java.vendor"))) {
51 // See corresponding code in
52 // javaunohelper/com/sun/star/comp/helper/Bootstrap.java for more
55 boolean disable_dynloading
= false;
57 System
.loadLibrary("lo-bootstrap");
58 } catch (UnsatisfiedLinkError e
) {
59 disable_dynloading
= true;
62 if (!disable_dynloading
)
63 System
.loadLibrary("juh");
65 System
.loadLibrary("juh");
68 private static native boolean component_writeInfo(
69 String libName
, XMultiServiceFactory smgr
, XRegistryKey regKey
,
72 private static native Object
component_getFactory(
73 String libName
, String implName
, XMultiServiceFactory smgr
,
74 XRegistryKey regKey
, ClassLoader loader
);
77 * Supplies the ServiceFactory of the default SharedLibraryLoader.
78 * The defaults are "shlibloader.uno"
79 * for the library and "com.sun.star.comp.stoc.DLLComponentLoader"
80 * for the component name.
82 * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code> and
83 * <code>com.sun.star.registry.RegistryKey</code>.
85 * @return the factory for the "com.sun.star.comp.stoc.DLLComponentLoader" component.
86 * @param smgr the ServiceManager
87 * @param regKey the root registry key
88 * @see com.sun.star.loader.SharedLibrary
90 public static XSingleServiceFactory
getServiceFactory(
91 XMultiServiceFactory smgr
,
94 return UnoRuntime
.queryInterface(
95 XSingleServiceFactory
.class,
97 DEFAULT_LIBRARY
, DEFAULT_IMPLEMENTATION
, smgr
, regKey
,
98 SharedLibraryLoader
.class.getClassLoader() ) );
102 * Loads and returns a specific factory for a given library and implementation name.
104 * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code> and
105 * <code>com.sun.star.registry.RegistryKey</code>.
107 * @return the factory of the component
108 * @param libName the name of the shared library
109 * @param impName the implementation name of the component
110 * @param smgr the ServiceManager
111 * @param regKey the root registry key
112 * @see com.sun.star.loader.SharedLibrary
114 public static XSingleServiceFactory
getServiceFactory(
117 XMultiServiceFactory smgr
,
118 XRegistryKey regKey
)
120 return UnoRuntime
.queryInterface(
121 XSingleServiceFactory
.class,
122 component_getFactory(
123 libName
, impName
, smgr
, regKey
,
124 SharedLibraryLoader
.class.getClassLoader() ) );
128 * Registers the SharedLibraryLoader under a RegistryKey.
130 * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code> and
131 * <code>com.sun.star.registry.RegistryKey</code>.
133 * @return true if the registration was successful - otherwise false
134 * @param smgr the ServiceManager
135 * @param regKey the root key under that the component should be registered
136 * @see com.sun.star.loader.SharedLibrary
138 public static boolean writeRegistryServiceInfo(
139 com
.sun
.star
.lang
.XMultiServiceFactory smgr
,
140 com
.sun
.star
.registry
.XRegistryKey regKey
)
142 return component_writeInfo(
143 DEFAULT_LIBRARY
, smgr
, regKey
,
144 SharedLibraryLoader
.class.getClassLoader() );
148 * Registers the SharedLibraryLoader under a RegistryKey.
150 * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code> and
151 * <code>com.sun.star.registry.RegistryKey</code>.
153 * @return true if the registration was successful - otherwise false
154 * @param libName name of the shared library
155 * @param smgr the ServiceManager
156 * @param regKey the root key under that the component should be registered
157 * @throws com.sun.star.registry.InvalidRegistryException
158 * if the registry is not valid.
160 * @see com.sun.star.loader.SharedLibrary
162 public static boolean writeRegistryServiceInfo(
164 com
.sun
.star
.lang
.XMultiServiceFactory smgr
,
165 com
.sun
.star
.registry
.XRegistryKey regKey
)
167 throws com
.sun
.star
.registry
.InvalidRegistryException
,
168 com
.sun
.star
.uno
.RuntimeException
170 return component_writeInfo(
171 libName
, smgr
, regKey
, SharedLibraryLoader
.class.getClassLoader() );
175 // vim:set shiftwidth=4 softtabstop=4 expandtab: