xref: /AOO41X/main/javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package com.sun.star.comp.helper;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
30*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
31*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
32*cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey;
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir /**
35*cdf0e10cSrcweir  * @deprecated use class Bootstrap bootstrapping a native UNO installation
36*cdf0e10cSrcweir  *             and use the shared library loader service.
37*cdf0e10cSrcweir  *
38*cdf0e10cSrcweir  * The <code>SharedLibraryLoader</code> class provides the functionality of the <code>com.sun.star.loader.SharedLibrary</code>
39*cdf0e10cSrcweir  * service.
40*cdf0e10cSrcweir  * <p>
41*cdf0e10cSrcweir  * @see         com.sun.star.loader.SharedLibrary
42*cdf0e10cSrcweir  * @see         com.sun.star.comp.servicemanager.ServiceManager
43*cdf0e10cSrcweir  * @see			com.sun.star.lang.ServiceManager
44*cdf0e10cSrcweir  */
45*cdf0e10cSrcweir public class SharedLibraryLoader {
46*cdf0e10cSrcweir 	/**
47*cdf0e10cSrcweir 	 * The default library which contains the SharedLibraryLoader component
48*cdf0e10cSrcweir 	 */
49*cdf0e10cSrcweir 	public static final String DEFAULT_LIBRARY = "shlibloader.uno";
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 	/**
52*cdf0e10cSrcweir 	 * The default implementation name
53*cdf0e10cSrcweir 	 */
54*cdf0e10cSrcweir 	public static final String DEFAULT_IMPLEMENTATION = "com.sun.star.comp.stoc.DLLComponentLoader";
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir 	static {
57*cdf0e10cSrcweir 		System.loadLibrary("juh");
58*cdf0e10cSrcweir 	}
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 	private static native boolean component_writeInfo(
61*cdf0e10cSrcweir 			String libName, XMultiServiceFactory smgr, XRegistryKey regKey,
62*cdf0e10cSrcweir             ClassLoader loader );
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 	private static native Object component_getFactory(
65*cdf0e10cSrcweir 			String libName, String implName, XMultiServiceFactory smgr,
66*cdf0e10cSrcweir             XRegistryKey regKey, ClassLoader loader );
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir 	/**
69*cdf0e10cSrcweir 	 * Supplies the ServiceFactory of the default SharedLibraryLoader.
70*cdf0e10cSrcweir 	 * The defaults are "shlibloader.uno"
71*cdf0e10cSrcweir 	 * for the library and "com.sun.star.comp.stoc.DLLComponentLoader"
72*cdf0e10cSrcweir 	 * for the component name.
73*cdf0e10cSrcweir 	 * <p>
74*cdf0e10cSrcweir 	 * @return	the factory for the "com.sun.star.comp.stoc.DLLComponentLoader" component.
75*cdf0e10cSrcweir 	 * @param	smgr	the ServiceManager
76*cdf0e10cSrcweir 	 * @param	regKey	the root registry key
77*cdf0e10cSrcweir 	 * @see		com.sun.star.loader.SharedLibrary
78*cdf0e10cSrcweir 	 * @see		com.sun.star.lang.ServiceManager
79*cdf0e10cSrcweir 	 * @see		com.sun.star.registry.RegistryKey
80*cdf0e10cSrcweir 	 */
81*cdf0e10cSrcweir 	public static XSingleServiceFactory getServiceFactory(
82*cdf0e10cSrcweir 				XMultiServiceFactory smgr,
83*cdf0e10cSrcweir 				XRegistryKey regKey )
84*cdf0e10cSrcweir 	{
85*cdf0e10cSrcweir 		return UnoRuntime.queryInterface(
86*cdf0e10cSrcweir 					XSingleServiceFactory.class,
87*cdf0e10cSrcweir 					component_getFactory(
88*cdf0e10cSrcweir                         DEFAULT_LIBRARY, DEFAULT_IMPLEMENTATION, smgr, regKey,
89*cdf0e10cSrcweir                         SharedLibraryLoader.class.getClassLoader() ) );
90*cdf0e10cSrcweir 	}
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	/**
93*cdf0e10cSrcweir 	 * Loads and returns a specific factory for a given library and implementation name.
94*cdf0e10cSrcweir 	 * <p>
95*cdf0e10cSrcweir 	 * @return	the factory of the component
96*cdf0e10cSrcweir 	 * @param	libName	the name of the shared library
97*cdf0e10cSrcweir 	 * @param	impName	the implementation name of the component
98*cdf0e10cSrcweir 	 * @param	smgr	the ServiceManager
99*cdf0e10cSrcweir 	 * @param	regKey	the root registry key
100*cdf0e10cSrcweir 	 * @see		com.sun.star.loader.SharedLibrary
101*cdf0e10cSrcweir 	 * @see		com.sun.star.lang.ServiceManager
102*cdf0e10cSrcweir 	 * @see		com.sun.star.registry.RegistryKey
103*cdf0e10cSrcweir 	 */
104*cdf0e10cSrcweir 	public static XSingleServiceFactory getServiceFactory(
105*cdf0e10cSrcweir 				String libName,
106*cdf0e10cSrcweir 				String impName,
107*cdf0e10cSrcweir 				XMultiServiceFactory smgr,
108*cdf0e10cSrcweir 				XRegistryKey regKey )
109*cdf0e10cSrcweir 	{
110*cdf0e10cSrcweir 		return UnoRuntime.queryInterface(
111*cdf0e10cSrcweir 					XSingleServiceFactory.class,
112*cdf0e10cSrcweir 					component_getFactory(
113*cdf0e10cSrcweir                         libName, impName, smgr, regKey,
114*cdf0e10cSrcweir                         SharedLibraryLoader.class.getClassLoader() ) );
115*cdf0e10cSrcweir 	}
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 	/**
118*cdf0e10cSrcweir 	 * Registers the SharedLibraryLoader under a RegistryKey.
119*cdf0e10cSrcweir 	 * <p>
120*cdf0e10cSrcweir 	 * @return	true if the registration was successfull - otherwise false
121*cdf0e10cSrcweir 	 * @param	smgr	the ServiceManager
122*cdf0e10cSrcweir 	 * @param	regKey	the root key under that the component should be registered
123*cdf0e10cSrcweir 	 * @see		com.sun.star.loader.SharedLibrary
124*cdf0e10cSrcweir 	 * @see		com.sun.star.lang.ServiceManager
125*cdf0e10cSrcweir 	 * @see		com.sun.star.registry.RegistryKey
126*cdf0e10cSrcweir 	 */
127*cdf0e10cSrcweir 	public static boolean writeRegistryServiceInfo(
128*cdf0e10cSrcweir 				com.sun.star.lang.XMultiServiceFactory smgr,
129*cdf0e10cSrcweir 				com.sun.star.registry.XRegistryKey regKey )
130*cdf0e10cSrcweir 	{
131*cdf0e10cSrcweir 		return component_writeInfo(
132*cdf0e10cSrcweir             DEFAULT_LIBRARY, smgr, regKey,
133*cdf0e10cSrcweir             SharedLibraryLoader.class.getClassLoader() );
134*cdf0e10cSrcweir 	}
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 	/**
137*cdf0e10cSrcweir 	 * Registers the SharedLibraryLoader under a RegistryKey.
138*cdf0e10cSrcweir 	 * <p>
139*cdf0e10cSrcweir 	 * @return	true if the registration was successfull - otherwise false
140*cdf0e10cSrcweir 	 * @param	libName	name of the shared library
141*cdf0e10cSrcweir 	 * @param	smgr	the ServiceManager
142*cdf0e10cSrcweir 	 * @param	regKey	the root key under that the component should be registered
143*cdf0e10cSrcweir 	 * @see		com.sun.star.loader.SharedLibrary
144*cdf0e10cSrcweir 	 * @see		com.sun.star.lang.ServiceManager
145*cdf0e10cSrcweir 	 * @see		com.sun.star.registry.RegistryKey
146*cdf0e10cSrcweir 	 */
147*cdf0e10cSrcweir 	public static boolean writeRegistryServiceInfo(
148*cdf0e10cSrcweir 				String libName,
149*cdf0e10cSrcweir 				com.sun.star.lang.XMultiServiceFactory smgr,
150*cdf0e10cSrcweir 				com.sun.star.registry.XRegistryKey regKey )
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 			throws 	com.sun.star.registry.InvalidRegistryException,
153*cdf0e10cSrcweir 					com.sun.star.uno.RuntimeException
154*cdf0e10cSrcweir 	{
155*cdf0e10cSrcweir 		return component_writeInfo(
156*cdf0e10cSrcweir             libName, smgr, regKey, SharedLibraryLoader.class.getClassLoader() );
157*cdf0e10cSrcweir 	}
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160