public class Library
extends java.lang.Object
Library class is responsible for providing the
Function class instances that are used for calling functions
from native code libraries. Unlike standard functionality provided, a library
can be dynamically loaded and unloaded.unload() method.| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
NATIVE_CODE |
static java.lang.String |
NATIVE_NAME |
| Constructor and Description |
|---|
Library(java.lang.String name)
Constructs a library using its name.
|
Library(java.lang.String libraryName,
byte callingConvention)
Constructs a library using its name and default calling convention.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
ensureNativeCode()
Ensures that the native code implementation is loaded.
|
static LibraryLoader |
getDefaultLibraryLoader()
Returns a library loader used in methods that do not take the library
loader as an argument.
|
Function |
getFunction(java.lang.String name)
A convenience method for getting a function when parameter types do
affect loaded function.
|
Function |
getFunction(java.lang.String name,
java.lang.Class[] paramTypes)
This returns a
Function object that reflects the exported
native function from the library. |
static Library |
getJNIWrapperLibrary()
Returns the instance of loaded JNIWrapper library.
|
protected static java.util.List |
getJVMLibraries()
Returns the list of libraries which were loaded by JVM.
|
LibraryLoader |
getLibraryLoader()
This method returns the loader of this library.
|
java.lang.String |
getName()
Returns the library name.
|
void |
getVariable(java.lang.String name,
Parameter variable)
Maps variable to memory address of a global variable in library.
|
boolean |
isLoaded()
Returns loaded status of this library.
|
void |
load()
Loads a library by its name using default mechanism.
|
void |
load(java.lang.ClassLoader classLoader)
Special method for loading a library from the context of the specified class loader.
|
void |
load(java.io.File directory)
Loads a library from the passed directory.
|
void |
load(LibraryLoader loader)
Loads a library using a given library loader.
|
void |
loadAsJNI() |
static void |
loadNativeCode()
Initializes the native support library using standard library search
behavior and predefined native library name.
|
static void |
loadNativeCode(LibraryLoader loader)
Loads a native support library using a specified library loader.
|
static void |
loadNativeCode(java.lang.String nativeSupportPath)
Loads a native support library from the passed full file name.
|
static void |
setDefaultLibraryLoader(LibraryLoader libraryLoader)
Sets a library loader used in methods that do not take the library loader
as an argument.
|
protected void |
unload()
This method is designed for unloading an unused library.
|
static java.lang.String |
unloadNativeCode()
Unloads JNI library from the Java classloader.
|
public static final java.lang.String NATIVE_CODE
public static final java.lang.String NATIVE_NAME
public Library(java.lang.String libraryName,
byte callingConvention)
libraryName - the name of the librarycallingConvention - specifies the calling convention for all functions from this librarypublic Library(java.lang.String name)
name - library namepublic static Library getJNIWrapperLibrary()
protected static java.util.List getJVMLibraries()
public static java.lang.String unloadNativeCode()
public static void loadNativeCode(LibraryLoader loader) throws java.lang.SecurityException, java.lang.UnsatisfiedLinkError
java.lang.SecurityExceptionjava.lang.UnsatisfiedLinkErrorpublic static void loadNativeCode(java.lang.String nativeSupportPath)
throws java.lang.SecurityException,
java.lang.UnsatisfiedLinkError
java.lang.SecurityExceptionjava.lang.UnsatisfiedLinkErrorpublic static void loadNativeCode()
throws java.lang.SecurityException,
java.lang.UnsatisfiedLinkError
java.lang.SecurityExceptionjava.lang.UnsatisfiedLinkErrorpublic static void ensureNativeCode()
public void loadAsJNI()
public void load()
throws LibraryNotFoundException
LibraryNotFoundExceptionpublic void load(java.io.File directory)
throws LibraryNotFoundException
LibraryNotFoundExceptionpublic void load(LibraryLoader loader) throws LibraryNotFoundException
LibraryNotFoundExceptionpublic void load(java.lang.ClassLoader classLoader)
getLibraryLoader function.classLoader - a class loader is the context to load the native library fromprotected void unload()
public boolean isLoaded()
public java.lang.String getName()
public Function getFunction(java.lang.String name, java.lang.Class[] paramTypes) throws NoSuchFunctionException, LibraryNotFoundException
Function object that reflects the exported
native function from the library.public Function getFunction(java.lang.String name) throws NoSuchFunctionException, LibraryNotFoundException
public void getVariable(java.lang.String name,
Parameter variable)
throws NoSuchVariableException
#define operator in a header file,
but only those variables, which are specially declared as global variables, for example:
extern "C" __declspec(dllexport) Type Name; name - a variable namevariable - a variable to loadNoSuchVariableExceptionpublic LibraryLoader getLibraryLoader()
public static LibraryLoader getDefaultLibraryLoader()
public static void setDefaultLibraryLoader(LibraryLoader libraryLoader)