|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.izforge.izpack.util.Librarian
public class Librarian
This class handles loading of native libraries. There must only be one instance of
Librarian
per Java runtime, therefore this class is implemented as a 'Singleton'.
Librarian
is capable of loading native libraries from a variety of different
source locations. However, you should place your library files in the 'native' directory. The
primary reason for supporting different source locations is to facilitate testing in a
development environment, without the need to actually packing the application into a *.jar file.
Field Summary | |
---|---|
private static int |
BLOCK_SIZE
The block size used for reading and writing data, 4k. |
private static java.lang.String |
CLIENT_EXTENSION
The extension appended to the client name when searching for it as a resource. |
private java.util.Vector |
clients
A list of references to clients that use libraries that were extracted from a *.jar file. |
private java.lang.String |
extension
The extension to use for native libraries. |
private static java.lang.String |
FILE_PROTOCOL
Used to identify file URL protocols |
private static java.lang.String |
JAR_PROTOCOL
Used to identify jar URL protocols |
private java.util.Vector |
libraryNames
A list of library names as they appear in the temporary directory. |
private static Librarian |
me
The reference to the single instance of Librarian . |
private static java.lang.String |
NATIVE
The default directory for native library files. |
private java.lang.String |
nativeDirectory
The directory that is used to hold all native libraries. |
private static java.lang.String |
TEMP_LOCATION_KEY
The key used to retrieve the location of temporary files form the system properties. |
private java.util.Vector |
temporaryFileNames
A list of fully qualified library names. |
private java.util.Vector |
trackList
A list that is used to track all libraries that have been loaded. |
Constructor Summary | |
---|---|
private |
Librarian()
This class is implemented as a 'Singleton'. |
Method Summary | |
---|---|
void |
cleanUp()
This method attempts to remove all native libraries that have been temporarily created from the system. |
private void |
extractFromJar(java.lang.String name,
java.lang.String destination,
NativeLibraryClient client)
Makes an attempt to extract the named library from the jar file and to store it on the local file system for temporary use. |
private java.lang.String |
getClientPath(java.lang.String name,
java.net.URL clientURL)
Returns the complete path (including file name) for the native library, assuming the native library is located in the same directory from which the client was loaded. |
static Librarian |
getInstance()
Returns an instance of Librarian to use. |
private java.lang.String |
getNativePath(java.lang.String name,
NativeLibraryClient client)
Returns the complete path (including file name) for the native library, assuming the native library is located in a directory where native libraries are ordinarily expected. |
private java.lang.String |
getTempFileName(java.lang.String name)
Builds a temporary file name for the native library. |
private boolean |
loaded(java.lang.String name)
Verifies if the library has already been loaded and keeps track of all libraries that are verified. |
void |
loadLibrary(java.lang.String name,
NativeLibraryClient client)
Loads the requested library. |
private java.io.InputStream |
openInputStream(java.lang.String name,
NativeLibraryClient client)
Opens an InputStream to the native library. |
private java.lang.String |
revisePath(java.lang.String in)
Revises the given path to a file compatible path. |
void |
setNativeDirectory(java.lang.String directory)
Sets the directory where Librarian will search for native files. |
private java.lang.String |
strip(java.lang.String name)
Strips the extension of the library name, if it has one. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String JAR_PROTOCOL
private static final java.lang.String FILE_PROTOCOL
private static final java.lang.String TEMP_LOCATION_KEY
private static final java.lang.String CLIENT_EXTENSION
private static final java.lang.String NATIVE
private static final int BLOCK_SIZE
private static Librarian me
Librarian
. Used in static methods in
place of this
.
private java.util.Vector trackList
private java.util.Vector clients
private java.util.Vector libraryNames
clients
list.
private java.util.Vector temporaryFileNames
clients
list.
private java.lang.String extension
private java.lang.String nativeDirectory
Constructor Detail |
---|
private Librarian()
getInstance()
to obtain an instance for use.
Method Detail |
---|
public static Librarian getInstance()
Librarian
to use.
Librarian
.public void loadLibrary(java.lang.String name, NativeLibraryClient client) throws java.lang.Exception
this
must be replaced by the reference
of the class that links with the library.
Librarian.getInstance ().loadLibrary ("MyLibrary", this);
name
- the name of the library. A file extension and path are not needed, in fact if
supplied, both is stripped off. A specific extension is appended.client
- the object that made the load request
java.lang.Exception
- if all attempts to load the library fail.setNativeDirectory(java.lang.String)
private boolean loaded(java.lang.String name)
name
- name of the library to verify
true
if the library had already been loaded, otherwise
false
.private java.lang.String strip(java.lang.String name)
name
- the name of the library
private void extractFromJar(java.lang.String name, java.lang.String destination, NativeLibraryClient client) throws java.lang.Exception
name
- the simple name of the librarydestination
- the fully qualified name of the destination file.client
- the class that made the load request.
java.lang.Exception
- if the library can not be extracted from the *.jar file.
java.io.FileNotFoundException
- if the *.jar file does not exist. The way things operate
here, this should actually never happen.private java.lang.String getClientPath(java.lang.String name, java.net.URL clientURL)
name
- the simple name of the libraryclientURL
- a URL that points to the client class
private java.lang.String getNativePath(java.lang.String name, NativeLibraryClient client)
name
- the simple name of the libraryclient
- the class that made the load request.
private java.lang.String revisePath(java.lang.String in)
in
- path to be revised
private java.io.InputStream openInputStream(java.lang.String name, NativeLibraryClient client) throws java.lang.Exception
InputStream
to the native library.
name
- the simple name of the libraryclient
- the class that made the load request.
InputStream
from which the library can be read.
java.lang.Exception
- if the library can not be located.private java.lang.String getTempFileName(java.lang.String name)
name
- the file name of the library
public void setNativeDirectory(java.lang.String directory)
Librarian
will search for native files. Directories
are denoted relative to the root, where the root is the same location where the top level
Java package directory is located (usually called com
). The default directory
is native
.
directory
- the directory where native files are located.public void cleanUp()
cleanUp
in interface CleanupClient
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |