JaceLib : A Java wrapper for acelib
The main objective for creating JaceLib was to facilitate direct access from java to acedb. This will allow fast prototyping of acedb Java and c++ programs. If in the future Xace should fully integrate acelib, it should also allow Java displays to be integrated directly.
Direct interface to the library is carried out via java 1.1 native method calls. A shared c library is used to access the acelib. Java type variables are passed to this interface and converted to their c types using the JNI library from Sun (supplied as a standard part of JDK 1.1). See http://java.sun.com/docs/books/tutorial/native1.1/index.html for a tutorial and http://java.sun.com/products/jdk/1.1/docs/guide/jni/spec/jniTOC.doc.html for the specifications.
The return values are then converted back to Java types.
The JaceLib class abstracts the opening of the database and the setting up of file I/O. Once this class has been created then separated Jace objects can be obtained which encapsulate an acecontext and allow database access as in AceLib.
Context management will be managed for the user via different Jace instances (java ace contexts). An ace handle object will also be designed to allow for memory management.
JaceLib includes java exception handling. Wherever acelib returns a null or false, meaning a function hasn’t worked, then Jace (or JaceLib) will throw a JaceException with a message saying (hopefully J ) what went wrong.
Jace requires java 1.1 or above (Sun suggests 1.1.3 which has better jni), acelib.a and a c compiler capable of making c shared libraries.
At the present time Jace has only been tested on Solaris.
javac *.java
On Solaris:
cc -G -I. –I<ACEDB_SRC>/wh -I<PATHTO JAVA 1.1>/include –I<PATH TO JAVA 1.1>/include/solaris JaceLib.c -o testlib.so –L<PATH TO libace.a> -lace
On other machines:
gcc -shared -I. –I<PATH TO ACEDB wh> -I<PATHTO JAVA 1.1>/include –I<PATH TO JAVA 1.1>/include/<MACHINE> JaceLib.c -o testlib.so –L<PATH TO libace.a> -lace
public class JaceTest{ // test class
public static void main(String[] args){ // standard main
JaceLib l = null ; // define a pointer to a JaceLib
Jace j = null; // define a pointer to a Jace
try { // JaceLib wil throw an exception if init fails
l = new JaceLib("<PATH TO DATABASE>"); //create a JaceLib with the local path to database
j = l.getJace("MyName"); //get a context with a client identifier
} catch (Exception e){ // catch any exception thrown
System.out.println(e); // print out an error message
System.exit(0); // exit as doing any calls on the Jace or JaceLib will result in a JVM crash
}
String[] classes = j.getClasses(); // get classes and store them in an array of strings
for (int k = 0; k < classes.length; k++) { // for each class
System.out.println( classes[k] + ": " + j.getClassSize(classes[k]));
// print out the number of objects in that class
}
try{ // try again for the exception handling
j.CloseContext(false); // close the context
// j.Quit(false); should be here but not implemented yet
} catch (Exception e){ // catch any exception thrown
System.out.println(e); // print error
System.exit(0); // end
}
}
}