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