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