The Java Binding

1st February 2013

Update (1st February 2013)

DO NOT READ THIS PAGE.

The only Java client library for Z39.50 that we would recommend is Index Data's YAZ4J, a set of Java classes that wrap the popular and powerful ZOOM-C functions. See also this tutorial.

All the rest of the content of this page, and those it links to, is retained for historical interest only. Most of the software it mentions is now abandonware. If you choose to read on, do so at your own peril.

1. Java Binding Specification
2. Canonical Sample Program
3. Java Binding Implementations
4. Commentary

1. Java Binding Specification

The Java binding is maintained by Matthew Dovey <m.dovey@ceridwen.com>

You probably want the current version.

The Java binding is largely specified: it's complete enough that it's possible to build working implementations (I have done so), but it should not be considered stable. It is liable to change: in particular, towards being more idiomatic Java.

The following version of the interface specification are available:

2. Canonical Sample Program

To give a flavour of the Java binding, here is ZOOM's equivalent of the ``Hello World'' program: a tiny Z39.50 client that fetches and displays the MARC record for Farlow & Brett Surman's The Complete Dinosaur from the Library of Congress.

import uk.org.miketaylor.zoom.*;

class Canonical {
    public static void main (String[] args) throws Exception {
	Connection conn = new Connection("z3950.loc.gov", 7090);
	conn.option("databaseName", "Voyager");
	conn.option("preferredRecordSyntax", "USMARC");
	Query q = new PrefixQuery("@attr 1=7 0253333490");
	ResultSet rs = conn.search(q);
	System.out.println(rs.getRecord(0).render());
    }
}

3. Java Binding Implementations

NEW! We finally have a complete are released open-source implementation for Java: YAZ4J (indexdata.com/yaz4j) is a JNI wrapper for ZOOM-C, originally written by Talis and packaged, released and maintained by Index Data.

At least three other streams of work begun on Java bindings, though none had reached a releasable level of maturity the last time I looked:

4. Commentary

As I was writing the binding specification, I ran into a surprising number of issues which may be of interest to others. Some of them are no doubt just down to my lack of familiarity with Java; others seem to highlight real deficiencies in the language[1]. Here they are, for anyone who wants to understand more of the reasoning behind the decisions made in this binding.

 


Notes

[1]
When that sad day comes that I lie on my death-bed, and heartbroken throngs surround my frail and aged form, looking to glean what wisdom they may from my last words; and when one particularly attractive young acoloyte leans across and asks, ``O exalted master, what one thing remaineth a mystery to thee after these many years?'', twelve gets you seven[2] that I'll reply with my dying breath, ``Why in the name of all that is holy doesn't Java have enum?'' [back]
[2]
``Call it hell, call it heaven / But it's a probable twelve to seven / That the guy's only trying to figure why Java doesn't support enumerated types.'' - Frank Loesser, Guys and Dolls. [back]

Feedback to <mike@indexdata.com> is welcome!