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 28 package com.sun.star.sdbcx.comp.hsqldb; 29 30 import java.io.File; 31 import java.net.URL; 32 import java.net.URLClassLoader; 33 34 final class NativeLibraries { 35 public static void load() { 36 if (System.getProperty( "os.name" ).startsWith("Windows")) { 37 loadLibrary("msvcr71"); 38 loadLibrary("uwinapi"); 39 loadLibrary("sal3"); 40 loadLibrary("dbtoolsmi"); 41 } 42 loadLibrary("hsqldb"); 43 } 44 45 private static void loadLibrary(String libname) { 46 // At least on Mac OS X Tiger, System.loadLibrary("hsqldb2") does not 47 // find the hsqldb2 library one directory above sdbc_hsqldb.jar, even 48 // though ".." is on the jar's Class-Path; however, the alternative 49 // code (needing Java 1.5, which is given for Mac OS X Tiger) works 50 // there: 51 try { 52 System.loadLibrary(libname); 53 } catch (UnsatisfiedLinkError e) { 54 ClassLoader cl = NativeLibraries.class.getClassLoader(); 55 if (cl instanceof URLClassLoader) { 56 URL url = ((URLClassLoader) cl).findResource( 57 System.mapLibraryName(libname)); 58 if (url != null) { 59 try { 60 System.load( 61 ((File) File.class.getConstructor( 62 new Class[] { 63 ClassLoader.getSystemClassLoader(). 64 loadClass("java.net.URI") }). 65 newInstance( 66 new Object[] { 67 URL.class.getMethod("toURI", new Class[0]). 68 invoke(url, (java.lang.Object[])null) })). 69 getAbsolutePath()); 70 } catch (Throwable t) { 71 throw new UnsatisfiedLinkError( 72 e.toString()+ " - " + t.toString()); 73 } 74 } 75 } 76 } 77 } 78 79 private NativeLibraries() {} 80 } 81