1a5b190bfSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3a5b190bfSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4a5b190bfSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5a5b190bfSAndrew Rist  * distributed with this work for additional information
6a5b190bfSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7a5b190bfSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8a5b190bfSAndrew Rist  * "License"); you may not use this file except in compliance
9a5b190bfSAndrew Rist  * with the License.  You may obtain a copy of the License at
10a5b190bfSAndrew Rist  *
11a5b190bfSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12a5b190bfSAndrew Rist  *
13a5b190bfSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14a5b190bfSAndrew Rist  * software distributed under the License is distributed on an
15a5b190bfSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16a5b190bfSAndrew Rist  * KIND, either express or implied.  See the License for the
17a5b190bfSAndrew Rist  * specific language governing permissions and limitations
18a5b190bfSAndrew Rist  * under the License.
19a5b190bfSAndrew Rist  *
20a5b190bfSAndrew Rist  *************************************************************/
21a5b190bfSAndrew Rist 
22a5b190bfSAndrew Rist 
23cdf0e10cSrcweir package com.sun.star.comp.helper;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
26cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
27cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
28cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /**
31cdf0e10cSrcweir  * @deprecated use class Bootstrap bootstrapping a native UNO installation
32cdf0e10cSrcweir  *             and use the shared library loader service.
33cdf0e10cSrcweir  *
34cdf0e10cSrcweir  * The <code>SharedLibraryLoader</code> class provides the functionality of the <code>com.sun.star.loader.SharedLibrary</code>
35cdf0e10cSrcweir  * service.
36cdf0e10cSrcweir  * <p>
37*c86fe57eSDamjan Jovanovic  * @see         "com.sun.star.loader.SharedLibrary"
38cdf0e10cSrcweir  * @see         com.sun.star.comp.servicemanager.ServiceManager
39*c86fe57eSDamjan Jovanovic  * @see	        "com.sun.star.lang.ServiceManager"
40cdf0e10cSrcweir  */
41cdf0e10cSrcweir public class SharedLibraryLoader {
42cdf0e10cSrcweir 	/**
43cdf0e10cSrcweir 	 * The default library which contains the SharedLibraryLoader component
44cdf0e10cSrcweir 	 */
45cdf0e10cSrcweir 	public static final String DEFAULT_LIBRARY = "shlibloader.uno";
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 	/**
48cdf0e10cSrcweir 	 * The default implementation name
49cdf0e10cSrcweir 	 */
50cdf0e10cSrcweir 	public static final String DEFAULT_IMPLEMENTATION = "com.sun.star.comp.stoc.DLLComponentLoader";
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	static {
53cdf0e10cSrcweir 		System.loadLibrary("juh");
54cdf0e10cSrcweir 	}
55cdf0e10cSrcweir 
component_writeInfo( String libName, XMultiServiceFactory smgr, XRegistryKey regKey, ClassLoader loader )56cdf0e10cSrcweir 	private static native boolean component_writeInfo(
57cdf0e10cSrcweir 			String libName, XMultiServiceFactory smgr, XRegistryKey regKey,
58cdf0e10cSrcweir             ClassLoader loader );
59cdf0e10cSrcweir 
component_getFactory( String libName, String implName, XMultiServiceFactory smgr, XRegistryKey regKey, ClassLoader loader )60cdf0e10cSrcweir 	private static native Object component_getFactory(
61cdf0e10cSrcweir 			String libName, String implName, XMultiServiceFactory smgr,
62cdf0e10cSrcweir             XRegistryKey regKey, ClassLoader loader );
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	/**
65cdf0e10cSrcweir 	 * Supplies the ServiceFactory of the default SharedLibraryLoader.
66cdf0e10cSrcweir 	 * The defaults are "shlibloader.uno"
67cdf0e10cSrcweir 	 * for the library and "com.sun.star.comp.stoc.DLLComponentLoader"
68cdf0e10cSrcweir 	 * for the component name.
69cdf0e10cSrcweir 	 * <p>
70cdf0e10cSrcweir 	 * @return	the factory for the "com.sun.star.comp.stoc.DLLComponentLoader" component.
71cdf0e10cSrcweir 	 * @param	smgr	the ServiceManager
72cdf0e10cSrcweir 	 * @param	regKey	the root registry key
73*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.loader.SharedLibrary"
74*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.lang.ServiceManager"
75*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.registry.RegistryKey"
76cdf0e10cSrcweir 	 */
getServiceFactory( XMultiServiceFactory smgr, XRegistryKey regKey )77cdf0e10cSrcweir 	public static XSingleServiceFactory getServiceFactory(
78cdf0e10cSrcweir 				XMultiServiceFactory smgr,
79cdf0e10cSrcweir 				XRegistryKey regKey )
80cdf0e10cSrcweir 	{
81cdf0e10cSrcweir 		return UnoRuntime.queryInterface(
82cdf0e10cSrcweir 					XSingleServiceFactory.class,
83cdf0e10cSrcweir 					component_getFactory(
84cdf0e10cSrcweir                         DEFAULT_LIBRARY, DEFAULT_IMPLEMENTATION, smgr, regKey,
85cdf0e10cSrcweir                         SharedLibraryLoader.class.getClassLoader() ) );
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	/**
89cdf0e10cSrcweir 	 * Loads and returns a specific factory for a given library and implementation name.
90cdf0e10cSrcweir 	 * <p>
91cdf0e10cSrcweir 	 * @return	the factory of the component
92cdf0e10cSrcweir 	 * @param	libName	the name of the shared library
93cdf0e10cSrcweir 	 * @param	impName	the implementation name of the component
94cdf0e10cSrcweir 	 * @param	smgr	the ServiceManager
95cdf0e10cSrcweir 	 * @param	regKey	the root registry key
96*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.loader.SharedLibrary"
97*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.lang.ServiceManager"
98*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.registry.RegistryKey"
99cdf0e10cSrcweir 	 */
getServiceFactory( String libName, String impName, XMultiServiceFactory smgr, XRegistryKey regKey )100cdf0e10cSrcweir 	public static XSingleServiceFactory getServiceFactory(
101cdf0e10cSrcweir 				String libName,
102cdf0e10cSrcweir 				String impName,
103cdf0e10cSrcweir 				XMultiServiceFactory smgr,
104cdf0e10cSrcweir 				XRegistryKey regKey )
105cdf0e10cSrcweir 	{
106cdf0e10cSrcweir 		return UnoRuntime.queryInterface(
107cdf0e10cSrcweir 					XSingleServiceFactory.class,
108cdf0e10cSrcweir 					component_getFactory(
109cdf0e10cSrcweir                         libName, impName, smgr, regKey,
110cdf0e10cSrcweir                         SharedLibraryLoader.class.getClassLoader() ) );
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	/**
114cdf0e10cSrcweir 	 * Registers the SharedLibraryLoader under a RegistryKey.
115cdf0e10cSrcweir 	 * <p>
116a893be29SPedro Giffuni 	 * @return	true if the registration was successful - otherwise false
117cdf0e10cSrcweir 	 * @param	smgr	the ServiceManager
118cdf0e10cSrcweir 	 * @param	regKey	the root key under that the component should be registered
119*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.loader.SharedLibrary"
120*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.lang.ServiceManager"
121*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.registry.RegistryKey"
122cdf0e10cSrcweir 	 */
writeRegistryServiceInfo( com.sun.star.lang.XMultiServiceFactory smgr, com.sun.star.registry.XRegistryKey regKey )123cdf0e10cSrcweir 	public static boolean writeRegistryServiceInfo(
124cdf0e10cSrcweir 				com.sun.star.lang.XMultiServiceFactory smgr,
125cdf0e10cSrcweir 				com.sun.star.registry.XRegistryKey regKey )
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		return component_writeInfo(
128cdf0e10cSrcweir             DEFAULT_LIBRARY, smgr, regKey,
129cdf0e10cSrcweir             SharedLibraryLoader.class.getClassLoader() );
130cdf0e10cSrcweir 	}
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	/**
133cdf0e10cSrcweir 	 * Registers the SharedLibraryLoader under a RegistryKey.
134cdf0e10cSrcweir 	 * <p>
135a893be29SPedro Giffuni 	 * @return	true if the registration was successful - otherwise false
136cdf0e10cSrcweir 	 * @param	libName	name of the shared library
137cdf0e10cSrcweir 	 * @param	smgr	the ServiceManager
138cdf0e10cSrcweir 	 * @param	regKey	the root key under that the component should be registered
139*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.loader.SharedLibrary"
140*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.lang.ServiceManager"
141*c86fe57eSDamjan Jovanovic 	 * @see		"com.sun.star.registry.RegistryKey"
142cdf0e10cSrcweir 	 */
writeRegistryServiceInfo( String libName, com.sun.star.lang.XMultiServiceFactory smgr, com.sun.star.registry.XRegistryKey regKey )143cdf0e10cSrcweir 	public static boolean writeRegistryServiceInfo(
144cdf0e10cSrcweir 				String libName,
145cdf0e10cSrcweir 				com.sun.star.lang.XMultiServiceFactory smgr,
146cdf0e10cSrcweir 				com.sun.star.registry.XRegistryKey regKey )
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 			throws 	com.sun.star.registry.InvalidRegistryException,
149cdf0e10cSrcweir 					com.sun.star.uno.RuntimeException
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir 		return component_writeInfo(
152cdf0e10cSrcweir             libName, smgr, regKey, SharedLibraryLoader.class.getClassLoader() );
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156