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,
20 String host, int port) {
21 int errorCode = yaz4jlib.ZOOM_connection_errcode(zoomConnection);
24 case yaz4jlibConstants.ZOOM_ERROR_NONE:
26 case yaz4jlib.ZOOM_ERROR_CONNECT:
27 message = String.format("Connection could not be made to %s:%d", host,
29 return new ConnectionUnavailableException(message);
30 case yaz4jlib.ZOOM_ERROR_INVALID_QUERY:
31 message = String.format(
32 "The query requested is not valid or not supported");
33 return new InvalidQueryException(message);
34 case yaz4jlib.ZOOM_ERROR_INIT:
35 message = String.format("Server %s:%d rejected our init request", host,
37 return new InitRejectedException(message);
38 case yaz4jlib.ZOOM_ERROR_TIMEOUT:
39 message = String.format("Server %s:%d timed out handling our request",
41 return new ConnectionTimeoutException(message);
42 case yaz4jlib.ZOOM_ERROR_MEMORY:
43 case yaz4jlib.ZOOM_ERROR_ENCODE:
44 case yaz4jlib.ZOOM_ERROR_DECODE:
45 case yaz4jlib.ZOOM_ERROR_CONNECTION_LOST:
46 case yaz4jlib.ZOOM_ERROR_INTERNAL:
47 case yaz4jlib.ZOOM_ERROR_UNSUPPORTED_PROTOCOL:
48 case yaz4jlib.ZOOM_ERROR_UNSUPPORTED_QUERY:
49 message = yaz4jlib.ZOOM_connection_errmsg(zoomConnection);
50 return new ZoomImplementationException("A fatal error occurred in Yaz: "
51 + errorCode + " - " + message);
53 String errMsgBib1 = "Bib1Exception: Error Code = " + errorCode + " (" + Bib1Diagnostic.
54 getError(errorCode) + ")";
55 return new Bib1Exception(errMsgBib1);