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