cryptix.provider.md

Class NativeLink

final class NativeLink extends Object implements LinkStatus

A class to handle loading and versioning of native code in a VM-independent way.

SECURITY: this class must be package-private, and not accessible to untrusted code. Therefore the source file must be copied to each package that needs it, with the package statement adjusted accordingly. Make sure that any changes are reflected in all copies.

Copyright © 1997 Systemics Ltd on behalf of the Cryptix Development Team.
All rights reserved.

$Revision: 1.10 $

Since: Cryptix 2.2.2

Author: David Hopwood Raif S. Naffah

Constructor Summary
NativeLink(String libname, int major, int minor)
Constructs a NativeLink object that can be used to load the given native library.
Method Summary
booleanattemptLoad()
Tries to load the native library, if it is enabled.
voidcheck(String reason)
If reason is null, this method returns silently.
voidcheckNative()
voidcheckVersion(int major, int minor)
Sets the actual major and minor version numbers of the library.
voidfail(Throwable e)
Marks the library as having failed a test.
StringgetLibraryName()
StringgetLinkErrorString()
intgetMajorVersion()
intgetMinorVersion()
intgetRequiredMajorVersion()
intgetRequiredMinorVersion()
booleanisLibraryCorrect()
booleanisLibraryLoaded()
voidsetNative(boolean wanted)
booleanuseNative()

Constructor Detail

NativeLink

NativeLink(String libname, int major, int minor)
Constructs a NativeLink object that can be used to load the given native library. libname is the platform-independent part of the name.

Parameters: libname the library name major the required major version number minor the required minor version number

Method Detail

attemptLoad

boolean attemptLoad()
Tries to load the native library, if it is enabled. Returns true if the library was successfully loaded by this call (but not if it was already loaded).

check

void check(String reason)
If reason is null, this method returns silently. Otherwise, an UnsatisfiedLinkError is thrown with reason included in the detail message.

This is useful for handling native methods that return null on success, or an error String on failure.

Parameters: reason either null or an error message

checkNative

public void checkNative()

checkVersion

void checkVersion(int major, int minor)
Sets the actual major and minor version numbers of the library. If they are not compatible with the required version numbers passed to the NativeLink constructor, an UnsatisfiedLinkError is thrown.

The major version must match the required major version exactly, and the minor version must be at least the required minor version, in order for the library to be compatible.

Parameters: major the actual major version number minor the actual minor version number

fail

void fail(Throwable e)
Marks the library as having failed a test.

Parameters: e the exception that was thrown to indicate the failure.

getLibraryName

public String getLibraryName()

getLinkErrorString

public String getLinkErrorString()

getMajorVersion

public int getMajorVersion()

getMinorVersion

public int getMinorVersion()

getRequiredMajorVersion

public int getRequiredMajorVersion()

getRequiredMinorVersion

public int getRequiredMinorVersion()

isLibraryCorrect

public boolean isLibraryCorrect()

isLibraryLoaded

public boolean isLibraryLoaded()

setNative

public void setNative(boolean wanted)

useNative

public boolean useNative()