org.arakhne.vmutil
Class LibraryLoader

java.lang.Object
  extended by org.arakhne.vmutil.LibraryLoader

public class LibraryLoader
extends Object

This class provides more generic means for loading dynamical libraries.

The library loader may be enabled or not. When library loader is enable, it is able to retreive and load native libraries. When it is disable, it ignore all the loading queries.

Version:
6.3 (rev:285) 2011-10-14 12:02:41
Author:
Stéphane GALLAND
Maven Group Id:
org.arakhne.afc
Maven Artifact Id:
arakhneVmutils

Constructor Summary
LibraryLoader()
           
 
Method Summary
static URL findLibraryURL(String libName)
          Replies the URL for the specified library.
static URL findLibraryURL(String path, String libName)
          Replies the URL for the specified library.
(package private) static int getOperatingSystemArchitectureDataModel()
          Replies the data model of the current operating system: 32 or 64 bits.
static boolean isEnable()
          Replies if this library loader is enable.
static void load(File filename)
          Loads a code file with the specified filename from the local file system as a dynamic library.
static void load(String filename)
          Loads a code file with the specified filename from the local file system as a dynamic library.
static void load(URL filename)
          Loads a code file with the specified filename from the local file system as a dynamic library.
static void loadLibrary(String libname)
          Loads the system library specified by the libname argument.
static void loadPlatformDependentLibrary(String libname)
          Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...).
static void loadPlatformDependentLibrary(String path, String libname)
          Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...).
(package private) static void loadPlatformDependentLibrary(String libname, String platform, String... paths)
          Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...).
static void setEnable(boolean enable)
          Replies if this library loader is enable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LibraryLoader

public LibraryLoader()
Method Detail

isEnable

public static boolean isEnable()
Replies if this library loader is enable.

The library loader is able to load native libraries when it is enable. Otherwise it ignore all the loading queries.

Returns:
true if the library loader is enable, otherwise false
Since:
5.0

setEnable

public static void setEnable(boolean enable)
Replies if this library loader is enable.

The library loader is able to load native libraries when it is enable. Otherwise it ignore all the loading queries.

Parameters:
enable - is true to allow this loader to retreive native libraries, or false to ignore all the loading queries.
Since:
5.0

load

public static void load(String filename)
Loads a code file with the specified filename from the local file system as a dynamic library. The filename argument must be a complete path name.

The call LibraryLoader.load(name) is effectively equivalent to the call:

 System.load(name)
 

Parameters:
filename - is the file to load.
Throws:
SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
UnsatisfiedLinkError - if the file does not exist.
NullPointerException - if filename is null
See Also:
System.load(java.lang.String)

loadLibrary

public static void loadLibrary(String libname)
Loads the system library specified by the libname argument. The manner in which a library name is mapped to the actual system library is system dependent.

The call LibraryLoader.loadLibrary(name) is effectively equivalent to the call

 System.loadLibrary(name)
 

Parameters:
libname - the name of the library.
Throws:
SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
UnsatisfiedLinkError - if the library does not exist.
NullPointerException - if libname is null
See Also:
System.loadLibrary(java.lang.String)

load

public static void load(File filename)
Loads a code file with the specified filename from the local file system as a dynamic library. The filename argument must be a complete path name.

The call LibraryLoader.load(name) is effectively equivalent to the call:

 System.load(name.getAbsolutePath())
 

Parameters:
filename - is the file to load.
Throws:
SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
UnsatisfiedLinkError - if the file does not exist.
NullPointerException - if filename is null
See Also:
System.load(java.lang.String)

findLibraryURL

public static URL findLibraryURL(String libName)
Replies the URL for the specified library.

Parameters:
libName - is the name of the library
Returns:
the URL where the specified library was located.

findLibraryURL

public static URL findLibraryURL(String path,
                                 String libName)
Replies the URL for the specified library.

The call LibraryLoader.findLibraryURL(path,name) is effectively equivalent to the call:

 getClassLoader().getResource(path+System.mapLibraryName(name))
 

Parameters:
path - is the resource's path where the library was located.
libName - is the name of the library
Returns:
the URL where the specified library was located.

load

public static void load(URL filename)
                 throws IOException
Loads a code file with the specified filename from the local file system as a dynamic library. The filename argument must be a complete path name.

Parameters:
filename - is the file to load.
Throws:
IOException
SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
UnsatisfiedLinkError - if the file does not exist.
NullPointerException - if filename is null
See Also:
System.load(java.lang.String)

loadPlatformDependentLibrary

public static void loadPlatformDependentLibrary(String libname)
                                         throws IOException
Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...). A 64 bits library is assumed to be named libname64.dll on Windows® and liblibname64.so on Unix. A 32 bits library is assumed to be named libname32.dll on Windows® and liblibname32.so on Unix. A library which could be ran either on 32 and 64 platforms is assumed to be named libname.dll on Windows® and liblibname.so on Unix.

Parameters:
libname - is the name of the library.
Throws:
IOException
SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
UnsatisfiedLinkError - if the file does not exist.
NullPointerException - if filename is null
See Also:
System.load(java.lang.String)

getOperatingSystemArchitectureDataModel

static int getOperatingSystemArchitectureDataModel()
Replies the data model of the current operating system: 32 or 64 bits.

Returns:
the integer which is corresponding to the data model, or 0 if it could not be determined.

loadPlatformDependentLibrary

public static void loadPlatformDependentLibrary(String path,
                                                String libname)
                                         throws IOException
Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...). A 64 bits library is assumed to be named libname64.dll on Windows® and liblibname64.so on Unix. A 32 bits library is assumed to be named libname32.dll on Windows® and liblibname32.so on Unix. A library which could be ran either on 32 and 64 platforms is assumed to be named libname.dll on Windows® and liblibname.so on Unix.

Parameters:
path - is the resource's path where the library was located.
libname - is the name of the library.
Throws:
IOException
SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
UnsatisfiedLinkError - if the file does not exist.
NullPointerException - if filename is null
See Also:
System.load(java.lang.String)

loadPlatformDependentLibrary

static void loadPlatformDependentLibrary(String libname,
                                         String platform,
                                         String... paths)
                                  throws IOException
Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...). A 64 bits library is assumed to be named libname64.dll on Windows® and liblibname64.so on Unix. A 32 bits library is assumed to be named libname32.dll on Windows® and liblibname32.so on Unix. A library which could be ran either on 32 and 64 platforms is assumed to be named libname.dll on Windows® and liblibname.so on Unix.

Parameters:
libname - is the name of the library.
platform - is the name of the current OS platform.
paths - are the resource's paths where the library was located.
Throws:
IOException
SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
UnsatisfiedLinkError - if the file does not exist.
NullPointerException - if filename is null
See Also:
System.load(java.lang.String)


Copyright © 2006-2011 Arakhnê.org Consortium. All rights reserved under LGPL license terms.