xref: /AOO41X/main/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeLibraries.java (revision c3ab0d6a971c09227d821facfabab1b8154c7921)
1*c3ab0d6aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c3ab0d6aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c3ab0d6aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c3ab0d6aSAndrew Rist  * distributed with this work for additional information
6*c3ab0d6aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c3ab0d6aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c3ab0d6aSAndrew Rist  * "License"); you may not use this file except in compliance
9*c3ab0d6aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*c3ab0d6aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*c3ab0d6aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c3ab0d6aSAndrew Rist  * software distributed under the License is distributed on an
15*c3ab0d6aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c3ab0d6aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c3ab0d6aSAndrew Rist  * specific language governing permissions and limitations
18*c3ab0d6aSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*c3ab0d6aSAndrew Rist  *************************************************************/
21*c3ab0d6aSAndrew Rist 
22*c3ab0d6aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.sdbcx.comp.hsqldb;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.io.File;
27cdf0e10cSrcweir import java.net.URL;
28cdf0e10cSrcweir import java.net.URLClassLoader;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir final class NativeLibraries {
load()31cdf0e10cSrcweir     public static void load() {
32cdf0e10cSrcweir         if (System.getProperty( "os.name" ).startsWith("Windows")) {
33cdf0e10cSrcweir             loadLibrary("msvcr71");
34cdf0e10cSrcweir             loadLibrary("uwinapi");
35cdf0e10cSrcweir             loadLibrary("sal3");
36cdf0e10cSrcweir             loadLibrary("dbtoolsmi");
37cdf0e10cSrcweir         }
38cdf0e10cSrcweir         loadLibrary("hsqldb");
39cdf0e10cSrcweir     }
40cdf0e10cSrcweir 
loadLibrary(String libname)41cdf0e10cSrcweir     private static void loadLibrary(String libname) {
42cdf0e10cSrcweir         // At least on Mac OS X Tiger, System.loadLibrary("hsqldb2") does not
43cdf0e10cSrcweir         // find the hsqldb2 library one directory above sdbc_hsqldb.jar, even
44cdf0e10cSrcweir         // though ".." is on the jar's Class-Path; however, the alternative
45cdf0e10cSrcweir         // code (needing Java 1.5, which is given for Mac OS X Tiger) works
46cdf0e10cSrcweir         // there:
47cdf0e10cSrcweir         try {
48cdf0e10cSrcweir             System.loadLibrary(libname);
49cdf0e10cSrcweir         } catch (UnsatisfiedLinkError e) {
50cdf0e10cSrcweir             ClassLoader cl = NativeLibraries.class.getClassLoader();
51cdf0e10cSrcweir             if (cl instanceof URLClassLoader) {
52cdf0e10cSrcweir                 URL url = ((URLClassLoader) cl).findResource(
53cdf0e10cSrcweir                     System.mapLibraryName(libname));
54cdf0e10cSrcweir                 if (url != null) {
55cdf0e10cSrcweir                     try {
56cdf0e10cSrcweir                         System.load(
57cdf0e10cSrcweir                             ((File) File.class.getConstructor(
58cdf0e10cSrcweir                                 new Class[] {
59cdf0e10cSrcweir                                     ClassLoader.getSystemClassLoader().
60cdf0e10cSrcweir                                     loadClass("java.net.URI") }).
61cdf0e10cSrcweir                              newInstance(
62cdf0e10cSrcweir                                  new Object[] {
63cdf0e10cSrcweir                                      URL.class.getMethod("toURI", new Class[0]).
64cdf0e10cSrcweir                                      invoke(url, (java.lang.Object[])null) })).
65cdf0e10cSrcweir                             getAbsolutePath());
66cdf0e10cSrcweir                     } catch (Throwable t) {
67cdf0e10cSrcweir                         throw new UnsatisfiedLinkError(
68cdf0e10cSrcweir                             e.toString()+ " - " + t.toString());
69cdf0e10cSrcweir                     }
70cdf0e10cSrcweir                 }
71cdf0e10cSrcweir             }
72cdf0e10cSrcweir         }
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir 
NativeLibraries()75cdf0e10cSrcweir     private NativeLibraries() {}
76cdf0e10cSrcweir }
77