1*a5b190bfSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*a5b190bfSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a5b190bfSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a5b190bfSAndrew Rist  * distributed with this work for additional information
6*a5b190bfSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a5b190bfSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a5b190bfSAndrew Rist  * "License"); you may not use this file except in compliance
9*a5b190bfSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*a5b190bfSAndrew Rist  *
11*a5b190bfSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*a5b190bfSAndrew Rist  *
13*a5b190bfSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a5b190bfSAndrew Rist  * software distributed under the License is distributed on an
15*a5b190bfSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a5b190bfSAndrew Rist  * KIND, either express or implied.  See the License for the
17*a5b190bfSAndrew Rist  * specific language governing permissions and limitations
18*a5b190bfSAndrew Rist  * under the License.
19*a5b190bfSAndrew Rist  *
20*a5b190bfSAndrew Rist  *************************************************************/
21*a5b190bfSAndrew Rist 
22*a5b190bfSAndrew 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>
37cdf0e10cSrcweir  * @see         com.sun.star.loader.SharedLibrary
38cdf0e10cSrcweir  * @see         com.sun.star.comp.servicemanager.ServiceManager
39cdf0e10cSrcweir  * @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 
56cdf0e10cSrcweir 	private static native boolean component_writeInfo(
57cdf0e10cSrcweir 			String libName, XMultiServiceFactory smgr, XRegistryKey regKey,
58cdf0e10cSrcweir             ClassLoader loader );
59cdf0e10cSrcweir 
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
73cdf0e10cSrcweir 	 * @see		com.sun.star.loader.SharedLibrary
74cdf0e10cSrcweir 	 * @see		com.sun.star.lang.ServiceManager
75cdf0e10cSrcweir 	 * @see		com.sun.star.registry.RegistryKey
76cdf0e10cSrcweir 	 */
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
96cdf0e10cSrcweir 	 * @see		com.sun.star.loader.SharedLibrary
97cdf0e10cSrcweir 	 * @see		com.sun.star.lang.ServiceManager
98cdf0e10cSrcweir 	 * @see		com.sun.star.registry.RegistryKey
99cdf0e10cSrcweir 	 */
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>
116cdf0e10cSrcweir 	 * @return	true if the registration was successfull - otherwise false
117cdf0e10cSrcweir 	 * @param	smgr	the ServiceManager
118cdf0e10cSrcweir 	 * @param	regKey	the root key under that the component should be registered
119cdf0e10cSrcweir 	 * @see		com.sun.star.loader.SharedLibrary
120cdf0e10cSrcweir 	 * @see		com.sun.star.lang.ServiceManager
121cdf0e10cSrcweir 	 * @see		com.sun.star.registry.RegistryKey
122cdf0e10cSrcweir 	 */
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>
135cdf0e10cSrcweir 	 * @return	true if the registration was successfull - 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
139cdf0e10cSrcweir 	 * @see		com.sun.star.loader.SharedLibrary
140cdf0e10cSrcweir 	 * @see		com.sun.star.lang.ServiceManager
141cdf0e10cSrcweir 	 * @see		com.sun.star.registry.RegistryKey
142cdf0e10cSrcweir 	 */
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