2 * Copyright (c) 1995-2010, Index Data
4 * See the file LICENSE for details.
8 import org.yaz4j.exception.*;
9 import org.yaz4j.jni.SWIGTYPE_p_ZOOM_connection_p;
10 import org.yaz4j.jni.yaz4jlib;
11 import org.yaz4j.jni.yaz4jlibConstants;
14 * Utility class to map ZOOM errors into ZoomExceptions
19 static ZoomException getError(SWIGTYPE_p_ZOOM_connection_p zoomConnection, String host, int port) {
20 int errorCode = yaz4jlib.ZOOM_connection_errcode(zoomConnection);
23 case yaz4jlibConstants.ZOOM_ERROR_NONE:
25 case yaz4jlib.ZOOM_ERROR_CONNECT:
26 message = String.format("Connection could not be made to %s:%d", host,
28 return new ConnectionUnavailableException(message);
29 case yaz4jlib.ZOOM_ERROR_INVALID_QUERY:
30 message = String.format(
31 "The query requested is not valid or not supported");
32 return new InvalidQueryException(message);
33 case yaz4jlib.ZOOM_ERROR_INIT:
34 message = String.format("Server %s:%d rejected our init request", host,
36 return new InitRejectedException(message);
37 case yaz4jlib.ZOOM_ERROR_TIMEOUT:
38 message = String.format("Server %s:%d timed out handling our request",
40 return new ConnectionTimeoutException(message);
41 case yaz4jlib.ZOOM_ERROR_MEMORY:
42 case yaz4jlib.ZOOM_ERROR_ENCODE:
43 case yaz4jlib.ZOOM_ERROR_DECODE:
44 case yaz4jlib.ZOOM_ERROR_CONNECTION_LOST:
45 case yaz4jlib.ZOOM_ERROR_INTERNAL:
46 case yaz4jlib.ZOOM_ERROR_UNSUPPORTED_PROTOCOL:
47 case yaz4jlib.ZOOM_ERROR_UNSUPPORTED_QUERY:
48 message = yaz4jlib.ZOOM_connection_errmsg(zoomConnection);
49 return new ZoomImplementationException("A fatal error occurred in Yaz: " +
50 errorCode + " - " + message);
52 String errMsgBib1 = "Bib1Exception: Error Code = " + errorCode + " (" +
53 Bib1Diagnostic.getError(errorCode) + ")";
54 return new Bib1Exception(errMsgBib1);