From: Adam Dickmeiss Date: Tue, 22 Sep 2009 13:32:47 +0000 (+0200) Subject: Reformat (NetBeans). X-Git-Tag: v1.0 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=1182e040f5a025caff6565e6e37a3a669e9354fb;p=yaz4j-moved-to-github.git Reformat (NetBeans). Let's hope this doesn't screw anything up. --- diff --git a/src/main/java/org/yaz4j/Bib1Diagnostic.java b/src/main/java/org/yaz4j/Bib1Diagnostic.java index 5dd8c11..f567112 100644 --- a/src/main/java/org/yaz4j/Bib1Diagnostic.java +++ b/src/main/java/org/yaz4j/Bib1Diagnostic.java @@ -2,133 +2,132 @@ package org.yaz4j; import java.util.Hashtable; -class Bib1Diagnostic -{ - private static Hashtable errorCodes = new Hashtable(); +class Bib1Diagnostic { - static - { - errorCodes.put( 1, "PermanentSystemError" ) ; - errorCodes.put( 2, "TemporarySystemError" ) ; - errorCodes.put( 3, "UnsupportedSearch" ) ; - errorCodes.put( 4, "TermsOnlyIncludesExclusionOrStopWords" ) ; - errorCodes.put( 5, "TooManyArgumentWords" ) ; - errorCodes.put( 6, "TooManyBooleanOperators" ) ; - errorCodes.put( 7, "TooManyTruncatedWords" ) ; - errorCodes.put( 8, "TooManyIncompleteSubfields" ) ; - errorCodes.put( 9, "TruncatedWordsTooShort" ) ; - errorCodes.put( 10, "InvalidFormatForRecordNumberInSearchTerm" ) ; - errorCodes.put( 11, "TooManyCharactersInSearchStatement" ) ; - errorCodes.put( 12, "TooManyRecordsRetrieved" ) ; - errorCodes.put( 13, "PresentRequestOutOfRange" ) ; - errorCodes.put( 14, "SystemErrorInPresentingRecords" ) ; - errorCodes.put( 15, "RecordNotAuthorizedToBeSentIntersystem" ) ; - errorCodes.put( 16, "RecordExceedsPreferredMessageSize" ) ; - errorCodes.put( 17, "RecordExceedsExceptionalRecordSize" ) ; - errorCodes.put( 18, "ResultSetNotSupportedAsASearchTerm" ) ; - errorCodes.put( 19, "OnlySingleResultSetAsSearchTermSupported" ) ; - errorCodes.put( 20, "OnlyAndingOfASingleResultSetAsSearchTerm" ) ; - errorCodes.put( 21, "ResultSetExistsAndReplaceIndicatorOff" ) ; - errorCodes.put( 22, "ResultSetNamingNotSupported" ) ; - errorCodes.put( 23, "SpecifiedCombinationOfDatabasesNotSupported" ) ; - errorCodes.put( 24, "ElementSetNamesNotSupported" ) ; - errorCodes.put( 25, "SpecifiedElementSetNameNotValidForSpecifiedDatabase" ) ; - errorCodes.put( 26, "OnlyGenericFormOfElementSetNameSupported" ) ; - errorCodes.put( 27, "ResultSetNoLongerExistsUnilaterallyDeletedByTarget" ) ; - errorCodes.put( 28, "ResultSetIsInUse" ) ; - errorCodes.put( 29, "OneOfTheSpecifiedDatabasesIsLocked" ) ; - errorCodes.put( 30, "SpecifiedResultSetDoesNotExist" ) ; - errorCodes.put( 31, "ResourcesExhaustedNoResultsAvailable" ) ; - errorCodes.put( 32, "ResourcesExhaustedUnpredictablePartialResultsAvailable" ) ; - errorCodes.put( 33, "ResourcesExhaustedValidSubsetOfResultsAvailable" ) ; - errorCodes.put( 100, "UnspecifiedError" ) ; - errorCodes.put( 101, "AccessControlFailure" ) ; - errorCodes.put( 102, "ChallengeRequiredCouldNotBeIssuedOperationTerminated" ) ; - errorCodes.put( 103, "ChallengeRequiredCouldNotBeIssuedRecordNotIncluded" ) ; - errorCodes.put( 104, "ChallengeFailedRecordNotIncluded" ) ; - errorCodes.put( 105, "TerminatedAtOriginRequest" ) ; - errorCodes.put( 106, "NoAbstractSyntaxesAgreedToForThisRecord" ) ; - errorCodes.put( 107, "QueryTypeNotSupported" ) ; - errorCodes.put( 108, "MalformedQuery" ) ; - errorCodes.put( 109, "DatabaseUnavailable" ) ; - errorCodes.put( 110, "OperatorUnsupported" ) ; - errorCodes.put( 111, "TooManyDatabasesSpecified" ) ; - errorCodes.put( 112, "TooManyResultSetsCreated" ) ; - errorCodes.put( 113, "UnsupportedAttributeType" ) ; - errorCodes.put( 114, "UnsupportedUseAttribute" ) ; - errorCodes.put( 115, "UnsupportedTermValueForUseAttribute" ) ; - errorCodes.put( 116, "UseAttributeRequiredButNotSupplied" ) ; - errorCodes.put( 117, "UnsupportedRelationAttribute" ) ; - errorCodes.put( 118, "UnsupportedStructureAttribute" ) ; - errorCodes.put( 119, "UnsupportedPositionAttribute" ) ; - errorCodes.put( 120, "UnsupportedTruncationAttribute" ) ; - errorCodes.put( 121, "UnsupportedAttributeSet" ) ; - errorCodes.put( 122, "UnsupportedCompletenessAttribute" ) ; - errorCodes.put( 123, "UnsupportedAttributeCombination" ) ; - errorCodes.put( 124, "UnsupportedCodedValueForTerm" ) ; - errorCodes.put( 125, "MalformedSearchTerm" ) ; - errorCodes.put( 126, "IllegalTermValueForAttribute" ) ; - errorCodes.put( 127, "UnparsableFormatForUnNormalizedValue" ) ; - errorCodes.put( 128, "IllegalResultSetName" ) ; - errorCodes.put( 129, "ProximitySearchOfSetsNotSupported" ) ; - errorCodes.put( 130, "IllegalResultSetInProximitySearch" ) ; - errorCodes.put( 131, "UnsupportedProximityRelation" ) ; - errorCodes.put( 132, "UnsupportedProximityUnitCode" ) ; - errorCodes.put( 201, "ProximityNotSupportedWithThisAttributeCombinationAttribute" ) ; - errorCodes.put( 202, "UnsupportedDistanceForProximity" ) ; - errorCodes.put( 203, "OrderedFlagNotSupportedForProximity" ) ; - errorCodes.put( 205, "OnlyZeroStepSizeSupportedForScan" ) ; - errorCodes.put( 206, "SpecifiedStepSizeNotSupportedForScanStep" ) ; - errorCodes.put( 207, "CannotSortAccordingToSequence" ) ; - errorCodes.put( 208, "NoResultSetNameSuppliedOnSort" ) ; - errorCodes.put( 209, "GenericSortNotSupported" ) ; - errorCodes.put( 210, "DatabaseSpecificSortNotSupported" ) ; - errorCodes.put( 211, "TooManySortKeys" ) ; - errorCodes.put( 212, "DuplicateSortKeys" ) ; - errorCodes.put( 213, "UnsupportedMissingDataAction" ) ; - errorCodes.put( 214, "IllegalSortRelation" ) ; - errorCodes.put( 215, "IllegalCaseValue" ) ; - errorCodes.put( 216, "IllegalMissingDataAction" ) ; - errorCodes.put( 217, "SegmentationCannotGuaranteeRecordsWillFitInSpecifiedSegments" ) ; - errorCodes.put( 218, "EsPackageNameAlreadyInUse" ) ; - errorCodes.put( 219, "EsNoSuchPackageOnModifyDelete" ) ; - errorCodes.put( 220, "EsQuotaExceeded" ) ; - errorCodes.put( 221, "EsExtendedServiceTypeNotSupported" ) ; - errorCodes.put( 222, "EsPermissionDeniedOnEsIdNotAuthorized" ) ; - errorCodes.put( 223, "EsPermissionDeniedOnEsCannotModifyOrDelete" ) ; - errorCodes.put( 224, "EsImmediateExecutionFailed" ) ; - errorCodes.put( 225, "EsImmediateExecutionNotSupportedForThisService" ) ; - errorCodes.put( 226, "EsImmediateExecutionNotSupportedForTheseParameters" ) ; - errorCodes.put( 227, "NoDataAvailableInRequestedRecordSyntax" ) ; - errorCodes.put( 228, "ScanMalformedScan" ) ; - errorCodes.put( 229, "TermTypeNotSupported" ) ; - errorCodes.put( 230, "SortTooManyInputResults" ) ; - errorCodes.put( 231, "SortIncompatibleRecordFormats" ) ; - errorCodes.put( 232, "ScanTermListNotSupported" ) ; - errorCodes.put( 233, "ScanUnsupportedValueOfPositionInResponse" ) ; - errorCodes.put( 234, "TooManyIndexTermsProcessed" ) ; - errorCodes.put( 235, "DatabaseDoesNotExist" ) ; - errorCodes.put( 236, "AccessToSpecifiedDatabaseDenied" ) ; - errorCodes.put( 237, "SortIllegalSort" ) ; - errorCodes.put( 238, "RecordNotAvailableInRequestedSyntax" ) ; - errorCodes.put( 239, "RecordSyntaxNotSupported" ) ; - errorCodes.put( 240, "ScanResourcesExhaustedLookingForSatisfyingTerms" ) ; - errorCodes.put( 241, "ScanBeginningOrEndOfTermList" ) ; - errorCodes.put( 242, "SegmentationMaxSegmentSizeTooSmallToSegmentRecord" ) ; - errorCodes.put( 243, "PresentAdditionalRangesParameterNotSupported" ) ; - errorCodes.put( 244, "PresentCompSpecParameterNotSupported" ) ; - errorCodes.put( 245, "Type1QueryRestrictionOperandNotSupported" ) ; - errorCodes.put( 246, "Type1QueryComplexAttributevalueNotSupported" ) ; - errorCodes.put( 247, "Type1QueryAttributesetAsPartOfAttributeelementNotSupported" ) ; - } + private static Hashtable errorCodes = new Hashtable(); - public static String GetError( int errorCode ) - { - String errorText = "Unknown Error" ; - - if( errorCodes.containsKey(errorCode) ) - errorText = errorCodes.get( errorCode ); + static { + errorCodes.put(1, "PermanentSystemError"); + errorCodes.put(2, "TemporarySystemError"); + errorCodes.put(3, "UnsupportedSearch"); + errorCodes.put(4, "TermsOnlyIncludesExclusionOrStopWords"); + errorCodes.put(5, "TooManyArgumentWords"); + errorCodes.put(6, "TooManyBooleanOperators"); + errorCodes.put(7, "TooManyTruncatedWords"); + errorCodes.put(8, "TooManyIncompleteSubfields"); + errorCodes.put(9, "TruncatedWordsTooShort"); + errorCodes.put(10, "InvalidFormatForRecordNumberInSearchTerm"); + errorCodes.put(11, "TooManyCharactersInSearchStatement"); + errorCodes.put(12, "TooManyRecordsRetrieved"); + errorCodes.put(13, "PresentRequestOutOfRange"); + errorCodes.put(14, "SystemErrorInPresentingRecords"); + errorCodes.put(15, "RecordNotAuthorizedToBeSentIntersystem"); + errorCodes.put(16, "RecordExceedsPreferredMessageSize"); + errorCodes.put(17, "RecordExceedsExceptionalRecordSize"); + errorCodes.put(18, "ResultSetNotSupportedAsASearchTerm"); + errorCodes.put(19, "OnlySingleResultSetAsSearchTermSupported"); + errorCodes.put(20, "OnlyAndingOfASingleResultSetAsSearchTerm"); + errorCodes.put(21, "ResultSetExistsAndReplaceIndicatorOff"); + errorCodes.put(22, "ResultSetNamingNotSupported"); + errorCodes.put(23, "SpecifiedCombinationOfDatabasesNotSupported"); + errorCodes.put(24, "ElementSetNamesNotSupported"); + errorCodes.put(25, "SpecifiedElementSetNameNotValidForSpecifiedDatabase"); + errorCodes.put(26, "OnlyGenericFormOfElementSetNameSupported"); + errorCodes.put(27, "ResultSetNoLongerExistsUnilaterallyDeletedByTarget"); + errorCodes.put(28, "ResultSetIsInUse"); + errorCodes.put(29, "OneOfTheSpecifiedDatabasesIsLocked"); + errorCodes.put(30, "SpecifiedResultSetDoesNotExist"); + errorCodes.put(31, "ResourcesExhaustedNoResultsAvailable"); + errorCodes.put(32, "ResourcesExhaustedUnpredictablePartialResultsAvailable"); + errorCodes.put(33, "ResourcesExhaustedValidSubsetOfResultsAvailable"); + errorCodes.put(100, "UnspecifiedError"); + errorCodes.put(101, "AccessControlFailure"); + errorCodes.put(102, "ChallengeRequiredCouldNotBeIssuedOperationTerminated"); + errorCodes.put(103, "ChallengeRequiredCouldNotBeIssuedRecordNotIncluded"); + errorCodes.put(104, "ChallengeFailedRecordNotIncluded"); + errorCodes.put(105, "TerminatedAtOriginRequest"); + errorCodes.put(106, "NoAbstractSyntaxesAgreedToForThisRecord"); + errorCodes.put(107, "QueryTypeNotSupported"); + errorCodes.put(108, "MalformedQuery"); + errorCodes.put(109, "DatabaseUnavailable"); + errorCodes.put(110, "OperatorUnsupported"); + errorCodes.put(111, "TooManyDatabasesSpecified"); + errorCodes.put(112, "TooManyResultSetsCreated"); + errorCodes.put(113, "UnsupportedAttributeType"); + errorCodes.put(114, "UnsupportedUseAttribute"); + errorCodes.put(115, "UnsupportedTermValueForUseAttribute"); + errorCodes.put(116, "UseAttributeRequiredButNotSupplied"); + errorCodes.put(117, "UnsupportedRelationAttribute"); + errorCodes.put(118, "UnsupportedStructureAttribute"); + errorCodes.put(119, "UnsupportedPositionAttribute"); + errorCodes.put(120, "UnsupportedTruncationAttribute"); + errorCodes.put(121, "UnsupportedAttributeSet"); + errorCodes.put(122, "UnsupportedCompletenessAttribute"); + errorCodes.put(123, "UnsupportedAttributeCombination"); + errorCodes.put(124, "UnsupportedCodedValueForTerm"); + errorCodes.put(125, "MalformedSearchTerm"); + errorCodes.put(126, "IllegalTermValueForAttribute"); + errorCodes.put(127, "UnparsableFormatForUnNormalizedValue"); + errorCodes.put(128, "IllegalResultSetName"); + errorCodes.put(129, "ProximitySearchOfSetsNotSupported"); + errorCodes.put(130, "IllegalResultSetInProximitySearch"); + errorCodes.put(131, "UnsupportedProximityRelation"); + errorCodes.put(132, "UnsupportedProximityUnitCode"); + errorCodes.put(201, "ProximityNotSupportedWithThisAttributeCombinationAttribute"); + errorCodes.put(202, "UnsupportedDistanceForProximity"); + errorCodes.put(203, "OrderedFlagNotSupportedForProximity"); + errorCodes.put(205, "OnlyZeroStepSizeSupportedForScan"); + errorCodes.put(206, "SpecifiedStepSizeNotSupportedForScanStep"); + errorCodes.put(207, "CannotSortAccordingToSequence"); + errorCodes.put(208, "NoResultSetNameSuppliedOnSort"); + errorCodes.put(209, "GenericSortNotSupported"); + errorCodes.put(210, "DatabaseSpecificSortNotSupported"); + errorCodes.put(211, "TooManySortKeys"); + errorCodes.put(212, "DuplicateSortKeys"); + errorCodes.put(213, "UnsupportedMissingDataAction"); + errorCodes.put(214, "IllegalSortRelation"); + errorCodes.put(215, "IllegalCaseValue"); + errorCodes.put(216, "IllegalMissingDataAction"); + errorCodes.put(217, "SegmentationCannotGuaranteeRecordsWillFitInSpecifiedSegments"); + errorCodes.put(218, "EsPackageNameAlreadyInUse"); + errorCodes.put(219, "EsNoSuchPackageOnModifyDelete"); + errorCodes.put(220, "EsQuotaExceeded"); + errorCodes.put(221, "EsExtendedServiceTypeNotSupported"); + errorCodes.put(222, "EsPermissionDeniedOnEsIdNotAuthorized"); + errorCodes.put(223, "EsPermissionDeniedOnEsCannotModifyOrDelete"); + errorCodes.put(224, "EsImmediateExecutionFailed"); + errorCodes.put(225, "EsImmediateExecutionNotSupportedForThisService"); + errorCodes.put(226, "EsImmediateExecutionNotSupportedForTheseParameters"); + errorCodes.put(227, "NoDataAvailableInRequestedRecordSyntax"); + errorCodes.put(228, "ScanMalformedScan"); + errorCodes.put(229, "TermTypeNotSupported"); + errorCodes.put(230, "SortTooManyInputResults"); + errorCodes.put(231, "SortIncompatibleRecordFormats"); + errorCodes.put(232, "ScanTermListNotSupported"); + errorCodes.put(233, "ScanUnsupportedValueOfPositionInResponse"); + errorCodes.put(234, "TooManyIndexTermsProcessed"); + errorCodes.put(235, "DatabaseDoesNotExist"); + errorCodes.put(236, "AccessToSpecifiedDatabaseDenied"); + errorCodes.put(237, "SortIllegalSort"); + errorCodes.put(238, "RecordNotAvailableInRequestedSyntax"); + errorCodes.put(239, "RecordSyntaxNotSupported"); + errorCodes.put(240, "ScanResourcesExhaustedLookingForSatisfyingTerms"); + errorCodes.put(241, "ScanBeginningOrEndOfTermList"); + errorCodes.put(242, "SegmentationMaxSegmentSizeTooSmallToSegmentRecord"); + errorCodes.put(243, "PresentAdditionalRangesParameterNotSupported"); + errorCodes.put(244, "PresentCompSpecParameterNotSupported"); + errorCodes.put(245, "Type1QueryRestrictionOperandNotSupported"); + errorCodes.put(246, "Type1QueryComplexAttributevalueNotSupported"); + errorCodes.put(247, "Type1QueryAttributesetAsPartOfAttributeelementNotSupported"); + } - return errorText; - } + public static String GetError(int errorCode) { + String errorText = "Unknown Error"; + + if (errorCodes.containsKey(errorCode)) { + errorText = errorCodes.get(errorCode); + } + + return errorText; + } } diff --git a/src/main/java/org/yaz4j/Bib1Exception.java b/src/main/java/org/yaz4j/Bib1Exception.java index 742b9ab..86d2877 100644 --- a/src/main/java/org/yaz4j/Bib1Exception.java +++ b/src/main/java/org/yaz4j/Bib1Exception.java @@ -1,16 +1,14 @@ package org.yaz4j; -public class Bib1Exception extends RuntimeException -{ - private static final long serialVersionUID = 1L; +public class Bib1Exception extends RuntimeException { - public Bib1Exception() - { - super(); - } - - public Bib1Exception(String message ) - { - super( message ); - } + private static final long serialVersionUID = 1L; + + public Bib1Exception() { + super(); + } + + public Bib1Exception(String message) { + super(message); + } } diff --git a/src/main/java/org/yaz4j/CQLQuery.java b/src/main/java/org/yaz4j/CQLQuery.java index 1411e28..b854a47 100644 --- a/src/main/java/org/yaz4j/CQLQuery.java +++ b/src/main/java/org/yaz4j/CQLQuery.java @@ -1,21 +1,18 @@ package org.yaz4j; -public class CQLQuery -{ - private String query = null; - - public CQLQuery(String query) - { - this.query = query; - } +public class CQLQuery { - public String getQueryString() - { - return query ; - } - - public void setQueryString( String query) - { - this.query = query ; - } + private String query = null; + + public CQLQuery(String query) { + this.query = query; + } + + public String getQueryString() { + return query; + } + + public void setQueryString(String query) { + this.query = query; + } } diff --git a/src/main/java/org/yaz4j/Connection.java b/src/main/java/org/yaz4j/Connection.java index 42dcb1c..680dabc 100644 --- a/src/main/java/org/yaz4j/Connection.java +++ b/src/main/java/org/yaz4j/Connection.java @@ -8,226 +8,183 @@ import org.yaz4j.jni.SWIGTYPE_p_p_char; import org.yaz4j.jni.yaz4jlib; import org.yaz4j.jni.yaz4jlibConstants; -public class Connection -{ - private String host ; - private int port ; - private ConnectionOptionsCollection options = null ; - protected SWIGTYPE_p_ZOOM_connection_p zoomConnection = null ; - private boolean connected = false; - private boolean disposed = false; - - static - { - // on Linux 'yaz4j' maps to 'libyaz4j.so' (i.e. 'lib' prefix & '.so' extension) - // on Windows 'yaz4j' maps to 'yaz4j.dll' (i.e. '.dll' extension) - String libName = "yaz4j" ; - try - { - // System.err.println( "Loading library '"+ System.mapLibraryName( libName ) + "'" ); - System.loadLibrary( libName ); - } - catch( Throwable e ) - { - System.err.println( "Fatal Error: Failed to load library '" + System.mapLibraryName( libName ) + "'"); - e.printStackTrace(); - } - } - - public Connection(String host, int port) - { - this.host = host ; - this.port = port ; - - options = new ConnectionOptionsCollection(); - zoomConnection = yaz4jlib.ZOOM_connection_create(options.zoomOptions); - - SWIGTYPE_p_p_char cp = null; - SWIGTYPE_p_p_char addinfo = null ; - int errorCode = yaz4jlib.ZOOM_connection_error(zoomConnection, cp, addinfo); - CheckErrorCodeAndThrow(errorCode); - } - - public void finalize() - { - Dispose(); - } - - private void CheckErrorCodeAndThrow(int errorCode) - { - String message; - - if( errorCode == yaz4jlibConstants.ZOOM_ERROR_NONE ) - { - return ; - } - else if( errorCode == yaz4jlib.ZOOM_ERROR_CONNECT ) - { - message = String.format("Connection could not be made to %s:%d", host, port); - throw new ConnectionUnavailableException(message); - } - else if( errorCode == yaz4jlib.ZOOM_ERROR_INVALID_QUERY ) - { - message = String.format("The query requested is not valid or not supported"); - throw new InvalidQueryException(message); - } - else if( errorCode == yaz4jlib.ZOOM_ERROR_INIT ) - { - message = String.format("Server %s:%d rejected our init request", host, port); - throw new InitRejectedException(message); - } - else if( errorCode == yaz4jlib.ZOOM_ERROR_TIMEOUT ) - { - message = String.format("Server %s:%d timed out handling our request", host, port); - throw new ConnectionTimeoutException(message); - } - else if( ( errorCode == yaz4jlib.ZOOM_ERROR_MEMORY ) - || ( errorCode == yaz4jlib.ZOOM_ERROR_ENCODE ) - || ( errorCode == yaz4jlib.ZOOM_ERROR_DECODE ) - || ( errorCode == yaz4jlib.ZOOM_ERROR_CONNECTION_LOST ) - || ( errorCode == yaz4jlib.ZOOM_ERROR_INTERNAL ) - || ( errorCode == yaz4jlib.ZOOM_ERROR_UNSUPPORTED_PROTOCOL ) - || ( errorCode == yaz4jlib.ZOOM_ERROR_UNSUPPORTED_QUERY ) ) - { - message = yaz4jlib.ZOOM_connection_errmsg(zoomConnection); - throw new ZoomImplementationException("A fatal error occurred in Yaz: " + errorCode + " - " + message); +public class Connection { + + private String host; + private int port; + private ConnectionOptionsCollection options = null; + protected SWIGTYPE_p_ZOOM_connection_p zoomConnection = null; + private boolean connected = false; + private boolean disposed = false; + + static { + // on Linux 'yaz4j' maps to 'libyaz4j.so' (i.e. 'lib' prefix & '.so' extension) + // on Windows 'yaz4j' maps to 'yaz4j.dll' (i.e. '.dll' extension) + String libName = "yaz4j"; + try { + // System.err.println( "Loading library '"+ System.mapLibraryName( libName ) + "'" ); + System.loadLibrary(libName); + } catch (Throwable e) { + System.err.println("Fatal Error: Failed to load library '" + System.mapLibraryName(libName) + "'"); + e.printStackTrace(); } - else - { - String errMsgBib1 = "Bib1Exception: Error Code = " + errorCode + " (" + Bib1Diagnostic.GetError(errorCode) + ")" ; - throw new Bib1Exception( errMsgBib1 ); + } + + public Connection(String host, int port) { + this.host = host; + this.port = port; + + options = new ConnectionOptionsCollection(); + zoomConnection = yaz4jlib.ZOOM_connection_create(options.zoomOptions); + + SWIGTYPE_p_p_char cp = null; + SWIGTYPE_p_p_char addinfo = null; + int errorCode = yaz4jlib.ZOOM_connection_error(zoomConnection, cp, addinfo); + CheckErrorCodeAndThrow(errorCode); + } + + public void finalize() { + Dispose(); + } + + private void CheckErrorCodeAndThrow(int errorCode) { + String message; + + if (errorCode == yaz4jlibConstants.ZOOM_ERROR_NONE) { + return; + } else if (errorCode == yaz4jlib.ZOOM_ERROR_CONNECT) { + message = String.format("Connection could not be made to %s:%d", host, port); + throw new ConnectionUnavailableException(message); + } else if (errorCode == yaz4jlib.ZOOM_ERROR_INVALID_QUERY) { + message = String.format("The query requested is not valid or not supported"); + throw new InvalidQueryException(message); + } else if (errorCode == yaz4jlib.ZOOM_ERROR_INIT) { + message = String.format("Server %s:%d rejected our init request", host, port); + throw new InitRejectedException(message); + } else if (errorCode == yaz4jlib.ZOOM_ERROR_TIMEOUT) { + message = String.format("Server %s:%d timed out handling our request", host, port); + throw new ConnectionTimeoutException(message); + } else if ((errorCode == yaz4jlib.ZOOM_ERROR_MEMORY) || (errorCode == yaz4jlib.ZOOM_ERROR_ENCODE) || (errorCode == yaz4jlib.ZOOM_ERROR_DECODE) || (errorCode == yaz4jlib.ZOOM_ERROR_CONNECTION_LOST) || (errorCode == yaz4jlib.ZOOM_ERROR_INTERNAL) || (errorCode == yaz4jlib.ZOOM_ERROR_UNSUPPORTED_PROTOCOL) || (errorCode == yaz4jlib.ZOOM_ERROR_UNSUPPORTED_QUERY)) { + message = yaz4jlib.ZOOM_connection_errmsg(zoomConnection); + throw new ZoomImplementationException("A fatal error occurred in Yaz: " + errorCode + " - " + message); + } else { + String errMsgBib1 = "Bib1Exception: Error Code = " + errorCode + " (" + Bib1Diagnostic.GetError(errorCode) + ")"; + throw new Bib1Exception(errMsgBib1); } - } - - private enum QueryType { CQLQuery, PrefixQuery }; - - public ResultSet Search(PrefixQuery query) - { - return Search( query.getQueryString(), QueryType.PrefixQuery); - } - - public ResultSet Search(CQLQuery query) - { - return Search( query.getQueryString(), QueryType.CQLQuery); - } - - private ResultSet Search(String query, QueryType queryType) - { - EnsureConnected(); - - SWIGTYPE_p_ZOOM_query_p yazQuery = yaz4jlib.ZOOM_query_create(); + } + + private enum QueryType { + + CQLQuery, PrefixQuery + }; + + public ResultSet Search(PrefixQuery query) { + return Search(query.getQueryString(), QueryType.PrefixQuery); + } + + public ResultSet Search(CQLQuery query) { + return Search(query.getQueryString(), QueryType.CQLQuery); + } + + private ResultSet Search(String query, QueryType queryType) { + EnsureConnected(); + + SWIGTYPE_p_ZOOM_query_p yazQuery = yaz4jlib.ZOOM_query_create(); ResultSet resultSet = null; - try - { - if( queryType == QueryType.CQLQuery ) - yaz4jlib.ZOOM_query_cql(yazQuery, query); - else if( queryType == QueryType.PrefixQuery ) - yaz4jlib.ZOOM_query_prefix(yazQuery, query); - else - throw new InvalidQueryException("queryType"); - - SWIGTYPE_p_ZOOM_resultset_p yazResultSet = yaz4jlib.ZOOM_connection_search(zoomConnection, yazQuery); - - int errorCode = yaz4jlib.ZOOM_connection_errcode( zoomConnection ); - if (errorCode != yaz4jlib.ZOOM_ERROR_NONE) - { - yaz4jlib.ZOOM_resultset_destroy(yazResultSet); + try { + if (queryType == QueryType.CQLQuery) { + yaz4jlib.ZOOM_query_cql(yazQuery, query); + } else if (queryType == QueryType.PrefixQuery) { + yaz4jlib.ZOOM_query_prefix(yazQuery, query); + } else { + throw new InvalidQueryException("queryType"); + } + + SWIGTYPE_p_ZOOM_resultset_p yazResultSet = yaz4jlib.ZOOM_connection_search(zoomConnection, yazQuery); + + int errorCode = yaz4jlib.ZOOM_connection_errcode(zoomConnection); + if (errorCode != yaz4jlib.ZOOM_ERROR_NONE) { + yaz4jlib.ZOOM_resultset_destroy(yazResultSet); } CheckErrorCodeAndThrow(errorCode); resultSet = new ResultSet(yazResultSet, zoomConnection); - } - finally - { - yaz4jlib.ZOOM_query_destroy(yazQuery); // deallocate yazQuery also when exceptions + } finally { + yaz4jlib.ZOOM_query_destroy(yazQuery); // deallocate yazQuery also when exceptions yazQuery = null; } return resultSet; - } - - public ScanSet Scan(String query) - { - EnsureConnected(); - SWIGTYPE_p_ZOOM_scanset_p yazScanSet = yaz4jlib.ZOOM_connection_scan(zoomConnection, query); - - int errorCode = yaz4jlib.ZOOM_connection_errcode(zoomConnection); - if( errorCode != yaz4jlib.ZOOM_ERROR_NONE ) - { - yaz4jlib.ZOOM_scanset_destroy(yazScanSet); - } - CheckErrorCodeAndThrow(errorCode); - - ScanSet scanSet = new ScanSet(yazScanSet, this); - return scanSet; - } - - public ConnectionOptionsCollection getOptions() - { - return options; - } - - protected void EnsureConnected() - { - if (! connected ) - Connect(); - } - - public void Connect() - { - yaz4jlib.ZOOM_connection_connect( zoomConnection, host, port); - int errorCode = yaz4jlib.ZOOM_connection_errcode(zoomConnection); - CheckErrorCodeAndThrow(errorCode); - connected = true; - } - - public void Dispose() - { - if (! disposed ) - { - yaz4jlib.ZOOM_connection_destroy(zoomConnection); - zoomConnection = null; - disposed = true; - } - } - - public String getSyntax() - { - return options.get("preferredRecordSyntax"); - } - - public void setSyntax( String value) - { - options.set("preferredRecordSyntax", value ) ; - } - - public String getDatabaseName() - { - return options.get("databaseName"); - } - - public void setDatabaseName( String value ) - { - options.set("databaseName", value); - } - - public String getUsername() - { - return options.get("user"); - } - - public void setUsername( String value ) - { - options.set("user", value); - } - - public String getPassword() - { - return options.get("password"); - } - - public void setPassword( String value ) - { - options.set("password", value); - } + } + + public ScanSet Scan(String query) { + EnsureConnected(); + SWIGTYPE_p_ZOOM_scanset_p yazScanSet = yaz4jlib.ZOOM_connection_scan(zoomConnection, query); + + int errorCode = yaz4jlib.ZOOM_connection_errcode(zoomConnection); + if (errorCode != yaz4jlib.ZOOM_ERROR_NONE) { + yaz4jlib.ZOOM_scanset_destroy(yazScanSet); + } + CheckErrorCodeAndThrow(errorCode); + + ScanSet scanSet = new ScanSet(yazScanSet, this); + return scanSet; + } + + public ConnectionOptionsCollection getOptions() { + return options; + } + + protected void EnsureConnected() { + if (!connected) { + Connect(); + } + } + + public void Connect() { + yaz4jlib.ZOOM_connection_connect(zoomConnection, host, port); + int errorCode = yaz4jlib.ZOOM_connection_errcode(zoomConnection); + CheckErrorCodeAndThrow(errorCode); + connected = true; + } + + public void Dispose() { + if (!disposed) { + yaz4jlib.ZOOM_connection_destroy(zoomConnection); + zoomConnection = null; + disposed = true; + } + } + + public String getSyntax() { + return options.get("preferredRecordSyntax"); + } + + public void setSyntax(String value) { + options.set("preferredRecordSyntax", value); + } + + public String getDatabaseName() { + return options.get("databaseName"); + } + + public void setDatabaseName(String value) { + options.set("databaseName", value); + } + + public String getUsername() { + return options.get("user"); + } + + public void setUsername(String value) { + options.set("user", value); + } + + public String getPassword() { + return options.get("password"); + } + + public void setPassword(String value) { + options.set("password", value); + } } diff --git a/src/main/java/org/yaz4j/ConnectionExtended.java b/src/main/java/org/yaz4j/ConnectionExtended.java index 8d9744b..629e51e 100644 --- a/src/main/java/org/yaz4j/ConnectionExtended.java +++ b/src/main/java/org/yaz4j/ConnectionExtended.java @@ -4,21 +4,19 @@ import org.yaz4j.jni.SWIGTYPE_p_ZOOM_options_p; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_package_p; import org.yaz4j.jni.yaz4jlib; -public class ConnectionExtended extends Connection -{ - public ConnectionExtended(String host, int port) - { - super(host, port); - } +public class ConnectionExtended extends Connection { - public Package Package(String type) - { + public ConnectionExtended(String host, int port) { + super(host, port); + } + + public Package Package(String type) { EnsureConnected(); Package pack = null; - + SWIGTYPE_p_ZOOM_options_p options = yaz4jlib.ZOOM_options_create(); - SWIGTYPE_p_ZOOM_package_p yazPackage = yaz4jlib.ZOOM_connection_package( zoomConnection, options); + SWIGTYPE_p_ZOOM_package_p yazPackage = yaz4jlib.ZOOM_connection_package(zoomConnection, options); pack = new Package(yazPackage, this, type); return pack; } diff --git a/src/main/java/org/yaz4j/ConnectionOptionsCollection.java b/src/main/java/org/yaz4j/ConnectionOptionsCollection.java index fb60263..3823336 100644 --- a/src/main/java/org/yaz4j/ConnectionOptionsCollection.java +++ b/src/main/java/org/yaz4j/ConnectionOptionsCollection.java @@ -4,39 +4,32 @@ import org.yaz4j.jni.SWIGTYPE_p_ZOOM_connection_p; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_options_p; import org.yaz4j.jni.yaz4jlib; -public class ConnectionOptionsCollection -{ - SWIGTYPE_p_ZOOM_options_p zoomOptions = null ; - - ConnectionOptionsCollection() - { - zoomOptions = yaz4jlib.ZOOM_options_create(); - } - - public void finalize() - { - Dispose(); - } - - public void Dispose() - { - yaz4jlib.ZOOM_options_destroy( zoomOptions ); - zoomOptions = null ; - } - - SWIGTYPE_p_ZOOM_connection_p CreateConnection() - { - return yaz4jlib.ZOOM_connection_create(zoomOptions); - } - - public String get(String key) - { - return yaz4jlib.ZOOM_options_get(zoomOptions, key) ; - } - - public void set(String key, String value) - { - yaz4jlib.ZOOM_options_set(zoomOptions, key, value) ; - } - +public class ConnectionOptionsCollection { + + SWIGTYPE_p_ZOOM_options_p zoomOptions = null; + + ConnectionOptionsCollection() { + zoomOptions = yaz4jlib.ZOOM_options_create(); + } + + public void finalize() { + Dispose(); + } + + public void Dispose() { + yaz4jlib.ZOOM_options_destroy(zoomOptions); + zoomOptions = null; + } + + SWIGTYPE_p_ZOOM_connection_p CreateConnection() { + return yaz4jlib.ZOOM_connection_create(zoomOptions); + } + + public String get(String key) { + return yaz4jlib.ZOOM_options_get(zoomOptions, key); + } + + public void set(String key, String value) { + yaz4jlib.ZOOM_options_set(zoomOptions, key, value); + } } diff --git a/src/main/java/org/yaz4j/ConnectionTimeoutException.java b/src/main/java/org/yaz4j/ConnectionTimeoutException.java index 7f6c574..7cf88ec 100644 --- a/src/main/java/org/yaz4j/ConnectionTimeoutException.java +++ b/src/main/java/org/yaz4j/ConnectionTimeoutException.java @@ -1,16 +1,14 @@ package org.yaz4j; -public class ConnectionTimeoutException extends RuntimeException -{ - private static final long serialVersionUID = 1L; +public class ConnectionTimeoutException extends RuntimeException { - public ConnectionTimeoutException() - { - super(); - } - - public ConnectionTimeoutException(String message ) - { - super( message ); - } + private static final long serialVersionUID = 1L; + + public ConnectionTimeoutException() { + super(); + } + + public ConnectionTimeoutException(String message) { + super(message); + } } diff --git a/src/main/java/org/yaz4j/ConnectionUnavailableException.java b/src/main/java/org/yaz4j/ConnectionUnavailableException.java index 25c7226..283ec30 100644 --- a/src/main/java/org/yaz4j/ConnectionUnavailableException.java +++ b/src/main/java/org/yaz4j/ConnectionUnavailableException.java @@ -1,16 +1,14 @@ package org.yaz4j; -public class ConnectionUnavailableException extends RuntimeException -{ - private static final long serialVersionUID = 1L; +public class ConnectionUnavailableException extends RuntimeException { - public ConnectionUnavailableException() - { - super(); - } - - public ConnectionUnavailableException(String message ) - { - super( message ); - } + private static final long serialVersionUID = 1L; + + public ConnectionUnavailableException() { + super(); + } + + public ConnectionUnavailableException(String message) { + super(message); + } } diff --git a/src/main/java/org/yaz4j/InitRejectedException.java b/src/main/java/org/yaz4j/InitRejectedException.java index 83c3c8d..3cd9893 100644 --- a/src/main/java/org/yaz4j/InitRejectedException.java +++ b/src/main/java/org/yaz4j/InitRejectedException.java @@ -1,16 +1,14 @@ package org.yaz4j; -public class InitRejectedException extends RuntimeException -{ - private static final long serialVersionUID = 1L; +public class InitRejectedException extends RuntimeException { - public InitRejectedException() - { - super(); - } - - public InitRejectedException(String message ) - { - super( message ); - } + private static final long serialVersionUID = 1L; + + public InitRejectedException() { + super(); + } + + public InitRejectedException(String message) { + super(message); + } } diff --git a/src/main/java/org/yaz4j/InvalidQueryException.java b/src/main/java/org/yaz4j/InvalidQueryException.java index 4f265c2..23edfae 100644 --- a/src/main/java/org/yaz4j/InvalidQueryException.java +++ b/src/main/java/org/yaz4j/InvalidQueryException.java @@ -1,16 +1,14 @@ package org.yaz4j; -public class InvalidQueryException extends RuntimeException -{ - private static final long serialVersionUID = 1L; +public class InvalidQueryException extends RuntimeException { - public InvalidQueryException() - { - super(); - } - - public InvalidQueryException(String message ) - { - super( message ); - } + private static final long serialVersionUID = 1L; + + public InvalidQueryException() { + super(); + } + + public InvalidQueryException(String message) { + super(message); + } } diff --git a/src/main/java/org/yaz4j/Package.java b/src/main/java/org/yaz4j/Package.java index 590b172..8de3ab7 100644 --- a/src/main/java/org/yaz4j/Package.java +++ b/src/main/java/org/yaz4j/Package.java @@ -3,41 +3,35 @@ package org.yaz4j; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_package_p; import org.yaz4j.jni.yaz4jlib; -public class Package -{ - private SWIGTYPE_p_ZOOM_package_p pack = null ; - private ConnectionExtended connection = null ; - private String type; - - Package(SWIGTYPE_p_ZOOM_package_p pack, ConnectionExtended connection, String type) - { - this.type = type; - this.connection = connection; - this.pack = pack; - } - - public void finalize() - { - Dispose(); - } - - public PackageOptionsCollection getPackageOptions() - { - return new PackageOptionsCollection(pack); - } - - public void Send() - { - yaz4jlib.ZOOM_package_send( pack, type ); - } - - public void Dispose() - { - if ( pack != null ) - { - yaz4jlib.ZOOM_package_destroy( pack ); - connection = null; - pack = null ; - } - } +public class Package { + + private SWIGTYPE_p_ZOOM_package_p pack = null; + private ConnectionExtended connection = null; + private String type; + + Package(SWIGTYPE_p_ZOOM_package_p pack, ConnectionExtended connection, String type) { + this.type = type; + this.connection = connection; + this.pack = pack; + } + + public void finalize() { + Dispose(); + } + + public PackageOptionsCollection getPackageOptions() { + return new PackageOptionsCollection(pack); + } + + public void Send() { + yaz4jlib.ZOOM_package_send(pack, type); + } + + public void Dispose() { + if (pack != null) { + yaz4jlib.ZOOM_package_destroy(pack); + connection = null; + pack = null; + } + } } diff --git a/src/main/java/org/yaz4j/PackageOptionsCollection.java b/src/main/java/org/yaz4j/PackageOptionsCollection.java index 7cff946..419c742 100644 --- a/src/main/java/org/yaz4j/PackageOptionsCollection.java +++ b/src/main/java/org/yaz4j/PackageOptionsCollection.java @@ -3,27 +3,23 @@ package org.yaz4j; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_package_p; import org.yaz4j.jni.yaz4jlib; -public class PackageOptionsCollection -{ - private SWIGTYPE_p_ZOOM_package_p pack = null; - - PackageOptionsCollection(SWIGTYPE_p_ZOOM_package_p pack) - { +public class PackageOptionsCollection { + + private SWIGTYPE_p_ZOOM_package_p pack = null; + + PackageOptionsCollection(SWIGTYPE_p_ZOOM_package_p pack) { this.pack = pack; } - - public void Dispose() - { + + public void Dispose() { pack = null; } - - public String get(String key) - { - return yaz4jlib.ZOOM_package_option_get( pack, key) ; + + public String get(String key) { + return yaz4jlib.ZOOM_package_option_get(pack, key); } - public void set(String key, String value) - { - yaz4jlib.ZOOM_package_option_set( pack, key, value) ; + public void set(String key, String value) { + yaz4jlib.ZOOM_package_option_set(pack, key, value); } } diff --git a/src/main/java/org/yaz4j/PrefixQuery.java b/src/main/java/org/yaz4j/PrefixQuery.java index f8d2e53..54f144b 100644 --- a/src/main/java/org/yaz4j/PrefixQuery.java +++ b/src/main/java/org/yaz4j/PrefixQuery.java @@ -1,21 +1,18 @@ package org.yaz4j; -public class PrefixQuery -{ - private String query = null; - - public PrefixQuery(String query) - { - this.query = query; - } +public class PrefixQuery { - public String getQueryString() - { - return query ; - } - - public void setQueryString( String query) - { - this.query = query ; - } + private String query = null; + + public PrefixQuery(String query) { + this.query = query; + } + + public String getQueryString() { + return query; + } + + public void setQueryString(String query) { + this.query = query; + } } diff --git a/src/main/java/org/yaz4j/Record.java b/src/main/java/org/yaz4j/Record.java index 830f4d7..8fcfdc4 100644 --- a/src/main/java/org/yaz4j/Record.java +++ b/src/main/java/org/yaz4j/Record.java @@ -6,56 +6,47 @@ import org.yaz4j.jni.SWIGTYPE_p_ZOOM_record_p; import org.yaz4j.jni.SWIGTYPE_p_int; import org.yaz4j.jni.yaz4jlib; -public class Record -{ - private SWIGTYPE_p_ZOOM_record_p record = null ; - private ResultSet resultSet = null ; - private boolean disposed = false; - - Record(SWIGTYPE_p_ZOOM_record_p record, ResultSet resultSet) - { - this.resultSet = resultSet; - this.record = record; - } - - public void finalize() - { - Dispose(); - } - - public byte[] get(String type) - { - SWIGTYPE_p_int length = null ; - return yaz4jlib.ZOOM_record_get_bytes(record, type, length) ; +public class Record { + + private SWIGTYPE_p_ZOOM_record_p record = null; + private ResultSet resultSet = null; + private boolean disposed = false; + + Record(SWIGTYPE_p_ZOOM_record_p record, ResultSet resultSet) { + this.resultSet = resultSet; + this.record = record; + } + + public void finalize() { + Dispose(); + } + + public byte[] get(String type) { + SWIGTYPE_p_int length = null; + return yaz4jlib.ZOOM_record_get_bytes(record, type, length); + } + + public String render() { + return new String(get("render")); + } + + public byte[] getContent() { + return get("raw"); + } + + public String getSyntax() { + return new String(get("syntax")); + } + + public String getDatabase() { + return new String(get("database")); + } + + public void Dispose() { + if (!disposed) { + resultSet = null; + record = null; + disposed = true; } - - public String render() - { - return new String(get("render")); - } - - public byte[] getContent() - { - return get("raw"); - } - - public String getSyntax() - { - return new String(get("syntax")); - } - - public String getDatabase() - { - return new String(get("database")); - } - - public void Dispose() - { - if (!disposed) - { - resultSet = null; - record = null; - disposed = true; - } - } + } } diff --git a/src/main/java/org/yaz4j/ResultSet.java b/src/main/java/org/yaz4j/ResultSet.java index b70a03e..300cbad 100644 --- a/src/main/java/org/yaz4j/ResultSet.java +++ b/src/main/java/org/yaz4j/ResultSet.java @@ -5,62 +5,54 @@ import org.yaz4j.jni.SWIGTYPE_p_ZOOM_record_p; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_resultset_p; import org.yaz4j.jni.yaz4jlib; -public class ResultSet -{ - private SWIGTYPE_p_ZOOM_resultset_p resultSet; - private SWIGTYPE_p_ZOOM_connection_p connection; - private long size = 0 ; - private Record[] records = null ; - private boolean disposed = false; - - ResultSet(SWIGTYPE_p_ZOOM_resultset_p resultSet, SWIGTYPE_p_ZOOM_connection_p connection) - { - this.resultSet = resultSet ; - this.connection = connection ; - size = yaz4jlib.ZOOM_resultset_size(this.resultSet); - records = new Record[(int)size]; - } - - public void finalize() - { - this.Dispose(); - } +public class ResultSet { - ResultSetOptionsCollection getResultSetOptions() - { - return new ResultSetOptionsCollection(resultSet); + private SWIGTYPE_p_ZOOM_resultset_p resultSet; + private SWIGTYPE_p_ZOOM_connection_p connection; + private long size = 0; + private Record[] records = null; + private boolean disposed = false; + + ResultSet(SWIGTYPE_p_ZOOM_resultset_p resultSet, SWIGTYPE_p_ZOOM_connection_p connection) { + this.resultSet = resultSet; + this.connection = connection; + size = yaz4jlib.ZOOM_resultset_size(this.resultSet); + records = new Record[(int) size]; + } + + public void finalize() { + this.Dispose(); + } + + ResultSetOptionsCollection getResultSetOptions() { + return new ResultSetOptionsCollection(resultSet); + } + + public Record getRecord(int index) { + if (records[index] == null) { + SWIGTYPE_p_ZOOM_record_p recordTemp = yaz4jlib.ZOOM_resultset_record(resultSet, index); + records[index] = new Record(recordTemp, this); + } + + return this.records[index]; + } + + public int getSize() { + return (int) size; } - - public Record getRecord(int index) - { - if ( records[index] == null) - { - SWIGTYPE_p_ZOOM_record_p recordTemp = yaz4jlib.ZOOM_resultset_record(resultSet, index); - records[index] = new Record(recordTemp, this); - } - - return this.records[index]; - } - - public int getSize() - { - return (int)size ; - } - - public void Dispose() - { - if (! disposed ) - { - for( int i=0 ; i