com.jniwrapper
Class DefaultLibraryLoader

java.lang.Object
  extended by com.jniwrapper.DefaultLibraryLoader
All Implemented Interfaces:
LibraryLoader

public class DefaultLibraryLoader
extends java.lang.Object
implements LibraryLoader

Default implementation for LibraryLoader that realizes Singleton pattern. Paths for searching libraries can be added via the addPath() methods. The instance of this class can be obtained via getInstance().


Field Summary
static java.lang.String JAVA_LIBRARY_PATH
           
 
Method Summary
 void addPath(java.io.File directory)
          Adds a directory to the path for searching libraries.
 void addPath(java.util.List directories)
          Adds a directory list to the path for searching libraries.
 void addPath(java.lang.String path)
          Adds a colon-separated path.
 java.io.File findLibrary(java.lang.String name)
          Finds a library by its name.
static DefaultLibraryLoader getInstance()
          Returns a Singleton instance.
static java.lang.String getLibraryExtension()
          Returns a file extension for native code libraries used under a current platform.
 void loadLibrary(java.lang.String name)
          Loads a native library by its name.
static java.lang.String mapLibraryName(java.lang.String libName)
          Maps a libary name to a platform-specific file name.
 void prependPath(java.io.File directory)
          Adds a directory to the path for searching libraries.
static java.lang.String urlToPath(java.net.URL url)
          Converts the URL with specified symbols (such as %20, %2B etc.) to the appropriate chars.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAVA_LIBRARY_PATH

public static final java.lang.String JAVA_LIBRARY_PATH
See Also:
Constant Field Values
Method Detail

getInstance

public static DefaultLibraryLoader getInstance()
Returns a Singleton instance.


addPath

public void addPath(java.io.File directory)
Adds a directory to the path for searching libraries.

Parameters:
directory - a directory to the path for searching libraries

prependPath

public void prependPath(java.io.File directory)
Adds a directory to the path for searching libraries.

Parameters:
directory - a directory to the path for searching libraries

addPath

public void addPath(java.util.List directories)
Adds a directory list to the path for searching libraries.

Parameters:
directories - a directory list to the path for searching libraries

addPath

public void addPath(java.lang.String path)
Adds a colon-separated path.

Parameters:
path - a colon-separated path

findLibrary

public java.io.File findLibrary(java.lang.String name)
Finds a library by its name.

Specified by:
findLibrary in interface LibraryLoader

urlToPath

public static java.lang.String urlToPath(java.net.URL url)
Converts the URL with specified symbols (such as %20, %2B etc.) to the appropriate chars.

Parameters:
url - the URL with specified symbols (such as %20, %2B etc.)
Returns:
the string with replaces symbols

loadLibrary

public void loadLibrary(java.lang.String name)
Loads a native library by its name. This method looks for a library within java.library.path as well as within added paths.

Specified by:
loadLibrary in interface LibraryLoader

mapLibraryName

public static java.lang.String mapLibraryName(java.lang.String libName)
Maps a libary name to a platform-specific file name. If the passed name already has a file extension, it is returned as the result of this method.

Parameters:
libName - a specified library name
Returns:
a platform-specific library name

getLibraryExtension

public static java.lang.String getLibraryExtension()
Returns a file extension for native code libraries used under a current platform.

Returns:
a file extension for native code libraries