From 832c86a73de7d1dc97a7abcb4623b5f566c227b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Thu, 16 Nov 2017 00:37:06 +0100 Subject: [PATCH] initial commit --- .gitignore | 9 + CREDITS.txt | 14 + LICENSE.txt | 202 +++++ asn1/config/checkstyle/checkstyle.xml | 323 ++++++++ asn1/config/maven/repo-settings.xml | 24 + asn1/src/main/java/org/xbib/asn1/ASN1Any.java | 94 +++ .../java/org/xbib/asn1/ASN1BitString.java | 156 ++++ .../main/java/org/xbib/asn1/ASN1Boolean.java | 127 +++ .../main/java/org/xbib/asn1/ASN1Decoder.java | 66 ++ .../org/xbib/asn1/ASN1EncodingException.java | 16 + .../java/org/xbib/asn1/ASN1Enumerated.java | 147 ++++ .../java/org/xbib/asn1/ASN1Exception.java | 18 + .../main/java/org/xbib/asn1/ASN1External.java | 282 +++++++ .../java/org/xbib/asn1/ASN1GeneralString.java | 49 ++ .../org/xbib/asn1/ASN1GeneralizedTime.java | 51 ++ .../java/org/xbib/asn1/ASN1GraphicString.java | 40 + .../java/org/xbib/asn1/ASN1IA5String.java | 51 ++ .../main/java/org/xbib/asn1/ASN1Integer.java | 150 ++++ .../src/main/java/org/xbib/asn1/ASN1Null.java | 85 +++ .../java/org/xbib/asn1/ASN1NumericString.java | 49 ++ .../org/xbib/asn1/ASN1ObjectDescriptor.java | 53 ++ .../org/xbib/asn1/ASN1ObjectIdentifier.java | 193 +++++ .../java/org/xbib/asn1/ASN1OctetString.java | 220 ++++++ .../org/xbib/asn1/ASN1PrintableString.java | 57 ++ .../main/java/org/xbib/asn1/ASN1Sequence.java | 138 ++++ asn1/src/main/java/org/xbib/asn1/ASN1Set.java | 138 ++++ .../java/org/xbib/asn1/ASN1T61String.java | 44 ++ .../main/java/org/xbib/asn1/ASN1UTCTime.java | 62 ++ .../org/xbib/asn1/ASN1VideotexString.java | 51 ++ .../java/org/xbib/asn1/ASN1VisibleString.java | 52 ++ .../java/org/xbib/asn1/BERConstructed.java | 122 +++ .../main/java/org/xbib/asn1/BEREncoding.java | 424 ++++++++++ .../main/java/org/xbib/asn1/BERPrimitive.java | 113 +++ .../main/java/org/xbib/asn1/package-info.java | 4 + build.gradle | 80 ++ config/checkstyle/checkstyle.xml | 323 ++++++++ config/checkstyle/suppressions.xml | 7 + gradle.properties | 5 + gradle/ext.gradle | 8 + gradle/publish.gradle | 70 ++ gradle/sonarqube.gradle | 40 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54708 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 +++++ gradlew.bat | 84 ++ settings.gradle | 4 + z3950/build.gradle | 9 + z3950/config/checkstyle/checkstyle.xml | 323 ++++++++ z3950/config/maven/repo-settings.xml | 24 + .../jacc/org/xbib/io/iso23950/pqf/PQF.jacc | 1 + .../org/xbib/io/iso23950/Diagnostics.java | 59 ++ .../org/xbib/io/iso23950/ErrorRecord.java | 11 + .../org/xbib/io/iso23950/InitListener.java | 10 + .../java/org/xbib/io/iso23950/Record.java | 35 + .../org/xbib/io/iso23950/RecordListener.java | 10 + .../xbib/io/iso23950/ResponseListener.java | 12 + .../java/org/xbib/io/iso23950/ZClient.java | 504 ++++++++++++ .../xbib/io/iso23950/cql/CQLRPNGenerator.java | 334 ++++++++ .../xbib/io/iso23950/cql/SyntaxException.java | 37 + .../xbib/io/iso23950/cql/package-info.java | 4 + .../MessageSizeTooSmallException.java | 13 + .../NoRecordsReturnedException.java | 14 + ...estTerminatedByAccessControlException.java | 13 + .../RequestTerminatedException.java | 13 + .../io/iso23950/exceptions/ZException.java | 51 ++ .../io/iso23950/exceptions/package-info.java | 4 + .../io/iso23950/operations/InitOperation.java | 114 +++ .../iso23950/operations/PresentOperation.java | 118 +++ .../iso23950/operations/SearchOperation.java | 121 +++ .../io/iso23950/operations/package-info.java | 4 + .../org/xbib/io/iso23950/package-info.java | 4 + .../org/xbib/io/iso23950/pqf/AttrStr.java | 47 ++ .../org/xbib/io/iso23950/pqf/Expression.java | 30 + .../java/org/xbib/io/iso23950/pqf/Node.java | 15 + .../java/org/xbib/io/iso23950/pqf/PQF.java | 34 + .../xbib/io/iso23950/pqf/PQFRPNGenerator.java | 122 +++ .../java/org/xbib/io/iso23950/pqf/Query.java | 97 +++ .../org/xbib/io/iso23950/pqf/Setname.java | 26 + .../xbib/io/iso23950/pqf/SyntaxException.java | 18 + .../java/org/xbib/io/iso23950/pqf/Term.java | 26 + .../org/xbib/io/iso23950/pqf/Visitor.java | 39 + .../xbib/io/iso23950/pqf/package-info.java | 4 + .../io/iso23950/v3/AccessControlRequest.java | 163 ++++ ...AccessControlRequestSecurityChallenge.java | 131 ++++ .../io/iso23950/v3/AccessControlResponse.java | 215 ++++++ ...trolResponseSecurityChallengeResponse.java | 130 ++++ .../xbib/io/iso23950/v3/AttributeElement.java | 162 ++++ .../v3/AttributeElementAttributeValue.java | 119 +++ ...AttributeElementAttributeValueComplex.java | 182 +++++ .../xbib/io/iso23950/v3/AttributeList.java | 110 +++ .../xbib/io/iso23950/v3/AttributeSetId.java | 82 ++ .../io/iso23950/v3/AttributesPlusTerm.java | 136 ++++ .../java/org/xbib/io/iso23950/v3/Close.java | 261 +++++++ .../org/xbib/io/iso23950/v3/CloseReason.java | 97 +++ .../org/xbib/io/iso23950/v3/CompSpec.java | 243 ++++++ .../io/iso23950/v3/CompSpecDbSpecific.java | 144 ++++ .../org/xbib/io/iso23950/v3/DatabaseName.java | 92 +++ .../io/iso23950/v3/DefaultDiagFormat.java | 137 ++++ .../iso23950/v3/DefaultDiagFormatAddinfo.java | 113 +++ .../iso23950/v3/DeleteResultSetRequest.java | 218 ++++++ .../iso23950/v3/DeleteResultSetResponse.java | 268 +++++++ .../xbib/io/iso23950/v3/DeleteSetStatus.java | 97 +++ .../java/org/xbib/io/iso23950/v3/DiagRec.java | 114 +++ .../xbib/io/iso23950/v3/ElementSetName.java | 87 +++ .../xbib/io/iso23950/v3/ElementSetNames.java | 143 ++++ .../v3/ElementSetNamesDatabaseSpecific.java | 131 ++++ .../java/org/xbib/io/iso23950/v3/Entry.java | 127 +++ .../iso23950/v3/ExtendedServicesRequest.java | 392 ++++++++++ .../iso23950/v3/ExtendedServicesResponse.java | 246 ++++++ .../xbib/io/iso23950/v3/FragmentSyntax.java | 141 ++++ .../xbib/io/iso23950/v3/IdAuthentication.java | 234 ++++++ .../iso23950/v3/IdAuthenticationIdPass.java | 226 ++++++ .../org/xbib/io/iso23950/v3/InfoCategory.java | 177 +++++ .../io/iso23950/v3/InitializeRequest.java | 501 ++++++++++++ .../io/iso23950/v3/InitializeResponse.java | 484 ++++++++++++ .../java/org/xbib/io/iso23950/v3/IntUnit.java | 175 +++++ .../io/iso23950/v3/InternationalString.java | 83 ++ .../io/iso23950/v3/KnownProximityUnit.java | 94 +++ .../org/xbib/io/iso23950/v3/ListEntries.java | 232 ++++++ .../org/xbib/io/iso23950/v3/ListStatuses.java | 115 +++ .../xbib/io/iso23950/v3/ListStatuses1.java | 166 ++++ .../xbib/io/iso23950/v3/NamePlusRecord.java | 202 +++++ .../io/iso23950/v3/NamePlusRecordRecord.java | 312 ++++++++ .../iso23950/v3/OccurrenceByAttributes.java | 123 +++ .../iso23950/v3/OccurrenceByAttributes1.java | 238 ++++++ .../v3/OccurrenceByAttributesOccurrences.java | 207 +++++ ...enceByAttributesOccurrencesByDatabase.java | 216 ++++++ .../java/org/xbib/io/iso23950/v3/Operand.java | 198 +++++ .../org/xbib/io/iso23950/v3/Operator.java | 240 ++++++ .../java/org/xbib/io/iso23950/v3/Options.java | 97 +++ .../xbib/io/iso23950/v3/OtherInformation.java | 139 ++++ .../io/iso23950/v3/OtherInformation1.java | 179 +++++ .../v3/OtherInformationInformation.java | 221 ++++++ .../java/org/xbib/io/iso23950/v3/PDU.java | 722 ++++++++++++++++++ .../org/xbib/io/iso23950/v3/Permissions.java | 117 +++ .../org/xbib/io/iso23950/v3/Permissions1.java | 204 +++++ .../xbib/io/iso23950/v3/PresentRequest.java | 512 +++++++++++++ .../v3/PresentRequestRecordComposition.java | 133 ++++ .../xbib/io/iso23950/v3/PresentResponse.java | 314 ++++++++ .../xbib/io/iso23950/v3/PresentStatus.java | 98 +++ .../xbib/io/iso23950/v3/ProtocolVersion.java | 92 +++ .../io/iso23950/v3/ProximityOperator.java | 297 +++++++ .../ProximityOperatorProximityUnitCode.java | 169 ++++ .../java/org/xbib/io/iso23950/v3/Query.java | 333 ++++++++ .../org/xbib/io/iso23950/v3/RPNQuery.java | 126 +++ .../org/xbib/io/iso23950/v3/RPNStructure.java | 161 ++++ .../io/iso23950/v3/RPNStructureRpnRpnOp.java | 197 +++++ .../java/org/xbib/io/iso23950/v3/Range.java | 180 +++++ .../java/org/xbib/io/iso23950/v3/Records.java | 249 ++++++ .../org/xbib/io/iso23950/v3/ReferenceId.java | 113 +++ .../iso23950/v3/ResourceControlRequest.java | 387 ++++++++++ .../iso23950/v3/ResourceControlResponse.java | 261 +++++++ .../xbib/io/iso23950/v3/ResourceReport.java | 79 ++ .../xbib/io/iso23950/v3/ResourceReportId.java | 86 +++ .../io/iso23950/v3/ResourceReportRequest.java | 262 +++++++ .../iso23950/v3/ResourceReportResponse.java | 269 +++++++ .../org/xbib/io/iso23950/v3/ResultSetId.java | 100 +++ .../iso23950/v3/ResultSetPlusAttributes.java | 127 +++ .../org/xbib/io/iso23950/v3/ScanRequest.java | 297 +++++++ .../org/xbib/io/iso23950/v3/ScanResponse.java | 386 ++++++++++ .../xbib/io/iso23950/v3/SearchRequest.java | 461 +++++++++++ .../xbib/io/iso23950/v3/SearchResponse.java | 401 ++++++++++ .../java/org/xbib/io/iso23950/v3/Segment.java | 270 +++++++ .../org/xbib/io/iso23950/v3/SortElement.java | 208 +++++ .../v3/SortElementDatabaseSpecific.java | 155 ++++ .../java/org/xbib/io/iso23950/v3/SortKey.java | 175 +++++ .../io/iso23950/v3/SortKeySortAttributes.java | 124 +++ .../org/xbib/io/iso23950/v3/SortKeySpec.java | 230 ++++++ .../v3/SortKeySpecMissingValueAction.java | 192 +++++ .../org/xbib/io/iso23950/v3/SortRequest.java | 300 ++++++++ .../org/xbib/io/iso23950/v3/SortResponse.java | 278 +++++++ .../xbib/io/iso23950/v3/Specification.java | 204 +++++ .../iso23950/v3/SpecificationElementSpec.java | 159 ++++ .../xbib/io/iso23950/v3/StringOrNumeric.java | 156 ++++ .../java/org/xbib/io/iso23950/v3/Term.java | 329 ++++++++ .../org/xbib/io/iso23950/v3/TermInfo.java | 386 ++++++++++ .../v3/TriggerResourceControlRequest.java | 285 +++++++ .../java/org/xbib/io/iso23950/v3/Unit.java | 278 +++++++ .../org/xbib/io/iso23950/v3/package-info.java | 4 + .../jflex/org/xbib/io/iso23950/pqf/PQF.jflex | 172 +++++ .../xsl/isodis25577-sru-response.xsl | 60 ++ .../java/org/xbib/io/iso23950/Bib1Test.java | 26 + .../java/org/xbib/io/iso23950/ParserTest.java | 39 + .../java/org/xbib/io/iso23950/SearchTest.java | 42 + .../org/xbib/io/iso23950/ZClientTest.java | 56 ++ .../org/xbib/io/iso23950/cql/CQL2RPNTest.java | 21 + .../xbib/io/iso23950/cql/package-info.java | 4 + .../org/xbib/io/iso23950/package-info.java | 4 + .../xbib/io/iso23950/pqf/PQFParserTest.java | 36 + .../xbib/io/iso23950/pqf/package-info.java | 4 + z3950/src/test/resources/log4j2.xml | 13 + .../org/xbib/io/iso23950/pqf/pqf-must-succeed | 17 + 192 files changed, 27423 insertions(+) create mode 100644 .gitignore create mode 100644 CREDITS.txt create mode 100644 LICENSE.txt create mode 100644 asn1/config/checkstyle/checkstyle.xml create mode 100644 asn1/config/maven/repo-settings.xml create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1Any.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1BitString.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1Boolean.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1Decoder.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1EncodingException.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1Enumerated.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1Exception.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1External.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1GeneralString.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1GeneralizedTime.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1GraphicString.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1IA5String.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1Integer.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1Null.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1NumericString.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1ObjectDescriptor.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1ObjectIdentifier.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1OctetString.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1PrintableString.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1Sequence.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1Set.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1T61String.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1UTCTime.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1VideotexString.java create mode 100644 asn1/src/main/java/org/xbib/asn1/ASN1VisibleString.java create mode 100644 asn1/src/main/java/org/xbib/asn1/BERConstructed.java create mode 100644 asn1/src/main/java/org/xbib/asn1/BEREncoding.java create mode 100644 asn1/src/main/java/org/xbib/asn1/BERPrimitive.java create mode 100644 asn1/src/main/java/org/xbib/asn1/package-info.java create mode 100644 build.gradle create mode 100644 config/checkstyle/checkstyle.xml create mode 100644 config/checkstyle/suppressions.xml create mode 100644 gradle.properties create mode 100644 gradle/ext.gradle create mode 100644 gradle/publish.gradle create mode 100644 gradle/sonarqube.gradle create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle create mode 100644 z3950/build.gradle create mode 100644 z3950/config/checkstyle/checkstyle.xml create mode 100644 z3950/config/maven/repo-settings.xml create mode 100755 z3950/src/main/jacc/org/xbib/io/iso23950/pqf/PQF.jacc create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/Diagnostics.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/ErrorRecord.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/InitListener.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/Record.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/RecordListener.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/ResponseListener.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/ZClient.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/cql/CQLRPNGenerator.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/cql/SyntaxException.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/cql/package-info.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/exceptions/MessageSizeTooSmallException.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/exceptions/NoRecordsReturnedException.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/exceptions/RequestTerminatedByAccessControlException.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/exceptions/RequestTerminatedException.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/exceptions/ZException.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/exceptions/package-info.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/operations/InitOperation.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/operations/PresentOperation.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/operations/SearchOperation.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/operations/package-info.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/package-info.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/pqf/AttrStr.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/pqf/Expression.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/pqf/Node.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/pqf/PQF.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/pqf/PQFRPNGenerator.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/pqf/Query.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/pqf/Setname.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/pqf/SyntaxException.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/pqf/Term.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/pqf/Visitor.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/pqf/package-info.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlRequest.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlRequestSecurityChallenge.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlResponse.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlResponseSecurityChallengeResponse.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElement.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElementAttributeValue.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElementAttributeValueComplex.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeList.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeSetId.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/AttributesPlusTerm.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Close.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/CloseReason.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/CompSpec.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/CompSpecDbSpecific.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/DatabaseName.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/DefaultDiagFormat.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/DefaultDiagFormatAddinfo.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteResultSetRequest.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteResultSetResponse.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteSetStatus.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/DiagRec.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetName.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetNames.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetNamesDatabaseSpecific.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Entry.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ExtendedServicesRequest.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ExtendedServicesResponse.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/FragmentSyntax.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/IdAuthentication.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/IdAuthenticationIdPass.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/InfoCategory.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/InitializeRequest.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/InitializeResponse.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/IntUnit.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/InternationalString.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/KnownProximityUnit.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ListEntries.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ListStatuses.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ListStatuses1.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/NamePlusRecord.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/NamePlusRecordRecord.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributes.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributes1.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributesOccurrences.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributesOccurrencesByDatabase.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Operand.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Operator.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Options.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformation.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformation1.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformationInformation.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/PDU.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Permissions.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Permissions1.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/PresentRequest.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/PresentRequestRecordComposition.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/PresentResponse.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/PresentStatus.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ProtocolVersion.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ProximityOperator.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ProximityOperatorProximityUnitCode.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Query.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/RPNQuery.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/RPNStructure.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/RPNStructureRpnRpnOp.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Range.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Records.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ReferenceId.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceControlRequest.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceControlResponse.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReport.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportId.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportRequest.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportResponse.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ResultSetId.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ResultSetPlusAttributes.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ScanRequest.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/ScanResponse.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/SearchRequest.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/SearchResponse.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Segment.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/SortElement.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/SortElementDatabaseSpecific.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/SortKey.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySortAttributes.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySpec.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySpecMissingValueAction.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/SortRequest.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/SortResponse.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Specification.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/SpecificationElementSpec.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/StringOrNumeric.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Term.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/TermInfo.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/TriggerResourceControlRequest.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/Unit.java create mode 100644 z3950/src/main/java/org/xbib/io/iso23950/v3/package-info.java create mode 100755 z3950/src/main/jflex/org/xbib/io/iso23950/pqf/PQF.jflex create mode 100644 z3950/src/main/resources/xsl/isodis25577-sru-response.xsl create mode 100644 z3950/src/test/java/org/xbib/io/iso23950/Bib1Test.java create mode 100644 z3950/src/test/java/org/xbib/io/iso23950/ParserTest.java create mode 100644 z3950/src/test/java/org/xbib/io/iso23950/SearchTest.java create mode 100644 z3950/src/test/java/org/xbib/io/iso23950/ZClientTest.java create mode 100644 z3950/src/test/java/org/xbib/io/iso23950/cql/CQL2RPNTest.java create mode 100644 z3950/src/test/java/org/xbib/io/iso23950/cql/package-info.java create mode 100644 z3950/src/test/java/org/xbib/io/iso23950/package-info.java create mode 100644 z3950/src/test/java/org/xbib/io/iso23950/pqf/PQFParserTest.java create mode 100644 z3950/src/test/java/org/xbib/io/iso23950/pqf/package-info.java create mode 100644 z3950/src/test/resources/log4j2.xml create mode 100644 z3950/src/test/resources/org/xbib/io/iso23950/pqf/pqf-must-succeed diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2a9a1fa --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/.idea +/.settings +/.classpath +/.project +/.gradle +build +.DS_Store +*.iml +*.properties diff --git a/CREDITS.txt b/CREDITS.txt new file mode 100644 index 0000000..00aafd5 --- /dev/null +++ b/CREDITS.txt @@ -0,0 +1,14 @@ +This software is based on the work of + +Zebulun https://github.com/jafer-org/zebulun + +a low level Java implementation of the NISO Z39.50 protocol, + +and + +Java Access For Electronic Resources (Jafer) https://github.com/jafer-org/jafer + +The JAFER Project (Java Access For Electronic Resources) was a Jisc funded project (2000 - 2003) +based at Oxford University to produce an easy to use toolkit for building portals +and information sources without having to deal with the technical intricacies of the Z39.50 protocol. + diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/asn1/config/checkstyle/checkstyle.xml b/asn1/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000..55e59d2 --- /dev/null +++ b/asn1/config/checkstyle/checkstyle.xml @@ -0,0 +1,323 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/asn1/config/maven/repo-settings.xml b/asn1/config/maven/repo-settings.xml new file mode 100644 index 0000000..5968882 --- /dev/null +++ b/asn1/config/maven/repo-settings.xml @@ -0,0 +1,24 @@ + + ~/.m2/repository + + xbib + + + + xbib + + + xbib + http://xbib.org/repository + + true + always + + + true + + + + + + \ No newline at end of file diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1Any.java b/asn1/src/main/java/org/xbib/asn1/ASN1Any.java new file mode 100644 index 0000000..cde54b3 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1Any.java @@ -0,0 +1,94 @@ +package org.xbib.asn1; + +/** + * ASN1 ANY + * The ANY type denotes an arbitary value of an arbitary type. + * This class also serves as the base class for all ASN.1 classes. + * The ASN.1 syntax is defined in + * Information Technology - Open Systems Interconnection - + * Specification of Abstract Syntax Notation One (ASN.1) + * AS 3625-1991 + * ISO/IEC 8824:1990 + * The current implementation assumes values are limited to 32-bit + * signed integers for tags, lengths, etc. + */ +public class ASN1Any { + + /* Hack to support creation of ASN1 ANY types from a BER and have + it behave normally. This is not used by any other ASN.1 subclasses. + It is a waste of space in that respect. */ + + private BEREncoding asn1anyBer; + + public ASN1Any() { + // + } + + /** + * Constructor for an ASN.1 ANY object from a BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Does nothing for ASN1Any. + * @throws ASN1Exception if the BER encoding is incorrect. + */ + public ASN1Any(BEREncoding ber, boolean checkTag) throws ASN1Exception { + berDecode(ber, checkTag); + } + + /** + * Method for initializing the object from a BER encoding. + * All classes derived from this one must implement a version of this. + * This method will be overridden by derived types. + * + * @param berEncoding The BER encoding to use. + * @param checkTag If true, it checks the tag. Does nothing for ASN1Any. + * @throws ASN1Exception If the BER encoding is incorrect. + * Never occurs for ASN1Any. + */ + public void berDecode(BEREncoding berEncoding, boolean checkTag) + throws ASN1Exception { + asn1anyBer = berEncoding; + } + + /** + * Constructs a BER encoding for this ASN.1 object. + * This method is usually overridden by a subclass method. + * + * @return BER encoding + * @throws ASN1Exception If the object cannot be BER encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + if (asn1anyBer == null) { + throw new ASN1EncodingException("uninitialised"); + } + return asn1anyBer; + } + + /** + * Returns a BER encoding of ASN1Any, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag number. + * @return The BER encoding of the object. + * @throws ASN1Exception when invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + if (asn1anyBer == null) { + throw new ASN1EncodingException("uninitialised"); + } + throw new ASN1EncodingException("cannot implicitly tag"); + } + + /** + * Returns a new String object representing this ASN.1 object's value. + * + * @return A text string representation. + */ + @Override + public String toString() { + if (asn1anyBer == null) { + return ""; + } + return asn1anyBer.toString(); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1BitString.java b/asn1/src/main/java/org/xbib/asn1/ASN1BitString.java new file mode 100644 index 0000000..6dc1d72 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1BitString.java @@ -0,0 +1,156 @@ +package org.xbib.asn1; + +/** + * Representation of an ASN.1 BIT STRING. + * The BIT STRING type denotes an arbitary string of bits (ones and zeros). + * A BIT STRING value can have any length, including zero. The type is a + * string type. + */ +public final class ASN1BitString extends ASN1Any { + /** + * This constant is the ASN.1 UNIVERSAL tag value for BIT STRING. + */ + public static final int BIT_STRING_TAG = 0x03; + + /** + * The values of the BIT STRING are stored in this array of boolean + * values. + */ + private boolean[] bits; + + /** + * Constructor for an ASN.1 BIT STRING object. It sets the tag + * to the default value of UNIVERSAL 3, and the bits to the + * given bit values. + * + * @param bitValues - array of booleans representing the bit string. + */ + public ASN1BitString(boolean[] bitValues) { + bits = bitValues; + } + + /** + * Constructor for an ASN.1 BIT STRING object from a BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1BitString(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); // superclass will call berDecode + } + + /** + * Method for initializing the object from a BER encoding. + * + * @param berEncoding The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1EncodingException If the BER encoding is incorrect. + */ + @Override + public void berDecode(BEREncoding berEncoding, boolean checkTag) + throws ASN1EncodingException { + if (checkTag && (berEncoding.tagGet() != BIT_STRING_TAG || berEncoding.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("ASN.1 BIT STRING: bad BER: tag=" + berEncoding.tagGet() + + " expected " + BIT_STRING_TAG + "\n"); + } + if (berEncoding instanceof BERPrimitive) { + BERPrimitive ber = (BERPrimitive) berEncoding; + int[] encoding = ber.peek(); + if (encoding.length < 1) { + throw new ASN1EncodingException("ASN1 BIT STRING: invalid encoding, length = " + encoding.length); + } + int unusedBits = encoding[0] & 0x07; + int numBits = (encoding.length - 1) * 8 - unusedBits; + bits = new boolean[numBits]; + for (int bit = 0; bit < numBits; bit++) { + int octet = encoding[bit / 8 + 1]; + octet <<= (bit % 8); + bits[bit] = (octet & 0x80) != 0; + } + } else { + throw new ASN1EncodingException("ASN.1 BIT STRING: decoding constructed NOT IMPLEMENTED YET"); + } + } + + /** + * Returns a BER encoding of the BIT STRING. + * Bit strings can have a primitive encoding and a constructed + * encoding. This method performs the primitive encoding (which + * is the one specified for DER encoding). + * + * @return The BER encoding of the BIT STRING + * @throws ASN1Exception when the BIT STRING is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, BIT_STRING_TAG); + } + + /** + * Returns a BER encoding of the BIT STRING. + * Bit strings can have a primitive encoding and a constructed + * encoding. This method performs the primitive encoding (which + * is the one specified for DER encoding). + * + * @return The BER encoding of the BIT STRING + * @throws ASN1Exception when the BIT STRING is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numOctets = (bits.length + 7) / 8; + int[] encoding = new int[numOctets + 1]; + encoding[0] = (numOctets * 8) - bits.length; + for (int count = 1; count <= numOctets; count++) { + encoding[count] = 0x00; + int bitBaseIndex = (count - 1) * 8; + for (int bitIndex = 0; bitIndex < 8; bitIndex++) { + int n = bitBaseIndex + bitIndex; + encoding[count] <<= 1; + if (n < bits.length && bits[n]) { + encoding[count] |= 0x01; + } + } + } + return new BERPrimitive(tagType, tag, encoding); + } + + /** + * Method to set the bit string's value. + * + * @param newBits the value to set the BIT STRING to. + * @return the object. + */ + public ASN1BitString set(boolean[] newBits) { + bits = newBits; + return this; + } + + /** + * Method to get the bit string's value. + * + * @return the BIT STRING's current value. + */ + public boolean[] get() { + return bits; + } + + /** + * Returns a new String object representing this ASN.1 object's value. + * + * @return A text string representation of the BitString. + */ + @Override + public String toString() { + StringBuilder str = new StringBuilder(); + str.append('\''); + for (boolean bit : bits) { + str.append(bit ? '1' : '0'); + } + str.append("'B"); + return str.toString(); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1Boolean.java b/asn1/src/main/java/org/xbib/asn1/ASN1Boolean.java new file mode 100644 index 0000000..aee3fe2 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1Boolean.java @@ -0,0 +1,127 @@ +package org.xbib.asn1; + +/** + * Representation of an ASN.1 BOOLEAN. + * The BOOLEAN type denotes a Boolean value: either true or false. + */ +public final class ASN1Boolean extends ASN1Any { + + /** + * This constant is the ASN.1 UNIVERSAL tag value for BOOLEAN. + */ + public static final int TAG = 0x01; + /** + * The value of the BOOLEAN is stored in this variable. + */ + private boolean value; + + /** + * Default constructor for an ASN.1 BOOLEAN object. It sets the tag + * to the default of UNIVERSAL 1, and the value to bool. + * + * @param bool the value of the BOOLEAN. + */ + + public ASN1Boolean(boolean bool) { + value = bool; + } + + /** + * Constructor for an ASN.1 BOOLEAN object from a BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception if the BER encoding is incorrect. + */ + public ASN1Boolean(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); // superclass will call berDecode + } + + /** + * Method for initializing the object from a BER encoding. + * + * @param berEncoding The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1EncodingException if the BER encoding is incorrect. + */ + @Override + public void berDecode(BEREncoding berEncoding, boolean checkTag) + throws ASN1EncodingException { + if (checkTag && (berEncoding.tagGet() != TAG || berEncoding.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException + ("ASN.1 BOOLEAN: bad BER: tag=" + berEncoding.tagGet() + + " expected " + "TAG\n"); + } + if (berEncoding instanceof BERPrimitive) { + BERPrimitive ber = (BERPrimitive) berEncoding; + int[] encoding = ber.peek(); + if (encoding.length != 1) { + throw new ASN1EncodingException("ASN.1 BOOLEAN: invalid encoding, length = " + encoding.length); + } + value = encoding[0] != 0; + } else { + throw new ASN1EncodingException + ("ASN.1 BOOLEAN: bad BER: decoding constructed NOT IMPLEMENTED YET"); + } + } + + /** + * Returns a BER encoding of the BOOLEAN. + * + * @return The BER encoding of the BOOLEAN + * @throws ASN1Exception when the BOOLEAN is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, TAG); + } + + /** + * Returns a BER encoding of the BOOLEAN. Implicitly tagged. + * + * @return The BER encoding of the BOOLEAN + * @throws ASN1Exception when the BOOLEAN is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int[] encoding = new int[1]; + if (value) { + encoding[0] = 0xff; // TRUE (in fact, any non-zero will do) + } else { + encoding[0] = 0x00; // FALSE + } + return new BERPrimitive(tagType, tag, encoding); + } + + /** + * Method to set the boolean's value. + * + * @param newVal the value to set the BOOLEAN to. + * @return the boolean + */ + public ASN1Boolean set(boolean newVal) { + value = newVal; + return this; + } + + /** + * Method to get the boolean's value. + * + * @return the BOOLEAN's current value. + */ + public boolean get() { + return value; + } + + /** + * Returns a new String object representing this ASN.1 object's value. + */ + @Override + public String toString() { + return value ? "true" : "false"; + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1Decoder.java b/asn1/src/main/java/org/xbib/asn1/ASN1Decoder.java new file mode 100644 index 0000000..067503b --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1Decoder.java @@ -0,0 +1,66 @@ +package org.xbib.asn1; + +/** + * ASN1Decoder. + * This is an ASN1 decoder which can handle all the standard ASN.1 types + * (those with UNIVERSAL tag types). + * It is used for decoding generic BER encodings into ASN.1 objects. + */ +public class ASN1Decoder { + + private ASN1Decoder() { + // private constructor + } + + public static ASN1Any toASN1(BEREncoding ber) throws ASN1Exception { + if (ber.tagTypeGet() == BEREncoding.UNIVERSAL_TAG) { + switch (ber.tagGet()) { + case ASN1Boolean.TAG: + return new ASN1Boolean(ber, true); + case ASN1Integer.INTEGER_TAG: + return new ASN1Integer(ber, true); + case ASN1BitString.BIT_STRING_TAG: + return new ASN1BitString(ber, true); + case ASN1OctetString.OCTET_STRING_TAG: + return new ASN1OctetString(ber, true); + case ASN1Null.NULL_TAG: + return new ASN1Null(ber, true); + case ASN1ObjectIdentifier.OBJECT_IDENTIFIER_TAG: + return new ASN1ObjectIdentifier(ber, true); + case ASN1ObjectDescriptor.OBJECT_DESCRIPTOR_TAG: + return new ASN1ObjectDescriptor(ber, true); + case ASN1External.EXTERNAL_TAG: + return new ASN1External(ber, true); + case ASN1Enumerated.ENUMERATED_TAG: + return new ASN1Enumerated(ber, true); + case ASN1Sequence.SEQUENCE_TAG: + return new ASN1Sequence(ber, true); + case ASN1Set.SET_TAG: + return new ASN1Set(ber, true); + case ASN1NumericString.NUMERIC_STRING_TAG: + return new ASN1NumericString(ber, true); + case ASN1PrintableString.PRINTABLE_STRING_TAG: + return new ASN1PrintableString(ber, true); + case ASN1T61String.T61_STRING_TAG: + return new ASN1T61String(ber, true); + case ASN1VideotexString.VIDEOTEX_STRING_TAG: + return new ASN1VideotexString(ber, true); + case ASN1IA5String.IA5_STRING_TAG: + return new ASN1IA5String(ber, true); + case ASN1UTCTime.UTC_TIME_TAG: + return new ASN1UTCTime(ber, true); + case ASN1GeneralizedTime.GENERALIZED_TIME_TAG: + return new ASN1GeneralizedTime(ber, true); + case ASN1GraphicString.GRAPHIC_STRING_TAG: + return new ASN1GraphicString(ber, true); + case ASN1VisibleString.TAG: + return new ASN1VisibleString(ber, true); + case ASN1GeneralString.GENERAL_STRING_TAG: + return new ASN1GeneralString(ber, true); + default: + break; + } + } + return new ASN1Any(ber, true); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1EncodingException.java b/asn1/src/main/java/org/xbib/asn1/ASN1EncodingException.java new file mode 100644 index 0000000..45af4a6 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1EncodingException.java @@ -0,0 +1,16 @@ +package org.xbib.asn1; + +/** + * ASN1EncodingException. + */ +public class ASN1EncodingException extends ASN1Exception { + private static final long serialVersionUID = 2063392457642967553L; + + public ASN1EncodingException() { + super("ASN.1 encoding exception"); + } + + public ASN1EncodingException(String message) { + super(message); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1Enumerated.java b/asn1/src/main/java/org/xbib/asn1/ASN1Enumerated.java new file mode 100644 index 0000000..1d58558 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1Enumerated.java @@ -0,0 +1,147 @@ +package org.xbib.asn1; + +/** + * Representation of an ASN.1 ENUMERATED. + * The ENUMERATED type denotes an integer from a selected set. + * ASN.1 ENUMERATED values can be positive, negative, or zero; and can + * have any magnitude. + * The current implementation limits the values of ENUMERATED to 32-bit + * two's complement values. + */ +public final class ASN1Enumerated extends ASN1Any { + /** + * This constant is the ASN.1 UNIVERSAL tag value for ENUMERATED. + */ + public static final int ENUMERATED_TAG = 0x0A; + + /** + * The value of the ENUMERATED is stored in this variable. + * This is private for good information hiding, so that we are able + * to change its representation (e.g. to a long) at a later date + * without affecting the interface. + */ + private int value; + + /** + * Constructor for an ASN.1 ENUMERATED object. The tag is + * set to the default tag of UNIVERSAL 2, and the value to the + * given number. + * + * @param number the value of the ENUMERATED. + */ + public ASN1Enumerated(int number) { + value = number; + } + + /** + * Constructor for an ASN.1 ENUMERATED object from a BER encoding. + * @param ber the BER encoding + * @param checkTag the check tag + * @throws ASN1Exception if the BER encoding is incorrect. + */ + public ASN1Enumerated(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Method for initializing the object from a BER encoding. + * + * @throws ASN1EncodingException if the BER encoding is incorrect. + */ + @Override + public void berDecode(BEREncoding berEncoding, boolean checkTag) + throws ASN1EncodingException { + if (checkTag && (berEncoding.tagGet() != ENUMERATED_TAG || + berEncoding.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + berEncoding.tagGet() + + " expected " + ENUMERATED_TAG + "\n"); + } + if (!(berEncoding instanceof BERPrimitive)) { + throw new ASN1EncodingException("bad form, constructed"); + } + BERPrimitive ber = (BERPrimitive) berEncoding; + int[] encoding = ber.peek(); + if (encoding.length < 1) { + throw new ASN1EncodingException("invalid encoding, length = " + encoding.length); + } + value = (byte) encoding[0]; // to ensure sign extension + for (int x = 1; x < encoding.length; x++) { + value <<= 8; + value |= (encoding[x] & 0xff); + } + } + + /** + * Returns a BER encoding of the ENUMERATED. + * + * @return The BER encoding of the ENUMERATED + * @throws ASN1Exception when the ENUMERATED is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ENUMERATED_TAG); + } + + /** + * Returns a BER encoding of the ENUMERATED. Explicitly tagged with + * the supplied tag. + * + * @return The BER encoding of the ENUMERATED + * @throws ASN1Exception when the ENUMERATED is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int length = 0; + int shifted = value; + if (value < 0) { + shifted = ~value; + } + boolean needPad; + do { + needPad = (shifted & 0x80) == 0x80; + shifted >>= 8; + length++; + } while (shifted != 0); + if (needPad) { + length++; + } + int[] encoding = new int[length]; + int index = 0; + while (0 < length) { + encoding[index++] = (value >> (8 * (length - 1))) & 0xff; + length--; + } + return new BERPrimitive(tagType, tag, encoding); + } + + /** + * Method to set the integer's value. + * + * @param newVal the value to set the ENUMERATED to. + * @return the object. + */ + public ASN1Enumerated set(int newVal) { + value = newVal; + return this; + } + + /** + * Method to get the integer's value. + * + * @return the ENUMERATED's current value. + */ + public int get() { + return value; + } + + /** + * Returns a new String object representing this ASN.1 object's value. + */ + @Override + public String toString() { + return String.valueOf(value); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1Exception.java b/asn1/src/main/java/org/xbib/asn1/ASN1Exception.java new file mode 100644 index 0000000..92049e9 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1Exception.java @@ -0,0 +1,18 @@ +package org.xbib.asn1; + +import java.io.IOException; + +/** + * ASN1Exception. + */ +public class ASN1Exception extends IOException { + private static final long serialVersionUID = -339688617660261367L; + + public ASN1Exception() { + super("ASN.1 exception"); + } + + public ASN1Exception(String message) { + super(message); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1External.java b/asn1/src/main/java/org/xbib/asn1/ASN1External.java new file mode 100644 index 0000000..8943769 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1External.java @@ -0,0 +1,282 @@ +package org.xbib.asn1; + +/** + * ASN1 EXTERNAL + * The EXTERNAL type represents an external object. + * According to clause 34.4 of the ASN.1 standard, + * the EXTERNAL type can be defined as: + *
+ * EXTERNAL := [UNIVERSAL 8] IMPLICIT SEQUENCE {
+ *               direct_reference OBJECT IDENTIFIER OPTIONAL,
+ *               indirect_reference INTEGER OPTIONAL,
+ *               data_value_descriptor ObjectDescriptor OPTIONAL,
+ *               encoding CHOICE {
+ *                 single_ASN1_type [0] ANY,
+ *                 octet_Aligned    [1] IMPLICIT OCTET STRING,
+ *                 arbitrary        [2] IMPLICIT BIT STRING
+ *               }
+ *             }
+ * 
+ * This construct has been represented by a class with six + * variables: + * sDirectReference, + * sIndirectReference, + * sDataValueDescriptor, + * cSingleASN1Type, + * cOctetAligned, + * cArbitrary. + * The first three should be set to point to the appropriate object + * if present, or null if not. + * One of the last three variables should be set to non-null (the choice) + * and the rest to null. + */ +public final class ASN1External extends ASN1Any { + /** + * This constant is the ASN.1 UNIVERSAL tag value for an EXTERNAL. + */ + public static final int EXTERNAL_TAG = 0x08; + + /* + * The values are stored in these variables. + */ + private ASN1ObjectIdentifier sDirectReference; + private ASN1Integer sIndirectReference; + private ASN1ObjectDescriptor sDataValueDescriptor; + private ASN1Any cSingleASN1Type; + private ASN1OctetString cOctetAligned; + private ASN1BitString cArbitrary; + + /** + * Constructor for an ASN.1 EXTERNAL object. It sets the tag to the + * default value of UNIVERSAL 8. + */ + public ASN1External() { + // + } + + /** + * Constructor for an ASN.1 EXTERNAL object from a BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1External(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Method for initializing the object from a BER encoding. + * + * @param berEncoding The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + @Override + public void berDecode(BEREncoding berEncoding, boolean checkTag) + throws ASN1Exception { + if (checkTag && (berEncoding.tagGet() != EXTERNAL_TAG || berEncoding.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + berEncoding.tagGet() + + " expected " + EXTERNAL_TAG + "\n"); + } + if (berEncoding instanceof BERPrimitive) { + throw new ASN1EncodingException("incorrect form, primitive encoding"); + } + BERConstructed ber = (BERConstructed) berEncoding; + sDirectReference = null; + sIndirectReference = null; + sDataValueDescriptor = null; + cSingleASN1Type = null; + cOctetAligned = null; + cArbitrary = null; + int numParts = ber.numberComponents(); + if (numParts < 1) { + throw new ASN1EncodingException("incomplete"); + } + int part = 0; + BEREncoding p = ber.elementAt(part); + if (p.tagGet() == ASN1ObjectIdentifier.OBJECT_IDENTIFIER_TAG && + p.tagTypeGet() == BEREncoding.UNIVERSAL_TAG) { + sDirectReference = new ASN1ObjectIdentifier(p, true); + if (numParts <= ++part) { + throw new ASN1EncodingException("incomplete"); + } + p = ber.elementAt(part); + } + if (p.tagGet() == ASN1Integer.INTEGER_TAG && + p.tagTypeGet() == BEREncoding.UNIVERSAL_TAG) { + sIndirectReference = new ASN1Integer(p, true); + if (numParts <= ++part) { + throw new ASN1EncodingException("incomplete"); + } + p = ber.elementAt(part); + } + if (p.tagGet() == ASN1ObjectDescriptor.OBJECT_DESCRIPTOR_TAG && + p.tagTypeGet() == BEREncoding.UNIVERSAL_TAG) { + sDataValueDescriptor = new ASN1ObjectDescriptor(p, true); + if (numParts <= ++part) { + throw new ASN1EncodingException("incomplete"); + } + p = ber.elementAt(part); + } + switch (p.tagGet()) { + case 0: + if (!(p instanceof BERConstructed)) { + throw new ASN1EncodingException("singleASN1type: bad form, primitive"); + } + if (((BERConstructed) p).numberComponents() != 1) { + throw new ASN1EncodingException("singleASN1type: bad form, no explicit tag"); + } + cSingleASN1Type = ASN1Decoder.toASN1(((BERConstructed) p).elementAt(0)); + break; + case 1: + // octetAligned [1] IMPLICIT OCTET STRING + if (p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("encoding: bad tag type " + p); + } + cOctetAligned = new ASN1OctetString(p, false); + break; + case 2: + // arbitrary [2] IMPLICIT BIT STRING + if (p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("encoding: bad tag type " + p); + } + cArbitrary = new ASN1BitString(p, false); + break; + default: + throw new ASN1EncodingException("encoding: tag = " + p.tagGet()); + } + if (part != (numParts - 1)) { + throw new ASN1Exception("extra element(s)"); + } + } + + public ASN1OctetString getcOctetAligned() { + return cOctetAligned; + } + + public ASN1Any getSingleASN1Type() { + return cSingleASN1Type; + } + + /** + * Returns a BER encoding of the EXTERNAL. + * + * @return The BER encoding of the EXTERNAL + * @throws ASN1Exception when the EXTERNAL is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, EXTERNAL_TAG); + } + + /** + * Returns a BER encoding of the EXTERNAL. + * + * @return The BER encoding of the EXTERNAL + * @throws ASN1Exception when the EXTERNAL is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numParts = 0; + if (cSingleASN1Type != null) { + numParts++; + } + if (cOctetAligned != null) { + numParts++; + } + if (cArbitrary != null) { + numParts++; + } + if (numParts < 1) { + throw new ASN1Exception("no encoding has been set"); + } + if (1 < numParts) { + throw new ASN1Exception("more than one encoding set"); + } + if (sDirectReference != null) { + numParts++; + } + if (sIndirectReference != null) { + numParts++; + } + if (sDataValueDescriptor != null) { + numParts++; + } + BEREncoding[] parts = new BEREncoding[numParts]; + int part = 0; + if (sDirectReference != null) { + parts[part++] = sDirectReference.berEncode(); + } + if (sIndirectReference != null) { + parts[part++] = sIndirectReference.berEncode(); + } + if (sDataValueDescriptor != null) { + parts[part++] = sDataValueDescriptor.berEncode(); + } + if (cSingleASN1Type != null) { + BEREncoding[] contents = new BEREncoding[1]; + contents[0] = cSingleASN1Type.berEncode(); + parts[part] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 0, + contents); + } else if (cOctetAligned != null) { + parts[part] = cOctetAligned.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, + 1); + } else if (cArbitrary != null) { + parts[part] = cArbitrary.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, + 2); + } + return new BERConstructed(tagType, tag, parts); + } + + /** + * Returns a new String object representing this ASN.1 object's value. + */ + @Override + public String toString() { + StringBuilder str = new StringBuilder("{"); + boolean hasElement = false; + if (sDirectReference != null) { + str.append("directReference "); + str.append(sDirectReference); + hasElement = true; + } + if (sIndirectReference != null) { + if (hasElement) { + str.append(", "); + } + str.append("indirectReference "); + str.append(sIndirectReference); + hasElement = true; + } + if (sDataValueDescriptor != null) { + if (hasElement) { + str.append(", "); + } + str.append("dataValueDescriptor "); + str.append(sDataValueDescriptor); + hasElement = true; + } + if (hasElement) { + str.append(", "); + } + str.append("encoding {"); + if (cSingleASN1Type != null) { + str.append("singleASN1type "); + str.append(cSingleASN1Type); + } + if (cOctetAligned != null) { + str.append("octetAligned "); + str.append(cOctetAligned); + } + if (cArbitrary != null) { + str.append("arbitrary "); + str.append(cArbitrary); + } + str.append("}}"); + return str.toString(); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1GeneralString.java b/asn1/src/main/java/org/xbib/asn1/ASN1GeneralString.java new file mode 100644 index 0000000..5b3dd8d --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1GeneralString.java @@ -0,0 +1,49 @@ +package org.xbib.asn1; + +/** + * ASN.1 GeneralString. + * The GeneralString type denotes an arbitary string + * of General characters. + * This type is a string type. + */ +public class ASN1GeneralString extends ASN1OctetString { + /** + * This constant is the UNIVERSAL tag value for GeneralString. + */ + public static final int GENERAL_STRING_TAG = 0x1B; + + /** + * Constructor for a GeneralString object. It sets the tag to the + * default value of UNIVERSAL 27 (0x1B). + * + * @param value The string value. + */ + public ASN1GeneralString(String value) { + super(value); + } + + /** + * Constructor for a GeneralString object from a primitive BER encoding. + * @param ber ber + * @param checkTag check tag + * @throws ASN1Exception if the BER encoding is incorrect. + */ + public ASN1GeneralString(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, false); + if (checkTag && (ber.tagGet() != GENERAL_STRING_TAG || ber.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + ber.tagGet() + + " expected " + GENERAL_STRING_TAG + "\n"); + } + } + + /** + * Encode with no explicit tag. + * + * @throws ASN1Exception if the BER encoding cannot be made. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, GENERAL_STRING_TAG); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1GeneralizedTime.java b/asn1/src/main/java/org/xbib/asn1/ASN1GeneralizedTime.java new file mode 100644 index 0000000..6316257 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1GeneralizedTime.java @@ -0,0 +1,51 @@ +package org.xbib.asn1; + +/** + * ASN.1 GeneralizedTime. + * The GeneralizedTime type denotes a string corrsponding + * to an ISO 8601 date string. + * This type is a string type. + */ +public final class ASN1GeneralizedTime extends ASN1VisibleString { + /** + * This constant is the UNIVERSAL tag value for GeneralizedTime. + */ + public static final int GENERALIZED_TIME_TAG = 0x18; + + /** + * Constructor for an GeneralizedTime object. It sets the tag to the + * default value of UNIVERSAL 24 (0x18). + * @param value value + */ + public ASN1GeneralizedTime(String value) { + super(value); + } + + /** + * Constructor for a GeneralizedTime object from a BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception if the BER encoding is incorrect. + */ + public ASN1GeneralizedTime(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, false); + if (checkTag && (ber.tagGet() != GENERALIZED_TIME_TAG || ber.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + ber.tagGet() + + " expected " + GENERALIZED_TIME_TAG + "\n"); + } + } + + /** + * Returns a BER encoding with no implicit tag. + * + * @return The BER encoding + * @throws ASN1Exception when the object is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, GENERALIZED_TIME_TAG); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1GraphicString.java b/asn1/src/main/java/org/xbib/asn1/ASN1GraphicString.java new file mode 100644 index 0000000..ff106b3 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1GraphicString.java @@ -0,0 +1,40 @@ +package org.xbib.asn1; + +/** + * ASN.1 GraphicString. + * The GraphicString type denotes an arbitary string + * of Graphic characters. + * This type is a string type. + */ +public class ASN1GraphicString extends ASN1OctetString { + /** + * This constant is the UNIVERSAL tag value for GraphicString. + */ + public static final int GRAPHIC_STRING_TAG = 0x19; + + /** + * Constructor for a GraphicString object. It sets the tag to the + * default value of UNIVERSAL 25 (0x19). + * + * @param value The string value + */ + + public ASN1GraphicString(String value) { + super(value); + } + + /** + * Constructor for a GraphicString object from a primitive BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception if the BER encoding is incorrect. + */ + public ASN1GraphicString(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, false); + if (checkTag && (ber.tagGet() != GRAPHIC_STRING_TAG || ber.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + ber.tagGet() + + " expected " + GRAPHIC_STRING_TAG + "\n"); + } + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1IA5String.java b/asn1/src/main/java/org/xbib/asn1/ASN1IA5String.java new file mode 100644 index 0000000..8e4cfed --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1IA5String.java @@ -0,0 +1,51 @@ +package org.xbib.asn1; + +/** + * Representation for ASN.1 IA5String. + * The IA5String type denotes an arbitary string of IA5 + * characters. IA5 stands for International Alphabet 5, which is + * the same as ASCII. The character set includes non-printing control + * characters. An IA5String can be of any length, including zero. + */ +public final class ASN1IA5String extends ASN1OctetString { + /** + * This constant is the ASN.1 UNIVERSAL tag value for IA5String. + */ + public static final int IA5_STRING_TAG = 0x16; + + /** + * Constructor for a IA5String object. It sets the tag to the + * default value of UNIVERSAL 22 (0x16). + * @param value value + */ + public ASN1IA5String(String value) { + super(value); + } + + /** + * Constructor for a IA5String object from a primitive BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1IA5String(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, false); + if (checkTag && (ber.tagGet() != IA5_STRING_TAG || ber.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + ber.tagGet() + + " expected " + IA5_STRING_TAG + "\n"); + } + } + + /** + * Returns a BER encoding with no implicit tag. + * + * @return The BER encoding + * @throws ASN1Exception when the object is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, IA5_STRING_TAG); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1Integer.java b/asn1/src/main/java/org/xbib/asn1/ASN1Integer.java new file mode 100644 index 0000000..e54a0a2 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1Integer.java @@ -0,0 +1,150 @@ +package org.xbib.asn1; + +/** + * Representation of an ASN.1 INTEGER. + * The INTEGER type denotes an arbitary integer. + * ASN.1 INTEGER values can be positive, negative, or zero; and can + * have any magnitude. + * The current implementation limits the values of INTEGERs to 32-bit + * two's complement values. + */ +public final class ASN1Integer extends ASN1Any { + /** + * This constant is the ASN.1 UNIVERSAL tag value for INTEGER. + */ + public static final int INTEGER_TAG = 0x02; + + /** + * The value of the INTEGER is stored in this variable. + * This is private for good information hiding, so that we are able + * to change its representation (e.g. to a long) at a later date + * without affecting the interface. + */ + private int value; + + /** + * Constructor for an ASN.1 INTEGER object. The tag is + * set to the default tag of UNIVERSAL 2, and the value to the + * given number. + * + * @param number the value of the INTEGER. + */ + public ASN1Integer(int number) { + value = number; + } + + /** + * Constructor for an ASN.1 INTEGER object from a BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1Integer(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Method for initializing the object from a BER encoding. + * + * @param berEncoding The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1EncodingException If the BER encoding is incorrect. + */ + @Override + public void berDecode(BEREncoding berEncoding, boolean checkTag) + throws ASN1EncodingException { + if (checkTag && (berEncoding.tagGet() != INTEGER_TAG || + berEncoding.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + berEncoding.tagGet() + + " expected " + INTEGER_TAG + "\n"); + } + if (!(berEncoding instanceof BERPrimitive)) { + throw new ASN1EncodingException("bad form, constructed"); + } + BERPrimitive ber = (BERPrimitive) berEncoding; + int[] encoding = ber.peek(); + if (encoding.length < 1) { + throw new ASN1EncodingException("invalid encoding, length = " + encoding.length); + } + value = (byte) encoding[0]; + for (int x = 1; x < encoding.length; x++) { + value <<= 8; + value |= (encoding[x] & 0xff); + } + } + + /** + * Returns a BER encoding of the INTEGER. + * + * @return The BER encoding of the INTEGER + * @throws ASN1Exception when the INTEGER is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, INTEGER_TAG); + } + + /** + * Returns a BER encoding of the INTEGER. Explicitly tagged with + * the supplied tag. + * + * @return The BER encoding of the INTEGER + * @throws ASN1Exception when the INTEGER is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int length = 0; + int shifted = value; + if (value < 0) { + shifted = ~value; + } + boolean needPad; + do { + needPad = (shifted & 0x80) == 0x80; + shifted >>= 8; + length++; + } while (shifted != 0); + if (needPad) { + length++; + } + int[] encoding = new int[length]; + int index = 0; + while (0 < length) { + encoding[index++] = (value >> (8 * (length - 1))) & 0xff; + length--; + } + return new BERPrimitive(tagType, tag, encoding); + } + + /** + * Method to set the integer's value. + * + * @param newVal the value to set the INTEGER to. + * @return the object. + */ + public ASN1Integer set(int newVal) { + value = newVal; + return this; + } + + /** + * Method to get the integer's value. + * + * @return the INTEGER's current value. + */ + + public int get() { + return value; + } + + /** + * Returns a new String object representing this ASN.1 object's value. + */ + @Override + public String toString() { + return String.valueOf(value); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1Null.java b/asn1/src/main/java/org/xbib/asn1/ASN1Null.java new file mode 100644 index 0000000..939e488 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1Null.java @@ -0,0 +1,85 @@ +package org.xbib.asn1; + +/** + * Representation of an ASN.1 NULL. + * This class represents a null value. A NULL is used + * when only the tag is of interest, and not any value. + */ +public final class ASN1Null extends ASN1Any { + /** + * This constant is the ASN.1 UNIVERSAL tag value for NULL. + */ + public static final int NULL_TAG = 0x05; + + /** + * Default constructor for an ASN.1 NULL object. The tag is set + * to the default tag of UNIVERSAL 5. A NULL has no value. + */ + public ASN1Null() { + // + } + + /** + * Constructor for an ASN.1 NULL object from a primitive BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1Null(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Method for initializing the object from a BER encoding. + * + * @param berEncoding The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1EncodingException If the BER encoding is incorrect. + */ + @Override + public void berDecode(BEREncoding berEncoding, boolean checkTag) + throws ASN1EncodingException { + if (checkTag && (berEncoding.tagGet() != NULL_TAG || + berEncoding.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + berEncoding.tagGet() + + " expected " + NULL_TAG + "\n"); + } + if (!(berEncoding instanceof BERPrimitive)) { + throw new ASN1EncodingException("bad form, constructed"); + } + } + + /** + * Returns a BER encoding of the NULL. + * + * @return The BER encoding of the NULL + * @throws ASN1Exception when the NULL is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, NULL_TAG); + } + + /** + * Returns a BER encoding of the NULL. + * + * @return The BER encoding of the NULL + * @throws ASN1Exception when the NULL is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int[] encoding = new int[0]; + return new BERPrimitive(tagType, tag, encoding); + } + + /** + * Returns a new String object representing this ASN.1 object's value. + */ + @Override + public String toString() { + return "null"; + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1NumericString.java b/asn1/src/main/java/org/xbib/asn1/ASN1NumericString.java new file mode 100644 index 0000000..62de801 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1NumericString.java @@ -0,0 +1,49 @@ +package org.xbib.asn1; + +/** + * Representation for an ASN.1 NumericString. + * The NumericString type denotes an arbitary string + * of Numeric characters (digits and space). + * This type is a string type. + */ +public class ASN1NumericString extends ASN1OctetString { + /** + * This constant is the ASN.1 UNIVERSAL tag value for NumericString. + */ + public static final int NUMERIC_STRING_TAG = 0x12; + + /** + * Constructor for an ASN.1 NumericString object. It sets the tag to the + * default value of UNIVERSAL 18 (0x12). + * @param value value + */ + public ASN1NumericString(String value) { + super(value); + } + + /** + * Constructor for a NumericString object from a primitive BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1NumericString(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, false); + if (checkTag && (ber.tagGet() != NUMERIC_STRING_TAG || ber.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + ber.tagGet() + + " expected " + NUMERIC_STRING_TAG + "\n"); + } + } + + /** + * Encodes the numeric string. + * + * @throws ASN1Exception if the BER encoding cannot be formed. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, NUMERIC_STRING_TAG); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1ObjectDescriptor.java b/asn1/src/main/java/org/xbib/asn1/ASN1ObjectDescriptor.java new file mode 100644 index 0000000..5062655 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1ObjectDescriptor.java @@ -0,0 +1,53 @@ +package org.xbib.asn1; + +/** + * Representation for an ASN.1 OBJECT DESCRIPTOR. + * The ASN.1 OBJECT DESCRIPTOR consists of a human-readable text + * which serves to describe an information object. + * According to clause 35.3 of the standard, + * ObjectDescriptor ::= [UNIVERSAL 7] IMPLICIT GraphicString + */ +public final class ASN1ObjectDescriptor extends ASN1GraphicString { + /** + * This constant is the UNIVERSAL tag value for ObjectDescriptor. + */ + public static final int OBJECT_DESCRIPTOR_TAG = 0x07; + + /** + * Constructor for an ObjectDescriptor object. It sets the tag to the + * default value of UNIVERSAL 7, and the descriptor to the given value. + * @param descriptor descriptor + */ + public ASN1ObjectDescriptor(String descriptor) { + super(descriptor); + } + + /** + * Constructor for a ObjectDescriptor object from a primitive BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception if the BER encoding is incorrect. + */ + public ASN1ObjectDescriptor(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, false); + if (checkTag && (ber.tagGet() != OBJECT_DESCRIPTOR_TAG || ber.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException + ("ASN.1 ObjectDescriptor: bad BER: tag=" + ber.tagGet() + + " expected " + OBJECT_DESCRIPTOR_TAG + "\n"); + } + } + + /** + * Returns a BER encoding with no implicit tag. + * + * @return The BER encoding + * @throws ASN1Exception when the object is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, OBJECT_DESCRIPTOR_TAG); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1ObjectIdentifier.java b/asn1/src/main/java/org/xbib/asn1/ASN1ObjectIdentifier.java new file mode 100644 index 0000000..81deae6 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1ObjectIdentifier.java @@ -0,0 +1,193 @@ +package org.xbib.asn1; + +/** + * Representation of an ASN.1 OBJECT IDENTIFIER. + * The OBJECT IDENTIFIER type denotes an object identifier, + * which is a sequence of integer components. An OBJECT IDENTIFIER can + * have any number of components, whch are generally non-negative. + * This type is a non-string type. + */ +public final class ASN1ObjectIdentifier extends ASN1Any { + /** + * This constant is the ASN.1 UNIVERSAL tag value for OBJECT IDENTIFIER. + */ + public static final int OBJECT_IDENTIFIER_TAG = 0x06; + + /** + * The components of the OBJECT IDENTIFER are stored in this + * variable as an array of integers. + */ + private int[] oid; + + /** + * Constructor for an ASN.1 OBJECT IDENTIFER object. The tag is set + * to the default tag of UNIVERSAL 6, and the given OID value. + * @param oidValue OID + */ + public ASN1ObjectIdentifier(int[] oidValue) { + oid = oidValue; + } + + /** + * Constructor for an ASN.1 OBJECT IDENTIFIER object from a BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1ObjectIdentifier(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Method for initializing the object from a BER encoding. + * + * @param berEncoding The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1EncodingException If the BER encoding cannot be decoded. + */ + @Override + public void berDecode(BEREncoding berEncoding, boolean checkTag) throws ASN1EncodingException { + if (checkTag && (berEncoding.tagGet() != OBJECT_IDENTIFIER_TAG || + berEncoding.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + berEncoding.tagGet() + + " expected " + OBJECT_IDENTIFIER_TAG + "\n"); + } + if (!(berEncoding instanceof BERPrimitive)) { + throw new ASN1EncodingException("bad form, constructed"); + } + BERPrimitive ber = (BERPrimitive) berEncoding; + int[] encoding = ber.peek(); + if (encoding.length < 2) { + throw new ASN1EncodingException("invalid encoding, length = " + + encoding.length); + } + int numComponents = 2; + for (int index = 1; index < encoding.length; index++) { + if ((encoding[index] & 0x80) == 0) { + numComponents++; + } + } + oid = new int[numComponents]; + oid[0] = encoding[0] / 40; + oid[1] = encoding[0] % 40; + int index = 1; + for (int component = 2; component < numComponents; component++) { + oid[component] = 0; + int octet; + do { + octet = encoding[index++]; + oid[component] <<= 7; + oid[component] |= (octet & 0x7f); + } while ((octet & 0x80) != 0); + } + } + + /** + * Returns a BER encoding of the OBJECT IDENTIFIER. + * The current implementation rejects negative OID components (should it?) + * + * @return The BER encoding of the OBJECT IDENTIFIER + * @throws ASN1Exception when the OBJECT IDENTIFIER is invalid + * and cannot be encoded. According to X.208, an OBJECT + * IDENTIFIER must have at least two components, the first + * has values of (0, 1, or 2) and the second between 0 and 39 + * inclusive. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, OBJECT_IDENTIFIER_TAG); + } + + /** + * Returns a BER encoding of the OBJECT IDENTIFIER. + * The current implementation rejects negative OID components. + * + * @return The BER encoding of the OBJECT IDENTIFIER + * @throws ASN1Exception when the OBJECT IDENTIFIER is invalid + * and cannot be encoded. According to X.208, an OBJECT + * IDENTIFIER must have at least two components, the first + * has values of (0, 1, or 2) and the second between 0 and 39 + * inclusive. + */ + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + if (oid.length < 2) { + throw new ASN1Exception("less than 2 components, violates X.208"); + } + if (oid[0] < 0 || 2 < oid[0]) { + throw new ASN1Exception("First component invalid, value = " + oid[0]); + } + if (oid[1] < 0 || 39 < oid[1]) { + throw new ASN1Exception("Second component invalid, value = " + oid[1]); + } + int numBytes = 1; + for (int index = 2; index < oid.length; index++) { + int tmpValue = oid[index]; + if (tmpValue < 0) { + throw new ASN1Exception("component " + (index + 1) + + " is negative, value = " + tmpValue); + } + do { + numBytes++; + tmpValue >>= 7; + } while (tmpValue != 0); + } + int[] octets = new int[numBytes]; + octets[0] = (40 * oid[0]) + oid[1]; + int bcount = 0; + for (int index = 2; index < oid.length; index++) { + int numberBytes = 0; + int tmpValue = oid[index]; + do { + numberBytes++; + tmpValue >>= 7; + } while (tmpValue != 0); + tmpValue = oid[index]; + for (int digit = numberBytes - 1; 0 <= digit; digit--) { + octets[++bcount] = (tmpValue >> (digit * 7)) & 0x7f; + if (digit != 0) { + octets[bcount] |= 0x80; + } + } + } + return new BERPrimitive(tagType, tag, octets); + } + + /** + * Method to set the OBJECT IDENTIFIER's value. + * + * @param newVal the value to set the OBJECT IDENTIFIER to. + * @return this object identifier + */ + public ASN1ObjectIdentifier set(int[] newVal) { + oid = newVal; + return this; + } + + /** + * Method to get the OBJECT IDENTIFIER's value. The returned value + * should not be modified in any way. + * + * @return the OBJECT IDENTIFIER's current value. + */ + public int[] get() { + return oid; + } + + /** + * Returns a new String object representing this ASN.1 object's value. + */ + @Override + public String toString() { + StringBuilder str = new StringBuilder(); + for (int index = 0; index < oid.length; index++) { + if (index != 0) { + str.append('.'); + } + str.append(String.valueOf(oid[index])); + } + return new String(str); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1OctetString.java b/asn1/src/main/java/org/xbib/asn1/ASN1OctetString.java new file mode 100644 index 0000000..c3cfe6b --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1OctetString.java @@ -0,0 +1,220 @@ +package org.xbib.asn1; + +import java.nio.charset.StandardCharsets; + +/** + * Representation of an ASN.1 OCTET STRING. + * This class is used to store an ASN.1 OCTET STRING which is an + * arbitary string of octets (eight-bit values). An OCTET STRING + * can have any length including zero. The type is a string type. + */ +public class ASN1OctetString extends ASN1Any { + + /** + * This constant is the ASN.1 UNIVERSAL tag value for OCTET STRING. + */ + public static final int OCTET_STRING_TAG = 0x04; + + private static final char[] oct = {'0', '1', '2', '3', '4', '5', '6', '7'}; + + private static final char[] hex = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f'}; + + /** + * The values of the OCTET STRING are stored in this string. Only + * the lower bytes are valid. + */ + + private byte[] octets; + + /** + * Constructor for an OCTET STRING object. The tag is set to the + * default of UNIVERSAL 4, and its value to the given bytes. + * @param data data + */ + public ASN1OctetString(byte[] data) { + octets = new byte[data.length]; + System.arraycopy(data, 0, octets, 0, data.length); + } + + /** + * Constructor for an OCTET STRING object. The tag is set to the + * default of UNIVERSAL 4, and its value to the lower bytes of the + * characters of the given string. + * @param str string + */ + public ASN1OctetString(String str) { + octets = str.getBytes(StandardCharsets.ISO_8859_1); + } + + /** + * Constructor for a OCTET STRING object from a primitive BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1OctetString(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Method for initializing the object from a BER encoding. + * + * @param berEncoding The BER encoding to use. + * @param checkTag If true, it checks the tag. Does nothing for ASN1Any. + * @throws ASN1EncodingException If the BER cannot be decoded. + */ + @Override + public void berDecode(BEREncoding berEncoding, boolean checkTag) + throws ASN1EncodingException { + if (checkTag && (berEncoding.tagGet() != OCTET_STRING_TAG || + berEncoding.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + berEncoding.tagGet() + + " expected " + OCTET_STRING_TAG + "\n"); + } + if (berEncoding instanceof BERPrimitive) { + BERPrimitive ber = (BERPrimitive) berEncoding; + int[] encoding = ber.peek(); + StringBuilder buf = new StringBuilder(encoding.length); + for (int anEncoding : encoding) { + buf.append((char) (anEncoding & 0x00ff)); + } + octets = buf.toString().getBytes(StandardCharsets.ISO_8859_1); + } else { + throw new ASN1EncodingException("decode from constructed NOT IMPLEMENTED YET"); + } + } + + /** + * Makes a BER encoding of the OCTET STRING. + * OCTET STRINGs can have a primitive encoding and a constructed + * encoding. This implemented performs the primitive encoding (which + * is the DER form). + * + * @return The BER encoding of the OCTET STRING + * @throws ASN1Exception when the OCTET STRING is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, OCTET_STRING_TAG); + } + + /** + * Makes a BER encoding of the OCTET STRING. + * OCTET STRINGs can have a primitive encoding and a constructed + * encoding. This implemented performs the primitive encoding (which + * is the DER form). + * + * @return The BER encoding of the OCTET STRING + * @throws ASN1Exception when the OCTET STRING is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int size = octets.length; + int[] encoding = new int[size]; + for (int index = 0; index < size; index++) { + encoding[index] = octets[index] & 0x00ff; + } + return new BERPrimitive(tagType, tag, encoding); + } + + /** + * Method to set the OCTET STRING's value. + * + * @param octetArray the value to set the OCTET STRING to. + * @return the object. + */ + public ASN1OctetString set(byte[] octetArray) { + octets = new byte[octetArray.length]; + System.arraycopy(octetArray, 0, octets, 0, octetArray.length); + return this; + } + + /** + * Method to set the OCTET STRING's value. + * + * @param str the value to set the OCTET STRING to. + * @return the object. + */ + public ASN1OctetString set(String str) { + octets = str.getBytes(StandardCharsets.ISO_8859_1); + return this; + } + + /** + * Method to get the OCTET STRING's value as a String. + * + * @return the OCTET STRING's current value. + */ + public String get() { + return new String(octets, StandardCharsets.ISO_8859_1); + } + + /** + * Method to get the OCTET STRING's value as an array of bytes. + * + * @return the OCTET STRING's current value. + */ + public byte[] getBytes() { + return octets; + } + + /** + * Returns a new String object representing this ASN.1 object's value. + */ + @Override + public String toString() { + int size = octets.length; + StringBuilder buf = new StringBuilder(32 + (size * 4)); + int printable = 0; + int binary = 0; + for (byte octet1 : octets) { + char octet = (char) octet1; + if ((' ' <= octet && octet <= '~') || octet == '\n') { + printable++; + } else { + binary++; + } + } + if (binary <= printable) { + buf.append('"'); + for (byte octet1 : octets) { + char octet = (char) octet1; + if (' ' <= octet && octet <= '~') { + if (octet == '\\' || octet == '"' || octet == '\'') { + buf.append('\\'); + } + buf.append(octet); + } else if (octet == '\n') { + buf.append("\\n"); + } else if (octet == '\t') { + buf.append("\\t"); + } else if (octet == '\r') { + buf.append("\\r"); + } else if (octet == '\b') { + buf.append("\\b"); + } else if (octet == '\f') { + buf.append("\\f"); + } else { + buf.append('\\'); + buf.append(oct[(octet >> 6) & 0x07]); + buf.append(oct[(octet >> 3) & 0x07]); + buf.append(oct[octet & 0x07]); + } + } + buf.append('"'); + } else { + buf.append('\''); + for (byte octet1 : octets) { + char octet = (char) octet1; + buf.append(hex[(octet >> 4) & 0x0f]); + buf.append(hex[octet & 0x0f]); + } + buf.append("'H"); + } + return buf.toString(); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1PrintableString.java b/asn1/src/main/java/org/xbib/asn1/ASN1PrintableString.java new file mode 100644 index 0000000..434eec0 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1PrintableString.java @@ -0,0 +1,57 @@ +package org.xbib.asn1; + +/** + * Representation for ASN.1 PrintableString. + * The PrintableString type denotes an arbitary string + * of printable characters from the following character set: + * + * + *
Printable Strings
Capital lettersA, B, ... , Z + *
Small lettersa, b, ..., z + *
Digits0, 1, ..., 9 + *
Space + *
Apostrophe' + *
Left partnthesis( + *
Right partnthesis) + *
Plus+ + *
comma, + *
hyphen- + *
Full stop. + *
Solidus/ + *
Colon: + *
Equal sign= + *
Question mark? + *
+ * This type is a string type. + */ +public final class ASN1PrintableString extends ASN1OctetString { + /** + * This constant is the ASN.1 UNIVERSAL tag value for PrintableString. + */ + public static final int PRINTABLE_STRING_TAG = 0x13; + + /** + * Constructor for a PrintableString object. It sets the tag to the + * default value of UNIVERSAL 19 (0x13). + * @param text text + */ + public ASN1PrintableString(String text) { + super(text); + } + + /** + * Constructor for a PrintableString object from a primitive BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1PrintableString(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, false); + if (checkTag && (ber.tagGet() != PRINTABLE_STRING_TAG || ber.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("ASN.1 PrintableString: bad BER: tag=" + ber.tagGet() + + " expected " + PRINTABLE_STRING_TAG + "\n"); + } + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1Sequence.java b/asn1/src/main/java/org/xbib/asn1/ASN1Sequence.java new file mode 100644 index 0000000..bb8823e --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1Sequence.java @@ -0,0 +1,138 @@ +package org.xbib.asn1; + +/** + * Representation of an ASN.1 SEQUENCE. + * The SEQUENCE type denotes an ordered collection + * of one or more types. The SEQUENCE OF type denotes an ordered + * collection of zero or more occurances of a given type. + * This class is available for the generic handling of ASN.1 + * definitions. However, specialised ASN.1 productions will usually + * use their own encoding for SEQUENCES directly. + */ +public final class ASN1Sequence extends ASN1Any { + /** + * This constant tag value is the ASN.1 UNIVERSAL tag value for + * a SEQUENCE or a SEQUENCE OF type. + */ + public static final int SEQUENCE_TAG = 0x10; + + /** + * The values of the SEQUENCE are stored in this array. + */ + + private ASN1Any[] elements; + + /** + * Default constructor for an ASN.1 SEQUENCE object. The tag is set + * to the default value. + * + * @param elementArray the ASN.1 objects that make up the sequence. + */ + + public ASN1Sequence(ASN1Any[] elementArray) { + elements = elementArray; + } + + /** + * Constructor for an ASN.1 SEQUENCE object from a BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1Sequence(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Method for initializing the object from a BER encoding. + * + * @param berEncoding The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + @Override + public void berDecode(BEREncoding berEncoding, boolean checkTag) + throws ASN1Exception { + if (checkTag && (berEncoding.tagGet() != SEQUENCE_TAG || berEncoding.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException + ("ASN.1 SEQUENCE: bad BER: tag=" + berEncoding.tagGet() + + " expected " + SEQUENCE_TAG + "\n"); + } + if (berEncoding instanceof BERPrimitive) { + throw new ASN1EncodingException("ASN.1 SEQUENCE: bad form, primitive"); + } + BERConstructed ber = (BERConstructed) berEncoding; + int len = ber.numberComponents(); + elements = new ASN1Any[len]; + for (int x = 0; x < len; x++) { + elements[x] = ASN1Decoder.toASN1(ber.elementAt(x)); + } + } + + /** + * Returns a BER encoding with no implicit tag. + * + * @return The BER encoding + * @throws ASN1Exception when the object is invalid and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of the SEQUENCE implcitly tagged. + * + * @param tagType The type of the implcit tag + * @param tag The implicit tag number + * @return The BER encoding of the SEQUENCE + * @throws ASN1Exception when the SEQUENCE is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int len = elements.length; + BEREncoding[] encodings = new BEREncoding[len]; + for (int index = 0; index < len; index++) { + encodings[index] = elements[index].berEncode(); + } + return new BERConstructed(tagType, tag, encodings); + } + + /** + * Method to set the SEQUENCE's elements. + * + * @param elementArray an array of ASN.1 object + * @return ASN.1 sequence + */ + public ASN1Sequence set(ASN1Any[] elementArray) { + elements = elementArray; + return this; + } + + /** + * Method to get the elements of the SEQUENCE. + * + * @return an array containing the SEQUENCE's elements. + */ + public ASN1Any[] get() { + return elements; + } + + /** + * Returns a new String object representing this ASN.1 object's value. + */ + @Override + public String toString() { + StringBuilder str = new StringBuilder("{"); + for (int index = 0; index < elements.length; index++) { + if (index != 0) { + str.append(", "); + } + str.append(elements[index].toString()); + } + str.append('}'); + return new String(str); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1Set.java b/asn1/src/main/java/org/xbib/asn1/ASN1Set.java new file mode 100644 index 0000000..b1ff076 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1Set.java @@ -0,0 +1,138 @@ +package org.xbib.asn1; + +/** + * Representation of an ASN.1 SET. + * The SET type denotes an ordered collection + * of one or more types. The SET OF type denotes an ordered + * collection of zero or more occurances of a given type. + * This class is available for the generic handling of ASN.1 + * definitions. However, specialised ASN.1 productions will usually + * use their own encoding for SETs directly. + * For DER encoding, DEFAULTs are not included and all the elements + * are sorted according to tag number. + */ +public final class ASN1Set extends ASN1Any { + /** + * This constant value is the ASN.1 UNIVERSAL tag value indicating + * a SET or a SET OF type. + */ + public static final int SET_TAG = 0x11; + + /** + * The values of the SET are stored in this array. + */ + + private ASN1Any[] elements; + + /** + * Constructor for an ASN.1 SET object. The tag is set to the + * default of UNIVERSAL 17 (0x11) and the elements to the given array. + * + * @param elementArray Elements in the set. + */ + public ASN1Set(ASN1Any[] elementArray) { + elements = elementArray; + } + + /** + * Constructor for a SET object from a BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1Set(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Method for initializing the object from a BER encoding. + * + * @param berEncoding The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + @Override + public void berDecode(BEREncoding berEncoding, boolean checkTag) + throws ASN1Exception { + if (checkTag && (berEncoding.tagGet() != SET_TAG || + berEncoding.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + berEncoding.tagGet() + + " expected " + SET_TAG + "\n"); + } + if (berEncoding instanceof BERPrimitive) { + throw new ASN1EncodingException("bad form, primitive"); + } + BERConstructed ber = (BERConstructed) berEncoding; + int len = ber.numberComponents(); + elements = new ASN1Any[len]; + for (int x = 0; x < len; x++) { + elements[x] = ASN1Decoder.toASN1(ber.elementAt(x)); + } + } + + /** + * Returns a BER encoding of the SET. + * + * @return The BER encoding of the SET + * @throws ASN1Exception when the SET is invalid and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, SET_TAG); + } + + /** + * Returns a BER encoding of the SET. + * + * @param tagType The type of the implcit tag + * @param tag The implicit tag number + * @return The BER encoding of the SET + * @throws ASN1Exception when the SET is invalid and cannot be encoded. + */ + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int len = elements.length; + BEREncoding[] encodings = new BEREncoding[len]; + for (int index = 0; index < len; index++) { + encodings[index] = elements[index].berEncode(); + } + return new BERConstructed(tagType, tag, encodings); + } + + /** + * Method to set the SET's elements. + * + * @param elementArray an array of ASN.1 objects. + */ + + public void set(ASN1Any[] elementArray) { + elements = elementArray; + } + + /** + * Method to get the elements of the SET. + * + * @return an array containing the SET's elements. + */ + + public ASN1Any[] get() { + return elements; + } + + /** + * Returns a new String object representing this ASN.1 object's value. + */ + @Override + public String toString() { + StringBuilder str = new StringBuilder("{"); + for (int index = 0; index < elements.length; index++) { + if (index != 0) { + str.append(", "); + } + str.append(elements[index].toString()); + } + str.append('}'); + return new String(str); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1T61String.java b/asn1/src/main/java/org/xbib/asn1/ASN1T61String.java new file mode 100644 index 0000000..c8e08e9 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1T61String.java @@ -0,0 +1,44 @@ +package org.xbib.asn1; + +/** + * Representation for ASN.1 T61String. + * The T61String type denotes an arbitary string + * of T.61 characters, or TeletextString. T.61 is an eight-bit extension + * to the ASCII character set. Special escape sequences specify the + * interpretation of subsequent character values (e.g. as + * Japanese rather than Latin). A T61String value can be of + * any length, including zero. This type is a string type. + */ +public final class ASN1T61String extends ASN1OctetString { + /** + * This constant is the UNIVERSAL tag value for T61String. + */ + public static final int T61_STRING_TAG = 0x14; + + /** + * Constructor for an T61String object. It sets the tag to the + * default value of UNIVERSAL 20 (0x14). + * + * @param value The string value. + */ + public ASN1T61String(String value) { + super(value); + } + + /** + * Constructor for a T61String object from a primitive BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1T61String(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, false); + if (checkTag && (ber.tagGet() != T61_STRING_TAG || ber.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException + ("ASN.1 T61String: bad BER: tag=" + ber.tagGet() + + " expected " + T61_STRING_TAG + "\n"); + } + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1UTCTime.java b/asn1/src/main/java/org/xbib/asn1/ASN1UTCTime.java new file mode 100644 index 0000000..b2b3500 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1UTCTime.java @@ -0,0 +1,62 @@ +package org.xbib.asn1; + +/** + * ASN.1 UTCTime. + * The UTCTime type denotes a "coordinated universal time" + * or Greenwich Mean Time (GMT) value. The value includes the local + * time precise to either minutes or seconds, and an offset from GMT + * in hours and minutes. + * It can take any of the following form: + * YYMMDDhhmmZ + * YYMMDDhhmm+hh'mm' + * YYMMDDhhmm-hh'mm' + * YYMMDDhhmmssZ + * YYMMDDhhmmss+hh'mm' + * YYMMDDhhmmss-hh'mm' + * YYMMDDhhmmZ + * YYMMDDhhmmZ + */ +public final class ASN1UTCTime extends ASN1VisibleString { + /** + * This constant is the UNIVERSAL tag value for UTCTime. + */ + public static final int UTC_TIME_TAG = 0x17; + + /** + * Constructor for an UTCTime object. It sets the tag to the + * default value of UNIVERSAL 23 (0x17). + * + * @param value The string value. + */ + public ASN1UTCTime(String value) { + super(value); + } + + /** + * Constructor for a UTCTime object from a BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1UTCTime(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, false); + if (checkTag && (ber.tagGet() != UTC_TIME_TAG || ber.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException + ("ASN.1 UTCTime: bad BER: tag=" + ber.tagGet() + + " expected " + UTC_TIME_TAG + "\n"); + } + } + + /** + * Returns a BER encoding with no implicit tag. + * + * @return The BER encoding + * @throws ASN1Exception when the object is invalid and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, UTC_TIME_TAG); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1VideotexString.java b/asn1/src/main/java/org/xbib/asn1/ASN1VideotexString.java new file mode 100644 index 0000000..eea4112 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1VideotexString.java @@ -0,0 +1,51 @@ +package org.xbib.asn1; + +/** + * Representation for an ASN.1 VideotexString. + * The VideotexString type denotes an arbitary string + * of Videotex characters. + * This type is a string type. + */ +public class ASN1VideotexString extends ASN1OctetString { + /** + * This constant is the ASN.1 UNIVERSAL tag value for VideotexString. + */ + public static final int VIDEOTEX_STRING_TAG = 0x15; + + /** + * Constructor for an ASN.1 VideotexString object. It sets the tag to the + * default value of UNIVERSAL 15 (0x21). + * @param value value + */ + public ASN1VideotexString(String value) { + super(value); + } + + /** + * Constructor for a VideotexString object from a primitive BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + public ASN1VideotexString(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, false); + if (checkTag && (ber.tagGet() != VIDEOTEX_STRING_TAG || ber.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + ber.tagGet() + + " expected " + VIDEOTEX_STRING_TAG + "\n"); + } + } + + /** + * Returns a BER encoding with no implicit tag. + * + * @return The BER encoding + * @throws ASN1Exception when the object is invalid + * and cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, VIDEOTEX_STRING_TAG); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/ASN1VisibleString.java b/asn1/src/main/java/org/xbib/asn1/ASN1VisibleString.java new file mode 100644 index 0000000..5ccf849 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/ASN1VisibleString.java @@ -0,0 +1,52 @@ +package org.xbib.asn1; + +/** + * ASN.1 VisibleString. + * The VisibleString type denotes an arbitary string + * of Visible characters. It is also known as ISO646String, or + * InternationalString. + * This type is a string type. + */ +public class ASN1VisibleString extends ASN1OctetString { + /** + * This constant is the ASN.1 UNIVERSAL tag value for VisibleString. + */ + public static final int TAG = 0x1a; + + /** + * Constructor for a VisibleString object. It sets the tag to the + * default value of UNIVERSAL 26 (0x1a). + * @param value value + */ + public ASN1VisibleString(String value) { + super(value); + } + + /** + * Constructor for a VisibleString object from a primitive BER encoding. + * + * @param ber The BER encoding to use. + * @param checkTag If true, it checks the tag. Use false if is implicitly tagged. + * @throws ASN1Exception If the BER encoding is incorrect. + */ + + public ASN1VisibleString(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, false); + if (checkTag && (ber.tagGet() != TAG || ber.tagTypeGet() != BEREncoding.UNIVERSAL_TAG)) { + throw new ASN1EncodingException("bad BER: tag=" + ber.tagGet() + + " expected " + TAG + "\n"); + } + } + + /** + * Encode with no explicit tag. + * + * @return The BER encoding + * @throws ASN1Exception If the BER encoding is incorrect. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, TAG); + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/BERConstructed.java b/asn1/src/main/java/org/xbib/asn1/BERConstructed.java new file mode 100644 index 0000000..14d8498 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/BERConstructed.java @@ -0,0 +1,122 @@ +package org.xbib.asn1; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * BERConstructed. + * This class represents a BER encoded ASN.1 object which is + * constructed from component BER encodings. + * Generally it is used to store the BER encoding of constructed types + * (i.e. SEQUENCE, SEQUENCE OF, SET, and SET OF) The end-of-content + * octets, if required, must be added to the end of the elements by + * the creator. + */ +public class BERConstructed extends BEREncoding { + + private BEREncoding[] contentElements; + + /** + * Constructor for a non-primitive BEREncoding. + * + * @param asn1Class The tag type. + * @param tag The tag number. + * @param elements The components making up the constructed BER. + * @throws ASN1Exception If tag or tag type is invalid + * @see org.xbib.asn1.BEREncoding#UNIVERSAL_TAG + * @see org.xbib.asn1.BEREncoding#APPLICATION_TAG + * @see org.xbib.asn1.BEREncoding#CONTEXT_SPECIFIC_TAG + * @see org.xbib.asn1.BEREncoding#PRIVATE_TAG + */ + public BERConstructed(int asn1Class, int tag, BEREncoding[] elements) + throws ASN1Exception { + int contentLength = 0; + for (BEREncoding element : elements) { + contentLength += element.iTotalLength; + } + init(asn1Class, true, tag, contentLength); + contentElements = elements; + } + + /** + * This method outputs the encoded octets for this object + * to the output stream. + * Note: the output is not flushed, so you must explicitly + * flush the output stream after calling this method to ensure that + * the data has been written out. + * + * @param dest OutputStream to write encoding to. + */ + @Override + public void output(OutputStream dest) throws IOException { + outputHead(dest); + for (BEREncoding contentElement : contentElements) { + contentElement.output(dest); + } + } + + /** + * This method returns the number of BER encoded elements that this + * object is made up of to be returned. + * @return integer + */ + public int numberComponents() { + return contentElements.length; + } + + /** + * This method allows the elements of the BER encoding to be examined. + * + * @param index - the index of the BER object required, + * it must be in the range, [0, numberComponents() - 1] + * @return BER encoding + */ + public BEREncoding elementAt(int index) { + return contentElements[index]; + } + + /** + * Returns a new String object representing this ASN.1 object's value. + */ + @Override + public String toString() { + StringBuilder str = new StringBuilder("["); + switch (iTagType) { + case BEREncoding.UNIVERSAL_TAG: + str.append("UNIVERSAL "); + break; + case BEREncoding.APPLICATION_TAG: + str.append("APPLICATION "); + break; + case BEREncoding.CONTEXT_SPECIFIC_TAG: + str.append("CONTEXT SPECIFIC "); + break; + case BEREncoding.PRIVATE_TAG: + str.append("PRIVATE "); + break; + default: + break; + } + str.append(String.valueOf(iTag)).append("]{"); + for (int x = 0; x < contentElements.length; x++) { + if (x != 0) { + str.append(','); + } + str.append(contentElements[x].toString()); + } + str.append('}'); + return new String(str); + } + + /** + * This protected method is used to implement the "get_encoding" method. + */ + @Override + protected int iEncodingGet(int offset, byte[] data) { + int i = iGetHead(offset, data); + for (BEREncoding contentElement : contentElements) { + i = contentElement.iEncodingGet(i, data); + } + return i; + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/BEREncoding.java b/asn1/src/main/java/org/xbib/asn1/BEREncoding.java new file mode 100644 index 0000000..7a4d6b2 --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/BEREncoding.java @@ -0,0 +1,424 @@ +package org.xbib.asn1; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * This class represents a BER (Basic Encoding Rules) encoded ASN.1 object. + * This is an abstract base class from which there are two specific + * representations are used: primitive and constructed. This superclass + * is tightly coupled with its subclasses BERPrimitive and BERConstructed. + * The BER encoding is described in + * Information technology - + * Open Systems Interconnection - + * Specification of basic encoding rules for Abstract Syntax Notation + * One (ASN.1) + * AS 3626-1991 + * ISO/IEC 8825:1990 + * + * @see org.xbib.asn1.BERPrimitive + * @see org.xbib.asn1.BERConstructed + */ +public abstract class BEREncoding { + + private static final String ERROR = "Unexpected end in BER encoding"; + + /** + * Constant for indicating UNIVERSAL tag type. The value matches + * the BER bit encoding. Universal tags are for types defined in + * the ASN.1 standard. + */ + public static final int UNIVERSAL_TAG = 0x00; + + /** + * Constant for indicating APPLICATION tag type. The value matches + * the BER bit encoding. APPLICATION tags are globally unique to an + * application. + */ + public static final int APPLICATION_TAG = 0x40; + + /** + * Constant for indicating CONTEXT SPECIFIC tag type. The value matches + * the BER bit encoding. CONTEXT SPECIFIC tags are used in applications, + * but do not have to be globally unique. + */ + public static final int CONTEXT_SPECIFIC_TAG = 0x80; + + /** + * Constant for indicating PRIVATE tag type. The value matches + * the BER bit encoding. + */ + public static final int PRIVATE_TAG = 0xC0; + + private static final int MAX_BER_SIZE = 65536 * 4; + /** + * The tag type of this BER encoded object. This value must be + * the same as that encoded in the identiferEncoding. + * This is an internal member. You should not use this. + */ + protected int iTagType; + /** + * The tag number of this BER encoded object. This value must be + * the same as that encoded in the identiferEncoding. + * This is an internal member. You should not use this. + */ + protected int iTag; + /** + * The total length of this BER object (the identifier octets, plus + * length octets, plus content octects). This variable must be + * set up before this object is used (using the init method). + * This is an internal member. You should not use this. + */ + protected int iTotalLength; + /** + * Storage for the identifier octets. This variable is set up by + * calling the make_identifer method. + * The octets are internally stored as int[] for efficiency over byte[]. + */ + private int[] identifierEncoding; + /** + * Storage for the length encoding octets. This will be set up by + * calling the makeLength method. + * The octets are internally stored as int[] for efficiency over byte[]. + */ + private int[] lengthEncoding; + + /** + * The public wrapping for doInput() method. + * + * @param inputStream the InputStream to read the raw BER from. + * @return Returns the next complete BEREncoding object read + * in from the input stream. Returns null if the + * end has been reached. + * @throws ASN1Exception If data does not represent a BER encoding + * @throws IOException On input I/O error + */ + public static BEREncoding input(InputStream inputStream) throws IOException { + int[] numBytesRead = new int[1]; + numBytesRead[0] = 0; + return doInput(inputStream, numBytesRead); + } + + /** + * Constructs a complete BER encoding object from octets read in from + * an InputStream. + * This routine handles all forms of encoding, including the + * indefite-length method. The length is always known with this + * class. With indefinite-length encodings, + * the end-of-contents octets are not included in the returned + * object (i.e. the returned the raw BER is converted to an object + * which is in the definite-length form). + * + * @param numBytesRead a counter for all read bytes. + * @param inputStream the InputStream to read the raw BER from. + * @return the next complete BEREncoding object read + * in from the input stream. Returns null if the + * end has been reached. + * @throws IOException If data does not represent a BER encoding or input I/O error + */ + protected static BEREncoding doInput(InputStream inputStream, int[] numBytesRead) throws IOException { + int octet = inputStream.read(); + if (octet < 0) { + return null; + } + numBytesRead[0]++; + int tagType = octet & 0xC0; + boolean isCons = false; + if ((octet & 0x20) != 0) { + isCons = true; + } + int tag = octet & 0x1F; + if (tag == 0x1F) { + tag = 0; + do { + octet = inputStream.read(); + if (octet < 0) { + throw new ASN1EncodingException(ERROR); + } + numBytesRead[0]++; + tag <<= 7; + tag |= (octet & 0x7F); + } while ((octet & 0x80) != 0); + } + int length; + octet = inputStream.read(); + if (octet < 0) { + throw new ASN1EncodingException(ERROR); + } + numBytesRead[0]++; + if ((octet & 0x80) != 0) { + if ((octet & 0x7f) == 0) { + length = -1; + if (!isCons) { + throw new ASN1EncodingException("BER encoding corrupted primitive"); + } + } else { + if (4 < (octet & 0x7f)) { + throw new ASN1EncodingException("BER encoding too long"); + } + length = 0; + for (int numBytes = octet & 0x7f; 0 < numBytes; numBytes--) { + octet = inputStream.read(); + if (octet < 0) { + throw new ASN1EncodingException(ERROR); + } + numBytesRead[0]++; + length <<= 8; + length |= (octet & 0xff); + } + if (length < 0 || MAX_BER_SIZE < length) { + throw new ASN1EncodingException("BER encoding too long"); + } + } + } else { + length = octet & 0x7F; + } + if (!isCons) { + int[] contents = new int[length]; + for (int x = 0; x < length; x++) { + octet = inputStream.read(); + if (octet < 0) { + throw new ASN1EncodingException(ERROR); + } + numBytesRead[0]++; + contents[x] = octet; + } + return new BERPrimitive(tagType, tag, contents); + } else { + List chunks = new ArrayList<>(); + int totalRead = 0; + if (0 <= length) { + while (totalRead < length) { + int currentRead = numBytesRead[0]; + BEREncoding chunk = BEREncoding.doInput(inputStream, numBytesRead); + if (chunk == null) { + throw new ASN1EncodingException(ERROR); + } + chunks.add(chunk); + totalRead += numBytesRead[0] - currentRead; + } + } else { + while (true) { + BEREncoding chunk = BEREncoding.doInput(inputStream, numBytesRead); + if (chunk == null) { + throw new ASN1EncodingException(ERROR); + } + if (chunk.iTag == 0 && chunk.iTagType == BEREncoding.UNIVERSAL_TAG && chunk.iTotalLength == 2) { + break; + } else { + chunks.add(chunk); + } + } + } + int numElements = chunks.size(); + BEREncoding[] parts = new BEREncoding[numElements]; + for (int x = 0; x < numElements; x++) { + parts[x] = chunks.get(x); + } + return new BERConstructed(tagType, tag, parts); + } + } + + /** + * Outputs the BER object to an OutputStream. This method should work + * with any OutputStream, whether it is from a socket, file, etc. + * Note: the output is not flushed, so you must explicitly + * flush the output stream after calling this method to ensure that + * the data has been written out. + * + * @param dest - the OutputStream to write the encoding to. + * @throws IOException On output I/O error + */ + public abstract void output(OutputStream dest) throws IOException; + + /** + * Returns the BER encoded object as an array of bytes. This routine + * may be of use if you want to use the encoding rather than sending + * it off. If you want to just output it, it is more efficient to + * use the output method. + * @return byte array + */ + public byte[] encodingGet() { + byte[] result = new byte[iTotalLength]; + iEncodingGet(0, result); + return result; + } + + /** + * Method to examine the tag type of the BER encoded ASN.1 object. + * @return integer + */ + public int tagTypeGet() { + return iTagType; + } + + /** + * Method to examine the tag number of the BER encoded ASN.1 object. + * @return integer + */ + public int tagGet() { + return iTag; + } + + /** + * Returns the total number of bytes the encoding occupies. + * @return integer + */ + public int totalLength() { + return iTotalLength; + } + + /** + * This is the initialization method used by the subclasses. + * The length must be the total length of the encoding of the + * contents (i.e. not including the identifier or length encodings). + * + * @param tagType The tag type. + * @param isConstructed True if constructed, or false if primitive. + * @param tag The tag number. + * @param length length + * @throws ASN1Exception if tag or tag type is invalid + */ + protected void init(int tagType, boolean isConstructed, int tag, int length) + throws ASN1Exception { + makeIdentifier(tagType, isConstructed, tag); + makeLength(length); + iTotalLength = identifierEncoding.length + lengthEncoding.length + length; + } + + /* + * This is a protected routine used for outputting an array of + * integers, interpreted as bytes, to an OutputStream. It is used + * by the superclasses to implement the "output" method. + */ + protected void outputBytes(int[] data, OutputStream dest) throws IOException { + for (int aData : data) { + dest.write(aData); + } + } + + /* + * This is a protected method used to output the encoded identifier + * and length octets to an OutputStream. It is used by the superclasses + * to implement the "output" method. + */ + protected void outputHead(OutputStream dest) throws IOException { + outputBytes(identifierEncoding, dest); + outputBytes(lengthEncoding, dest); + } + + /* + * Internal protected method fills in the data array (starting from index + * position offset) with the encoding for the identifier and length. + * This is used by the superclasses to implement the "encodingGet" + * method. + */ + protected int iGetHead(int offset, byte[] data) { + for (int anIdentifierEncoding : identifierEncoding) { + data[offset++] = (byte) anIdentifierEncoding; + } + for (int aLengthEncoding : lengthEncoding) { + data[offset++] = (byte) aLengthEncoding; + } + return offset; + } + + /* + * This is an abstract method used for implementing the "getEncoding" + * method. This method places the bytes of the encoding into the data + * array (as bytes), starting at offset into the array. The + * offset of the last element used plus one is returned. + */ + protected abstract int iEncodingGet(int offset, byte[] data); + + /** + * This private method encodes the identifier octets. When a BER + * object is created, this method should be used to set up the encoding + * of the identifier, called via the "init" method. + * This method sets the internal variables "iTagType" and "iTag" + * so this object can be queried for the tag type and tag value without + * needing to decode them from the encoding octets. + * + * @param tagType is the tag type of the object, which + * must be one of the special value defined in ASN1_Any + * @param isConstructed is a boolean flag: true indicating the + * contents is constructed, or false indicating it is primitive. + * @param tag is the value of the tag, which must be non-negative. + * @throws ASN1Exception when the tagType is improper, or + * the tag value is negative. + */ + private void makeIdentifier(int tagType, boolean isConstructed, int tag) + throws ASN1Exception { + int b; + if ((tagType & ~0x00C0) != 0) { + throw new ASN1Exception("Invalid ASN.1 tag type"); + } + if (tag < 0) { + throw new ASN1Exception("ASN.1 tag value is negative"); + } + iTagType = tagType & 0xC0; + b = iTagType; + if (isConstructed) { + b |= 0x20; + } + iTag = tag; + if (tag <= 30) { + b |= (tag & 0x1F); + identifierEncoding = new int[1]; + identifierEncoding[0] = b; + } else { + b |= 0x1F; + int numberBytes = 1; + int tmpTag = tag; + do { + numberBytes++; + tmpTag >>= 7; + } while (tmpTag != 0); + identifierEncoding = new int[numberBytes]; + identifierEncoding[0] = b; + int index = 0; + for (int digit = numberBytes - 2; 0 <= digit; digit--) { + identifierEncoding[++index] = (tag >> (digit * 7)) & 0x7f; + if (digit != 0) { + identifierEncoding[index] |= 0x80; + } + } + } + } + + /** + * This private method encodes the length octets. When a BER object + * is created, this method should be used to set up the encoding + * of the identifier. It should be used by calling the "init" method. + * + * @param length is the length value to be encoded. A negative + * value indicates an "indefinite length". + */ + private void makeLength(int length) { + if (length < 0) { + lengthEncoding = new int[1]; + lengthEncoding[0] = 0x80; + } else if (length < 128) { + lengthEncoding = new int[1]; + lengthEncoding[0] = length; + } else { + int count = 0; + int shifted = length; + while (shifted != 0) { + count++; + shifted >>= 8; + } + lengthEncoding = new int[count + 1]; + lengthEncoding[0] = count | 0x80; + int index = 0; + while (0 < count) { + count--; + int digit = (length >> (count * 8)) & 0xff; + lengthEncoding[++index] = digit; + } + } + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/BERPrimitive.java b/asn1/src/main/java/org/xbib/asn1/BERPrimitive.java new file mode 100644 index 0000000..c86b47b --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/BERPrimitive.java @@ -0,0 +1,113 @@ +package org.xbib.asn1; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * This class represents a primitive ASN.1 object encoded + * according to the Basic Encoding Rules. + * Information technology - + * Open Systems Interconnection - + * Specification of basic encoding rules for Abstract Syntax Notation + * One (ASN.1) + * AS 3626-1991 + * ISO/IEC 8825:1990 + * + * @see org.xbib.asn1.BEREncoding + */ +public class BERPrimitive extends BEREncoding { + + private static final char[] hex = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f'}; + + /** + * The octets of the encoding are stored in this array. + * They are internally stored as int[] for efficiency over byte[]. + */ + + private int[] contentsOctets; + + /** + * Constructor. + * Note that the contents is int[] because this is the internal + * representation, which can only be used by the ASN.1 standard object + * classes. It is not intended that higher level classes create + * BERPrimitives directly. + * + * @see org.xbib.asn1.BEREncoding#UNIVERSAL_TAG + * @see org.xbib.asn1.BEREncoding#APPLICATION_TAG + * @see org.xbib.asn1.BEREncoding#CONTEXT_SPECIFIC_TAG + * @see org.xbib.asn1.BEREncoding#PRIVATE_TAG + */ + BERPrimitive(int asn1Class, int tag, int[] contents) + throws ASN1Exception { + init(asn1Class, false, tag, contents.length); + contentsOctets = contents; + } + + /** + * This method allows the content octets to be examined. + * Once again, only the ASN.1 standard objects should be using this. + */ + int[] peek() { + return contentsOctets; + } + + /** + * This method outputs the encoded octets to the destination OutputStream. + * Note: the output is not flushed, so you must explicitly + * flush the output stream after calling this method to ensure that + * the data has been written out. + * + * @param dest - OutputStream to write encoding to. + */ + @Override + public void output(OutputStream dest) throws IOException { + outputHead(dest); + outputBytes(contentsOctets, dest); + } + + /** + * Returns a new String object representing this BER encoded + * ASN.1 object's value. + */ + @Override + public String toString() { + StringBuilder str = new StringBuilder("["); + switch (iTagType) { + case BEREncoding.UNIVERSAL_TAG: + str.append("UNIVERSAL "); + break; + case BEREncoding.APPLICATION_TAG: + str.append("APPLICATION "); + break; + case BEREncoding.CONTEXT_SPECIFIC_TAG: + str.append("CONTEXT SPECIFIC "); + break; + case BEREncoding.PRIVATE_TAG: + str.append("PRIVATE "); + break; + default: + break; + } + str.append(String.valueOf(iTag)).append("] '"); + for (int octet : contentsOctets) { + str.append(hex[(octet >> 4) & 0x0f]); + str.append(hex[octet & 0x0f]); + } + str.append("'H"); + return str.toString(); + } + + /** + * This protected method is used to implement the "get_encoding" method. + */ + @Override + protected int iEncodingGet(int offset, byte[] data) { + int i = iGetHead(offset, data); + for (int contentsOctet : contentsOctets) { + data[i++] = (byte) contentsOctet; + } + return i; + } +} diff --git a/asn1/src/main/java/org/xbib/asn1/package-info.java b/asn1/src/main/java/org/xbib/asn1/package-info.java new file mode 100644 index 0000000..139e5aa --- /dev/null +++ b/asn1/src/main/java/org/xbib/asn1/package-info.java @@ -0,0 +1,4 @@ +/** + * Classes for ASN.1. + */ +package org.xbib.asn1; diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..5733733 --- /dev/null +++ b/build.gradle @@ -0,0 +1,80 @@ +plugins { + id "org.sonarqube" version '2.5' + id "io.codearte.nexus-staging" version "0.7.0" +} + +printf "Host: %s\nOS: %s %s %s\nJVM: %s %s %s %s\nGroovy: %s\nGradle: %s\n" + + "Build: group: ${project.group} name: ${project.name} version: ${project.version}\n", + InetAddress.getLocalHost(), + System.getProperty("os.name"), + System.getProperty("os.arch"), + System.getProperty("os.version"), + System.getProperty("java.version"), + System.getProperty("java.vm.version"), + System.getProperty("java.vm.vendor"), + System.getProperty("java.vm.name"), + GroovySystem.getVersion(), + gradle.gradleVersion + + +subprojects { + apply plugin: 'java' + apply plugin: 'maven' + apply plugin: 'signing' + apply plugin: 'findbugs' + apply plugin: 'pmd' + apply plugin: 'checkstyle' + apply plugin: 'jacoco' + + repositories { + mavenCentral() + } + + configurations { + wagon + } + + dependencies { + testCompile 'junit:junit:4.12' + wagon 'org.apache.maven.wagon:wagon-ssh:2.12' + } + + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + + [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' + tasks.withType(JavaCompile) { + options.compilerArgs << "-Xlint:all,-fallthrough" << "-profile" << "compact1" + } + + clean { + delete 'out' + } + + test { + testLogging { + showStandardStreams = false + exceptionFormat = 'full' + } + } + + task sourcesJar(type: Jar, dependsOn: classes) { + classifier 'sources' + from sourceSets.main.allSource + } + task javadocJar(type: Jar, dependsOn: javadoc) { + classifier 'javadoc' + } + artifacts { + archives sourcesJar, javadocJar + } + if (project.hasProperty('signing.keyId')) { + signing { + sign configurations.archives + } + } + + apply from: "${rootProject.projectDir}/gradle/ext.gradle" + apply from: "${rootProject.projectDir}/gradle/publish.gradle" + apply from: "${rootProject.projectDir}/gradle/sonarqube.gradle" +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000..52fe33c --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,323 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml new file mode 100644 index 0000000..9b7e458 --- /dev/null +++ b/config/checkstyle/suppressions.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..1c8dc02 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,5 @@ +group = org.xbib +name = z3950 +version = 1.0.0 + +xbib-cql.version = 1.1.0 diff --git a/gradle/ext.gradle b/gradle/ext.gradle new file mode 100644 index 0000000..23349ac --- /dev/null +++ b/gradle/ext.gradle @@ -0,0 +1,8 @@ +ext { + user = 'xbib' + projectName = 'z3950' + projectDescription = 'Z39.50 for Java' + scmUrl = 'https://github.com/xbib/z3950' + scmConnection = 'scm:git:git://github.com/xbib/z3950.git' + scmDeveloperConnection = 'scm:git:git://github.com/xbib/z3950.git' +} diff --git a/gradle/publish.gradle b/gradle/publish.gradle new file mode 100644 index 0000000..9e1750d --- /dev/null +++ b/gradle/publish.gradle @@ -0,0 +1,70 @@ + +task xbibUpload(type: Upload, dependsOn: build) { + configuration = configurations.archives + uploadDescriptor = true + repositories { + if (project.hasProperty('xbibUsername')) { + mavenDeployer { + configuration = configurations.wagon + repository(url: uri('sftp://xbib.org/repository')) { + authentication(userName: xbibUsername, privateKey: xbibPrivateKey) + } + } + } + } +} + +task sonatypeUpload(type: Upload, dependsOn: build) { + configuration = configurations.archives + uploadDescriptor = true + repositories { + if (project.hasProperty('ossrhUsername')) { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + repository(url: uri(ossrhReleaseUrl)) { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + snapshotRepository(url: uri(ossrhSnapshotUrl)) { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + pom.project { + groupId project.group + artifactId project.name + version project.version + name project.name + description projectDescription + packaging 'jar' + inceptionYear '2017' + url scmUrl + organization { + name 'xbib' + url 'http://xbib.org' + } + developers { + developer { + id user + name 'Jörg Prante' + email 'joergprante@gmail.com' + url 'https://github.com/jprante' + } + } + scm { + url scmUrl + connection scmConnection + developerConnection scmDeveloperConnection + } + licenses { + license { + name 'The Apache License, Version 2.0' + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + } + } + } + } +} + +nexusStaging { + packageGroup = "org.xbib" +} diff --git a/gradle/sonarqube.gradle b/gradle/sonarqube.gradle new file mode 100644 index 0000000..df61702 --- /dev/null +++ b/gradle/sonarqube.gradle @@ -0,0 +1,40 @@ +tasks.withType(FindBugs) { + ignoreFailures = true + reports { + xml.enabled = false + html.enabled = true + } +} +tasks.withType(Pmd) { + ignoreFailures = true + reports { + xml.enabled = true + html.enabled = true + } +} +tasks.withType(Checkstyle) { + ignoreFailures = true + exclude '**/PQF*java' + reports { + xml.enabled = true + html.enabled = true + } +} + +jacocoTestReport { + reports { + xml.enabled = true + csv.enabled = false + } +} + +sonarqube { + properties { + property "sonar.projectName", "${project.group} ${project.name}" + property "sonar.sourceEncoding", "UTF-8" + property "sonar.tests", "src/test/java" + property "sonar.scm.provider", "git" + property "sonar.java.coveragePlugin", "jacoco" + property "sonar.junit.reportsPath", "build/test-results/test/" + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..736fb7d3f94c051b359fc7ae7212d351bc094bdd GIT binary patch literal 54708 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 ZypaY2tb=~UE;0eV1Nd9`dw%@&{{Y^v%e4Ri literal 0 HcmV?d00001 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..6468729 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Oct 09 13:24:07 CEST 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..e95643d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..dba40c7 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,4 @@ +rootProject.name = name + +include 'asn1' +include 'z3950' diff --git a/z3950/build.gradle b/z3950/build.gradle new file mode 100644 index 0000000..4e9d481 --- /dev/null +++ b/z3950/build.gradle @@ -0,0 +1,9 @@ +plugins { + id 'org.xbib.gradle.plugin.jflex' version '1.1.0' + id 'org.xbib.gradle.plugin.jacc' version '1.1.3' +} + +dependencies { + compile project(':asn1') + compile "org.xbib:cql:${project.property('xbib-cql.version')}" +} diff --git a/z3950/config/checkstyle/checkstyle.xml b/z3950/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000..55e59d2 --- /dev/null +++ b/z3950/config/checkstyle/checkstyle.xml @@ -0,0 +1,323 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/z3950/config/maven/repo-settings.xml b/z3950/config/maven/repo-settings.xml new file mode 100644 index 0000000..5968882 --- /dev/null +++ b/z3950/config/maven/repo-settings.xml @@ -0,0 +1,24 @@ + + ~/.m2/repository + + xbib + + + + xbib + + + xbib + http://xbib.org/repository + + true + always + + + true + + + + + + \ No newline at end of file diff --git a/z3950/src/main/jacc/org/xbib/io/iso23950/pqf/PQF.jacc b/z3950/src/main/jacc/org/xbib/io/iso23950/pqf/PQF.jacc new file mode 100755 index 0000000..be8fb94 --- /dev/null +++ b/z3950/src/main/jacc/org/xbib/io/iso23950/pqf/PQF.jacc @@ -0,0 +1 @@ +%{ import java.io.Reader; import java.io.IOException; /** Mike Taylor, IndexData: "Prefix Query Format (PQF), also known as Prefix Query Notation (PQN) was defined in 1995, as part of the YAZ toolkit, and has since become the de facto standard representation of RPN queries." From: http://www.indexdata.com/yaz/doc/tools.tkl#PQF The grammar of the PQF is as follows: query ::= top-set query-struct. top-set ::= [ '@attrset' string ] query-struct ::= attr-spec | simple | complex | '@term' term-type query attr-spec ::= '@attr' [ string ] string query-struct complex ::= operator query-struct query-struct. operator ::= '@and' | '@or' | '@not' | '@prox' proximity. simple ::= result-set | term. result-set ::= '@set' string. term ::= string. proximity ::= exclusion distance ordered relation which-code unit-code. exclusion ::= '1' | '0' | 'void'. distance ::= integer. ordered ::= '1' | '0'. relation ::= integer. which-code ::= 'known' | 'private' | integer. unit-code ::= integer. term-type ::= 'general' | 'numeric' | 'string' | 'oid' | 'datetime' | 'null'. You will note that the syntax above is a fairly faithful representation of RPN, except for the Attribute, which has been moved a step away from the term, allowing you to associate one or more attributes with an entire query structure. The parser will automatically apply the given attributes to each term as required. The @attr operator is followed by an attribute specification (attr-spec above). The specification consists of an optional attribute set, an attribute type-value pair and a sub-query. The attribute type-value pair is packed in one string: an attribute type, an equals sign, and an attribute value, like this: @attr 1=1003. The type is always an integer but the value may be either an integer or a string (if it doesn't start with a digit character). A string attribute-value is encoded as a Type-1 ``complex'' attribute with the list of values containing the single string specified, and including no semantic indicators. */ %} %class PQFParser %interface PQFTokens %package org.xbib.io.iso23950.pqf %token NL %token OR %token AND %token NOT %token ATTR %token ATTRSET %token TERM %token SET %token VOID %token KNOWN %token PRIVATE %token TERMTYPE %token CHARSTRING1 %token CHARSTRING2 %token OPERATORS %token EQUALS %token INTEGER %left AND %left OR %left NOT %type pqf %type querystruct %type expression %type attrstr %type term %type resultset %start pqf %% pqf : ATTRSET CHARSTRING1 querystruct { this.pqf = new PQF($2, $3); $$ = this.pqf; } | querystruct { this.pqf = new PQF($1); $$ = this.pqf; } ; querystruct : attrspec | simple | complex | TERM TERMTYPE pqf { $$ = new Query($3); }; attrspec : ATTR attrstr querystruct { $$ = new Query($2, $3); } | ATTR CHARSTRING1 attrstr querystruct { $$ = new Query($2, $3, $4); }; simple : resultset { $$ = new Query($1); } | term { $$ = new Query($1); }; complex : expression { $$ = new Query($1); }; resultset : SET CHARSTRING1 { $$ = new Setname($2); }; term : CHARSTRING1 { $$ = new Term($1); } | CHARSTRING2 { $$ = new Term($1); } }; attrstr: INTEGER EQUALS INTEGER { $$ = new AttrStr($1, $3); } | INTEGER EQUALS CHARSTRING1 { $$ = new AttrStr($1, $3); }; expression: AND querystruct querystruct { $$ = new Expression($1, $2, $3); } | OR querystruct querystruct { $$ = new Expression($1, $2, $3); } | NOT querystruct querystruct { $$ = new Expression($1, $2, $3); } ; %% private PQFLexer lexer; private PQF pqf; public PQFParser(Reader r) { this.lexer = new PQFLexer(r); lexer.nextToken(); } public void yyerror(String error) { throw new SyntaxException("PQF error at " + "[" + lexer.getLine() + "," + lexer.getColumn() +"]" + ": " + error); } public PQF getResult() { return pqf; } \ No newline at end of file diff --git a/z3950/src/main/java/org/xbib/io/iso23950/Diagnostics.java b/z3950/src/main/java/org/xbib/io/iso23950/Diagnostics.java new file mode 100644 index 0000000..957dd07 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/Diagnostics.java @@ -0,0 +1,59 @@ +package org.xbib.io.iso23950; + +import java.io.IOException; +import java.util.ResourceBundle; + +/** + * Diagnostics for Z server. + */ +public class Diagnostics extends IOException { + + private static final ResourceBundle bundle = + ResourceBundle.getBundle("org.xbib.io.iso23950.diagnostics"); + + private static final long serialVersionUID = -899201811019819079L; + + private int diagCode; + + private String message; + + private String details; + + public Diagnostics(int diagCode) { + super("" + diagCode); + this.diagCode = diagCode; + } + + public Diagnostics(int diagCode, String message) { + super("" + diagCode + " " + message); + this.diagCode = diagCode; + this.message = message; + } + + public Diagnostics(int diagCode, String message, String details) { + super("" + diagCode + " " + message + " " + details); + this.diagCode = diagCode; + this.message = message; + this.details = details; + } + + public String getPlainText() { + String[] s = bundle.getString(Integer.toString(diagCode)).split("\\|"); + if (message == null) { + message = s.length > 0 ? s[1] : ""; + } + if (details == null) { + details = s.length > 1 ? s[2] : ""; + } + StringBuilder sb = new StringBuilder(); + sb.append("diag code=").append(diagCode) + .append(" message=").append(message) + .append(" details=").append(details); + return sb.toString(); + } + + @Override + public String toString() { + return getPlainText(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/ErrorRecord.java b/z3950/src/main/java/org/xbib/io/iso23950/ErrorRecord.java new file mode 100644 index 0000000..bea445b --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/ErrorRecord.java @@ -0,0 +1,11 @@ +package org.xbib.io.iso23950; + +/** + * + */ +public class ErrorRecord extends Record { + + public ErrorRecord(int number, byte[] content) { + super(number, content); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/InitListener.java b/z3950/src/main/java/org/xbib/io/iso23950/InitListener.java new file mode 100644 index 0000000..01b5385 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/InitListener.java @@ -0,0 +1,10 @@ +package org.xbib.io.iso23950; + +/** + * + */ +@FunctionalInterface +public interface InitListener { + + void onInit(int version, String info); +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/Record.java b/z3950/src/main/java/org/xbib/io/iso23950/Record.java new file mode 100644 index 0000000..9ec57ee --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/Record.java @@ -0,0 +1,35 @@ +package org.xbib.io.iso23950; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.charset.Charset; + +/** + * A record for Z39.50 presentations. + */ +public class Record { + + private final int number; + + private final byte[] content; + + private final ByteArrayInputStream stream; + + public Record(int number, byte[] content) { + this.number = number; + this.content = content; + this.stream = new ByteArrayInputStream(content); + } + + public int getNumber() { + return number; + } + + public InputStream asStream() { + return stream; + } + + public String toString(Charset charset) { + return new String(content, charset); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/RecordListener.java b/z3950/src/main/java/org/xbib/io/iso23950/RecordListener.java new file mode 100644 index 0000000..e4e58d5 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/RecordListener.java @@ -0,0 +1,10 @@ +package org.xbib.io.iso23950; + +/** + * + */ +@FunctionalInterface +public interface RecordListener { + + void onRecord(Record record); +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/ResponseListener.java b/z3950/src/main/java/org/xbib/io/iso23950/ResponseListener.java new file mode 100644 index 0000000..0479cd4 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/ResponseListener.java @@ -0,0 +1,12 @@ +package org.xbib.io.iso23950; + +import java.io.IOException; + +/** + * + */ +@FunctionalInterface +public interface ResponseListener { + + void onResponse(int status, int recordCount, long elapsedMillis) throws IOException; +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/ZClient.java b/z3950/src/main/java/org/xbib/io/iso23950/ZClient.java new file mode 100644 index 0000000..4b67c16 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/ZClient.java @@ -0,0 +1,504 @@ +package org.xbib.io.iso23950; + +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.BEREncoding; +import org.xbib.cql.CQLParser; +import org.xbib.io.iso23950.cql.CQLRPNGenerator; +import org.xbib.io.iso23950.operations.InitOperation; +import org.xbib.io.iso23950.operations.PresentOperation; +import org.xbib.io.iso23950.operations.SearchOperation; +import org.xbib.io.iso23950.pqf.PQFParser; +import org.xbib.io.iso23950.pqf.PQFRPNGenerator; +import org.xbib.io.iso23950.v3.Close; +import org.xbib.io.iso23950.v3.CloseReason; +import org.xbib.io.iso23950.v3.PDU; +import org.xbib.io.iso23950.v3.RPNQuery; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.io.UncheckedIOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.text.MessageFormat; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Default Z client. + */ +public class ZClient implements AutoCloseable { + + private static final Logger logger = Logger.getLogger(ZClient.class.getName()); + + private final String host; + + private final int port; + + private final String user; + + private final String pass; + + private final long timeout; + + private final String preferredRecordSyntax; + + private final String resultSetName; + + private final String elementSetName; + + private final String encoding; + + private final String format; + + private final String type; + + private final List databases; + + private final Socket socket; + + private final BufferedInputStream src; + + private final BufferedOutputStream dest; + + public ZClient(String host, int port, String user, String pass, long timeout, + String preferredRecordSyntax, + String resultSetName, + String elementSetName, + String encoding, + String format, + String type, + List databases, + Integer preferredMessageSize, + InitListener initListener) throws IOException { + this.host = host; + this.port = port; + this.user = user; + this.pass = pass; + this.timeout = timeout; + this.preferredRecordSyntax = preferredRecordSyntax; + this.resultSetName = resultSetName; + this.elementSetName = elementSetName; + this.encoding = encoding; + this.format = format; + this.type = type; + this.databases = databases; + Socket socket = new Socket(); + socket.connect(new InetSocketAddress(host, port), (int) timeout); + socket.setSoTimeout((int) timeout * 1000); + this.socket = socket; + this.src = new BufferedInputStream(socket.getInputStream()); + this.dest = new BufferedOutputStream(socket.getOutputStream()); + // always send init operation after socket init + InitOperation init = new InitOperation(); + if (init.execute(this, preferredMessageSize, initListener)) { + throw new IOException("could not initiatie connection"); + } + } + + public static ZClient newZClient(String name) throws IOException { + return newZClient(getProperties(name)); + } + + public static Properties getProperties(String name) throws IOException { + Properties properties = new Properties(); + try (InputStream inputStream = + ZClient.class.getResourceAsStream("/org/xbib/io/iso23950/service/" + name + ".properties")) { + properties.load(inputStream); + } + return properties; + } + + public static ZClient newZClient(Properties properties) throws IOException { + Builder builder = builder(); + if (properties.containsKey("host")) { + builder.setHost(properties.getProperty("host")); + } + if (properties.containsKey("port")) { + builder.setPort(Integer.parseInt(properties.getProperty("port"))); + } + if (properties.containsKey("user")) { + builder.setUser(properties.getProperty("user")); + } + if (properties.containsKey("pass")) { + builder.setPass(properties.getProperty("pass")); + } + if (properties.containsKey("database")) { + builder.setDatabases(Collections.singletonList(properties.getProperty("database"))); + } + if (properties.containsKey("elementsetname")) { + builder.setElementSetName(properties.getProperty("elementsetname")); + } + if (properties.containsKey("preferredrecordsyntax")) { + builder.setPreferredRecordSyntax(properties.getProperty("preferredrecordsyntax")); + } + if (properties.containsKey("resultsetname")) { + builder.setResultSetName(properties.getProperty("resultsetname")); + } + if (properties.containsKey("encoding")) { + builder.setEncoding(properties.getProperty("encoding")); + } + if (properties.containsKey("format")) { + builder.setFormat(properties.getProperty("format")); + } + if (properties.containsKey("type")) { + builder.setType(properties.getProperty("type")); + } + return builder.build(); + } + + public boolean isConnected() { + return socket != null && socket.isConnected(); + } + + @Override + public void close() throws IOException { + if (isConnected()) { + try { + sendClose(0); + } catch (IOException e) { + logger.log(Level.WARNING, "while attempting to close connection: {}", e.getMessage()); + } + try { + if (src != null) { + src.close(); + } + } catch (IOException e) { + logger.log(Level.WARNING, "error attempting to close connection: {}", e.getMessage()); + } + try { + if (dest != null) { + dest.close(); + } + } catch (IOException e) { + logger.log(Level.WARNING, "error attempting to close connection: {}", e.getMessage()); + } + try { + if (socket != null) { + socket.close(); + } + } catch (IOException e) { + logger.log(Level.WARNING, "error attempting to close connection: {}", e.getMessage()); + } + } + } + + /** + * Send a close request to the server. + * + * @param reason reason Reason codes are: + * 0=finished 1=shutdown 2=system problem 3=cost limits + * 4=resources 5=security violation 6=protocol error 7=lack of activity + * 8=peer abort 9=unspecified + * @throws IOException if close fails + */ + public void sendClose(int reason) throws IOException { + PDU pdu = new PDU(); + pdu.c_close = new Close(); + pdu.c_close.sCloseReason = new CloseReason(); + pdu.c_close.sCloseReason.value = new ASN1Integer(reason); + pdu.c_close.sReferenceId = null; + writePDU(pdu); + // do not wait, it may hang + //waitClosePDU(); + } + + public void writePDU(PDU pdu) throws IOException { + if (dest == null) { + throw new IOException("no output stream"); + } + try { + pdu.berEncode().output(dest); + dest.flush(); + } catch (ASN1Exception ex) { + throw new IOException(ex); + } + } + + public PDU readPDU() throws IOException { + if (src == null) { + throw new IOException("no input"); + } + try { + BEREncoding ber = BEREncoding.input(src); + if (ber == null) { + throw new IOException("read PDU error"); + } + return new PDU(ber, true); + } catch (ASN1Exception ex) { + throw new IOException(ex); + } catch (NullPointerException ex) { + throw new IOException("connection read PDU error", ex); + } + } + + public int executeCQL(String query, int offset, int length, + ResponseListener responseListener, + RecordListener recordListener) throws IOException { + if (query == null) { + throw new IllegalArgumentException("no query"); + } + SearchOperation search = new SearchOperation(); + boolean success = search.execute(this, createRPNQueryFromCQL(query)); + if (!success) { + logger.log(Level.WARNING, MessageFormat.format("search was not a success [{0}]", query)); + } else { + if (responseListener == null) { + responseListener = (status, recordCount, elapsedMillis) -> { + logger.log(Level.INFO, MessageFormat.format("[{0}ms] [{1}] [{2}]", + elapsedMillis, recordCount, query)); + }; + } + if (search.getCount() > 0) { + PresentOperation present = new PresentOperation(); + if (offset < 1) { + // Z39.50 present bails out when offset = 0 + offset = 1; + } + if (length > search.getCount()) { + // avoid condition 13 "Present request out-of-range" + length = search.getCount(); + } + present.execute(this, offset, length, responseListener, recordListener); + } + } + return search.getCount(); + } + + public int executePQF(String query, int offset, int length, + ResponseListener responseListener, + RecordListener recordListener) throws IOException { + if (query == null) { + throw new IllegalArgumentException("no query"); + } + SearchOperation search = new SearchOperation(); + search.execute(this, createRPNQueryFromPQF(query)); + if (!search.isSuccess()) { + logger.log(Level.WARNING, MessageFormat.format("search was not a success [{0}]", query)); + } else { + if (responseListener == null) { + responseListener = (status, recordCount, elapsedMillis) -> { + logger.log(Level.INFO, MessageFormat.format("[{0}ms] [{1}] [{2}]", + elapsedMillis, recordCount, query)); + }; + } + if (search.getCount() > 0) { + logger.log(Level.INFO, "search returned " + search.getCount()); + PresentOperation present = new PresentOperation(); + if (offset < 1) { + // Z39.50 bails out when offset = 0 + offset = 1; + } + if (length > search.getCount()) { + // avoid condition 13 "Present request out-of-range" + length = search.getCount(); + } + present.execute(this, offset, length, responseListener, recordListener); + } + } + return search.getCount(); + } + + public String getHost() { + return host; + } + + public int getPort() { + return port; + } + + public String getUser() { + return user; + } + + public String getPass() { + return pass; + } + + public long getTimeout() { + return timeout; + } + + public String getPreferredRecordSyntax() { + return preferredRecordSyntax; + } + + public String getResultSetName() { + return resultSetName; + } + + public String getElementSetName() { + return elementSetName; + } + + public String getEncoding() { + return encoding; + } + + public String getFormat() { + return format; + } + + public String getType() { + return type; + } + + public List getDatabases() { + return databases; + } + + public RPNQuery createRPNQueryFromCQL(String query) throws IOException { + CQLRPNGenerator generator = new CQLRPNGenerator(); + CQLParser parser = new CQLParser(query); + parser.parse(); + parser.getCQLQuery().accept(generator); + return generator.getQueryResult(); + } + + + public RPNQuery createRPNQueryFromPQF(String query) throws IOException { + PQFRPNGenerator generator = new PQFRPNGenerator(); + PQFParser parser = new PQFParser(new StringReader(query)); + parser.parse(); + parser.getResult().accept(generator); + return generator.getResult(); + } + + public static Builder builder() { + return new Builder(); + } + + /** + * + */ + public static class Builder { + + private static final ResourceBundle recordSyntaxBundle = + ResourceBundle.getBundle("org.xbib.io.iso23950.recordsyntax"); + + private String host; + + private int port; + + private String user; + + private String pass; + + private long timeout; + + private String preferredRecordSyntax = "1.2.840.10003.5.10"; // marc21 + + private String resultSetName = "default"; + + private String elementSetName = "F"; + + private String encoding = "ANSEL"; + + private String format = "MARC21"; + + private String type = "Bibliographic"; + + private List databases = Collections.singletonList(""); + + private Integer preferredMessageSize = 1024 * 1024; + + private InitListener initListener; + + public Builder setHost(String host) { + this.host = host; + return this; + } + + public Builder setPort(int port) { + this.port = port; + return this; + } + + public Builder setUser(String user) { + this.user = user; + return this; + } + + public Builder setPass(String pass) { + this.pass = pass; + return this; + } + + public Builder setTimeout(long timeout) { + this.timeout = timeout; + return this; + } + + public Builder setPreferredRecordSyntax(String preferredRecordSyntax) { + this.preferredRecordSyntax = preferredRecordSyntax; + if (recordSyntaxBundle.containsKey(preferredRecordSyntax)) { + this.preferredRecordSyntax = recordSyntaxBundle.getString(preferredRecordSyntax); + } + return this; + } + + public Builder setResultSetName(String resultSetName) { + this.resultSetName = resultSetName; + return this; + } + + public Builder setElementSetName(String elementSetName) { + this.elementSetName = elementSetName; + return this; + } + + public Builder setEncoding(String encoding) { + this.encoding = encoding; + return this; + } + + public Builder setFormat(String format) { + this.format = format; + return this; + } + + public Builder setType(String type) { + this.type = type; + return this; + } + + public Builder setDatabases(List databases) { + this.databases = databases; + return this; + } + + public Builder setPreferredMessageSize(int preferredMessageSize) { + this.preferredMessageSize = preferredMessageSize; + return this; + } + + public Builder setInitListener(InitListener initListener) { + this.initListener = initListener; + return this; + } + + public ZClient build() { + try { + return new ZClient(host, port, user, pass, timeout, + preferredRecordSyntax, + resultSetName, + elementSetName, + encoding, + format, + type, + databases, + preferredMessageSize, + initListener); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/cql/CQLRPNGenerator.java b/z3950/src/main/java/org/xbib/io/iso23950/cql/CQLRPNGenerator.java new file mode 100644 index 0000000..cc791e5 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/cql/CQLRPNGenerator.java @@ -0,0 +1,334 @@ +package org.xbib.io.iso23950.cql; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Null; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.ASN1OctetString; +import org.xbib.cql.BooleanGroup; +import org.xbib.cql.BooleanOperator; +import org.xbib.cql.Identifier; +import org.xbib.cql.Index; +import org.xbib.cql.Modifier; +import org.xbib.cql.ModifierList; +import org.xbib.cql.PrefixAssignment; +import org.xbib.cql.Query; +import org.xbib.cql.Relation; +import org.xbib.cql.ScopedClause; +import org.xbib.cql.SearchClause; +import org.xbib.cql.SimpleName; +import org.xbib.cql.SingleSpec; +import org.xbib.cql.SortSpec; +import org.xbib.cql.SortedQuery; +import org.xbib.cql.Term; +import org.xbib.cql.Visitor; +import org.xbib.io.iso23950.v3.AttributeElement; +import org.xbib.io.iso23950.v3.AttributeElementAttributeValue; +import org.xbib.io.iso23950.v3.AttributeList; +import org.xbib.io.iso23950.v3.AttributeSetId; +import org.xbib.io.iso23950.v3.AttributesPlusTerm; +import org.xbib.io.iso23950.v3.Operand; +import org.xbib.io.iso23950.v3.Operator; +import org.xbib.io.iso23950.v3.RPNQuery; +import org.xbib.io.iso23950.v3.RPNStructure; +import org.xbib.io.iso23950.v3.RPNStructureRpnRpnOp; + +import java.util.HashMap; +import java.util.Map; +import java.util.MissingResourceException; +import java.util.ResourceBundle; +import java.util.Stack; + +/** + * This is a RPN (Type-1 query) generator for CQL queries. + * + * @see RPN + */ +public final class CQLRPNGenerator implements Visitor { + + /** + * BIB-1 Use attributes resource bundle. + */ + private static final ResourceBundle bib = + ResourceBundle.getBundle("org.xbib.io.iso23950.cql.bib-1"); + + /** + * Dublin Core Use attributes resource bundle. + */ + private static final ResourceBundle dc = + ResourceBundle.getBundle("org.xbib.io.iso23950.cql.dc"); + + /** + * Context map. + */ + private final Map contexts = new HashMap() { + private static final long serialVersionUID = 8199395368653216950L; + + { + put("bib", bib); + put("dc", dc); + } + }; + private Stack result; + private RPNQuery rpnQuery; + + public CQLRPNGenerator() { + this.result = new Stack<>(); + } + + public RPNQuery getQueryResult() { + return rpnQuery; + } + + @Override + public void visit(SortedQuery node) { + if (node.getSortSpec() != null) { + node.getSortSpec().accept(this); + } + if (node.getQuery() != null) { + node.getQuery().accept(this); + } + if (!result.isEmpty()) { + this.rpnQuery = new RPNQuery(); + rpnQuery.s_rpn = (RPNStructure) result.pop(); + // Z39.50 BIB-1: urn:oid:1.2.840.10003.3.1 + rpnQuery.s_attributeSet = new AttributeSetId(); + rpnQuery.s_attributeSet.value = new ASN1ObjectIdentifier(new int[]{1, 2, 840, 10003, 3, 1}); + } else { + throw new SyntaxException("unable to generate RPN from CQL"); + } + } + + @Override + public void visit(Query node) { + if (node.getPrefixAssignments() != null) { + for (PrefixAssignment assignment : node.getPrefixAssignments()) { + assignment.accept(this); + } + } + if (node.getQuery() != null) { + node.getQuery().accept(this); + } + if (node.getScopedClause() != null) { + node.getScopedClause().accept(this); + } + } + + @Override + public void visit(SortSpec node) { + if (node.getSingleSpec() != null) { + node.getSingleSpec().accept(this); + } + if (node.getSortSpec() != null) { + node.getSortSpec().accept(this); + } + } + + @Override + public void visit(SingleSpec node) { + if (node.getIndex() != null) { + node.getIndex().accept(this); + } + if (node.getModifierList() != null) { + node.getModifierList().accept(this); + } + } + + @Override + public void visit(PrefixAssignment node) { + node.getPrefix().accept(this); + node.getURI().accept(this); + } + + @Override + public void visit(ScopedClause node) { + if (node.getScopedClause() != null) { + node.getScopedClause().accept(this); + } + node.getSearchClause().accept(this); + if (node.getBooleanGroup() != null) { + node.getBooleanGroup().accept(this); + RPNStructure rpn = new RPNStructure(); + rpn.c_rpnRpnOp = new RPNStructureRpnRpnOp(); + rpn.c_rpnRpnOp.s_op = new Operator(); + BooleanOperator op = node.getBooleanGroup().getOperator(); + switch (op) { + case AND: + rpn.c_rpnRpnOp.s_op.c_and = new ASN1Null(); + break; + case OR: + rpn.c_rpnRpnOp.s_op.c_or = new ASN1Null(); + break; + case NOT: + rpn.c_rpnRpnOp.s_op.c_and_not = new ASN1Null(); + break; + default: + break; + } + rpn.c_rpnRpnOp.s_rpn1 = (RPNStructure) result.pop(); + rpn.c_rpnRpnOp.s_rpn2 = (RPNStructure) result.pop(); + result.push(rpn); + } + } + + @Override + public void visit(BooleanGroup node) { + if (node.getModifierList() != null) { + node.getModifierList().accept(this); + } + } + + @Override + public void visit(SearchClause node) { + if (node.getQuery() != null) { + node.getQuery().accept(this); + } + if (node.getTerm() != null) { + node.getTerm().accept(this); + } + if (node.getIndex() != null) { + node.getIndex().accept(this); + } + if (node.getRelation() != null) { + node.getRelation().accept(this); + } + Operand operand = new Operand(); + operand.c_attrTerm = new AttributesPlusTerm(); + operand.c_attrTerm.sTerm = new org.xbib.io.iso23950.v3.Term(); + operand.c_attrTerm.sTerm.c_general = new ASN1OctetString(node.getTerm().getValue()); + Stack attrs = new Stack<>(); + ASN1Any any = !result.isEmpty() && result.peek() instanceof AttributeElement ? result.pop() : null; + while (any != null) { + attrs.push((AttributeElement) any); + any = !result.isEmpty() && result.peek() instanceof AttributeElement ? result.pop() : null; + } + operand.c_attrTerm.sAttributes = new AttributeList(); + operand.c_attrTerm.sAttributes.value = attrs.toArray(new AttributeElement[attrs.size()]); + RPNStructure rpn = new RPNStructure(); + rpn.c_op = operand; + result.push(rpn); + } + + @Override + public void visit(Relation node) { + if (node.getModifierList() != null) { + node.getModifierList().accept(this); + } + int t = 2; + int n = 3; + switch (node.getComparitor()) { + case LESS: // 2=1 + n = 1; + break; + case LESS_EQUALS: // 2=2 + n = 2; + break; + case EQUALS: // 2=3 + n = 3; + break; + case GREATER_EQUALS: // 2=4 + n = 4; + break; + case GREATER: // 2=5 + n = 5; + break; + case NOT_EQUALS: // 2=6 + n = 6; + break; + case ALL: // 4=6 + t = 4; + n = 6; + break; + case ANY: // 4=105 + t = 4; + n = 104; + break; + default: + break; + } + if (n != 3) { + AttributeElement ae = new AttributeElement(); + ae.sAttributeType = new ASN1Integer(t); + ae.attributeValue = new AttributeElementAttributeValue(); + ae.attributeValue.cNumeric = new ASN1Integer(n); + result.push(ae); + } + } + + @Override + public void visit(Modifier node) { + if (node.getTerm() != null) { + node.getTerm().accept(this); + } + if (node.getName() != null) { + node.getName().accept(this); + } + } + + @Override + public void visit(ModifierList node) { + for (Modifier modifier : node.getModifierList()) { + modifier.accept(this); + } + } + + @Override + public void visit(Term node) { + int t = 5; + int n = 100; + // check for '*' + String v = node.getValue(); + if (v.endsWith("*")) { + if (v.startsWith("*")) { + n = 3; + } else { + n = 1; + } + } else if (v.startsWith("*")) { + n = 2; + } + if (n != 100) { + AttributeElement ae = new AttributeElement(); + ae.sAttributeType = new ASN1Integer(t); + ae.attributeValue = new AttributeElementAttributeValue(); + ae.attributeValue.cNumeric = new ASN1Integer(n); + result.push(ae); + v = v.replaceAll("\\*", ""); + } + ASN1OctetString s = new ASN1OctetString(v); + result.push(s); + } + + @Override + public void visit(Identifier node) { + } + + @Override + public void visit(SimpleName node) { + ASN1OctetString s = new ASN1OctetString(node.getName()); + result.push(s); + } + + @Override + public void visit(Index node) { + String context = node.getContext(); + if (context == null) { + context = "dc"; // default context + } + int t = 1; + int n = getUseAttr(context, node.getName()); + AttributeElement ae = new AttributeElement(); + ae.sAttributeType = new ASN1Integer(t); + ae.attributeValue = new AttributeElementAttributeValue(); + ae.attributeValue.cNumeric = new ASN1Integer(n); + result.push(ae); + } + + private int getUseAttr(String context, String attrName) { + try { + return Integer.parseInt(contexts.get(context).getString(attrName)); + } catch (MissingResourceException e) { + throw new SyntaxException("unknown use attribute '" + attrName + "' for context " + context, e); + } + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/cql/SyntaxException.java b/z3950/src/main/java/org/xbib/io/iso23950/cql/SyntaxException.java new file mode 100644 index 0000000..0ff7cc8 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/cql/SyntaxException.java @@ -0,0 +1,37 @@ +package org.xbib.io.iso23950.cql; + +/** + * Syntax exception. + */ +public class SyntaxException extends RuntimeException { + + private static final long serialVersionUID = -3601569690699438132L; + + /** + * Creates a new SyntaxException object. + * + * @param msg the message for this syntax exception + */ + public SyntaxException(String msg) { + super(msg); + } + + /** + * Creates a new SyntaxException object. + * + * @param t the throwable for this syntax exception + */ + public SyntaxException(Throwable t) { + super(t); + } + + /** + * Creates a new SyntaxException object. + * + * @param msg the message for this syntax exception + * @param t the throwable for this syntax exception + */ + public SyntaxException(String msg, Throwable t) { + super(msg, t); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/cql/package-info.java b/z3950/src/main/java/org/xbib/io/iso23950/cql/package-info.java new file mode 100644 index 0000000..ac6aa8f --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/cql/package-info.java @@ -0,0 +1,4 @@ +/** + * + */ +package org.xbib.io.iso23950.cql; diff --git a/z3950/src/main/java/org/xbib/io/iso23950/exceptions/MessageSizeTooSmallException.java b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/MessageSizeTooSmallException.java new file mode 100644 index 0000000..b89f7e4 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/MessageSizeTooSmallException.java @@ -0,0 +1,13 @@ +package org.xbib.io.iso23950.exceptions; + +/** + * + */ +public class MessageSizeTooSmallException extends ZException { + + private static final long serialVersionUID = 546319297081247810L; + + public MessageSizeTooSmallException(String message, int status, int number) { + super(message, status, number); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/exceptions/NoRecordsReturnedException.java b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/NoRecordsReturnedException.java new file mode 100644 index 0000000..ec4332b --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/NoRecordsReturnedException.java @@ -0,0 +1,14 @@ +package org.xbib.io.iso23950.exceptions; + +/** + * + */ +public class NoRecordsReturnedException extends ZException { + + private static final long serialVersionUID = -19157655707502087L; + + public NoRecordsReturnedException(String message, int status) { + super(message, status); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/exceptions/RequestTerminatedByAccessControlException.java b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/RequestTerminatedByAccessControlException.java new file mode 100644 index 0000000..54b490e --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/RequestTerminatedByAccessControlException.java @@ -0,0 +1,13 @@ +package org.xbib.io.iso23950.exceptions; + +/** + * + */ +public class RequestTerminatedByAccessControlException extends ZException { + + private static final long serialVersionUID = -54961304899756308L; + + public RequestTerminatedByAccessControlException(String message, int status, int number) { + super(message, status, number); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/exceptions/RequestTerminatedException.java b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/RequestTerminatedException.java new file mode 100644 index 0000000..f3cb312 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/RequestTerminatedException.java @@ -0,0 +1,13 @@ +package org.xbib.io.iso23950.exceptions; + +/** + * + */ +public class RequestTerminatedException extends ZException { + + private static final long serialVersionUID = 686537068801065383L; + + public RequestTerminatedException(String message, int status, int number) { + super(message, status, number); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/exceptions/ZException.java b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/ZException.java new file mode 100644 index 0000000..dbddd63 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/ZException.java @@ -0,0 +1,51 @@ +package org.xbib.io.iso23950.exceptions; + +import java.io.IOException; + +/** + * + */ +public class ZException extends IOException { + + private static final long serialVersionUID = 8199318316215867038L; + + private final int status; + + private final int number; + + public ZException(String message) { + this(message, -1, -1); + } + + public ZException(String message, int status) { + this(message, status, -1); + } + + public ZException(String message, int status, int number) { + super(message); + this.status = status; + this.number = number; + } + + public ZException(Throwable throwable) { + this(null, throwable); + } + + public ZException(String message, Throwable throwable) { + this(message, throwable, -1, -1); + } + + public ZException(String message, Throwable throwable, int status, int number) { + super(message, throwable); + this.status = status; + this.number = number; + } + + public int getNumber() { + return number; + } + + public int getStatus() { + return status; + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/exceptions/package-info.java b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/package-info.java new file mode 100644 index 0000000..7ecad78 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/exceptions/package-info.java @@ -0,0 +1,4 @@ +/** + * + */ +package org.xbib.io.iso23950.exceptions; diff --git a/z3950/src/main/java/org/xbib/io/iso23950/operations/InitOperation.java b/z3950/src/main/java/org/xbib/io/iso23950/operations/InitOperation.java new file mode 100644 index 0000000..2ac2b1b --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/operations/InitOperation.java @@ -0,0 +1,114 @@ +package org.xbib.io.iso23950.operations; + +import org.xbib.asn1.ASN1BitString; +import org.xbib.asn1.ASN1GeneralString; +import org.xbib.asn1.ASN1Integer; +import org.xbib.io.iso23950.InitListener; +import org.xbib.io.iso23950.ZClient; +import org.xbib.io.iso23950.v3.IdAuthentication; +import org.xbib.io.iso23950.v3.IdAuthenticationIdPass; +import org.xbib.io.iso23950.v3.InitializeRequest; +import org.xbib.io.iso23950.v3.InitializeResponse; +import org.xbib.io.iso23950.v3.InternationalString; +import org.xbib.io.iso23950.v3.Options; +import org.xbib.io.iso23950.v3.PDU; +import org.xbib.io.iso23950.v3.ProtocolVersion; + +import java.io.IOException; + +/** + * A Z39.50 Init operation. + */ +public class InitOperation { + + public boolean execute(ZClient client, Integer preferredMessageSize, + InitListener initListener) throws IOException { + InitializeRequest init = new InitializeRequest(); + boolean[] version = new boolean[3]; + version[0] = true; // any version, should alwasy be true + version[1] = true; // Z39.50 version 2 + version[2] = true; // Z39.50 version 3 + init.s_protocolVersion = new ProtocolVersion(); + init.s_protocolVersion.value = new ASN1BitString(version); + boolean[] options = new boolean[15]; + options[0] = true; // search + options[1] = true; // present + options[2] = true; // delete set + options[3] = false; // resource-report + options[4] = false; // trigger resource control + options[5] = false; // resource control + options[6] = false; // access control + options[7] = true; // scan + options[8] = false; // sort + options[9] = false; // (unused) + options[10] = false; // extended-services + options[11] = false; // level 1 segmentation + options[12] = false; // level 2 segmentation + options[13] = false; // concurrent operations + options[14] = true; // named result sets + init.s_options = new Options(); + init.s_options.value = new ASN1BitString(options); + init.s_preferredMessageSize = new ASN1Integer(preferredMessageSize); + init.s_exceptionalRecordSize = new ASN1Integer(preferredMessageSize * 2); + init.s_implementationId = new InternationalString(); + init.s_implementationId.value = new ASN1GeneralString("1"); + init.s_implementationName = new InternationalString(); + init.s_implementationName.value = new ASN1GeneralString("Java ZClient"); + init.s_implementationVersion = new InternationalString(); + init.s_implementationVersion.value = new ASN1GeneralString("1.00"); + if (client.getUser() != null) { + init.s_idAuthentication = new IdAuthentication(); + init.s_idAuthentication.c_idPass = new IdAuthenticationIdPass(); + init.s_idAuthentication.c_idPass.s_userId = new InternationalString(); + init.s_idAuthentication.c_idPass.s_userId.value = new ASN1GeneralString(client.getUser()); + if (client.getPass() != null) { + init.s_idAuthentication.c_idPass.s_password = new InternationalString(); + init.s_idAuthentication.c_idPass.s_password.value = new ASN1GeneralString(client.getPass()); + } + /*if (group != null) { + init.s_idAuthentication.c_idPass.s_groupId = new InternationalString(); + init.s_idAuthentication.c_idPass.s_groupId.value = new ASN1GeneralString(group); + }*/ + } + PDU pduOut = new PDU(); + pduOut.c_initRequest = init; + client.writePDU(pduOut); + PDU pduIn = client.readPDU(); + InitializeResponse initResp = pduIn.c_initResponse; + String targetInfo; + if (initResp.s_implementationName != null) { + targetInfo = initResp.s_implementationName.toString(); + if (initResp.s_implementationVersion != null) { + targetInfo += " - " + initResp.s_implementationVersion.toString(); + } + } else { + targetInfo = "server"; + } + int targetVersion = 0; + if (initResp.s_protocolVersion != null) { + for (int n = 0; n < initResp.s_protocolVersion.value.get().length; n++) { + if (initResp.s_protocolVersion.value.get()[n]) { + targetVersion = n + 1; + } + } + if (targetVersion > 0) { + targetInfo += " (Version " + targetVersion + ")"; + } + } else { + targetInfo += " (Version unknown)"; + } + if (initResp.s_userInformationField != null) { + if (initResp.s_userInformationField.getSingleASN1Type() != null) { + targetInfo += "\n" + initResp.s_userInformationField.getSingleASN1Type().toString(); + } + } + if (initResp.s_otherInfo != null) { + targetInfo += "\n" + initResp.s_otherInfo.toString(); + } + targetInfo = targetInfo.replaceAll("\"", ""); + if (initListener != null) { + initListener.onInit(targetVersion, targetInfo); + } + return !initResp.s_result.get(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/operations/PresentOperation.java b/z3950/src/main/java/org/xbib/io/iso23950/operations/PresentOperation.java new file mode 100644 index 0000000..1e51645 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/operations/PresentOperation.java @@ -0,0 +1,118 @@ +package org.xbib.io.iso23950.operations; + +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.ASN1GeneralString; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.io.iso23950.ErrorRecord; +import org.xbib.io.iso23950.Record; +import org.xbib.io.iso23950.RecordListener; +import org.xbib.io.iso23950.ResponseListener; +import org.xbib.io.iso23950.ZClient; +import org.xbib.io.iso23950.exceptions.MessageSizeTooSmallException; +import org.xbib.io.iso23950.exceptions.NoRecordsReturnedException; +import org.xbib.io.iso23950.exceptions.RequestTerminatedByAccessControlException; +import org.xbib.io.iso23950.exceptions.RequestTerminatedException; +import org.xbib.io.iso23950.exceptions.ZException; +import org.xbib.io.iso23950.v3.ElementSetNames; +import org.xbib.io.iso23950.v3.InternationalString; +import org.xbib.io.iso23950.v3.NamePlusRecord; +import org.xbib.io.iso23950.v3.PDU; +import org.xbib.io.iso23950.v3.PresentRequest; +import org.xbib.io.iso23950.v3.PresentRequestRecordComposition; +import org.xbib.io.iso23950.v3.PresentResponse; +import org.xbib.io.iso23950.v3.PresentStatus; +import org.xbib.io.iso23950.v3.ResultSetId; + +import java.io.IOException; + +/** + * Present operation for Z39.50. + */ +public class PresentOperation { + + public void execute(ZClient client, int offset, int length, + ResponseListener responseListener, RecordListener recordListener) throws IOException { + String resultSetName = client.getResultSetName(); + String elementSetName = client.getElementSetName(); + String preferredRecordSyntax = client.getPreferredRecordSyntax(); + PresentRequest pr = new PresentRequest(); + pr.s_resultSetId = new ResultSetId(); + pr.s_resultSetId.value = new InternationalString(); + pr.s_resultSetId.value.value = new ASN1GeneralString(resultSetName); + pr.s_resultSetStartPoint = new ASN1Integer(offset); + pr.s_numberOfRecordsRequested = new ASN1Integer(length); + pr.s_recordComposition = new PresentRequestRecordComposition(); + pr.s_recordComposition.c_simple = new ElementSetNames(); + pr.s_recordComposition.c_simple.cGenericElementSetName = new InternationalString(); + pr.s_recordComposition.c_simple.cGenericElementSetName.value = new ASN1GeneralString(elementSetName); + pr.s_preferredRecordSyntax = new ASN1ObjectIdentifier(makeOID(preferredRecordSyntax)); + PDU pdu = new PDU(); + pdu.c_presentRequest = pr; + long millis = System.currentTimeMillis(); + client.writePDU(pdu); + pdu = client.readPDU(); + PresentResponse response = pdu.c_presentResponse; + int nReturned = response.s_numberOfRecordsReturned != null ? response.s_numberOfRecordsReturned.get() : 0; + int status = response.s_presentStatus.value != null ? response.s_presentStatus.value.get() : 0; + if (responseListener != null) { + responseListener.onResponse(status, nReturned, System.currentTimeMillis() - millis); + } + if (status == PresentStatus.E_success) { + for (int n = 0; n < nReturned; n++) { + NamePlusRecord nr = response.s_records.c_responseRecords[n]; + try { + if (nr.s_record.c_retrievalRecord != null) { + ASN1External asn1External = new ASN1External(nr.s_record.c_retrievalRecord.berEncode(), true); + Record record = new Record(offset + n, asn1External.getcOctetAligned().getBytes()); + if (recordListener != null) { + recordListener.onRecord(record); + } + } else if (nr.s_record.c_surrogateDiagnostic != null) { + ASN1External asn1External = + new ASN1External(nr.s_record.c_surrogateDiagnostic.cDefaultFormat.berEncode(), true); + ErrorRecord record = new ErrorRecord(offset + n, asn1External.getcOctetAligned().getBytes()); + if (recordListener != null) { + recordListener.onRecord(record); + } + } + } catch (ASN1Exception e) { + throw new IOException("Present error: " + e.getMessage()); + } + } + } else { + throw createZExceptionFrom(status, nReturned, response); + } + } + + private int[] makeOID(String str) throws NumberFormatException { + String[] s = str.split("\\."); + int[] a = new int[s.length]; + for (int i = 0; i < a.length; i++) { + a[i] = Integer.parseInt(s[i]); + } + return a; + } + + private ZException createZExceptionFrom(int status, int nReturned, PresentResponse response) { + String message; + switch (status) { + case 1: + message = "Some records were not returned (request was terminated by access control)"; + return new NoRecordsReturnedException(message, status); + case 2: + message = "Some records were not returned (message size is too small)"; + return new MessageSizeTooSmallException(message, status, nReturned); + case 3: + message = "Some records were not returned (request was terminated by control, at origin request)"; + return new RequestTerminatedByAccessControlException(message, status, nReturned); + case 4: + message = "Some records were not returned (request was terminated by control, by the target)"; + return new RequestTerminatedException(message, status, nReturned); + case 5: + return new NoRecordsReturnedException(response.toString(), status); + } + return new ZException(response.toString(), status, nReturned); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/operations/SearchOperation.java b/z3950/src/main/java/org/xbib/io/iso23950/operations/SearchOperation.java new file mode 100644 index 0000000..bb89d6b --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/operations/SearchOperation.java @@ -0,0 +1,121 @@ +package org.xbib.io.iso23950.operations; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Boolean; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1GeneralString; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.io.iso23950.ZClient; +import org.xbib.io.iso23950.v3.DatabaseName; +import org.xbib.io.iso23950.v3.InternationalString; +import org.xbib.io.iso23950.v3.OtherInformation1; +import org.xbib.io.iso23950.v3.PDU; +import org.xbib.io.iso23950.v3.PresentStatus; +import org.xbib.io.iso23950.v3.Query; +import org.xbib.io.iso23950.v3.RPNQuery; +import org.xbib.io.iso23950.v3.SearchRequest; +import org.xbib.io.iso23950.v3.SearchResponse; + +import java.io.IOException; +import java.net.SocketTimeoutException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Base class for Z39.50 Search operation. + */ +public class SearchOperation { + + private int count = -1; + + private boolean status = false; + + private Map results = new HashMap<>(); + + public boolean execute(ZClient client, RPNQuery rpn) throws IOException { + try { + SearchRequest search = new SearchRequest(); + search.s_query = new Query(); + search.s_query.c_type_1 = rpn; + search.s_smallSetUpperBound = new ASN1Integer(0); + search.s_largeSetLowerBound = new ASN1Integer(1); + search.s_mediumSetPresentNumber = new ASN1Integer(0); + search.s_replaceIndicator = new ASN1Boolean(true); + search.s_resultSetName = new InternationalString(); + search.s_resultSetName.value = new ASN1GeneralString(client.getResultSetName()); + List databases = client.getDatabases(); + DatabaseName dbs[] = new DatabaseName[databases.size()]; + for (int n = 0; n < databases.size(); n++) { + dbs[n] = new DatabaseName(); + dbs[n].value = new InternationalString(); + dbs[n].value.value = new ASN1GeneralString(databases.get(n)); + } + search.s_databaseNames = dbs; + PDU pduRequest = new PDU(); + pduRequest.c_searchRequest = search; + client.writePDU(pduRequest); + PDU pduResponse = client.readPDU(); + SearchResponse response = pduResponse.c_searchResponse; + count = response.s_resultCount.get(); + ASN1Boolean b = response.s_searchStatus; + status = b != null && b.get(); + if (!status) { + String message = "no message"; + if (response.s_records != null && response.s_records.c_nonSurrogateDiagnostic != null) { + try { + message = "ASN error, non-surrogate diagnostics: " + + response.s_records.c_nonSurrogateDiagnostic.berEncode(); + } catch (ASN1Exception e) { + // + } + } + throw new IOException(client.getHost() + ": " + message); + } + PresentStatus presentStatus = response.s_presentStatus; + if (presentStatus != null && presentStatus.value != null && presentStatus.value.get() == 5) { + throw new IOException("present status is failure"); + } + if (response.s_additionalSearchInfo != null && response.s_additionalSearchInfo.value[0] != null) { + OtherInformation1 info = response.s_additionalSearchInfo.value[0]; + ASN1Sequence targetSeq = (ASN1Sequence) info.s_information.c_externallyDefinedInfo.getSingleASN1Type(); + ASN1Any[] targets = targetSeq.get(); + DatabaseName dbName; + for (int i = 0; i < targets.length; i++) { + ASN1Sequence target = (ASN1Sequence) targets[i]; + try { + ASN1Any[] details = target.get(); + dbName = new DatabaseName(details[0].berEncode(), false); + if (!dbName.value.value.get().equalsIgnoreCase(databases.get(i))) { + String message = "database name listed in additional search info " + + "doesn't match database name in names set."; + throw new IOException(client.getHost() + ": " + message); + } + ASN1Integer res = (ASN1Integer) details[1]; + results.put(target, res.get()); + } catch (ASN1Exception ex) { + // non-fatal String message = "Error in accessing additional search info."; + results.put(target, -1); + } + } + } + } catch (SocketTimeoutException e) { + throw new IOException(client.getHost() + ": timeout", e); + } + return status; + } + + public int getCount() { + return count; + } + + public boolean isSuccess() { + return status; + } + + public Map getResults() { + return results; + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/operations/package-info.java b/z3950/src/main/java/org/xbib/io/iso23950/operations/package-info.java new file mode 100644 index 0000000..abf2ec5 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/operations/package-info.java @@ -0,0 +1,4 @@ +/** + * + */ +package org.xbib.io.iso23950.operations; diff --git a/z3950/src/main/java/org/xbib/io/iso23950/package-info.java b/z3950/src/main/java/org/xbib/io/iso23950/package-info.java new file mode 100644 index 0000000..d679460 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/package-info.java @@ -0,0 +1,4 @@ +/** + * + */ +package org.xbib.io.iso23950; diff --git a/z3950/src/main/java/org/xbib/io/iso23950/pqf/AttrStr.java b/z3950/src/main/java/org/xbib/io/iso23950/pqf/AttrStr.java new file mode 100644 index 0000000..b76fb14 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/pqf/AttrStr.java @@ -0,0 +1,47 @@ +package org.xbib.io.iso23950.pqf; + +/** + * PQF abstract syntax tree. + */ +public class AttrStr extends Node { + + private Integer left; + private Integer right; + private String rightStr; + + public AttrStr(Integer left, Integer right) { + this.left = left; + this.right = right; + } + + public AttrStr(Integer left, String right) { + this.left = left; + this.rightStr = right; + } + + @Override + public void accept(Visitor visitor) { + if (rightStr != null) { + visitor.visit(rightStr); + } + if (right != null) { + visitor.visit(right); + } + if (left != null) { + visitor.visit(left); + } + visitor.visit(this); + } + + public Integer getLeft() { + return left; + } + + public Integer getRight() { + return right; + } + + public String getRightStr() { + return rightStr; + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/pqf/Expression.java b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Expression.java new file mode 100644 index 0000000..efb591c --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Expression.java @@ -0,0 +1,30 @@ +package org.xbib.io.iso23950.pqf; + +/** + * PQF abstract syntax tree. + */ +public class Expression extends Node { + + private String op; + + private Query q1; + + private Query q2; + + public Expression(String op, Query q1, Query q2) { + this.op = op; + this.q1 = q1; + this.q2 = q2; + } + + @Override + public void accept(Visitor visitor) { + q2.accept(visitor); + q1.accept(visitor); + visitor.visit(this); + } + + public String getOperator() { + return op; + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/pqf/Node.java b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Node.java new file mode 100644 index 0000000..43b9102 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Node.java @@ -0,0 +1,15 @@ +package org.xbib.io.iso23950.pqf; + +/** + * PQF abstract syntax tree. + */ +public abstract class Node { + + /** + * Try to accept this node by a visitor. + * + * @param v the visitor + */ + public abstract void accept(Visitor v); + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/pqf/PQF.java b/z3950/src/main/java/org/xbib/io/iso23950/pqf/PQF.java new file mode 100644 index 0000000..79d584e --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/pqf/PQF.java @@ -0,0 +1,34 @@ +package org.xbib.io.iso23950.pqf; + +/** + * PQF abstract syntax tree. + */ +public class PQF extends Node { + + private final String attrset; + private final Query query; + + public PQF(String attrset, Query query) { + this.attrset = attrset; + this.query = query; + } + + public PQF(Query query) { + this.attrset = null; // default + this.query = query; + } + + public void accept(Visitor visitor) { + query.accept(visitor); + visitor.visit(this); + } + + public String getAttrSet() { + return attrset; + } + + @Override + public String toString() { + return "[PQF: attrset=" + attrset + " query=" + query + "]"; + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/pqf/PQFRPNGenerator.java b/z3950/src/main/java/org/xbib/io/iso23950/pqf/PQFRPNGenerator.java new file mode 100644 index 0000000..b4235d9 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/pqf/PQFRPNGenerator.java @@ -0,0 +1,122 @@ +package org.xbib.io.iso23950.pqf; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Null; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.ASN1OctetString; +import org.xbib.io.iso23950.v3.AttributeElement; +import org.xbib.io.iso23950.v3.AttributeElementAttributeValue; +import org.xbib.io.iso23950.v3.AttributeList; +import org.xbib.io.iso23950.v3.AttributeSetId; +import org.xbib.io.iso23950.v3.AttributesPlusTerm; +import org.xbib.io.iso23950.v3.Operand; +import org.xbib.io.iso23950.v3.Operator; +import org.xbib.io.iso23950.v3.RPNQuery; +import org.xbib.io.iso23950.v3.RPNStructure; +import org.xbib.io.iso23950.v3.RPNStructureRpnRpnOp; + +import java.util.Stack; + +/** + * PQF abstract syntax tree. + */ +public class PQFRPNGenerator implements Visitor { + + private Stack result; + + private RPNQuery rpnQuery; + + public PQFRPNGenerator() { + this.result = new Stack<>(); + } + + public RPNQuery getResult() { + return rpnQuery; + } + + @Override + public void visit(PQF pqf) { + if (!result.isEmpty()) { + this.rpnQuery = new RPNQuery(); + rpnQuery.s_rpn = (RPNStructure) result.pop(); + if (pqf.getAttrSet() == null) { + // Z39.50 BIB-1: urn:oid:1.2.840.10003.3.1 + rpnQuery.s_attributeSet = new AttributeSetId(); + rpnQuery.s_attributeSet.value = new ASN1ObjectIdentifier(new int[]{1, 2, 840, 10003, 3, 1}); + } + } else { + throw new SyntaxException("no valid PQF found"); + } + } + + @Override + public void visit(Query query) { + Operand operand = new Operand(); + operand.c_attrTerm = new AttributesPlusTerm(); + operand.c_attrTerm.sTerm = new org.xbib.io.iso23950.v3.Term(); + operand.c_attrTerm.sTerm.c_general = new ASN1OctetString(query.getTerm().getValue()); + Stack attrs = new Stack<>(); + ASN1Any any = !result.isEmpty() && result.peek() instanceof AttributeElement ? result.pop() : null; + while (any != null) { + attrs.push((AttributeElement) any); + any = !result.isEmpty() && result.peek() instanceof AttributeElement ? result.pop() : null; + } + operand.c_attrTerm.sAttributes = new AttributeList(); + operand.c_attrTerm.sAttributes.value = attrs.toArray(new AttributeElement[attrs.size()]); + RPNStructure rpn = new RPNStructure(); + rpn.c_op = operand; + if (attrs.size() > 0) { + result.push(rpn); + } + } + + @Override + public void visit(Expression expr) { + String op = expr.getOperator(); + RPNStructure rpn = new RPNStructure(); + rpn.c_rpnRpnOp = new RPNStructureRpnRpnOp(); + rpn.c_rpnRpnOp.s_op = new Operator(); + if ("@and".equals(op)) { + rpn.c_rpnRpnOp.s_op.c_and = new ASN1Null(); + } + if ("@or".equals(op)) { + rpn.c_rpnRpnOp.s_op.c_or = new ASN1Null(); + } + if ("@not".equals(op)) { + rpn.c_rpnRpnOp.s_op.c_and_not = new ASN1Null(); + } + rpn.c_rpnRpnOp.s_rpn1 = (RPNStructure) result.pop(); + rpn.c_rpnRpnOp.s_rpn2 = (RPNStructure) result.pop(); + result.push(rpn); + } + + @Override + public void visit(AttrStr attrspec) { + AttributeElement ae = new AttributeElement(); + ae.sAttributeType = (ASN1Integer) result.pop(); + ae.attributeValue = new AttributeElementAttributeValue(); + ae.attributeValue.cNumeric = (ASN1Integer) result.pop(); + result.push(ae); + } + + @Override + public void visit(Term term) { + result.push(new ASN1OctetString(term.getValue())); + } + + @Override + public void visit(Setname name) { + result.push(new ASN1OctetString(name.getValue())); + } + + @Override + public void visit(Integer i) { + result.push(new ASN1Integer(i)); + } + + @Override + public void visit(String str) { + result.push(new ASN1OctetString(str)); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/pqf/Query.java b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Query.java new file mode 100644 index 0000000..3764e45 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Query.java @@ -0,0 +1,97 @@ +package org.xbib.io.iso23950.pqf; + +import java.util.LinkedList; + +/** + * PQF abstract syntax tree. + */ +public class Query extends Node { + + private String attrschema; + private LinkedList attrspec = new LinkedList<>(); + private Query querystruct; + private Setname setname; + private Term term; + private Expression expr; + private PQF pqf; + + // ATTR CHARSTRING1 attrstr querystruct + public Query(String attrschema, AttrStr attrspec, Query querystruct) { + this.attrschema = attrschema; + this.attrspec.add(attrspec); + this.querystruct = querystruct; + this.term = querystruct.getTerm(); + this.attrspec.addAll(querystruct.getAttrSpec()); + } + + // ATTR attrspec querystruct + public Query(AttrStr attrspec, Query querystruct) { + this.attrspec.add(attrspec); + this.querystruct = querystruct; + this.term = querystruct.getTerm(); + this.attrspec.addAll(querystruct.getAttrSpec()); + } + + // TERM TERMTYPE pqf + public Query(PQF pqf) { + this.pqf = pqf; + } + + // simple + public Query(Term term) { + this.term = term; + } + + // complex + public Query(Expression expr) { + this.expr = expr; + } + + public Query(Setname setname) { + this.setname = setname; + } + + public void accept(Visitor visitor) { + if (term != null) { + term.accept(visitor); + } + if (setname != null) { + setname.accept(visitor); + } + if (expr != null) { + expr.accept(visitor); + } + if (querystruct != null) { + querystruct.accept(visitor); + } + for (AttrStr attr : attrspec) { + attr.accept(visitor); + } + if (pqf != null) { + pqf.accept(visitor); + } + visitor.visit(this); + } + + public String getSchema() { + return attrschema; + } + + public Setname getSetname() { + return setname; + } + + public Term getTerm() { + return term; + } + + public LinkedList getAttrSpec() { + return attrspec; + } + + @Override + public String toString() { + return "[Query: term=" + term + " attrschema=" + attrschema + " setname=" + setname + + " querystruct=" + querystruct + "]"; + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/pqf/Setname.java b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Setname.java new file mode 100644 index 0000000..2a9162f --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Setname.java @@ -0,0 +1,26 @@ +package org.xbib.io.iso23950.pqf; + +/** + * + */ +public class Setname extends Node { + + private final String value; + + public Setname(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public void accept(Visitor visitor) { + visitor.visit(this); + } + + public String toString() { + return value; + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/pqf/SyntaxException.java b/z3950/src/main/java/org/xbib/io/iso23950/pqf/SyntaxException.java new file mode 100644 index 0000000..e671fb1 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/pqf/SyntaxException.java @@ -0,0 +1,18 @@ +package org.xbib.io.iso23950.pqf; + +/** + * Syntax exception. + */ +public class SyntaxException extends RuntimeException { + private static final long serialVersionUID = -962913398056374183L; + + /** + * Creates a new SyntaxException object. + * + * @param msg the message for this syntax exception + */ + public SyntaxException(String msg) { + super(msg); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/pqf/Term.java b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Term.java new file mode 100644 index 0000000..a9f0155 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Term.java @@ -0,0 +1,26 @@ +package org.xbib.io.iso23950.pqf; + +/** + * + */ +public class Term extends Node { + + private final String value; + + public Term(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public void accept(Visitor visitor) { + visitor.visit(this); + } + + public String toString() { + return value; + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/pqf/Visitor.java b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Visitor.java new file mode 100644 index 0000000..9a96781 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/pqf/Visitor.java @@ -0,0 +1,39 @@ +package org.xbib.io.iso23950.pqf; + +/** + * PQF abstract syntax tree visitor. + */ +public interface Visitor { + + /** + * Visit PQF. + * + * @param pqf the tree to visit. + */ + void visit(PQF pqf); + + /** + * Visit an query. + * + * @param query the query to visit. + */ + void visit(Query query); + + /** + * Visit an expression. + * + * @param expression the expression to visit. + */ + void visit(Expression expression); + + void visit(AttrStr attrspec); + + void visit(Term term); + + void visit(Setname name); + + void visit(String str); + + void visit(Integer i); + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/pqf/package-info.java b/z3950/src/main/java/org/xbib/io/iso23950/pqf/package-info.java new file mode 100644 index 0000000..251e741 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/pqf/package-info.java @@ -0,0 +1,4 @@ +/** + * + */ +package org.xbib.io.iso23950.pqf; diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlRequest.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlRequest.java new file mode 100644 index 0000000..bf47e43 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlRequest.java @@ -0,0 +1,163 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a AccessControlRequest from Z39-50-APDU-1995. + *
+ * AccessControlRequest ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   securityChallenge AccessControlRequest_securityChallenge
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class AccessControlRequest extends ASN1Any { + + public ReferenceId sReferenceId; // optional + + public AccessControlRequestSecurityChallenge sSecurityChallenge; + + public OtherInformation sOtherInfo; // optional + + /** + * Constructor for a AccessControlRequest from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public AccessControlRequest(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + @Override + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("AccessControlRequest: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("AccessControlRequest: incomplete"); + } + p = berConstructed.elementAt(part); + try { + sReferenceId = new ReferenceId(p, true); + part++; + } catch (ASN1Exception e) { + sReferenceId = null; // no, not present + } + if (numParts <= part) { + throw new ASN1Exception("AccessControlRequest: incomplete"); + } + p = berConstructed.elementAt(part); + sSecurityChallenge = new AccessControlRequestSecurityChallenge(p, true); + part++; + sOtherInfo = null; + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + try { + sOtherInfo = new OtherInformation(p, true); + part++; + } catch (ASN1Exception e) { + sOtherInfo = null; + } + if (part < numParts) { + throw new ASN1Exception("AccessControlRequest: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the AccessControlRequest. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of AccessControlRequest, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 1; + if (sReferenceId != null) { + numFields++; + } + if (sOtherInfo != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + if (sReferenceId != null) { + fields[x++] = sReferenceId.berEncode(); + } + fields[x++] = sSecurityChallenge.berEncode(); + if (sOtherInfo != null) { + fields[x] = sOtherInfo.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the AccessControlRequest. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (sReferenceId != null) { + str.append("referenceId "); + str.append(sReferenceId); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("securityChallenge "); + str.append(sSecurityChallenge); + outputted++; + if (sOtherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(sOtherInfo); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlRequestSecurityChallenge.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlRequestSecurityChallenge.java new file mode 100644 index 0000000..7a49907 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlRequestSecurityChallenge.java @@ -0,0 +1,131 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.ASN1OctetString; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a AccessControlRequest_securityChallenge from Z39-50-APDU-1995. + *
+ * AccessControlRequest_securityChallenge ::=
+ * CHOICE {
+ *   simpleForm [37] IMPLICIT OCTET STRING
+ *   externallyDefined [0] EXPLICIT EXTERNAL
+ * }
+ * 
+ */ +public final class AccessControlRequestSecurityChallenge extends ASN1Any { + + public ASN1OctetString cSimpleForm; + + public ASN1External cExternallyDefined; + + /** + * Constructor for a AccessControlRequest_securityChallenge from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public AccessControlRequestSecurityChallenge(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + @Override + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed tagwrapper; + cSimpleForm = null; + cExternallyDefined = null; + if (ber.tagGet() == 37 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + cSimpleForm = new ASN1OctetString(ber, false); + return; + } + if (ber.tagGet() == 0 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("AccessControlRequest_securityChallenge: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException("AccessControlRequest_securityChallenge: bad BER form\n"); + } + cExternallyDefined = new ASN1External(tagwrapper.elementAt(0), true); + return; + } + throw new ASN1Exception("AccessControlRequest_securityChallenge: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of AccessControlRequest_securityChallenge. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + BEREncoding enc[]; + if (cSimpleForm != null) { + chosen = cSimpleForm.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 37); + } + if (cExternallyDefined != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + enc = new BEREncoding[1]; + enc[0] = cExternallyDefined.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 0, enc); + } + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + @Override + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + throw new ASN1EncodingException("AccessControlRequest_securityChallenge: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the AccessControlRequest_securityChallenge. + */ + @Override + public String toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (cSimpleForm != null) { + found = true; + str.append("simpleForm "); + str.append(cSimpleForm); + } + if (cExternallyDefined != null) { + if (found) { + str.append(" "); + } + str.append("externallyDefined "); + str.append(cExternallyDefined); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlResponse.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlResponse.java new file mode 100644 index 0000000..9b23f8b --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlResponse.java @@ -0,0 +1,215 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a AccessControlResponse from Z39-50-APDU-1995. + *
+ * AccessControlResponse ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   securityChallengeResponse AccessControlResponse_securityChallengeResponse OPTIONAL
+ *   diagnostic [223] EXPLICIT DiagRec OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class AccessControlResponse extends ASN1Any { + + public ReferenceId referenceId; // optional + + public AccessControlResponseSecurityChallengeResponse securityChallengeResponse; // optional + + public DiagRec diagRec; // optional + + public OtherInformation otherInformation; // optional + + /** + * Constructor for a AccessControlResponse from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public AccessControlResponse(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + @Override + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("AccessControlResponse: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + referenceId = null; + securityChallengeResponse = null; + diagRec = null; + otherInformation = null; + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + try { + referenceId = new ReferenceId(p, true); + part++; + } catch (ASN1Exception e) { + referenceId = null; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + try { + securityChallengeResponse = new AccessControlResponseSecurityChallengeResponse(p, true); + part++; + } catch (ASN1Exception e) { + securityChallengeResponse = null; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 223 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException("AccessControlResponse: bad BER encoding: s_diagnostic tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException("AccessControlResponse: bad BER encoding: s_diagnostic tag bad\n"); + } + diagRec = new DiagRec(tagged.elementAt(0), true); + part++; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + try { + otherInformation = new OtherInformation(p, true); + part++; + } catch (ASN1Exception e) { + otherInformation = null; + } + if (part < numParts) { + throw new ASN1Exception("AccessControlResponse: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the AccessControlResponse. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + @Override + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of AccessControlResponse, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + @Override public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 0; // number of mandatories + if (referenceId != null) { + numFields++; + } + if (securityChallengeResponse != null) { + numFields++; + } + if (diagRec != null) { + numFields++; + } + if (otherInformation != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + if (referenceId != null) { + fields[x++] = referenceId.berEncode(); + } + if (securityChallengeResponse != null) { + fields[x++] = securityChallengeResponse.berEncode(); + } + if (diagRec != null) { + enc = new BEREncoding[1]; + enc[0] = diagRec.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 223, enc); + } + if (otherInformation != null) { + fields[x] = otherInformation.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the AccessControlResponse. + */ + @Override + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (referenceId != null) { + str.append("referenceId "); + str.append(referenceId); + outputted++; + } + if (securityChallengeResponse != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("securityChallengeResponse "); + str.append(securityChallengeResponse); + outputted++; + } + if (diagRec != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("diagnostic "); + str.append(diagRec); + outputted++; + } + if (otherInformation != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(otherInformation); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlResponseSecurityChallengeResponse.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlResponseSecurityChallengeResponse.java new file mode 100644 index 0000000..900a6b9 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/AccessControlResponseSecurityChallengeResponse.java @@ -0,0 +1,130 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.ASN1OctetString; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a AccessControlResponse_securityChallengeResponse from Z39-50-APDU-1995. + *
+ * AccessControlResponse_securityChallengeResponse ::=
+ * CHOICE {
+ *   simpleForm [38] IMPLICIT OCTET STRING
+ *   externallyDefined [0] EXPLICIT EXTERNAL
+ * }
+ * 
+ */ + + +public final class AccessControlResponseSecurityChallengeResponse extends ASN1Any { + + public ASN1OctetString cSimpleForm; + + public ASN1External cExternallyDefined; + + /** + * Constructor for a AccessControlResponse_securityChallengeResponse from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public AccessControlResponseSecurityChallengeResponse(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed tagwrapper; + cSimpleForm = null; + cExternallyDefined = null; + if (ber.tagGet() == 38 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + cSimpleForm = new ASN1OctetString(ber, false); + return; + } + if (ber.tagGet() == 0 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("AccessControlResponse_securityChallengeResponse: bad BER form"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException("AccessControlResponse_securityChallengeResponse: bad BER form"); + } + cExternallyDefined = new ASN1External(tagwrapper.elementAt(0), true); + return; + } + throw new ASN1Exception("AccessControlResponse_securityChallengeResponse: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of AccessControlResponse_securityChallengeResponse. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + BEREncoding enc[]; + if (cSimpleForm != null) { + chosen = cSimpleForm.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 38); + } + if (cExternallyDefined != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + enc = new BEREncoding[1]; + enc[0] = cExternallyDefined.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 0, enc); + } + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + throw new ASN1EncodingException("AccessControlResponse_securityChallengeResponse: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the AccessControlResponse_securityChallengeResponse. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (cSimpleForm != null) { + found = true; + str.append("simpleForm "); + str.append(cSimpleForm); + } + if (cExternallyDefined != null) { + if (found) { + str.append(" "); + } + str.append("externallyDefined "); + str.append(cExternallyDefined); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElement.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElement.java new file mode 100644 index 0000000..c839c5a --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElement.java @@ -0,0 +1,162 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a AttributeElement from Z39-50-APDU-1995. + *
+ * AttributeElement ::=
+ * SEQUENCE {
+ *   attributeSet [1] IMPLICIT AttributeSetId OPTIONAL
+ *   attributeType [120] IMPLICIT INTEGER
+ *   attributeValue AttributeElement_attributeValue
+ * }
+ * 
+ */ +public final class AttributeElement extends ASN1Any { + + public AttributeSetId attributeSetId; // optional + + public ASN1Integer sAttributeType; + + public AttributeElementAttributeValue attributeValue; + + /** + * Default constructor for a AttributeElement. + */ + + public AttributeElement() { + } + + /** + * Constructor for a AttributeElement from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public AttributeElement(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("AttributeElement: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("AttributeElement: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 1 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + attributeSetId = new AttributeSetId(p, false); + part++; + } + if (numParts <= part) { + throw new ASN1Exception("AttributeElement: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 120 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("AttributeElement: bad tag in s_attributeType\n"); + } + sAttributeType = new ASN1Integer(p, false); + part++; + if (numParts <= part) { + throw new ASN1Exception("AttributeElement: incomplete"); + } + p = berConstructed.elementAt(part); + attributeValue = new AttributeElementAttributeValue(p, true); + part++; + if (part < numParts) { + throw new ASN1Exception("AttributeElement: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the AttributeElement. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of AttributeElement, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + * @see org.xbib.asn1.BEREncoding#UNIVERSAL_TAG + * @see org.xbib.asn1.BEREncoding#APPLICATION_TAG + * @see org.xbib.asn1.BEREncoding#CONTEXT_SPECIFIC_TAG + * @see org.xbib.asn1.BEREncoding#PRIVATE_TAG + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 2; + if (attributeSetId != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + if (attributeSetId != null) { + fields[x++] = attributeSetId.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + fields[x++] = sAttributeType.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 120); + fields[x] = attributeValue.berEncode(); + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the AttributeElement. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (attributeSetId != null) { + str.append("attributeSet "); + str.append(attributeSetId); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("attributeType "); + str.append(sAttributeType); + outputted++; + if (0 < outputted) { + str.append(", "); + } + str.append("attributeValue "); + str.append(attributeValue); + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElementAttributeValue.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElementAttributeValue.java new file mode 100644 index 0000000..841eae2 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElementAttributeValue.java @@ -0,0 +1,119 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a AttributeElement_attributeValue from Z39-50-APDU-1995. + *
+ * AttributeElement_attributeValue ::=
+ * CHOICE {
+ *   numeric [121] IMPLICIT INTEGER
+ *   complex [224] IMPLICIT AttributeElement_attributeValue_complex
+ * }
+ * 
+ */ +public final class AttributeElementAttributeValue extends ASN1Any { + + public ASN1Integer cNumeric; + + public AttributeElementAttributeValueComplex attributeValueComplex; + + /** + * Default constructor for a AttributeElement_attributeValue. + */ + public AttributeElementAttributeValue() { + } + + /** + * Constructor for a AttributeElement_attributeValue from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public AttributeElementAttributeValue(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + cNumeric = null; + attributeValueComplex = null; + if (ber.tagGet() == 121 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + cNumeric = new ASN1Integer(ber, false); + return; + } + if (ber.tagGet() == 224 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + attributeValueComplex = new AttributeElementAttributeValueComplex(ber, false); + return; + } + throw new ASN1Exception("AttributeElement_attributeValue: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of AttributeElement_attributeValue. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + if (cNumeric != null) { + chosen = cNumeric.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 121); + } + if (attributeValueComplex != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = attributeValueComplex.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 224); + } + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + throw new ASN1EncodingException("AttributeElement_attributeValue: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the AttributeElement_attributeValue. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (cNumeric != null) { + found = true; + str.append("numeric "); + str.append(cNumeric); + } + if (attributeValueComplex != null) { + if (found) { + str.append(" "); + } + str.append("complex "); + str.append(attributeValueComplex); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElementAttributeValueComplex.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElementAttributeValueComplex.java new file mode 100644 index 0000000..262b51a --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeElementAttributeValueComplex.java @@ -0,0 +1,182 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a AttributeElement_attributeValue_complex from Z39-50-APDU-1995. + *
+ * AttributeElement_attributeValue_complex ::=
+ * SEQUENCE {
+ *   list [1] IMPLICIT SEQUENCE OF StringOrNumeric
+ *   semanticAction [2] IMPLICIT SEQUENCE OF INTEGER OPTIONAL
+ * }
+ * 
+ */ +public final class AttributeElementAttributeValueComplex extends ASN1Any { + + public StringOrNumeric[] sList; + public ASN1Integer[] sSemanticAction; // optional + + /** + * Constructor for a AttributeElement_attributeValue_complex from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public AttributeElementAttributeValueComplex(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("AttributeElement_attributeValue_complex: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("AttributeElement_attributeValue_complex: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 1 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("AttributeElement_attributeValue_complex: bad tag in s_list\n"); + } + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + sList = new StringOrNumeric[parts]; + int n; + for (n = 0; n < parts; n++) { + sList[n] = new StringOrNumeric(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + sSemanticAction = null; + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 2 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + sSemanticAction = new ASN1Integer[parts]; + int n; + for (n = 0; n < parts; n++) { + sSemanticAction[n] = new ASN1Integer(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + } + if (part < numParts) { + throw new ASN1Exception("AttributeElement_attributeValue_complex: bad BER: extra data " + + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the AttributeElement_attributeValue_complex. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of AttributeElement_attributeValue_complex, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 1; + if (sSemanticAction != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + f2 = new BEREncoding[sList.length]; + for (p = 0; p < sList.length; p++) { + f2[p] = sList[p].berEncode(); + } + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 1, f2); + if (sSemanticAction != null) { + f2 = new BEREncoding[sSemanticAction.length]; + for (p = 0; p < sSemanticAction.length; p++) { + f2[p] = sSemanticAction[p].berEncode(); + } + fields[x] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 2, f2); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the AttributeElement_attributeValue_complex. + */ + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + str.append("list "); + str.append("{"); + for (p = 0; p < sList.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(sList[p]); + } + str.append("}"); + outputted++; + if (sSemanticAction != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("semanticAction "); + str.append("{"); + for (p = 0; p < sSemanticAction.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(sSemanticAction[p]); + } + str.append("}"); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeList.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeList.java new file mode 100644 index 0000000..e7a1d77 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeList.java @@ -0,0 +1,110 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a AttributeList from Z39-50-APDU-1995. + *
+ * AttributeList ::=
+ * [44] IMPLICIT SEQUENCE OF AttributeElement
+ * 
+ */ +public final class AttributeList extends ASN1Any { + + public AttributeElement[] value; + + /** + * Default constructor for a AttributeList. + */ + public AttributeList() { + } + + /** + * Constructor for a AttributeList from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public AttributeList(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + if (checkTag) { + if (ber.tagGet() != 44 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("AttributeList: bad BER: tag=" + ber.tagGet() + " expected 44\n"); + } + } + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("AttributeList: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + value = new AttributeElement[numParts]; + int p; + for (p = 0; p < numParts; p++) { + value[p] = new AttributeElement(berConstructed.elementAt(p), true); + } + } + + /** + * Returns a BER encoding of the AttributeList. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 44); + } + + /** + * Returns a BER encoding of AttributeList, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + BEREncoding fields[] = new BERConstructed[value.length]; + int p; + for (p = 0; p < value.length; p++) { + fields[p] = value[p].berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the AttributeList. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int p; + for (p = 0; p < value.length; p++) { + str.append(value[p]); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeSetId.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeSetId.java new file mode 100644 index 0000000..d186ffa --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributeSetId.java @@ -0,0 +1,82 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a AttributeSetId from Z39-50-APDU-1995. + *
+ * AttributeSetId ::=
+ * OBJECT IDENTIFIER
+ * 
+ */ + +public final class AttributeSetId extends ASN1Any { + + public ASN1ObjectIdentifier value; + + /** + * Default constructor for a AttributeSetId. + */ + public AttributeSetId() { + } + + /** + * Constructor for a AttributeSetId from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public AttributeSetId(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + value = new ASN1ObjectIdentifier(ber, checkTag); + } + + /** + * Returns a BER encoding of the AttributeSetId. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return value.berEncode(); + } + + /** + * Returns a BER encoding of AttributeSetId, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the AttributeSetId. + */ + public String toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributesPlusTerm.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributesPlusTerm.java new file mode 100644 index 0000000..8756da2 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/AttributesPlusTerm.java @@ -0,0 +1,136 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a AttributesPlusTerm from Z39-50-APDU-1995. + *
+ * AttributesPlusTerm ::=
+ * [102] IMPLICIT SEQUENCE {
+ *   attributes AttributeList
+ *   term Term
+ * }
+ * 
+ */ +public final class AttributesPlusTerm extends ASN1Any { + + public AttributeList sAttributes; + + public Term sTerm; + + /** + * Default constructor for a AttributesPlusTerm. + */ + + public AttributesPlusTerm() { + } + + /** + * Constructor for a AttributesPlusTerm from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public AttributesPlusTerm(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + if (checkTag) { + if (ber.tagGet() != 102 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("AttributesPlusTerm: bad BER: tag=" + ber.tagGet() + " expected 102\n"); + } + } + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("AttributesPlusTerm: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("AttributesPlusTerm: incomplete"); + } + p = berConstructed.elementAt(part); + sAttributes = new AttributeList(p, true); + part++; + if (numParts <= part) { + throw new ASN1Exception("AttributesPlusTerm: incomplete"); + } + p = berConstructed.elementAt(part); + sTerm = new Term(p, true); + part++; + if (part < numParts) { + throw new ASN1Exception("AttributesPlusTerm: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the AttributesPlusTerm. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 102); + } + + /** + * Returns a BER encoding of AttributesPlusTerm, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 2; + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + fields[x++] = sAttributes.berEncode(); + fields[x] = sTerm.berEncode(); + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the AttributesPlusTerm. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + str.append("attributes "); + str.append(sAttributes); + outputted++; + if (0 < outputted) { + str.append(", "); + } + str.append("term "); + str.append(sTerm); + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Close.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Close.java new file mode 100644 index 0000000..cbf14b0 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Close.java @@ -0,0 +1,261 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a Close from Z39-50-APDU-1995. + *
+ * Close ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   closeReason CloseReason
+ *   diagnosticInformation [3] IMPLICIT InternationalString OPTIONAL
+ *   resourceReportFormat [4] IMPLICIT ResourceReportId OPTIONAL
+ *   resourceReport [5] EXPLICIT ResourceReport OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ + +public final class Close extends ASN1Any { + + public ReferenceId sReferenceId; // optional + + public CloseReason sCloseReason; + + public InternationalString sDiagnosticInformation; // optional + + public ResourceReportId sResourceReportFormat; // optional + + public ResourceReport sResourceReport; // optional + + public OtherInformation sOtherInfo; // optional + + /** + * Default constructor for a Close. + */ + public Close() { + } + + /** + * Constructor for a Close from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public Close(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("Close: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + if (numParts <= part) { + throw new ASN1Exception("Close: incomplete"); + } + p = berConstructed.elementAt(part); + try { + sReferenceId = new ReferenceId(p, true); + part++; + } catch (ASN1Exception e) { + sReferenceId = null; + } + if (numParts <= part) { + throw new ASN1Exception("Close: incomplete"); + } + p = berConstructed.elementAt(part); + sCloseReason = new CloseReason(p, true); + part++; + sDiagnosticInformation = null; + sResourceReportFormat = null; + sResourceReport = null; + sOtherInfo = null; + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 3 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sDiagnosticInformation = new InternationalString(p, false); + part++; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 4 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sResourceReportFormat = new ResourceReportId(p, false); + part++; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 5 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException("Close: bad BER encoding: s_resourceReport tag bad"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException("Close: bad BER encoding: s_resourceReport tag bad"); + } + sResourceReport = new ResourceReport(tagged.elementAt(0), true); + part++; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + try { + sOtherInfo = new OtherInformation(p, true); + part++; + } catch (ASN1Exception e) { + sOtherInfo = null; + } + if (part < numParts) { + throw new ASN1Exception("Close: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the Close. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of Close, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 1; + if (sReferenceId != null) { + numFields++; + } + if (sDiagnosticInformation != null) { + numFields++; + } + if (sResourceReportFormat != null) { + numFields++; + } + if (sResourceReport != null) { + numFields++; + } + if (sOtherInfo != null) { + numFields++; + } + BEREncoding[] fields = new BEREncoding[numFields]; + int x = 0; + BEREncoding[] enc; + if (sReferenceId != null) { + fields[x++] = sReferenceId.berEncode(); + } + fields[x++] = sCloseReason.berEncode(); + if (sDiagnosticInformation != null) { + fields[x++] = sDiagnosticInformation.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 3); + } + if (sResourceReportFormat != null) { + fields[x++] = sResourceReportFormat.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 4); + } + if (sResourceReport != null) { + enc = new BEREncoding[1]; + enc[0] = sResourceReport.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 5, enc); + } + if (sOtherInfo != null) { + fields[x] = sOtherInfo.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the Close. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (sReferenceId != null) { + str.append("referenceId "); + str.append(sReferenceId); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("closeReason "); + str.append(sCloseReason); + outputted++; + if (sDiagnosticInformation != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("diagnosticInformation "); + str.append(sDiagnosticInformation); + outputted++; + } + if (sResourceReportFormat != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("resourceReportFormat "); + str.append(sResourceReportFormat); + outputted++; + } + if (sResourceReport != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("resourceReport "); + str.append(sResourceReport); + outputted++; + } + if (sOtherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(sOtherInfo); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/CloseReason.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/CloseReason.java new file mode 100644 index 0000000..c688943 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/CloseReason.java @@ -0,0 +1,97 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a CloseReason from Z39-50-APDU-1995. + *
+ * CloseReason ::=
+ * [211] IMPLICIT INTEGER
+ * 
+ */ +public final class CloseReason extends ASN1Any { + + public static final int E_FINISHED = 0; + public static final int E_SHUTDOWN = 1; + public static final int E_SYSTEM_PROBLEM = 2; + public static final int E_COST_LIMIT = 3; + public static final int E_RESOURCES = 4; + public static final int E_SECURITY_VIOLATION = 5; + public static final int E_PROTOCOL_ERROR = 6; + public static final int E_LACK_OF_ACTIVITY = 7; + public static final int E_PEER_ABORT = 8; + public static final int E_UNSPECIFIED = 9; + public ASN1Integer value; + + /** + * Default constructor for a CloseReason. + */ + public CloseReason() { + } + + /** + * Constructor for a CloseReason from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public CloseReason(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + if (checkTag) { + if (ber.tagGet() != 211 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("CloseReason: bad BER: tag=" + ber.tagGet() + " expected 211"); + } + } + value = new ASN1Integer(ber, false); + } + + /** + * Returns a BER encoding of the CloseReason. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 211); + } + + /** + * Returns a BER encoding of CloseReason, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the CloseReason. + */ + public String toString() { + return value.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/CompSpec.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/CompSpec.java new file mode 100644 index 0000000..25f8722 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/CompSpec.java @@ -0,0 +1,243 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Boolean; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a CompSpec from Z39-50-APDU-1995. + *
+ * CompSpec ::=
+ * SEQUENCE {
+ *   selectAlternativeSyntax [1] IMPLICIT BOOLEAN
+ *   generic [2] IMPLICIT Specification OPTIONAL
+ *   dbSpecific [3] IMPLICIT SEQUENCE OF CompSpec_dbSpecific OPTIONAL
+ *   recordSyntax [4] IMPLICIT SEQUENCE OF OBJECT IDENTIFIER OPTIONAL
+ * }
+ * 
+ */ +public final class CompSpec extends ASN1Any { + + public ASN1Boolean sSelectAlternativeSyntax; + + public Specification sGeneric; // optional + + public CompSpecDbSpecific[] dbSpecifics; // optional + + public ASN1ObjectIdentifier[] objectIdentifiers; // optional + + /** + * Default constructor for a CompSpec. + */ + + public CompSpec() { + } + + /** + * Constructor for a CompSpec from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public CompSpec(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("CompSpec: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("CompSpec: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 1 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("CompSpec: bad tag in s_selectAlternativeSyntax\n"); + } + sSelectAlternativeSyntax = new ASN1Boolean(p, false); + part++; + sGeneric = null; + dbSpecifics = null; + objectIdentifiers = null; + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 2 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sGeneric = new Specification(p, false); + part++; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 3 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + dbSpecifics = new CompSpecDbSpecific[parts]; + int n; + for (n = 0; n < parts; n++) { + dbSpecifics[n] = new CompSpecDbSpecific(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 4 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + objectIdentifiers = new ASN1ObjectIdentifier[parts]; + int n; + for (n = 0; n < parts; n++) { + objectIdentifiers[n] = new ASN1ObjectIdentifier(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + } + if (part < numParts) { + throw new ASN1Exception("CompSpec: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the CompSpec. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of CompSpec, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 1; + if (sGeneric != null) { + numFields++; + } + if (dbSpecifics != null) { + numFields++; + } + if (objectIdentifiers != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + fields[x++] = sSelectAlternativeSyntax.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + if (sGeneric != null) { + fields[x++] = sGeneric.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + } + if (dbSpecifics != null) { + f2 = new BEREncoding[dbSpecifics.length]; + for (p = 0; p < dbSpecifics.length; p++) { + f2[p] = dbSpecifics[p].berEncode(); + } + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 3, f2); + } + if (objectIdentifiers != null) { + f2 = new BEREncoding[objectIdentifiers.length]; + for (p = 0; p < objectIdentifiers.length; p++) { + f2[p] = objectIdentifiers[p].berEncode(); + } + fields[x] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 4, f2); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the CompSpec. + */ + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + str.append("selectAlternativeSyntax "); + str.append(sSelectAlternativeSyntax); + outputted++; + if (sGeneric != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("generic "); + str.append(sGeneric); + outputted++; + } + if (dbSpecifics != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("dbSpecific "); + str.append("{"); + for (p = 0; p < dbSpecifics.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(dbSpecifics[p]); + } + str.append("}"); + outputted++; + } + if (objectIdentifiers != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("recordSyntax "); + str.append("{"); + for (p = 0; p < objectIdentifiers.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(objectIdentifiers[p]); + } + str.append("}"); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/CompSpecDbSpecific.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/CompSpecDbSpecific.java new file mode 100644 index 0000000..3856034 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/CompSpecDbSpecific.java @@ -0,0 +1,144 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a CompSpec_dbSpecific from Z39-50-APDU-1995. + *
+ * CompSpec_dbSpecific ::=
+ * SEQUENCE {
+ *   db [1] EXPLICIT DatabaseName
+ *   spec [2] IMPLICIT Specification
+ * }
+ * 
+ */ +public final class CompSpecDbSpecific extends ASN1Any { + + public DatabaseName sDb; + + public Specification sSpec; + + /** + * Constructor for a CompSpec_dbSpecific from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public CompSpecDbSpecific(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("CompSpec_dbSpecific: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + if (numParts <= part) { + throw new ASN1Exception("CompSpec_dbSpecific: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 1 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("CompSpec_dbSpecific: bad tag in s_db\n"); + } + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("CompSpec_dbSpecific: bad BER encoding: s_db tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException + ("CompSpec_dbSpecific: bad BER encoding: s_db tag bad\n"); + } + sDb = new DatabaseName(tagged.elementAt(0), true); + part++; + if (numParts <= part) { + throw new ASN1Exception("CompSpec_dbSpecific: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 2 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("CompSpec_dbSpecific: bad tag in s_spec\n"); + } + sSpec = new Specification(p, false); + part++; + if (part < numParts) { + throw new ASN1Exception("CompSpec_dbSpecific: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the CompSpec_dbSpecific. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of CompSpec_dbSpecific, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 2; + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + enc = new BEREncoding[1]; + enc[0] = sDb.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 1, enc); + fields[x] = sSpec.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the CompSpec_dbSpecific. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + str.append("db "); + str.append(sDb); + outputted++; + if (0 < outputted) { + str.append(", "); + } + str.append("spec "); + str.append(sSpec); + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/DatabaseName.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/DatabaseName.java new file mode 100644 index 0000000..e7439f9 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/DatabaseName.java @@ -0,0 +1,92 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a DatabaseName from Z39-50-APDU-1995. + *
+ * DatabaseName ::=
+ * [105] IMPLICIT InternationalString
+ * 
+ */ +public final class DatabaseName extends ASN1Any { + + public InternationalString value; + + /** + * Default constructor for a DatabaseName. + */ + + public DatabaseName() { + } + + /** + * Constructor for a DatabaseName from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public DatabaseName(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // Check tag matches + + if (checkTag) { + if (ber.tagGet() != 105 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("DatabaseName: bad BER: tag=" + ber.tagGet() + " expected 105\n"); + } + } + + value = new InternationalString(ber, false); + } + + /** + * Returns a BER encoding of the DatabaseName. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 105); + } + + /** + * Returns a BER encoding of DatabaseName, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the DatabaseName. + */ + + public String toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/DefaultDiagFormat.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/DefaultDiagFormat.java new file mode 100644 index 0000000..c8c0817 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/DefaultDiagFormat.java @@ -0,0 +1,137 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a DefaultDiagFormat from Z39-50-APDU-1995. + *
+ * DefaultDiagFormat ::=
+ * SEQUENCE {
+ *   diagnosticSetId OBJECT IDENTIFIER
+ *   condition INTEGER
+ *   addinfo DefaultDiagFormat_addinfo
+ * }
+ * 
+ */ +public final class DefaultDiagFormat extends ASN1Any { + + public ASN1ObjectIdentifier sDiagnosticSetId; + public ASN1Integer sCondition; + public DefaultDiagFormatAddinfo sAddinfo; + + /** + * Constructor for a DefaultDiagFormat from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public DefaultDiagFormat(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("DefaultDiagFormat: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("DefaultDiagFormat: incomplete"); + } + p = berConstructed.elementAt(part); + sDiagnosticSetId = new ASN1ObjectIdentifier(p, true); + part++; + if (numParts <= part) { + throw new ASN1Exception("DefaultDiagFormat: incomplete"); + } + p = berConstructed.elementAt(part); + sCondition = new ASN1Integer(p, true); + part++; + if (numParts <= part) { + throw new ASN1Exception("DefaultDiagFormat: incomplete"); + } + p = berConstructed.elementAt(part); + sAddinfo = new DefaultDiagFormatAddinfo(p, true); + part++; + if (part < numParts) { + throw new ASN1Exception("DefaultDiagFormat: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the DefaultDiagFormat. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of DefaultDiagFormat, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 3; // number of mandatories + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + fields[x++] = sDiagnosticSetId.berEncode(); + fields[x++] = sCondition.berEncode(); + fields[x] = sAddinfo.berEncode(); + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the DefaultDiagFormat. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + str.append("diagnosticSetId "); + str.append(sDiagnosticSetId); + outputted++; + if (0 < outputted) { + str.append(", "); + } + str.append("condition "); + str.append(sCondition); + outputted++; + if (0 < outputted) { + str.append(", "); + } + str.append("addinfo "); + str.append(sAddinfo); + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/DefaultDiagFormatAddinfo.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/DefaultDiagFormatAddinfo.java new file mode 100644 index 0000000..8a4699b --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/DefaultDiagFormatAddinfo.java @@ -0,0 +1,113 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1VisibleString; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a DefaultDiagFormat_addinfo from Z39-50-APDU-1995. + *
+ * DefaultDiagFormat_addinfo ::=
+ * CHOICE {
+ *   v2Addinfo VisibleString
+ *   v3Addinfo InternationalString
+ * }
+ * 
+ */ +public final class DefaultDiagFormatAddinfo extends ASN1Any { + + public ASN1VisibleString cV2Addinfo; + public InternationalString cV3Addinfo; + + /** + * Constructor for a DefaultDiagFormat_addinfo from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public DefaultDiagFormatAddinfo(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + cV2Addinfo = null; + cV3Addinfo = null; + try { + cV2Addinfo = new ASN1VisibleString(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + try { + cV3Addinfo = new InternationalString(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + throw new ASN1Exception("DefaultDiagFormat_addinfo: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of DefaultDiagFormat_addinfo. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + if (cV2Addinfo != null) { + chosen = cV2Addinfo.berEncode(); + } + if (cV3Addinfo != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = cV3Addinfo.berEncode(); + } + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + throw new ASN1EncodingException("DefaultDiagFormat_addinfo: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the DefaultDiagFormat_addinfo. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (cV2Addinfo != null) { + found = true; + str.append("v2Addinfo "); + str.append(cV2Addinfo); + } + if (cV3Addinfo != null) { + if (found) { + str.append(" "); + } + str.append("v3Addinfo "); + str.append(cV3Addinfo); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteResultSetRequest.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteResultSetRequest.java new file mode 100644 index 0000000..eebb84c --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteResultSetRequest.java @@ -0,0 +1,218 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a DeleteResultSetRequest from Z39-50-APDU-1995. + *
+ * DeleteResultSetRequest ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   deleteFunction [32] IMPLICIT INTEGER
+ *   resultSetList SEQUENCE OF ResultSetId OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ + +public final class DeleteResultSetRequest extends ASN1Any { + + // Enumerated constants for deleteFunction + public static final int E_LIST = 0; + public static final int E_ALL = 1; + public ReferenceId referenceId; // optional + public ASN1Integer sDeleteFunction; + public ResultSetId[] sResultSetList; // optional + public OtherInformation sOtherInfo; // optional + + /** + * Constructor for a DeleteResultSetRequest from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public DeleteResultSetRequest(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("DeleteResultSetRequest: bad BER form"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("DeleteResultSetRequest: incomplete"); + } + p = berConstructed.elementAt(part); + try { + referenceId = new ReferenceId(p, true); + part++; + } catch (ASN1Exception e) { + referenceId = null; + } + if (numParts <= part) { + throw new ASN1Exception("DeleteResultSetRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 32 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("DeleteResultSetRequest: bad tag in s_deleteFunction"); + } + sDeleteFunction = new ASN1Integer(p, false); + part++; + sResultSetList = null; + sOtherInfo = null; + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + try { + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + sResultSetList = new ResultSetId[parts]; + int n; + for (n = 0; n < parts; n++) { + sResultSetList[n] = new ResultSetId(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + } catch (ASN1Exception e) { + sResultSetList = null; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + try { + sOtherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + sOtherInfo = null; // no, not present + } + if (part < numParts) { + throw new ASN1Exception("DeleteResultSetRequest: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the DeleteResultSetRequest. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of DeleteResultSetRequest, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 1; + if (referenceId != null) { + numFields++; + } + if (sResultSetList != null) { + numFields++; + } + if (sOtherInfo != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + if (referenceId != null) { + fields[x++] = referenceId.berEncode(); + } + fields[x++] = sDeleteFunction.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 32); + if (sResultSetList != null) { + f2 = new BEREncoding[sResultSetList.length]; + for (p = 0; p < sResultSetList.length; p++) { + f2[p] = sResultSetList[p].berEncode(); + } + fields[x++] = new BERConstructed(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG, f2); + } + if (sOtherInfo != null) { + fields[x] = sOtherInfo.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the DeleteResultSetRequest. + */ + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (referenceId != null) { + str.append("referenceId "); + str.append(referenceId); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("deleteFunction "); + str.append(sDeleteFunction); + outputted++; + if (sResultSetList != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("resultSetList "); + str.append("{"); + for (p = 0; p < sResultSetList.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(sResultSetList[p]); + } + str.append("}"); + outputted++; + } + if (sOtherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(sOtherInfo); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteResultSetResponse.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteResultSetResponse.java new file mode 100644 index 0000000..65fe995 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteResultSetResponse.java @@ -0,0 +1,268 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a DeleteResultSetResponse from Z39-50-APDU-1995. + *
+ * DeleteResultSetResponse ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   deleteOperationStatus [0] IMPLICIT DeleteSetStatus
+ *   deleteListStatuses [1] IMPLICIT ListStatuses OPTIONAL
+ *   numberNotDeleted [34] IMPLICIT INTEGER OPTIONAL
+ *   bulkStatuses [35] IMPLICIT ListStatuses OPTIONAL
+ *   deleteMessage [36] IMPLICIT InternationalString OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ + +public final class DeleteResultSetResponse extends ASN1Any { + + public ReferenceId sReferenceId; // optional + public DeleteSetStatus sDeleteOperationStatus; + public ListStatuses sDeleteListStatuses; // optional + public ASN1Integer sNumberNotDeleted; // optional + public ListStatuses sBulkStatuses; // optional + public InternationalString sDeleteMessage; // optional + public OtherInformation sOtherInfo; // optional + + /** + * Constructor for a DeleteResultSetResponse from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public DeleteResultSetResponse(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("DeleteResultSetResponse: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("DeleteResultSetResponse: incomplete"); + } + p = berConstructed.elementAt(part); + try { + sReferenceId = new ReferenceId(p, true); + part++; + } catch (ASN1Exception e) { + sReferenceId = null; + } + if (numParts <= part) { + throw new ASN1Exception("DeleteResultSetResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 0 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("DeleteResultSetResponse: bad tag in s_deleteOperationStatus\n"); + } + sDeleteOperationStatus = new DeleteSetStatus(p, false); + part++; + sDeleteListStatuses = null; + sNumberNotDeleted = null; + sBulkStatuses = null; + sDeleteMessage = null; + sOtherInfo = null; + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 1 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sDeleteListStatuses = new ListStatuses(p, false); + part++; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 34 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sNumberNotDeleted = new ASN1Integer(p, false); + part++; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 35 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sBulkStatuses = new ListStatuses(p, false); + part++; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 36 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sDeleteMessage = new InternationalString(p, false); + part++; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + try { + sOtherInfo = new OtherInformation(p, true); + part++; + } catch (ASN1Exception e) { + sOtherInfo = null; // no, not present + } + if (part < numParts) { + throw new ASN1Exception("DeleteResultSetResponse: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the DeleteResultSetResponse. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of DeleteResultSetResponse, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 1; + if (sReferenceId != null) { + numFields++; + } + if (sDeleteListStatuses != null) { + numFields++; + } + if (sNumberNotDeleted != null) { + numFields++; + } + if (sBulkStatuses != null) { + numFields++; + } + if (sDeleteMessage != null) { + numFields++; + } + if (sOtherInfo != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + if (sReferenceId != null) { + fields[x++] = sReferenceId.berEncode(); + } + fields[x++] = sDeleteOperationStatus.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 0); + if (sDeleteListStatuses != null) { + fields[x++] = sDeleteListStatuses.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + if (sNumberNotDeleted != null) { + fields[x++] = sNumberNotDeleted.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 34); + } + if (sBulkStatuses != null) { + fields[x++] = sBulkStatuses.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 35); + } + if (sDeleteMessage != null) { + fields[x++] = sDeleteMessage.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 36); + } + if (sOtherInfo != null) { + fields[x] = sOtherInfo.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the DeleteResultSetResponse. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (sReferenceId != null) { + str.append("referenceId "); + str.append(sReferenceId); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("deleteOperationStatus "); + str.append(sDeleteOperationStatus); + outputted++; + if (sDeleteListStatuses != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("deleteListStatuses "); + str.append(sDeleteListStatuses); + outputted++; + } + if (sNumberNotDeleted != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("numberNotDeleted "); + str.append(sNumberNotDeleted); + outputted++; + } + if (sBulkStatuses != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("bulkStatuses "); + str.append(sBulkStatuses); + outputted++; + } + if (sDeleteMessage != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("deleteMessage "); + str.append(sDeleteMessage); + outputted++; + } + if (sOtherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(sOtherInfo); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteSetStatus.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteSetStatus.java new file mode 100644 index 0000000..821ba31 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/DeleteSetStatus.java @@ -0,0 +1,97 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a DeleteSetStatus from Z39-50-APDU-1995. + *
+ * DeleteSetStatus ::=
+ * [33] IMPLICIT INTEGER
+ * 
+ */ +public final class DeleteSetStatus extends ASN1Any { + + public static final int E_SUCCESS = 0; + public static final int E_RESULT_SET_DID_NOT_EXIST = 1; + public static final int E_PREVIOUSLY_DELETED_BY_TARGET = 2; + public static final int E_SYSTEM_PROBLEM_AT_TARGET = 3; + public static final int E_ACCESS_NOT_ALLOWED = 4; + public static final int E_RESOURCE_CONTROL_AT_ORIGIN = 5; + public static final int E_RESOURCE_CONTROL_AT_TARGET = 6; + public static final int E_BULK_DELETE_NOT_SUPPORTED = 7; + public static final int E_NOT_ALL_RSLT_SETS_DELETED_ON_BULK_DLTE = 8; + public static final int E_NOT_ALL_REQUESTED_RESULT_SETS_DELETED = 9; + public static final int E_RESULT_SET_IN_USE = 10; + public ASN1Integer value; + /** + * Constructor for a DeleteSetStatus from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public DeleteSetStatus(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + if (checkTag) { + if (ber.tagGet() != 33 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("DeleteSetStatus: bad BER: tag=" + ber.tagGet() + " expected 33\n"); + } + } + value = new ASN1Integer(ber, false); + } + + /** + * Returns a BER encoding of the DeleteSetStatus. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 33); + } + + /** + * Returns a BER encoding of DeleteSetStatus, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the DeleteSetStatus. + */ + + public String + toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/DiagRec.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/DiagRec.java new file mode 100644 index 0000000..907ef38 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/DiagRec.java @@ -0,0 +1,114 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a DiagRec from Z39-50-APDU-1995. + *
+ * DiagRec ::=
+ * CHOICE {
+ *   defaultFormat DefaultDiagFormat
+ *   externallyDefined EXTERNAL
+ * }
+ * 
+ */ + +public final class DiagRec extends ASN1Any { + + public DefaultDiagFormat cDefaultFormat; + public ASN1External cExternallyDefined; + + /** + * Constructor for a DiagRec from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public DiagRec(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + cDefaultFormat = null; + cExternallyDefined = null; + try { + cDefaultFormat = new DefaultDiagFormat(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + try { + cExternallyDefined = new ASN1External(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + throw new ASN1Exception("DiagRec: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of DiagRec. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + if (cDefaultFormat != null) { + chosen = cDefaultFormat.berEncode(); + } + if (cExternallyDefined != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = cExternallyDefined.berEncode(); + } + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + throw new ASN1EncodingException("DiagRec: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the DiagRec. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (cDefaultFormat != null) { + found = true; + str.append("defaultFormat "); + str.append(cDefaultFormat); + } + if (cExternallyDefined != null) { + if (found) { + str.append(" "); + } + str.append("externallyDefined "); + str.append(cExternallyDefined); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetName.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetName.java new file mode 100644 index 0000000..4eebab1 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetName.java @@ -0,0 +1,87 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ElementSetName from Z39-50-APDU-1995. + *
+ * ElementSetName ::=
+ * [103] IMPLICIT InternationalString
+ * 
+ */ +public final class ElementSetName extends ASN1Any { + + public InternationalString value; + + /** + * Constructor for a ElementSetName from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ElementSetName(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // Check tag matches + + if (checkTag) { + if (ber.tagGet() != 103 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("ElementSetName: bad BER: tag=" + ber.tagGet() + " expected 103\n"); + } + } + + value = new InternationalString(ber, false); + } + + /** + * Returns a BER encoding of the ElementSetName. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 103); + } + + /** + * Returns a BER encoding of ElementSetName, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the ElementSetName. + */ + + public String toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetNames.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetNames.java new file mode 100644 index 0000000..c63b076 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetNames.java @@ -0,0 +1,143 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ElementSetNames from Z39-50-APDU-1995. + *
+ * ElementSetNames ::=
+ * CHOICE {
+ *   genericElementSetName [0] IMPLICIT InternationalString
+ *   databaseSpecific [1] IMPLICIT SEQUENCE OF ElementSetNames_databaseSpecific
+ * }
+ * 
+ */ +public final class ElementSetNames extends ASN1Any { + + public InternationalString cGenericElementSetName; + public ElementSetNamesDatabaseSpecific[] cDatabaseSpecific; + + /** + * Default constructor for a ElementSetNames. + */ + + public ElementSetNames() { + } + + /** + * Constructor for a ElementSetNames from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ElementSetNames(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + cGenericElementSetName = null; + cDatabaseSpecific = null; + if (ber.tagGet() == 0 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + cGenericElementSetName = new InternationalString(ber, false); + return; + } + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + BEREncoding berData; + berData = ber; + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) berData; + } catch (ClassCastException e) { + throw new ASN1EncodingException("ElementSetNames: bad BER form"); + } + int numParts = berConstructed.numberComponents(); + int p; + cDatabaseSpecific = new ElementSetNamesDatabaseSpecific[numParts]; + for (p = 0; p < numParts; p++) { + cDatabaseSpecific[p] = new ElementSetNamesDatabaseSpecific(berConstructed.elementAt(p), true); + } + return; + } + throw new ASN1Exception("ElementSetNames: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of ElementSetNames. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + BEREncoding[] f2; + int p; + if (cGenericElementSetName != null) { + chosen = cGenericElementSetName.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 0); + } + if (cDatabaseSpecific != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + f2 = new BEREncoding[cDatabaseSpecific.length]; + for (p = 0; p < cDatabaseSpecific.length; p++) { + f2[p] = cDatabaseSpecific[p].berEncode(); + } + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 1, f2); + } + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + throw new ASN1EncodingException("ElementSetNames: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the ElementSetNames. + */ + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (cGenericElementSetName != null) { + found = true; + str.append("genericElementSetName "); + str.append(cGenericElementSetName); + } + if (cDatabaseSpecific != null) { + if (found) { + str.append(" "); + } + str.append("databaseSpecific "); + str.append("{"); + for (p = 0; p < cDatabaseSpecific.length; p++) { + str.append(cDatabaseSpecific[p]); + } + str.append("}"); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetNamesDatabaseSpecific.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetNamesDatabaseSpecific.java new file mode 100644 index 0000000..33d8c31 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ElementSetNamesDatabaseSpecific.java @@ -0,0 +1,131 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ElementSetNames_databaseSpecific from Z39-50-APDU-1995. + *
+ * ElementSetNames_databaseSpecific ::=
+ * SEQUENCE {
+ *   dbName DatabaseName
+ *   esn ElementSetName
+ * }
+ * 
+ */ + +public final class ElementSetNamesDatabaseSpecific extends ASN1Any { + + public DatabaseName sDbName; + public ElementSetName elementSetName; + + /** + * Default constructor for a ElementSetNames_databaseSpecific. + */ + + public ElementSetNamesDatabaseSpecific() { + } + + /** + * Constructor for a ElementSetNames_databaseSpecific from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ElementSetNamesDatabaseSpecific(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("ElementSetNames_databaseSpecific: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("ElementSetNames_databaseSpecific: incomplete"); + } + p = berConstructed.elementAt(part); + sDbName = new DatabaseName(p, true); + part++; + if (numParts <= part) { + throw new ASN1Exception("ElementSetNames_databaseSpecific: incomplete"); + } + p = berConstructed.elementAt(part); + elementSetName = new ElementSetName(p, true); + part++; + if (part < numParts) { + throw new ASN1Exception("ElementSetNames_databaseSpecific: bad BER: extra data " + + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ElementSetNames_databaseSpecific. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ElementSetNames_databaseSpecific, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 2; + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + fields[x++] = sDbName.berEncode(); + fields[x] = elementSetName.berEncode(); + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ElementSetNames_databaseSpecific. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + str.append("dbName "); + str.append(sDbName); + outputted++; + if (0 < outputted) { + str.append(", "); + } + str.append("esn "); + str.append(elementSetName); + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Entry.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Entry.java new file mode 100644 index 0000000..9150931 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Entry.java @@ -0,0 +1,127 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a Entry from Z39-50-APDU-1995. + *
+ * Entry ::=
+ * CHOICE {
+ *   termInfo [1] IMPLICIT TermInfo
+ *   surrogateDiagnostic [2] EXPLICIT DiagRec
+ * }
+ * 
+ */ +public final class Entry extends ASN1Any { + + public TermInfo cTermInfo; + public DiagRec cSurrogateDiagnostic; + + /** + * Constructor for a Entry from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Entry(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed tagwrapper; + cTermInfo = null; + cSurrogateDiagnostic = null; + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + cTermInfo = new TermInfo(ber, false); + return; + } + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Entry: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("Entry: bad BER form\n"); + } + cSurrogateDiagnostic = new DiagRec(tagwrapper.elementAt(0), true); + return; + } + throw new ASN1Exception("Entry: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of Entry. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + BEREncoding[] enc; + if (cTermInfo != null) { + chosen = cTermInfo.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + if (cSurrogateDiagnostic != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + enc = new BEREncoding[1]; + enc[0] = cSurrogateDiagnostic.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 2, enc); + } + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + throw new ASN1EncodingException("Entry: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the Entry. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (cTermInfo != null) { + found = true; + str.append("termInfo "); + str.append(cTermInfo); + } + if (cSurrogateDiagnostic != null) { + if (found) { + str.append(" "); + } + str.append("surrogateDiagnostic "); + str.append(cSurrogateDiagnostic); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ExtendedServicesRequest.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ExtendedServicesRequest.java new file mode 100644 index 0000000..55d742b --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ExtendedServicesRequest.java @@ -0,0 +1,392 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ExtendedServicesRequest from Z39-50-APDU-1995. + *
+ * ExtendedServicesRequest ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   function [3] IMPLICIT INTEGER
+ *   packageType [4] IMPLICIT OBJECT IDENTIFIER
+ *   packageName [5] IMPLICIT InternationalString OPTIONAL
+ *   userId [6] IMPLICIT InternationalString OPTIONAL
+ *   retentionTime [7] IMPLICIT IntUnit OPTIONAL
+ *   permissions [8] IMPLICIT Permissions OPTIONAL
+ *   description [9] IMPLICIT InternationalString OPTIONAL
+ *   taskSpecificParameters [10] IMPLICIT EXTERNAL OPTIONAL
+ *   waitAction [11] IMPLICIT INTEGER
+ *   elements ElementSetName OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ + +public final class ExtendedServicesRequest extends ASN1Any { + + public static final int E_CREATE = 1; + public static final int E_DELETE = 2; + public static final int E_MODIFY = 3; + public static final int E_WAIT = 1; + public static final int E_WAIT_IF_POSSIBLE = 2; + public static final int E_DONT_WAIT = 3; + public static final int E_DONT_RETURN_PACKAGE = 4; + public ReferenceId sReferenceId; // optional + public ASN1Integer sFunction; + public ASN1ObjectIdentifier sPackageType; + public InternationalString sPackageName; // optional + public InternationalString sUserId; // optional + public IntUnit sRetentionTime; // optional + public Permissions sPermissions; // optional + public InternationalString sDescription; // optional + public ASN1External sTaskSpecificParameters; // optional + public ASN1Integer sWaitAction; + public ElementSetName sElements; // optional + public OtherInformation sOtherInfo; // optional + + /** + * Constructor for a ExtendedServicesRequest from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ExtendedServicesRequest(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("ExtendedServicesRequest: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("ExtendedServicesRequest: incomplete"); + } + p = berConstructed.elementAt(part); + try { + sReferenceId = new ReferenceId(p, true); + part++; + } catch (ASN1Exception e) { + sReferenceId = null; // no, not present + } + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ExtendedServicesRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 3 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("ExtendedServicesRequest: bad tag in s_function\n"); + } + sFunction = new ASN1Integer(p, false); + part++; + if (numParts <= part) { + throw new ASN1Exception("ExtendedServicesRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 4 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("ExtendedServicesRequest: bad tag in s_packageType\n"); + } + sPackageType = new ASN1ObjectIdentifier(p, false); + part++; + if (numParts <= part) { + throw new ASN1Exception("ExtendedServicesRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 5 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sPackageName = new InternationalString(p, false); + part++; + } + if (numParts <= part) { + throw new ASN1Exception("ExtendedServicesRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 6 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sUserId = new InternationalString(p, false); + part++; + } + if (numParts <= part) { + throw new ASN1Exception("ExtendedServicesRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 7 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sRetentionTime = new IntUnit(p, false); + part++; + } + if (numParts <= part) { + throw new ASN1Exception("ExtendedServicesRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 8 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sPermissions = new Permissions(p, false); + part++; + } + if (numParts <= part) { + throw new ASN1Exception("ExtendedServicesRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 9 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sDescription = new InternationalString(p, false); + part++; + } + if (numParts <= part) { + throw new ASN1Exception("ExtendedServicesRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 10 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sTaskSpecificParameters = new ASN1External(p, false); + part++; + } + if (numParts <= part) { + throw new ASN1Exception("ExtendedServicesRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 11 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("ExtendedServicesRequest: bad tag in s_waitAction\n"); + } + sWaitAction = new ASN1Integer(p, false); + part++; + sElements = null; + sOtherInfo = null; + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + try { + sElements = new ElementSetName(p, true); + part++; + } catch (ASN1Exception e) { + sElements = null; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + try { + sOtherInfo = new OtherInformation(p, true); + part++; + } catch (ASN1Exception e) { + sOtherInfo = null; // no, not present + } + if (part < numParts) { + throw new ASN1Exception("ExtendedServicesRequest: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ExtendedServicesRequest. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ExtendedServicesRequest, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 3; + if (sReferenceId != null) { + numFields++; + } + if (sPackageName != null) { + numFields++; + } + if (sUserId != null) { + numFields++; + } + if (sRetentionTime != null) { + numFields++; + } + if (sPermissions != null) { + numFields++; + } + if (sDescription != null) { + numFields++; + } + if (sTaskSpecificParameters != null) { + numFields++; + } + if (sElements != null) { + numFields++; + } + if (sOtherInfo != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + if (sReferenceId != null) { + fields[x++] = sReferenceId.berEncode(); + } + fields[x++] = sFunction.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 3); + fields[x++] = sPackageType.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 4); + if (sPackageName != null) { + fields[x++] = sPackageName.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 5); + } + if (sUserId != null) { + fields[x++] = sUserId.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 6); + } + if (sRetentionTime != null) { + fields[x++] = sRetentionTime.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 7); + } + if (sPermissions != null) { + fields[x++] = sPermissions.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 8); + } + if (sDescription != null) { + fields[x++] = sDescription.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 9); + } + if (sTaskSpecificParameters != null) { + fields[x++] = sTaskSpecificParameters.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 10); + } + fields[x++] = sWaitAction.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 11); + if (sElements != null) { + fields[x++] = sElements.berEncode(); + } + if (sOtherInfo != null) { + fields[x] = sOtherInfo.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ExtendedServicesRequest. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (sReferenceId != null) { + str.append("referenceId "); + str.append(sReferenceId); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("function "); + str.append(sFunction); + outputted++; + if (0 < outputted) { + str.append(", "); + } + str.append("packageType "); + str.append(sPackageType); + outputted++; + if (sPackageName != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("packageName "); + str.append(sPackageName); + outputted++; + } + if (sUserId != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("userId "); + str.append(sUserId); + outputted++; + } + if (sRetentionTime != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("retentionTime "); + str.append(sRetentionTime); + outputted++; + } + if (sPermissions != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("permissions "); + str.append(sPermissions); + outputted++; + } + if (sDescription != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("description "); + str.append(sDescription); + outputted++; + } + if (sTaskSpecificParameters != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("taskSpecificParameters "); + str.append(sTaskSpecificParameters); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("waitAction "); + str.append(sWaitAction); + outputted++; + if (sElements != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("elements "); + str.append(sElements); + outputted++; + } + if (sOtherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(sOtherInfo); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ExtendedServicesResponse.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ExtendedServicesResponse.java new file mode 100644 index 0000000..7c34ffb --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ExtendedServicesResponse.java @@ -0,0 +1,246 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ExtendedServicesResponse from Z39-50-APDU-1995. + *
+ * ExtendedServicesResponse ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   operationStatus [3] IMPLICIT INTEGER
+ *   diagnostics [4] IMPLICIT SEQUENCE OF DiagRec OPTIONAL
+ *   taskPackage [5] IMPLICIT EXTERNAL OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class ExtendedServicesResponse extends ASN1Any { + + public static final int E_DONE = 1; + public static final int E_ACCEPTED = 2; + public static final int E_FAILURE = 3; + public ReferenceId sReferenceId; // optional + public ASN1Integer sOperationStatus; + public DiagRec[] sDiagnostics; // optional + public ASN1External sTaskPackage; // optional + public OtherInformation sOtherInfo; // optional + + /** + * Constructor for a ExtendedServicesResponse from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ExtendedServicesResponse(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("ExtendedServicesResponse: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ExtendedServicesResponse: incomplete"); + } + p = berConstructed.elementAt(part); + try { + sReferenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + sReferenceId = null; // no, not present + } + if (numParts <= part) { + throw new ASN1Exception("ExtendedServicesResponse: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 3 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("ExtendedServicesResponse: bad tag in s_operationStatus\n"); + } + sOperationStatus = new ASN1Integer(p, false); + part++; + sDiagnostics = null; + sTaskPackage = null; + sOtherInfo = null; + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 4 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + sDiagnostics = new DiagRec[parts]; + int n; + for (n = 0; n < parts; n++) { + sDiagnostics[n] = new DiagRec(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + } + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 5 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + sTaskPackage = new ASN1External(p, false); + part++; + } + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + try { + sOtherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + sOtherInfo = null; // no, not present + } + if (part < numParts) { + throw new ASN1Exception("ExtendedServicesResponse: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ExtendedServicesResponse. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ExtendedServicesResponse, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 1; + if (sReferenceId != null) { + numFields++; + } + if (sDiagnostics != null) { + numFields++; + } + if (sTaskPackage != null) { + numFields++; + } + if (sOtherInfo != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + if (sReferenceId != null) { + fields[x++] = sReferenceId.berEncode(); + } + fields[x++] = sOperationStatus.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 3); + if (sDiagnostics != null) { + f2 = new BEREncoding[sDiagnostics.length]; + for (p = 0; p < sDiagnostics.length; p++) { + f2[p] = sDiagnostics[p].berEncode(); + } + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 4, f2); + } + if (sTaskPackage != null) { + fields[x++] = sTaskPackage.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 5); + } + if (sOtherInfo != null) { + fields[x] = sOtherInfo.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ExtendedServicesResponse. + */ + + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (sReferenceId != null) { + str.append("referenceId "); + str.append(sReferenceId); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("operationStatus "); + str.append(sOperationStatus); + outputted++; + if (sDiagnostics != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("diagnostics "); + str.append("{"); + for (p = 0; p < sDiagnostics.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(sDiagnostics[p]); + } + str.append("}"); + outputted++; + } + if (sTaskPackage != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("taskPackage "); + str.append(sTaskPackage); + outputted++; + } + if (sOtherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(sOtherInfo); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/FragmentSyntax.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/FragmentSyntax.java new file mode 100644 index 0000000..2d8802c --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/FragmentSyntax.java @@ -0,0 +1,141 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.ASN1OctetString; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a FragmentSyntax from Z39-50-APDU-1995 + *
+ * FragmentSyntax ::=
+ * CHOICE {
+ *   externallyTagged EXTERNAL
+ *   notExternallyTagged OCTET STRING
+ * }
+ * 
+ */ +public final class FragmentSyntax extends ASN1Any { + + public ASN1External c_externallyTagged; + public ASN1OctetString c_notExternallyTagged; + + /** + * Constructor for a FragmentSyntax from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public FragmentSyntax(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + c_externallyTagged = null; + c_notExternallyTagged = null; + try { + c_externallyTagged = new ASN1External(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + try { + c_notExternallyTagged = new ASN1OctetString(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + throw new ASN1Exception("FragmentSyntax: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of FragmentSyntax. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + if (c_externallyTagged != null) { + chosen = c_externallyTagged.berEncode(); + } + if (c_notExternallyTagged != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_notExternallyTagged.berEncode(); + } + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("FragmentSyntax: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the FragmentSyntax. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (c_externallyTagged != null) { + found = true; + str.append("externallyTagged "); + str.append(c_externallyTagged); + } + if (c_notExternallyTagged != null) { + if (found) { + str.append(" "); + } + str.append("notExternallyTagged "); + str.append(c_notExternallyTagged); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/IdAuthentication.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/IdAuthentication.java new file mode 100644 index 0000000..e0f2e3e --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/IdAuthentication.java @@ -0,0 +1,234 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.ASN1Null; +import org.xbib.asn1.ASN1VisibleString; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a IdAuthentication from Z39-50-APDU-1995. + *
+ * IdAuthentication ::=
+ * CHOICE {
+ *   open VisibleString
+ *   idPass IdAuthentication_idPass
+ *   anonymous NULL
+ *   other EXTERNAL
+ * }
+ * 
+ */ + +public final class IdAuthentication extends ASN1Any { + + public ASN1VisibleString c_open; + public IdAuthenticationIdPass c_idPass; + public ASN1Null c_anonymous; + public ASN1External c_other; + + /** + * Default constructor for a IdAuthentication. + */ + + public IdAuthentication() { + } + + /** + * Constructor for a IdAuthentication from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public IdAuthentication(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Null out all choices + + c_open = null; + c_idPass = null; + c_anonymous = null; + c_other = null; + + // Try choice open + try { + c_open = new ASN1VisibleString(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + + // Try choice idPass + try { + c_idPass = new IdAuthenticationIdPass(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + + // Try choice anonymous + try { + c_anonymous = new ASN1Null(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + + // Try choice other + try { + c_other = new ASN1External(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + + throw new ASN1Exception("IdAuthentication: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of IdAuthentication. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + // Encoding choice: c_open + if (c_open != null) { + chosen = c_open.berEncode(); + } + + // Encoding choice: c_idPass + if (c_idPass != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_idPass.berEncode(); + } + + // Encoding choice: c_anonymous + if (c_anonymous != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_anonymous.berEncode(); + } + + // Encoding choice: c_other + if (c_other != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_other.berEncode(); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("IdAuthentication: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the IdAuthentication. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + + boolean found = false; + + if (c_open != null) { + found = true; + str.append("open "); + str.append(c_open); + } + + if (c_idPass != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("idPass "); + str.append(c_idPass); + } + + if (c_anonymous != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("anonymous "); + str.append(c_anonymous); + } + + if (c_other != null) { + if (found) { + str.append(" "); + } + str.append("other "); + str.append(c_other); + } + + str.append("}"); + + return str.toString(); + } + +} \ No newline at end of file diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/IdAuthenticationIdPass.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/IdAuthenticationIdPass.java new file mode 100644 index 0000000..9c81f70 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/IdAuthenticationIdPass.java @@ -0,0 +1,226 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a IdAuthentication_idPass from Z39-50-APDU-1995. + *
+ * IdAuthentication_idPass ::=
+ * SEQUENCE {
+ *   groupId [0] IMPLICIT InternationalString OPTIONAL
+ *   userId [1] IMPLICIT InternationalString OPTIONAL
+ *   password [2] IMPLICIT InternationalString OPTIONAL
+ * }
+ * 
+ */ +public final class IdAuthenticationIdPass extends ASN1Any { + + public InternationalString s_groupId; // optional + public InternationalString s_userId; // optional + public InternationalString s_password; // optional + + /** + * Default constructor for a IdAuthentication_idPass. + */ + + public IdAuthenticationIdPass() { + } + + /** + * Constructor for a IdAuthentication_idPass from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public IdAuthenticationIdPass(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // IdAuthentication_idPass should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("IdAuthentication_idPass: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_groupId = null; + s_userId = null; + s_password = null; + + // Decoding: groupId [0] IMPLICIT InternationalString OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 0 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_groupId = new InternationalString(p, false); + part++; + } + + // Decoding: userId [1] IMPLICIT InternationalString OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 1 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_userId = new InternationalString(p, false); + part++; + } + + // Decoding: password [2] IMPLICIT InternationalString OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 2 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_password = new InternationalString(p, false); + part++; + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("IdAuthentication_idPass: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the IdAuthentication_idPass. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of IdAuthentication_idPass, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 0; // number of mandatories + if (s_groupId != null) { + numFields++; + } + if (s_userId != null) { + numFields++; + } + if (s_password != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_groupId: InternationalString OPTIONAL + + if (s_groupId != null) { + fields[x++] = s_groupId.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 0); + } + + // Encoding s_userId: InternationalString OPTIONAL + + if (s_userId != null) { + fields[x++] = s_userId.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding s_password: InternationalString OPTIONAL + + if (s_password != null) { + fields[x] = s_password.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the IdAuthentication_idPass. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_groupId != null) { + str.append("groupId "); + str.append(s_groupId); + outputted++; + } + + if (s_userId != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("userId "); + str.append(s_userId); + outputted++; + } + + if (s_password != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("password "); + str.append(s_password); + } + + str.append("}"); + + return str.toString(); + } + +} \ No newline at end of file diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/InfoCategory.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/InfoCategory.java new file mode 100644 index 0000000..c6e46f2 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/InfoCategory.java @@ -0,0 +1,177 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a InfoCategory from Z39-50-APDU-1995. + *
+ * InfoCategory ::=
+ * SEQUENCE {
+ *   categoryTypeId [1] IMPLICIT OBJECT IDENTIFIER OPTIONAL
+ *   categoryValue [2] IMPLICIT INTEGER
+ * }
+ * 
+ */ +public final class InfoCategory extends ASN1Any { + + public ASN1ObjectIdentifier s_categoryTypeId; // optional + public ASN1Integer s_categoryValue; + + /** + * Constructor for a InfoCategory from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public InfoCategory(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // InfoCategory should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("InfoCategory: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: categoryTypeId [1] IMPLICIT OBJECT IDENTIFIER OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InfoCategory: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 1 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_categoryTypeId = new ASN1ObjectIdentifier(p, false); + part++; + } + + // Decoding: categoryValue [2] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InfoCategory: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 2 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("InfoCategory: bad tag in s_categoryValue\n"); + } + + s_categoryValue = new ASN1Integer(p, false); + part++; + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("InfoCategory: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the InfoCategory. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of InfoCategory, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 1; // number of mandatories + if (s_categoryTypeId != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_categoryTypeId: OBJECT IDENTIFIER OPTIONAL + + if (s_categoryTypeId != null) { + fields[x++] = s_categoryTypeId.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding s_categoryValue: INTEGER + + fields[x] = s_categoryValue.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the InfoCategory. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_categoryTypeId != null) { + str.append("categoryTypeId "); + str.append(s_categoryTypeId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("categoryValue "); + str.append(s_categoryValue); + + str.append("}"); + + return str.toString(); + } + +} \ No newline at end of file diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/InitializeRequest.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/InitializeRequest.java new file mode 100644 index 0000000..ebaaf56 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/InitializeRequest.java @@ -0,0 +1,501 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a InitializeRequest from Z39-50-APDU-1995. + *
+ * InitializeRequest ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   protocolVersion ProtocolVersion
+ *   options Options
+ *   preferredMessageSize [5] IMPLICIT INTEGER
+ *   exceptionalRecordSize [6] IMPLICIT INTEGER
+ *   idAuthentication [7] EXPLICIT IdAuthentication OPTIONAL
+ *   implementationId [110] IMPLICIT InternationalString OPTIONAL
+ *   implementationName [111] IMPLICIT InternationalString OPTIONAL
+ *   implementationVersion [112] IMPLICIT InternationalString OPTIONAL
+ *   userInformationField [11] EXPLICIT EXTERNAL OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class InitializeRequest extends ASN1Any { + + public ReferenceId s_referenceId; // optional + public ProtocolVersion s_protocolVersion; + public Options s_options; + public ASN1Integer s_preferredMessageSize; + public ASN1Integer s_exceptionalRecordSize; + public IdAuthentication s_idAuthentication; // optional + public InternationalString s_implementationId; // optional + public InternationalString s_implementationName; // optional + public InternationalString s_implementationVersion; // optional + public ASN1External s_userInformationField; // optional + public OtherInformation s_otherInfo; // optional + /** + * Default constructor for a InitializeRequest. + */ + public InitializeRequest() { + } + /** + * Constructor for a InitializeRequest from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public InitializeRequest(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // InitializeRequest should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("InitializeRequest: bad BER form"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InitializeRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: protocolVersion ProtocolVersion + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InitializeRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + s_protocolVersion = new ProtocolVersion(p, true); + part++; + + // Decoding: options Options + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InitializeRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + s_options = new Options(p, true); + part++; + + // Decoding: preferredMessageSize [5] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InitializeRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 5 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("InitializeRequest: bad tag in s_preferredMessageSize"); + } + + s_preferredMessageSize = new ASN1Integer(p, false); + part++; + + // Decoding: exceptionalRecordSize [6] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InitializeRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 6 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("InitializeRequest: bad tag in s_exceptionalRecordSize"); + } + + s_exceptionalRecordSize = new ASN1Integer(p, false); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_idAuthentication = null; + s_implementationId = null; + s_implementationName = null; + s_implementationVersion = null; + s_userInformationField = null; + s_otherInfo = null; + + // Decoding: idAuthentication [7] EXPLICIT IdAuthentication OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 7 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException("InitializeRequest: bad BER encoding: s_idAuthentication tag bad"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException("InitializeRequest: bad BER encoding: s_idAuthentication tag bad"); + } + + s_idAuthentication = new IdAuthentication(tagged.elementAt(0), true); + part++; + } + + // Decoding: implementationId [110] IMPLICIT InternationalString OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 110 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_implementationId = new InternationalString(p, false); + part++; + } + + // Decoding: implementationName [111] IMPLICIT InternationalString OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 111 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_implementationName = new InternationalString(p, false); + part++; + } + + // Decoding: implementationVersion [112] IMPLICIT InternationalString OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 112 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_implementationVersion = new InternationalString(p, false); + part++; + } + + // Decoding: userInformationField [11] EXPLICIT EXTERNAL OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 11 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException("InitializeRequest: bad BER encoding: s_userInformationField tag bad"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException("InitializeRequest: bad BER encoding: s_userInformationField tag bad"); + } + + s_userInformationField = new ASN1External(tagged.elementAt(0), true); + part++; + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("InitializeRequest: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the InitializeRequest. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of InitializeRequest, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + * @see org.xbib.asn1.BEREncoding#UNIVERSAL_TAG + * @see org.xbib.asn1.BEREncoding#APPLICATION_TAG + * @see org.xbib.asn1.BEREncoding#CONTEXT_SPECIFIC_TAG + * @see org.xbib.asn1.BEREncoding#PRIVATE_TAG + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 4; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_idAuthentication != null) { + numFields++; + } + if (s_implementationId != null) { + numFields++; + } + if (s_implementationName != null) { + numFields++; + } + if (s_implementationVersion != null) { + numFields++; + } + if (s_userInformationField != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_protocolVersion: ProtocolVersion + + fields[x++] = s_protocolVersion.berEncode(); + + // Encoding s_options: Options + + fields[x++] = s_options.berEncode(); + + // Encoding s_preferredMessageSize: INTEGER + + fields[x++] = s_preferredMessageSize.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 5); + + // Encoding s_exceptionalRecordSize: INTEGER + + fields[x++] = s_exceptionalRecordSize.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 6); + + // Encoding s_idAuthentication: IdAuthentication OPTIONAL + + if (s_idAuthentication != null) { + enc = new BEREncoding[1]; + enc[0] = s_idAuthentication.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 7, enc); + } + + // Encoding s_implementationId: InternationalString OPTIONAL + + if (s_implementationId != null) { + fields[x++] = s_implementationId.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 110); + } + + // Encoding s_implementationName: InternationalString OPTIONAL + + if (s_implementationName != null) { + fields[x++] = s_implementationName.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 111); + } + + // Encoding s_implementationVersion: InternationalString OPTIONAL + + if (s_implementationVersion != null) { + fields[x++] = s_implementationVersion.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 112); + } + + // Encoding s_userInformationField: EXTERNAL OPTIONAL + + if (s_userInformationField != null) { + enc = new BEREncoding[1]; + enc[0] = s_userInformationField.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 11, enc); + } + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x++] = s_otherInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the InitializeRequest. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("protocolVersion "); + str.append(s_protocolVersion); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("options "); + str.append(s_options); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("preferredMessageSize "); + str.append(s_preferredMessageSize); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("exceptionalRecordSize "); + str.append(s_exceptionalRecordSize); + outputted++; + + if (s_idAuthentication != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("idAuthentication "); + str.append(s_idAuthentication); + outputted++; + } + + if (s_implementationId != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("implementationId "); + str.append(s_implementationId); + outputted++; + } + + if (s_implementationName != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("implementationName "); + str.append(s_implementationName); + outputted++; + } + + if (s_implementationVersion != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("implementationVersion "); + str.append(s_implementationVersion); + outputted++; + } + + if (s_userInformationField != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("userInformationField "); + str.append(s_userInformationField); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/InitializeResponse.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/InitializeResponse.java new file mode 100644 index 0000000..140aede --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/InitializeResponse.java @@ -0,0 +1,484 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Boolean; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a InitializeResponse from Z39-50-APDU-1995. + *
+ * InitializeResponse ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   protocolVersion ProtocolVersion
+ *   options Options
+ *   preferredMessageSize [5] IMPLICIT INTEGER
+ *   exceptionalRecordSize [6] IMPLICIT INTEGER
+ *   result [12] IMPLICIT BOOLEAN
+ *   implementationId [110] IMPLICIT InternationalString OPTIONAL
+ *   implementationName [111] IMPLICIT InternationalString OPTIONAL
+ *   implementationVersion [112] IMPLICIT InternationalString OPTIONAL
+ *   userInformationField [11] EXPLICIT EXTERNAL OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class InitializeResponse extends ASN1Any { + + public ReferenceId s_referenceId; // optional + public ProtocolVersion s_protocolVersion; + public Options s_options; + public ASN1Integer s_preferredMessageSize; + public ASN1Integer s_exceptionalRecordSize; + public ASN1Boolean s_result; + public InternationalString s_implementationId; // optional + public InternationalString s_implementationName; // optional + public InternationalString s_implementationVersion; // optional + public ASN1External s_userInformationField; // optional + public OtherInformation s_otherInfo; // optional + /** + * Constructor for a InitializeResponse from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public InitializeResponse(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // InitializeResponse should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("InitializeResponse: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InitializeResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: protocolVersion ProtocolVersion + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InitializeResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + s_protocolVersion = new ProtocolVersion(p, true); + part++; + + // Decoding: options Options + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InitializeResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + s_options = new Options(p, true); + part++; + + // Decoding: preferredMessageSize [5] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InitializeResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 5 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("InitializeResponse: bad tag in s_preferredMessageSize\n"); + } + + s_preferredMessageSize = new ASN1Integer(p, false); + part++; + + // Decoding: exceptionalRecordSize [6] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InitializeResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 6 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("InitializeResponse: bad tag in s_exceptionalRecordSize\n"); + } + + s_exceptionalRecordSize = new ASN1Integer(p, false); + part++; + + // Decoding: result [12] IMPLICIT BOOLEAN + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("InitializeResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 12 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("InitializeResponse: bad tag in s_result\n"); + } + + s_result = new ASN1Boolean(p, false); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_implementationId = null; + s_implementationName = null; + s_implementationVersion = null; + s_userInformationField = null; + s_otherInfo = null; + + // Decoding: implementationId [110] IMPLICIT InternationalString OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 110 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_implementationId = new InternationalString(p, false); + part++; + } + + // Decoding: implementationName [111] IMPLICIT InternationalString OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 111 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_implementationName = new InternationalString(p, false); + part++; + } + + // Decoding: implementationVersion [112] IMPLICIT InternationalString OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 112 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_implementationVersion = new InternationalString(p, false); + part++; + } + + // Decoding: userInformationField [11] EXPLICIT EXTERNAL OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 11 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("InitializeResponse: bad BER encoding: s_userInformationField tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException + ("InitializeResponse: bad BER encoding: s_userInformationField tag bad\n"); + } + + s_userInformationField = new ASN1External(tagged.elementAt(0), true); + part++; + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("InitializeResponse: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the InitializeResponse. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of InitializeResponse, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 5; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_implementationId != null) { + numFields++; + } + if (s_implementationName != null) { + numFields++; + } + if (s_implementationVersion != null) { + numFields++; + } + if (s_userInformationField != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_protocolVersion: ProtocolVersion + + fields[x++] = s_protocolVersion.berEncode(); + + // Encoding s_options: Options + + fields[x++] = s_options.berEncode(); + + // Encoding s_preferredMessageSize: INTEGER + + fields[x++] = s_preferredMessageSize.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 5); + + // Encoding s_exceptionalRecordSize: INTEGER + + fields[x++] = s_exceptionalRecordSize.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 6); + + // Encoding s_result: BOOLEAN + + fields[x++] = s_result.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 12); + + // Encoding s_implementationId: InternationalString OPTIONAL + + if (s_implementationId != null) { + fields[x++] = s_implementationId.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 110); + } + + // Encoding s_implementationName: InternationalString OPTIONAL + + if (s_implementationName != null) { + fields[x++] = s_implementationName.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 111); + } + + // Encoding s_implementationVersion: InternationalString OPTIONAL + + if (s_implementationVersion != null) { + fields[x++] = s_implementationVersion.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 112); + } + + // Encoding s_userInformationField: EXTERNAL OPTIONAL + + if (s_userInformationField != null) { + enc = new BEREncoding[1]; + enc[0] = s_userInformationField.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 11, enc); + } + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the InitializeResponse. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("protocolVersion "); + str.append(s_protocolVersion); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("options "); + str.append(s_options); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("preferredMessageSize "); + str.append(s_preferredMessageSize); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("exceptionalRecordSize "); + str.append(s_exceptionalRecordSize); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("result "); + str.append(s_result); + outputted++; + + if (s_implementationId != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("implementationId "); + str.append(s_implementationId); + outputted++; + } + + if (s_implementationName != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("implementationName "); + str.append(s_implementationName); + outputted++; + } + + if (s_implementationVersion != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("implementationVersion "); + str.append(s_implementationVersion); + outputted++; + } + + if (s_userInformationField != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("userInformationField "); + str.append(s_userInformationField); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/IntUnit.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/IntUnit.java new file mode 100644 index 0000000..a7a8e0a --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/IntUnit.java @@ -0,0 +1,175 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a IntUnit from Z39-50-APDU-1995. + *
+ * IntUnit ::=
+ * SEQUENCE {
+ *   value [1] IMPLICIT INTEGER
+ *   unitUsed [2] IMPLICIT Unit
+ * }
+ * 
+ */ +public final class IntUnit extends ASN1Any { + + public ASN1Integer s_value; + public Unit s_unitUsed; + + /** + * Constructor for a IntUnit from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public IntUnit(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // IntUnit should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("IntUnit: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: value [1] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("IntUnit: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 1 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("IntUnit: bad tag in s_value\n"); + } + + s_value = new ASN1Integer(p, false); + part++; + + // Decoding: unitUsed [2] IMPLICIT Unit + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("IntUnit: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 2 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("IntUnit: bad tag in s_unitUsed\n"); + } + + s_unitUsed = new Unit(p, false); + part++; + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("IntUnit: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the IntUnit. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of IntUnit, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 2; // number of mandatories + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_value: INTEGER + + fields[x++] = s_value.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + + // Encoding s_unitUsed: Unit + + fields[x] = s_unitUsed.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the IntUnit. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + str.append("value "); + str.append(s_value); + outputted++; + if (0 < outputted) { + str.append(", "); + } + str.append("unitUsed "); + str.append(s_unitUsed); + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/InternationalString.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/InternationalString.java new file mode 100644 index 0000000..8a058b5 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/InternationalString.java @@ -0,0 +1,83 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1GeneralString; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a InternationalString from Z39-50-APDU-1995 + *
+ * InternationalString ::=
+ * GeneralString
+ * 
+ */ +public final class InternationalString extends ASN1Any { + + public ASN1GeneralString value; + + public InternationalString() { + } + + + /** + * Constructor for a InternationalString from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public InternationalString(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + value = new ASN1GeneralString(ber, checkTag); + } + + /** + * Returns a BER encoding of the InternationalString. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return value.berEncode(); + } + + /** + * Returns a BER encoding of InternationalString, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the InternationalString. + */ + + public String toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/KnownProximityUnit.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/KnownProximityUnit.java new file mode 100644 index 0000000..61d063f --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/KnownProximityUnit.java @@ -0,0 +1,94 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a KnownProximityUnit from Z39-50-APDU-1995. + *
+ * KnownProximityUnit ::=
+ * INTEGER
+ * 
+ */ +public final class KnownProximityUnit extends ASN1Any { + + public static final int E_character = 1; + public static final int E_word = 2; + public static final int E_sentence = 3; + public static final int E_paragraph = 4; + public static final int E_section = 5; + public static final int E_chapter = 6; + public static final int E_document = 7; + public static final int E_element = 8; + public static final int E_subelement = 9; + public static final int E_elementType = 10; + public static final int E_byte = 11; + public ASN1Integer value; + /** + * Constructor for a KnownProximityUnit from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public KnownProximityUnit(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + value = new ASN1Integer(ber, checkTag); + } + + /** + * Returns a BER encoding of the KnownProximityUnit. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return value.berEncode(); + } + + /** + * Returns a BER encoding of KnownProximityUnit, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the KnownProximityUnit. + */ + public String toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ListEntries.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ListEntries.java new file mode 100644 index 0000000..f60d26f --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ListEntries.java @@ -0,0 +1,232 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a ListEntries from Z39-50-APDU-1995 + *
+ * ListEntries ::=
+ * SEQUENCE {
+ *   entries [1] IMPLICIT SEQUENCE OF Entry OPTIONAL
+ *   nonsurrogateDiagnostics [2] IMPLICIT SEQUENCE OF DiagRec OPTIONAL
+ * }
+ * 
+ */ +public final class ListEntries extends ASN1Any { + + public Entry s_entries[]; // optional + public DiagRec s_nonsurrogateDiagnostics[]; // optional + + + /** + * Constructor for a ListEntries from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public ListEntries(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // ListEntries should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("ListEntries: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_entries = null; + s_nonsurrogateDiagnostics = null; + + // Decoding: entries [1] IMPLICIT SEQUENCE OF Entry OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 1 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + s_entries = new Entry[parts]; + int n; + for (n = 0; n < parts; n++) { + s_entries[n] = new Entry(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + } + + // Decoding: nonsurrogateDiagnostics [2] IMPLICIT SEQUENCE OF DiagRec OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 2 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + s_nonsurrogateDiagnostics = new DiagRec[parts]; + int n; + for (n = 0; n < parts; n++) { + s_nonsurrogateDiagnostics[n] = new DiagRec(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("ListEntries: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ListEntries. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ListEntries, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 0; // number of mandatories + if (s_entries != null) { + numFields++; + } + if (s_nonsurrogateDiagnostics != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + + // Encoding s_entries: SEQUENCE OF OPTIONAL + + if (s_entries != null) { + f2 = new BEREncoding[s_entries.length]; + + for (p = 0; p < s_entries.length; p++) { + f2[p] = s_entries[p].berEncode(); + } + + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 1, f2); + } + + // Encoding s_nonsurrogateDiagnostics: SEQUENCE OF OPTIONAL + + if (s_nonsurrogateDiagnostics != null) { + f2 = new BEREncoding[s_nonsurrogateDiagnostics.length]; + + for (p = 0; p < s_nonsurrogateDiagnostics.length; p++) { + f2[p] = s_nonsurrogateDiagnostics[p].berEncode(); + } + + fields[x] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 2, f2); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ListEntries. + */ + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_entries != null) { + str.append("entries "); + str.append("{"); + for (p = 0; p < s_entries.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(s_entries[p]); + } + str.append("}"); + outputted++; + } + + if (s_nonsurrogateDiagnostics != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("nonsurrogateDiagnostics "); + str.append("{"); + for (p = 0; p < s_nonsurrogateDiagnostics.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(s_nonsurrogateDiagnostics[p]); + } + str.append("}"); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ListStatuses.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ListStatuses.java new file mode 100644 index 0000000..316942e --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ListStatuses.java @@ -0,0 +1,115 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a ListStatuses from Z39-50-APDU-1995. + *
+ * ListStatuses ::=
+ * SEQUENCE OF ListStatuses1
+ * 
+ */ +public final class ListStatuses extends ASN1Any { + + public ListStatuses1 value[]; + + + /** + * Constructor for a ListStatuses from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ListStatuses(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // ListStatuses should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("ListStatuses: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + value = new ListStatuses1[numParts]; + int p; + for (p = 0; p < numParts; p++) { + value[p] = new ListStatuses1(berConstructed.elementAt(p), true); + } + } + + /** + * Returns a BER encoding of the ListStatuses. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ListStatuses, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + BEREncoding fields[] = new BERConstructed[value.length]; + int p; + + for (p = 0; p < value.length; p++) { + fields[p] = value[p].berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ListStatuses. + */ + + public String toString() { + StringBuilder str = new StringBuilder("{"); + int p; + + for (p = 0; p < value.length; p++) { + str.append(value[p]); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ListStatuses1.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ListStatuses1.java new file mode 100644 index 0000000..5d4ef33 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ListStatuses1.java @@ -0,0 +1,166 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a ListStatuses1 from Z39-50-APDU-1995. + *
+ * ListStatuses1 ::=
+ * SEQUENCE {
+ *   id ResultSetId
+ *   status DeleteSetStatus
+ * }
+ * 
+ */ +public final class ListStatuses1 extends ASN1Any { + + public ResultSetId s_id; + public DeleteSetStatus s_status; + + + /** + * Constructor for a ListStatuses1 from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ListStatuses1(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // ListStatuses1 should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("ListStatuses1: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: id ResultSetId + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ListStatuses1: incomplete"); + } + p = berConstructed.elementAt(part); + + s_id = new ResultSetId(p, true); + part++; + + // Decoding: status DeleteSetStatus + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ListStatuses1: incomplete"); + } + p = berConstructed.elementAt(part); + + s_status = new DeleteSetStatus(p, true); + part++; + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("ListStatuses1: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ListStatuses1. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ListStatuses1, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 2; // number of mandatories + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_id: ResultSetId + + fields[x++] = s_id.berEncode(); + + // Encoding s_status: DeleteSetStatus + + fields[x] = s_status.berEncode(); + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ListStatuses1. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + str.append("id "); + str.append(s_id); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("status "); + str.append(s_status); + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/NamePlusRecord.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/NamePlusRecord.java new file mode 100644 index 0000000..5bba4a2 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/NamePlusRecord.java @@ -0,0 +1,202 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a NamePlusRecord from Z39-50-APDU-1995 + *
+ * NamePlusRecord ::=
+ * SEQUENCE {
+ *   name [0] IMPLICIT DatabaseName OPTIONAL
+ *   record [1] EXPLICIT NamePlusRecord_record
+ * }
+ * 
+ */ + +public final class NamePlusRecord extends ASN1Any { + + public DatabaseName s_name; // optional + public NamePlusRecordRecord s_record; + + /** + * Default constructor for a NamePlusRecord. + */ + + public NamePlusRecord() { + } + + /** + * Constructor for a NamePlusRecord from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public NamePlusRecord(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // NamePlusRecord should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("NamePlusRecord: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + + // Decoding: name [0] IMPLICIT DatabaseName OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("NamePlusRecord: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 0 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_name = new DatabaseName(p, false); + part++; + } + + // Decoding: record [1] EXPLICIT NamePlusRecord_record + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("NamePlusRecord: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 1 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("NamePlusRecord: bad tag in s_record\n"); + } + + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException("NamePlusRecord: bad BER encoding: s_record tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException("NamePlusRecord: bad BER encoding: s_record tag bad\n"); + } + + s_record = new NamePlusRecordRecord(tagged.elementAt(0), true); + part++; + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("NamePlusRecord: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the NamePlusRecord. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of NamePlusRecord, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 1; // number of mandatories + if (s_name != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + + // Encoding s_name: DatabaseName OPTIONAL + + if (s_name != null) { + fields[x++] = s_name.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 0); + } + + // Encoding s_record: NamePlusRecord_record + + enc = new BEREncoding[1]; + enc[0] = s_record.berEncode(); + fields[x] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 1, enc); + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the NamePlusRecord. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_name != null) { + str.append("name "); + str.append(s_name); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("record "); + str.append(s_record); + + str.append("}"); + + return str.toString(); + } + +} \ No newline at end of file diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/NamePlusRecordRecord.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/NamePlusRecordRecord.java new file mode 100644 index 0000000..362a29f --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/NamePlusRecordRecord.java @@ -0,0 +1,312 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a NamePlusRecord_record from Z39-50-APDU-1995. + *
+ * NamePlusRecord_record ::=
+ * CHOICE {
+ *   retrievalRecord [1] EXPLICIT EXTERNAL
+ *   surrogateDiagnostic [2] EXPLICIT DiagRec
+ *   startingFragment [3] EXPLICIT FragmentSyntax
+ *   intermediateFragment [4] EXPLICIT FragmentSyntax
+ *   finalFragment [5] EXPLICIT FragmentSyntax
+ * }
+ * 
+ */ +public final class NamePlusRecordRecord extends ASN1Any { + + public ASN1External c_retrievalRecord; + public DiagRec c_surrogateDiagnostic; + public FragmentSyntax c_startingFragment; + public FragmentSyntax c_intermediateFragment; + public FragmentSyntax c_finalFragment; + + /** + * Constructor for a NamePlusRecord_record from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public NamePlusRecordRecord(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + BERConstructed tagwrapper; + + // Null out all choices + + c_retrievalRecord = null; + c_surrogateDiagnostic = null; + c_startingFragment = null; + c_intermediateFragment = null; + c_finalFragment = null; + + // Try choice retrievalRecord + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("NamePlusRecord_record: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("NamePlusRecord_record: bad BER form\n"); + } + c_retrievalRecord = new ASN1External(tagwrapper.elementAt(0), true); + return; + } + + // Try choice surrogateDiagnostic + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("NamePlusRecord_record: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("NamePlusRecord_record: bad BER form\n"); + } + c_surrogateDiagnostic = new DiagRec(tagwrapper.elementAt(0), true); + return; + } + + // Try choice startingFragment + if (ber.tagGet() == 3 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("NamePlusRecord_record: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("NamePlusRecord_record: bad BER form\n"); + } + c_startingFragment = new FragmentSyntax(tagwrapper.elementAt(0), true); + return; + } + + // Try choice intermediateFragment + if (ber.tagGet() == 4 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("NamePlusRecord_record: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("NamePlusRecord_record: bad BER form\n"); + } + c_intermediateFragment = new FragmentSyntax(tagwrapper.elementAt(0), true); + return; + } + + // Try choice finalFragment + if (ber.tagGet() == 5 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("NamePlusRecord_record: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("NamePlusRecord_record: bad BER form\n"); + } + c_finalFragment = new FragmentSyntax(tagwrapper.elementAt(0), true); + return; + } + + throw new ASN1Exception("NamePlusRecord_record: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of NamePlusRecord_record. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + BEREncoding enc[]; + + // Encoding choice: c_retrievalRecord + if (c_retrievalRecord != null) { + enc = new BEREncoding[1]; + enc[0] = c_retrievalRecord.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 1, enc); + } + + // Encoding choice: c_surrogateDiagnostic + if (c_surrogateDiagnostic != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + enc = new BEREncoding[1]; + enc[0] = c_surrogateDiagnostic.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 2, enc); + } + + // Encoding choice: c_startingFragment + if (c_startingFragment != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + enc = new BEREncoding[1]; + enc[0] = c_startingFragment.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 3, enc); + } + + // Encoding choice: c_intermediateFragment + if (c_intermediateFragment != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + enc = new BEREncoding[1]; + enc[0] = c_intermediateFragment.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 4, enc); + } + + // Encoding choice: c_finalFragment + if (c_finalFragment != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + enc = new BEREncoding[1]; + enc[0] = c_finalFragment.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 5, enc); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("NamePlusRecord_record: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the NamePlusRecord_record. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + + boolean found = false; + + if (c_retrievalRecord != null) { + found = true; + str.append("retrievalRecord "); + str.append(c_retrievalRecord); + } + + if (c_surrogateDiagnostic != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("surrogateDiagnostic "); + str.append(c_surrogateDiagnostic); + } + + if (c_startingFragment != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("startingFragment "); + str.append(c_startingFragment); + } + + if (c_intermediateFragment != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("intermediateFragment "); + str.append(c_intermediateFragment); + } + + if (c_finalFragment != null) { + if (found) { + str.append(" "); + } + str.append("finalFragment "); + str.append(c_finalFragment); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributes.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributes.java new file mode 100644 index 0000000..1cdb9ca --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributes.java @@ -0,0 +1,123 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a OccurrenceByAttributes from Z39-50-APDU-1995. + *
+ * OccurrenceByAttributes ::=
+ * SEQUENCE OF OccurrenceByAttributes1
+ * 
+ */ +public final class OccurrenceByAttributes extends ASN1Any { + public OccurrenceByAttributes1 value[]; + + + /** + * Constructor for a OccurrenceByAttributes from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public OccurrenceByAttributes(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // OccurrenceByAttributes should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("OccurrenceByAttributes: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + value = new OccurrenceByAttributes1[numParts]; + int p; + for (p = 0; p < numParts; p++) { + value[p] = new OccurrenceByAttributes1(berConstructed.elementAt(p), true); + } + } + + /** + * Returns a BER encoding of the OccurrenceByAttributes. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of OccurrenceByAttributes, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + BEREncoding fields[] = new BERConstructed[value.length]; + int p; + + for (p = 0; p < value.length; p++) { + fields[p] = value[p].berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the OccurrenceByAttributes. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int p; + + for (p = 0; p < value.length; p++) { + str.append(value[p]); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributes1.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributes1.java new file mode 100644 index 0000000..a67a239 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributes1.java @@ -0,0 +1,238 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a OccurrenceByAttributes1 from Z39-50-APDU-1995. + *
+ * OccurrenceByAttributes1 ::=
+ * SEQUENCE {
+ *   attributes [1] EXPLICIT AttributeList
+ *   occurrences OccurrenceByAttributes_occurrences OPTIONAL
+ *   otherOccurInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ + +public final class OccurrenceByAttributes1 extends ASN1Any { + + public AttributeList s_attributes; + public OccurrenceByAttributesOccurrences s_occurrences; // optional + public OtherInformation s_otherOccurInfo; // optional + + /** + * Constructor for a OccurrenceByAttributes1 from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public OccurrenceByAttributes1(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // OccurrenceByAttributes1 should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("OccurrenceByAttributes1: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + + // Decoding: attributes [1] EXPLICIT AttributeList + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("OccurrenceByAttributes1: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 1 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("OccurrenceByAttributes1: bad tag in s_attributes\n"); + } + + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("OccurrenceByAttributes1: bad BER encoding: s_attributes tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException + ("OccurrenceByAttributes1: bad BER encoding: s_attributes tag bad\n"); + } + + s_attributes = new AttributeList(tagged.elementAt(0), true); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_occurrences = null; + s_otherOccurInfo = null; + + // Decoding: occurrences OccurrenceByAttributes_occurrences OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_occurrences = new OccurrenceByAttributesOccurrences(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_occurrences = null; // no, not present + } + + // Decoding: otherOccurInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherOccurInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherOccurInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("OccurrenceByAttributes1: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the OccurrenceByAttributes1. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of OccurrenceByAttributes1, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 1; // number of mandatories + if (s_occurrences != null) { + numFields++; + } + if (s_otherOccurInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + + // Encoding s_attributes: AttributeList + + enc = new BEREncoding[1]; + enc[0] = s_attributes.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 1, enc); + + // Encoding s_occurrences: OccurrenceByAttributes_occurrences OPTIONAL + + if (s_occurrences != null) { + fields[x++] = s_occurrences.berEncode(); + } + + // Encoding s_otherOccurInfo: OtherInformation OPTIONAL + + if (s_otherOccurInfo != null) { + fields[x] = s_otherOccurInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the OccurrenceByAttributes1. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + str.append("attributes "); + str.append(s_attributes); + outputted++; + + if (s_occurrences != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("occurrences "); + str.append(s_occurrences); + outputted++; + } + + if (s_otherOccurInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherOccurInfo "); + str.append(s_otherOccurInfo); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributesOccurrences.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributesOccurrences.java new file mode 100644 index 0000000..ff1c0f8 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributesOccurrences.java @@ -0,0 +1,207 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a OccurrenceByAttributes_occurrences from Z39-50-APDU-1995. + *
+ * OccurrenceByAttributes_occurrences ::=
+ * CHOICE {
+ *   global [2] EXPLICIT INTEGER
+ *   byDatabase [3] IMPLICIT SEQUENCE OF OccurrenceByAttributes_occurrences_byDatabase
+ * }
+ * 
+ */ +public final class OccurrenceByAttributesOccurrences extends ASN1Any { + + public ASN1Integer c_global; + public OccurrenceByAttributesOccurrencesByDatabase c_byDatabase[]; + + + /** + * Constructor for a OccurrenceByAttributes_occurrences from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public OccurrenceByAttributesOccurrences(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed tagwrapper; + c_global = null; + c_byDatabase = null; + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("OccurrenceByAttributes_occurrences: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("OccurrenceByAttributes_occurrences: bad BER form\n"); + } + c_global = new ASN1Integer(tagwrapper.elementAt(0), true); + return; + } + + // Try choice byDatabase + if (ber.tagGet() == 3 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + BEREncoding ber_data; + ber_data = ber; + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber_data; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("OccurrenceByAttributes_occurrences: bad BER form\n"); + } + + int numParts = berConstructed.numberComponents(); + int p; + + c_byDatabase = new OccurrenceByAttributesOccurrencesByDatabase[numParts]; + + for (p = 0; p < numParts; p++) { + c_byDatabase[p] = new OccurrenceByAttributesOccurrencesByDatabase(berConstructed.elementAt(p), true); + } + return; + } + + throw new ASN1Exception("OccurrenceByAttributes_occurrences: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of OccurrenceByAttributes_occurrences. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + BEREncoding f2[]; + int p; + BEREncoding enc[]; + + // Encoding choice: c_global + if (c_global != null) { + enc = new BEREncoding[1]; + enc[0] = c_global.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 2, enc); + } + + // Encoding choice: c_byDatabase + if (c_byDatabase != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + f2 = new BEREncoding[c_byDatabase.length]; + + for (p = 0; p < c_byDatabase.length; p++) { + f2[p] = c_byDatabase[p].berEncode(); + } + + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 3, f2); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("OccurrenceByAttributes_occurrences: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the OccurrenceByAttributes_occurrences. + */ + + public String + toString() { + int p; + StringBuilder str = new StringBuilder("{"); + + boolean found = false; + + if (c_global != null) { + found = true; + str.append("global "); + str.append(c_global); + } + + if (c_byDatabase != null) { + if (found) { + str.append(" "); + } + str.append("byDatabase "); + str.append("{"); + for (p = 0; p < c_byDatabase.length; p++) { + str.append(c_byDatabase[p]); + } + str.append("}"); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributesOccurrencesByDatabase.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributesOccurrencesByDatabase.java new file mode 100644 index 0000000..6cc94aa --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/OccurrenceByAttributesOccurrencesByDatabase.java @@ -0,0 +1,216 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a OccurrenceByAttributes_occurrences_byDatabase from Z39-50-APDU-1995. + *
+ * OccurrenceByAttributes_occurrences_byDatabase ::=
+ * SEQUENCE {
+ *   db DatabaseName
+ *   num [1] IMPLICIT INTEGER OPTIONAL
+ *   otherDbInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class OccurrenceByAttributesOccurrencesByDatabase extends ASN1Any { + + public DatabaseName s_db; + public ASN1Integer s_num; // optional + public OtherInformation s_otherDbInfo; // optional + + /** + * Constructor for a OccurrenceByAttributes_occurrences_byDatabase from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public OccurrenceByAttributesOccurrencesByDatabase(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // OccurrenceByAttributes_occurrences_byDatabase should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("OccurrenceByAttributes_occurrences_byDatabase: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: db DatabaseName + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("OccurrenceByAttributes_occurrences_byDatabase: incomplete"); + } + p = berConstructed.elementAt(part); + + s_db = new DatabaseName(p, true); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_num = null; + s_otherDbInfo = null; + + // Decoding: num [1] IMPLICIT INTEGER OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 1 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_num = new ASN1Integer(p, false); + part++; + } + + // Decoding: otherDbInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherDbInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherDbInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("OccurrenceByAttributes_occurrences_byDatabase: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the OccurrenceByAttributes_occurrences_byDatabase. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of OccurrenceByAttributes_occurrences_byDatabase, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 1; // number of mandatories + if (s_num != null) { + numFields++; + } + if (s_otherDbInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_db: DatabaseName + + fields[x++] = s_db.berEncode(); + + // Encoding s_num: INTEGER OPTIONAL + + if (s_num != null) { + fields[x++] = s_num.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding s_otherDbInfo: OtherInformation OPTIONAL + + if (s_otherDbInfo != null) { + fields[x] = s_otherDbInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the OccurrenceByAttributes_occurrences_byDatabase. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + str.append("db "); + str.append(s_db); + outputted++; + + if (s_num != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("num "); + str.append(s_num); + outputted++; + } + + if (s_otherDbInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherDbInfo "); + str.append(s_otherDbInfo); + } + + str.append("}"); + + return str.toString(); + } + +} \ No newline at end of file diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Operand.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Operand.java new file mode 100644 index 0000000..660f885 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Operand.java @@ -0,0 +1,198 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a Operand from Z39-50-APDU-1995. + *
+ * Operand ::=
+ * CHOICE {
+ *   attrTerm AttributesPlusTerm
+ *   resultSet ResultSetId
+ *   resultAttr ResultSetPlusAttributes
+ * }
+ * 
+ */ +public final class Operand extends ASN1Any { + + public AttributesPlusTerm c_attrTerm; + public ResultSetId c_resultSet; + public ResultSetPlusAttributes c_resultAttr; + + + public Operand() { + } + + + /** + * Constructor for a Operand from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Operand(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Null out all choices + + c_attrTerm = null; + c_resultSet = null; + c_resultAttr = null; + + // Try choice attrTerm + try { + c_attrTerm = new AttributesPlusTerm(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + + // Try choice resultSet + try { + c_resultSet = new ResultSetId(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + + // Try choice resultAttr + try { + c_resultAttr = new ResultSetPlusAttributes(ber, checkTag); + return; + } catch (ASN1Exception e) { + // failed to decode, continue on + } + + throw new ASN1Exception("Operand: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of Operand. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + // Encoding choice: c_attrTerm + if (c_attrTerm != null) { + chosen = c_attrTerm.berEncode(); + } + + // Encoding choice: c_resultSet + if (c_resultSet != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_resultSet.berEncode(); + } + + // Encoding choice: c_resultAttr + if (c_resultAttr != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_resultAttr.berEncode(); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("Operand: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the Operand. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + + boolean found = false; + + if (c_attrTerm != null) { + found = true; + str.append("attrTerm "); + str.append(c_attrTerm); + } + + if (c_resultSet != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("resultSet "); + str.append(c_resultSet); + } + + if (c_resultAttr != null) { + if (found) { + str.append(" "); + } + str.append("resultAttr "); + str.append(c_resultAttr); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Operator.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Operator.java new file mode 100644 index 0000000..7c538fb --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Operator.java @@ -0,0 +1,240 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Null; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a Operator from Z39-50-APDU-1995. + *
+ * Operator ::=
+ * [46] EXPLICIT CHOICE {
+ *   and [0] IMPLICIT NULL
+ *   or [1] IMPLICIT NULL
+ *   and-not [2] IMPLICIT NULL
+ *   prox [3] IMPLICIT ProximityOperator
+ * }
+ * 
+ */ +public final class Operator extends ASN1Any { + + public ASN1Null c_and; + public ASN1Null c_or; + public ASN1Null c_and_not; + public ProximityOperator c_prox; + + + public Operator() { + } + + + /** + * Constructor for a Operator from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Operator(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Check tag matches + + if (checkTag) { + if (ber.tagGet() != 46 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("Operator: bad BER: tag=" + ber.tagGet() + " expected 46\n"); + } + } + + // Unwrap explicit tag + + BERConstructed tagwrapper; + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Operator: bad BER tag form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("Operator: bad BER tag form\n"); + } + ber = tagwrapper.elementAt(0); + + // Null out all choices + + c_and = null; + c_or = null; + c_and_not = null; + c_prox = null; + + // Try choice and + if (ber.tagGet() == 0 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_and = new ASN1Null(ber, false); + return; + } + + // Try choice or + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_or = new ASN1Null(ber, false); + return; + } + + // Try choice and-not + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_and_not = new ASN1Null(ber, false); + return; + } + + // Try choice prox + if (ber.tagGet() == 3 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_prox = new ProximityOperator(ber, false); + return; + } + + throw new ASN1Exception("Operator: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of Operator. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 46); + } + + /** + * Returns a BER encoding of Operator, implicitly tagged. + * + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + BEREncoding chosen = null; + + // Encoding choice: c_and + if (c_and != null) { + chosen = c_and.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 0); + } + + // Encoding choice: c_or + if (c_or != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_or.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding choice: c_and_not + if (c_and_not != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_and_not.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + } + + // Encoding choice: c_prox + if (c_prox != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_prox.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 3); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + // Return chosen element wrapped in its explicit tag + + BEREncoding exp_tag_data[] = new BEREncoding[1]; + exp_tag_data[0] = chosen; + return new BERConstructed(tagType, tag, exp_tag_data); + } + + /** + * Returns a new String object containing a text representing + * of the Operator. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + + boolean found = false; + + if (c_and != null) { + found = true; + str.append("and "); + str.append(c_and); + } + + if (c_or != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("or "); + str.append(c_or); + } + + if (c_and_not != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("and-not "); + str.append(c_and_not); + } + + if (c_prox != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("prox "); + str.append(c_prox); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Options.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Options.java new file mode 100644 index 0000000..4d35049 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Options.java @@ -0,0 +1,97 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1BitString; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a Options from Z39-50-APDU-1995. + *
+ * Options ::=
+ * [4] IMPLICIT BIT STRING
+ * 
+ */ +public final class Options extends ASN1Any { + public ASN1BitString value; + + /** + * Default constructor for a Options. + */ + public Options() { + } + + + /** + * Constructor for a Options from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Options(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Check tag matches + + if (checkTag) { + if (ber.tagGet() != 4 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("Options: bad BER: tag=" + ber.tagGet() + " expected 4\n"); + } + } + + value = new ASN1BitString(ber, false); + } + + /** + * Returns a BER encoding of the Options. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 4); + } + + /** + * Returns a BER encoding of Options, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the Options. + */ + public String toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformation.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformation.java new file mode 100644 index 0000000..b13ba3c --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformation.java @@ -0,0 +1,139 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a OtherInformation from Z39-50-APDU-1995. + *
+ * OtherInformation ::=
+ * [201] IMPLICIT SEQUENCE OF OtherInformation1
+ * 
+ */ +public final class OtherInformation extends ASN1Any { + public OtherInformation1 value[]; + + + /** + * Default constructor for a OtherInformation. + */ + + public OtherInformation() { + } + + + /** + * Constructor for a OtherInformation from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public OtherInformation(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Check tag matches + + if (checkTag) { + if (ber.tagGet() != 201 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("OtherInformation: bad BER: tag=" + ber.tagGet() + " expected 201\n"); + } + } + + // OtherInformation should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("OtherInformation: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + value = new OtherInformation1[numParts]; + int p; + for (p = 0; p < numParts; p++) { + value[p] = new OtherInformation1(berConstructed.elementAt(p), true); + } + } + + /** + * Returns a BER encoding of the OtherInformation. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 201); + } + + /** + * Returns a BER encoding of OtherInformation, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + BEREncoding fields[] = new BERConstructed[value.length]; + int p; + + for (p = 0; p < value.length; p++) { + fields[p] = value[p].berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the OtherInformation. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int p; + + for (p = 0; p < value.length; p++) { + str.append(value[p]); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformation1.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformation1.java new file mode 100644 index 0000000..8926353 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformation1.java @@ -0,0 +1,179 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a OtherInformation1 from Z39-50-APDU-1995. + *
+ * OtherInformation1 ::=
+ * SEQUENCE {
+ *   category [1] IMPLICIT InfoCategory OPTIONAL
+ *   information OtherInformation_information
+ * }
+ * 
+ */ +public final class OtherInformation1 extends ASN1Any { + + public InfoCategory s_category; // optional + public OtherInformationInformation s_information; + + /** + * Constructor for a OtherInformation1 from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public OtherInformation1(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // OtherInformation1 should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("OtherInformation1: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: category [1] IMPLICIT InfoCategory OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("OtherInformation1: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 1 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_category = new InfoCategory(p, false); + part++; + } + + // Decoding: information OtherInformation_information + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("OtherInformation1: incomplete"); + } + p = berConstructed.elementAt(part); + + s_information = new OtherInformationInformation(p, true); + part++; + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("OtherInformation1: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the OtherInformation1. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of OtherInformation1, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 1; // number of mandatories + if (s_category != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_category: InfoCategory OPTIONAL + + if (s_category != null) { + fields[x++] = s_category.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding s_information: OtherInformation_information + + fields[x] = s_information.berEncode(); + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the OtherInformation1. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_category != null) { + str.append("category "); + str.append(s_category); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + + + str.append("information "); + str.append(s_information); + + str.append("}"); + + return str.toString(); + } + +} \ No newline at end of file diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformationInformation.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformationInformation.java new file mode 100644 index 0000000..3086f8b --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/OtherInformationInformation.java @@ -0,0 +1,221 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.ASN1OctetString; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a OtherInformation_information from Z39-50-APDU-1995. + *
+ * OtherInformation_information ::=
+ * CHOICE {
+ *   characterInfo [2] IMPLICIT InternationalString
+ *   binaryInfo [3] IMPLICIT OCTET STRING
+ *   externallyDefinedInfo [4] IMPLICIT EXTERNAL
+ *   oid [5] IMPLICIT OBJECT IDENTIFIER
+ * }
+ * 
+ */ +public final class OtherInformationInformation extends ASN1Any { + + public InternationalString c_characterInfo; + public ASN1OctetString c_binaryInfo; + public ASN1External c_externallyDefinedInfo; + public ASN1ObjectIdentifier c_oid; + + /** + * Constructor for a OtherInformation_information from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public OtherInformationInformation(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Null out all choices + + c_characterInfo = null; + c_binaryInfo = null; + c_externallyDefinedInfo = null; + c_oid = null; + + // Try choice characterInfo + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_characterInfo = new InternationalString(ber, false); + return; + } + + // Try choice binaryInfo + if (ber.tagGet() == 3 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_binaryInfo = new ASN1OctetString(ber, false); + return; + } + + // Try choice externallyDefinedInfo + if (ber.tagGet() == 4 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_externallyDefinedInfo = new ASN1External(ber, false); + return; + } + + // Try choice oid + if (ber.tagGet() == 5 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_oid = new ASN1ObjectIdentifier(ber, false); + return; + } + + throw new ASN1Exception("OtherInformation_information: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of OtherInformation_information. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + // Encoding choice: c_characterInfo + if (c_characterInfo != null) { + chosen = c_characterInfo.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + } + + // Encoding choice: c_binaryInfo + if (c_binaryInfo != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_binaryInfo.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 3); + } + + // Encoding choice: c_externallyDefinedInfo + if (c_externallyDefinedInfo != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_externallyDefinedInfo.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 4); + } + + // Encoding choice: c_oid + if (c_oid != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_oid.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 5); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("OtherInformation_information: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the OtherInformation_information. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + + boolean found = false; + + if (c_characterInfo != null) { + found = true; + str.append("characterInfo "); + str.append(c_characterInfo); + } + + if (c_binaryInfo != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("binaryInfo "); + str.append(c_binaryInfo); + } + + if (c_externallyDefinedInfo != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("externallyDefinedInfo "); + str.append(c_externallyDefinedInfo); + } + + if (c_oid != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("oid "); + str.append(c_oid); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/PDU.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/PDU.java new file mode 100644 index 0000000..b43c563 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/PDU.java @@ -0,0 +1,722 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a PDU from Z39-50-APDU-1995. + *
+ * PDU ::=
+ * CHOICE {
+ *   initRequest [20] IMPLICIT InitializeRequest
+ *   initResponse [21] IMPLICIT InitializeResponse
+ *   searchRequest [22] IMPLICIT SearchRequest
+ *   searchResponse [23] IMPLICIT SearchResponse
+ *   presentRequest [24] IMPLICIT PresentRequest
+ *   presentResponse [25] IMPLICIT PresentResponse
+ *   deleteResultSetRequest [26] IMPLICIT DeleteResultSetRequest
+ *   deleteResultSetResponse [27] IMPLICIT DeleteResultSetResponse
+ *   accessControlRequest [28] IMPLICIT AccessControlRequest
+ *   accessControlResponse [29] IMPLICIT AccessControlResponse
+ *   resourceControlRequest [30] IMPLICIT ResourceControlRequest
+ *   resourceControlResponse [31] IMPLICIT ResourceControlResponse
+ *   triggerResourceControlRequest [32] IMPLICIT TriggerResourceControlRequest
+ *   resourceReportRequest [33] IMPLICIT ResourceReportRequest
+ *   resourceReportResponse [34] IMPLICIT ResourceReportResponse
+ *   scanRequest [35] IMPLICIT ScanRequest
+ *   scanResponse [36] IMPLICIT ScanResponse
+ *   sortRequest [43] IMPLICIT SortRequest
+ *   sortResponse [44] IMPLICIT SortResponse
+ *   segmentRequest [45] IMPLICIT Segment
+ *   extendedServicesRequest [46] IMPLICIT ExtendedServicesRequest
+ *   extendedServicesResponse [47] IMPLICIT ExtendedServicesResponse
+ *   close [48] IMPLICIT Close
+ * }
+ * 
+ */ +public final class PDU extends ASN1Any { + + public InitializeRequest c_initRequest; + public InitializeResponse c_initResponse; + public SearchRequest c_searchRequest; + public SearchResponse c_searchResponse; + public PresentRequest c_presentRequest; + public PresentResponse c_presentResponse; + public DeleteResultSetRequest c_deleteResultSetRequest; + public DeleteResultSetResponse c_deleteResultSetResponse; + public AccessControlRequest c_accessControlRequest; + public AccessControlResponse c_accessControlResponse; + public ResourceControlRequest c_resourceControlRequest; + public ResourceControlResponse c_resourceControlResponse; + public TriggerResourceControlRequest c_triggerResourceControlRequest; + public ResourceReportRequest c_resourceReportRequest; + public ResourceReportResponse c_resourceReportResponse; + public ScanRequest c_scanRequest; + public ScanResponse c_scanResponse; + public SortRequest c_sortRequest; + public SortResponse c_sortResponse; + public Segment c_segmentRequest; + public ExtendedServicesRequest c_extendedServicesRequest; + public ExtendedServicesResponse c_extendedServicesResponse; + public Close c_close; + /** + * Default constructor for a PDU. + */ + + public PDU() { + } + /** + * Constructor for a PDU from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public PDU(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + c_initRequest = null; + c_initResponse = null; + c_searchRequest = null; + c_searchResponse = null; + c_presentRequest = null; + c_presentResponse = null; + c_deleteResultSetRequest = null; + c_deleteResultSetResponse = null; + c_accessControlRequest = null; + c_accessControlResponse = null; + c_resourceControlRequest = null; + c_resourceControlResponse = null; + c_triggerResourceControlRequest = null; + c_resourceReportRequest = null; + c_resourceReportResponse = null; + c_scanRequest = null; + c_scanResponse = null; + c_sortRequest = null; + c_sortResponse = null; + c_segmentRequest = null; + c_extendedServicesRequest = null; + c_extendedServicesResponse = null; + c_close = null; + + // Try choice initRequest + if (ber.tagGet() == 20 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_initRequest = new InitializeRequest(ber, false); + return; + } + + // Try choice initResponse + if (ber.tagGet() == 21 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_initResponse = new InitializeResponse(ber, false); + return; + } + + // Try choice searchRequest + if (ber.tagGet() == 22 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_searchRequest = new SearchRequest(ber, false); + return; + } + + // Try choice searchResponse + if (ber.tagGet() == 23 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_searchResponse = new SearchResponse(ber, false); + return; + } + + // Try choice presentRequest + if (ber.tagGet() == 24 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_presentRequest = new PresentRequest(ber, false); + return; + } + + // Try choice presentResponse + if (ber.tagGet() == 25 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_presentResponse = new PresentResponse(ber, false); + return; + } + + // Try choice deleteResultSetRequest + if (ber.tagGet() == 26 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_deleteResultSetRequest = new DeleteResultSetRequest(ber, false); + return; + } + + // Try choice deleteResultSetResponse + if (ber.tagGet() == 27 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_deleteResultSetResponse = new DeleteResultSetResponse(ber, false); + return; + } + + // Try choice accessControlRequest + if (ber.tagGet() == 28 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_accessControlRequest = new AccessControlRequest(ber, false); + return; + } + + // Try choice accessControlResponse + if (ber.tagGet() == 29 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_accessControlResponse = new AccessControlResponse(ber, false); + return; + } + + // Try choice resourceControlRequest + if (ber.tagGet() == 30 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_resourceControlRequest = new ResourceControlRequest(ber, false); + return; + } + + // Try choice resourceControlResponse + if (ber.tagGet() == 31 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_resourceControlResponse = new ResourceControlResponse(ber, false); + return; + } + + // Try choice triggerResourceControlRequest + if (ber.tagGet() == 32 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_triggerResourceControlRequest = new TriggerResourceControlRequest(ber, false); + return; + } + + // Try choice resourceReportRequest + if (ber.tagGet() == 33 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_resourceReportRequest = new ResourceReportRequest(ber, false); + return; + } + + // Try choice resourceReportResponse + if (ber.tagGet() == 34 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_resourceReportResponse = new ResourceReportResponse(ber, false); + return; + } + + // Try choice scanRequest + if (ber.tagGet() == 35 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_scanRequest = new ScanRequest(ber, false); + return; + } + + // Try choice scanResponse + if (ber.tagGet() == 36 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_scanResponse = new ScanResponse(ber, false); + return; + } + + // Try choice sortRequest + if (ber.tagGet() == 43 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_sortRequest = new SortRequest(ber, false); + return; + } + + // Try choice sortResponse + if (ber.tagGet() == 44 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_sortResponse = new SortResponse(ber, false); + return; + } + + // Try choice segmentRequest + if (ber.tagGet() == 45 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_segmentRequest = new Segment(ber, false); + return; + } + + // Try choice extendedServicesRequest + if (ber.tagGet() == 46 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_extendedServicesRequest = new ExtendedServicesRequest(ber, false); + return; + } + + // Try choice extendedServicesResponse + if (ber.tagGet() == 47 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_extendedServicesResponse = new ExtendedServicesResponse(ber, false); + return; + } + + // Try choice close + if (ber.tagGet() == 48 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_close = new Close(ber, false); + return; + } + + throw new ASN1Exception("PDU: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of PDU. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + + // Encoding choice: c_initRequest + if (c_initRequest != null) { + chosen = c_initRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 20); + } + + // Encoding choice: c_initResponse + if (c_initResponse != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_initResponse.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 21); + } + + // Encoding choice: c_searchRequest + if (c_searchRequest != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_searchRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 22); + } + + // Encoding choice: c_searchResponse + if (c_searchResponse != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_searchResponse.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 23); + } + + // Encoding choice: c_presentRequest + if (c_presentRequest != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_presentRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 24); + } + + // Encoding choice: c_presentResponse + if (c_presentResponse != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_presentResponse.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 25); + } + + // Encoding choice: c_deleteResultSetRequest + if (c_deleteResultSetRequest != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_deleteResultSetRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 26); + } + + // Encoding choice: c_deleteResultSetResponse + if (c_deleteResultSetResponse != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_deleteResultSetResponse.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 27); + } + + // Encoding choice: c_accessControlRequest + if (c_accessControlRequest != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_accessControlRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 28); + } + + // Encoding choice: c_accessControlResponse + if (c_accessControlResponse != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_accessControlResponse.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 29); + } + + // Encoding choice: c_resourceControlRequest + if (c_resourceControlRequest != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_resourceControlRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 30); + } + + // Encoding choice: c_resourceControlResponse + if (c_resourceControlResponse != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_resourceControlResponse.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 31); + } + + // Encoding choice: c_triggerResourceControlRequest + if (c_triggerResourceControlRequest != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_triggerResourceControlRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 32); + } + + // Encoding choice: c_resourceReportRequest + if (c_resourceReportRequest != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_resourceReportRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 33); + } + + // Encoding choice: c_resourceReportResponse + if (c_resourceReportResponse != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_resourceReportResponse.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 34); + } + + // Encoding choice: c_scanRequest + if (c_scanRequest != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_scanRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 35); + } + + // Encoding choice: c_scanResponse + if (c_scanResponse != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_scanResponse.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 36); + } + + // Encoding choice: c_sortRequest + if (c_sortRequest != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_sortRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 43); + } + + // Encoding choice: c_sortResponse + if (c_sortResponse != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_sortResponse.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 44); + } + + // Encoding choice: c_segmentRequest + if (c_segmentRequest != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_segmentRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 45); + } + + // Encoding choice: c_extendedServicesRequest + if (c_extendedServicesRequest != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_extendedServicesRequest.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 46); + } + + // Encoding choice: c_extendedServicesResponse + if (c_extendedServicesResponse != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_extendedServicesResponse.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 47); + } + + // Encoding choice: c_close + if (c_close != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_close.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 48); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("PDU: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the PDU. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + + boolean found = false; + + if (c_initRequest != null) { + found = true; + str.append("initRequest "); + str.append(c_initRequest); + } + + if (c_initResponse != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("initResponse "); + str.append(c_initResponse); + } + + if (c_searchRequest != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("searchRequest "); + str.append(c_searchRequest); + } + + if (c_searchResponse != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("searchResponse "); + str.append(c_searchResponse); + } + + if (c_presentRequest != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("presentRequest "); + str.append(c_presentRequest); + } + + if (c_presentResponse != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("presentResponse "); + str.append(c_presentResponse); + } + + if (c_deleteResultSetRequest != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("deleteResultSetRequest "); + str.append(c_deleteResultSetRequest); + } + + if (c_deleteResultSetResponse != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("deleteResultSetResponse "); + str.append(c_deleteResultSetResponse); + } + + if (c_accessControlRequest != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("accessControlRequest "); + str.append(c_accessControlRequest); + } + + if (c_accessControlResponse != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("accessControlResponse "); + str.append(c_accessControlResponse); + } + + if (c_resourceControlRequest != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("resourceControlRequest "); + str.append(c_resourceControlRequest); + } + + if (c_resourceControlResponse != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("resourceControlResponse "); + str.append(c_resourceControlResponse); + } + + if (c_triggerResourceControlRequest != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("triggerResourceControlRequest "); + str.append(c_triggerResourceControlRequest); + } + + if (c_resourceReportRequest != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("resourceReportRequest "); + str.append(c_resourceReportRequest); + } + + if (c_resourceReportResponse != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("resourceReportResponse "); + str.append(c_resourceReportResponse); + } + + if (c_scanRequest != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("scanRequest "); + str.append(c_scanRequest); + } + + if (c_scanResponse != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("scanResponse "); + str.append(c_scanResponse); + } + + if (c_sortRequest != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("sortRequest "); + str.append(c_sortRequest); + } + + if (c_sortResponse != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("sortResponse "); + str.append(c_sortResponse); + } + + if (c_segmentRequest != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("segmentRequest "); + str.append(c_segmentRequest); + } + + if (c_extendedServicesRequest != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("extendedServicesRequest "); + str.append(c_extendedServicesRequest); + } + + if (c_extendedServicesResponse != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("extendedServicesResponse "); + str.append(c_extendedServicesResponse); + } + + if (c_close != null) { + if (found) { + str.append(" "); + } + str.append("close "); + str.append(c_close); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Permissions.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Permissions.java new file mode 100644 index 0000000..a4b5dc9 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Permissions.java @@ -0,0 +1,117 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a Permissions from Z39-50-APDU-1995. + *
+ * Permissions ::=
+ * SEQUENCE OF Permissions1
+ * 
+ */ +public final class Permissions extends ASN1Any { + + public Permissions1 value[]; + + /** + * Constructor for a Permissions from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Permissions(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Permissions should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("Permissions: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + value = new Permissions1[numParts]; + int p; + for (p = 0; p < numParts; p++) { + value[p] = new Permissions1(berConstructed.elementAt(p), true); + } + } + + /** + * Returns a BER encoding of the Permissions. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of Permissions, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + BEREncoding fields[] = new BERConstructed[value.length]; + int p; + + for (p = 0; p < value.length; p++) { + fields[p] = value[p].berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the Permissions. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int p; + for (p = 0; p < value.length; p++) { + str.append(value[p]); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Permissions1.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Permissions1.java new file mode 100644 index 0000000..bccae84 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Permissions1.java @@ -0,0 +1,204 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a Permissions1 from Z39-50-APDU-1995. + *
+ * Permissions1 ::=
+ * SEQUENCE {
+ *   userId [1] IMPLICIT InternationalString
+ *   allowableFunctions [2] IMPLICIT SEQUENCE OF INTEGER
+ * }
+ * 
+ */ +public final class Permissions1 extends ASN1Any { + + public InternationalString s_userId; + public ASN1Integer s_allowableFunctions[]; + + + /** + * Constructor for a Permissions1 from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Permissions1(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Permissions1 should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Permissions1: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: userId [1] IMPLICIT InternationalString + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("Permissions1: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 1 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("Permissions1: bad tag in s_userId\n"); + } + + s_userId = new InternationalString(p, false); + part++; + + // Decoding: allowableFunctions [2] IMPLICIT SEQUENCE OF INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("Permissions1: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 2 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("Permissions1: bad tag in s_allowableFunctions\n"); + } + + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + s_allowableFunctions = new ASN1Integer[parts]; + int n; + for (n = 0; n < parts; n++) { + s_allowableFunctions[n] = new ASN1Integer(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("Permissions1: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the Permissions1. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of Permissions1, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 2; // number of mandatories + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + + // Encoding s_userId: InternationalString + + fields[x++] = s_userId.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + + // Encoding s_allowableFunctions: SEQUENCE OF + + f2 = new BEREncoding[s_allowableFunctions.length]; + + for (p = 0; p < s_allowableFunctions.length; p++) { + f2[p] = s_allowableFunctions[p].berEncode(); + } + + fields[x] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 2, f2); + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the Permissions1. + */ + + public String + toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + str.append("userId "); + str.append(s_userId); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("allowableFunctions "); + str.append("{"); + for (p = 0; p < s_allowableFunctions.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(s_allowableFunctions[p]); + } + str.append("}"); + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentRequest.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentRequest.java new file mode 100644 index 0000000..5efba07 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentRequest.java @@ -0,0 +1,512 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a PresentRequest from Z39-50-APDU-1995. + *
+ * PresentRequest ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   resultSetId ResultSetId
+ *   resultSetStartPoint [30] IMPLICIT INTEGER
+ *   numberOfRecordsRequested [29] IMPLICIT INTEGER
+ *   additionalRanges [212] IMPLICIT SEQUENCE OF Range OPTIONAL
+ *   recordComposition PresentRequest_recordComposition OPTIONAL
+ *   preferredRecordSyntax [104] IMPLICIT OBJECT IDENTIFIER OPTIONAL
+ *   maxSegmentCount [204] IMPLICIT INTEGER OPTIONAL
+ *   maxRecordSize [206] IMPLICIT INTEGER OPTIONAL
+ *   maxSegmentSize [207] IMPLICIT INTEGER OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ + +public final class PresentRequest extends ASN1Any { + + public ReferenceId s_referenceId; // optional + public ResultSetId s_resultSetId; + public ASN1Integer s_resultSetStartPoint; + public ASN1Integer s_numberOfRecordsRequested; + public Range s_additionalRanges[]; // optional + public PresentRequestRecordComposition s_recordComposition; // optional + public ASN1ObjectIdentifier s_preferredRecordSyntax; // optional + public ASN1Integer s_maxSegmentCount; // optional + public ASN1Integer s_maxRecordSize; // optional + public ASN1Integer s_maxSegmentSize; // optional + public OtherInformation s_otherInfo; // optional + /** + * Default constructor for a PresentRequest. + */ + + public PresentRequest() { + } + /** + * Constructor for a PresentRequest from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public PresentRequest(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // PresentRequest should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("PresentRequest: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("PresentRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: resultSetId ResultSetId + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("PresentRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + s_resultSetId = new ResultSetId(p, true); + part++; + + // Decoding: resultSetStartPoint [30] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("PresentRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 30 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("PresentRequest: bad tag in s_resultSetStartPoint\n"); + } + + s_resultSetStartPoint = new ASN1Integer(p, false); + part++; + + // Decoding: numberOfRecordsRequested [29] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("PresentRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 29 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("PresentRequest: bad tag in s_numberOfRecordsRequested\n"); + } + + s_numberOfRecordsRequested = new ASN1Integer(p, false); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_additionalRanges = null; + s_recordComposition = null; + s_preferredRecordSyntax = null; + s_maxSegmentCount = null; + s_maxRecordSize = null; + s_maxSegmentSize = null; + s_otherInfo = null; + + // Decoding: additionalRanges [212] IMPLICIT SEQUENCE OF Range OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 212 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + s_additionalRanges = new Range[parts]; + int n; + for (n = 0; n < parts; n++) { + s_additionalRanges[n] = new Range(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + } + + // Decoding: recordComposition PresentRequest_recordComposition OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_recordComposition = new PresentRequestRecordComposition(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_recordComposition = null; // no, not present + } + + // Decoding: preferredRecordSyntax [104] IMPLICIT OBJECT IDENTIFIER OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 104 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_preferredRecordSyntax = new ASN1ObjectIdentifier(p, false); + part++; + } + + // Decoding: maxSegmentCount [204] IMPLICIT INTEGER OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 204 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_maxSegmentCount = new ASN1Integer(p, false); + part++; + } + + // Decoding: maxRecordSize [206] IMPLICIT INTEGER OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 206 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_maxRecordSize = new ASN1Integer(p, false); + part++; + } + + // Decoding: maxSegmentSize [207] IMPLICIT INTEGER OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 207 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_maxSegmentSize = new ASN1Integer(p, false); + part++; + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("PresentRequest: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the PresentRequest. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of PresentRequest, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 3; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_additionalRanges != null) { + numFields++; + } + if (s_recordComposition != null) { + numFields++; + } + if (s_preferredRecordSyntax != null) { + numFields++; + } + if (s_maxSegmentCount != null) { + numFields++; + } + if (s_maxRecordSize != null) { + numFields++; + } + if (s_maxSegmentSize != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_resultSetId: ResultSetId + + fields[x++] = s_resultSetId.berEncode(); + + // Encoding s_resultSetStartPoint: INTEGER + + fields[x++] = s_resultSetStartPoint.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 30); + + // Encoding s_numberOfRecordsRequested: INTEGER + + fields[x++] = s_numberOfRecordsRequested.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 29); + + // Encoding s_additionalRanges: SEQUENCE OF OPTIONAL + + if (s_additionalRanges != null) { + f2 = new BEREncoding[s_additionalRanges.length]; + + for (p = 0; p < s_additionalRanges.length; p++) { + f2[p] = s_additionalRanges[p].berEncode(); + } + + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 212, f2); + } + + // Encoding s_recordComposition: PresentRequest_recordComposition OPTIONAL + + if (s_recordComposition != null) { + fields[x++] = s_recordComposition.berEncode(); + } + + // Encoding s_preferredRecordSyntax: OBJECT IDENTIFIER OPTIONAL + + if (s_preferredRecordSyntax != null) { + fields[x++] = s_preferredRecordSyntax.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 104); + } + + // Encoding s_maxSegmentCount: INTEGER OPTIONAL + + if (s_maxSegmentCount != null) { + fields[x++] = s_maxSegmentCount.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 204); + } + + // Encoding s_maxRecordSize: INTEGER OPTIONAL + + if (s_maxRecordSize != null) { + fields[x++] = s_maxRecordSize.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 206); + } + + // Encoding s_maxSegmentSize: INTEGER OPTIONAL + + if (s_maxSegmentSize != null) { + fields[x++] = s_maxSegmentSize.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 207); + } + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the PresentRequest. + */ + + public String + toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("resultSetId "); + str.append(s_resultSetId); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("resultSetStartPoint "); + str.append(s_resultSetStartPoint); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("numberOfRecordsRequested "); + str.append(s_numberOfRecordsRequested); + outputted++; + + if (s_additionalRanges != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("additionalRanges "); + str.append("{"); + for (p = 0; p < s_additionalRanges.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(s_additionalRanges[p]); + } + str.append("}"); + outputted++; + } + + if (s_recordComposition != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("recordComposition "); + str.append(s_recordComposition); + outputted++; + } + + if (s_preferredRecordSyntax != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("preferredRecordSyntax "); + str.append(s_preferredRecordSyntax); + outputted++; + } + + if (s_maxSegmentCount != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("maxSegmentCount "); + str.append(s_maxSegmentCount); + outputted++; + } + + if (s_maxRecordSize != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("maxRecordSize "); + str.append(s_maxRecordSize); + outputted++; + } + + if (s_maxSegmentSize != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("maxSegmentSize "); + str.append(s_maxSegmentSize); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentRequestRecordComposition.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentRequestRecordComposition.java new file mode 100644 index 0000000..06cbfc6 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentRequestRecordComposition.java @@ -0,0 +1,133 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a PresentRequest_recordComposition from Z39-50-APDU-1995. + *
+ * PresentRequest_recordComposition ::=
+ * CHOICE {
+ *   simple [19] EXPLICIT ElementSetNames
+ *   complex [209] IMPLICIT CompSpec
+ * }
+ * 
+ */ +public final class PresentRequestRecordComposition extends ASN1Any { + + public ElementSetNames c_simple; + + public CompSpec c_complex; + + /** + * Default constructor for a PresentRequest_recordComposition. + */ + + public PresentRequestRecordComposition() { + } + + /** + * Constructor for a PresentRequest_recordComposition from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public PresentRequestRecordComposition(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed tagwrapper; + c_simple = null; + c_complex = null; + if (ber.tagGet() == 19 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("PresentRequest_recordComposition: bad BER form"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException("PresentRequest_recordComposition: bad BER form"); + } + c_simple = new ElementSetNames(tagwrapper.elementAt(0), true); + return; + } + if (ber.tagGet() == 209 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_complex = new CompSpec(ber, false); + return; + } + throw new ASN1Exception("PresentRequest_recordComposition: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of PresentRequest_recordComposition. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + BEREncoding[] enc; + if (c_simple != null) { + enc = new BEREncoding[1]; + enc[0] = c_simple.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 19, enc); + } + if (c_complex != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_complex.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 209); + } + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + throw new ASN1EncodingException("PresentRequest_recordComposition: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the PresentRequest_recordComposition. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (c_simple != null) { + found = true; + str.append("simple "); + str.append(c_simple); + } + if (c_complex != null) { + if (found) { + str.append(" "); + } + str.append("complex "); + str.append(c_complex); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentResponse.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentResponse.java new file mode 100644 index 0000000..8014aca --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentResponse.java @@ -0,0 +1,314 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a PresentResponse from Z39-50-APDU-1995. + *
+ * PresentResponse ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   numberOfRecordsReturned [24] IMPLICIT INTEGER
+ *   nextResultSetPosition [25] IMPLICIT INTEGER
+ *   presentStatus PresentStatus
+ *   records Records OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class PresentResponse extends ASN1Any { + + public ReferenceId s_referenceId; // optional + public ASN1Integer s_numberOfRecordsReturned; + public ASN1Integer s_nextResultSetPosition; + public PresentStatus s_presentStatus; + public Records s_records; // optional + public OtherInformation s_otherInfo; // optional + /** + * Constructor for a PresentResponse from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public PresentResponse(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // PresentResponse should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("PresentResponse: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("PresentResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: numberOfRecordsReturned [24] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("PresentResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 24 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("PresentResponse: bad tag in s_numberOfRecordsReturned\n"); + } + + s_numberOfRecordsReturned = new ASN1Integer(p, false); + part++; + + // Decoding: nextResultSetPosition [25] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("PresentResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 25 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("PresentResponse: bad tag in s_nextResultSetPosition\n"); + } + + s_nextResultSetPosition = new ASN1Integer(p, false); + part++; + + // Decoding: presentStatus PresentStatus + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("PresentResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + s_presentStatus = new PresentStatus(p, true); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_records = null; + s_otherInfo = null; + + // Decoding: records Records OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_records = new Records(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_records = null; // no, not present + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("PresentResponse: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the PresentResponse. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of PresentResponse, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 3; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_records != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_numberOfRecordsReturned: INTEGER + + fields[x++] = s_numberOfRecordsReturned.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 24); + + // Encoding s_nextResultSetPosition: INTEGER + + fields[x++] = s_nextResultSetPosition.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 25); + + // Encoding s_presentStatus: PresentStatus + + fields[x++] = s_presentStatus.berEncode(); + + // Encoding s_records: Records OPTIONAL + + if (s_records != null) { + fields[x++] = s_records.berEncode(); + } + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the PresentResponse. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("numberOfRecordsReturned "); + str.append(s_numberOfRecordsReturned); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("nextResultSetPosition "); + str.append(s_nextResultSetPosition); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("presentStatus "); + str.append(s_presentStatus); + outputted++; + + if (s_records != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("records "); + str.append(s_records); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentStatus.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentStatus.java new file mode 100644 index 0000000..906de7f --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/PresentStatus.java @@ -0,0 +1,98 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a PresentStatus from Z39-50-APDU-1995. + *
+ * PresentStatus ::=
+ * [27] IMPLICIT INTEGER
+ * 
+ */ +public final class PresentStatus extends ASN1Any { + /** + * success - All of the expected response records are available. + * partial-1 - Not all of the expected response records can be returned because the request was terminated by access control. + * partial-2 - Not all of the expected response records can be returned because they will not fit within the preferred message size. + * partial-3 - Not all of the expected response records can be returned because the request was terminated by resource control, at origin request. + * partial-4 - Not all of the expected response records can be returned because the request was terminated by resource control, by the target. + * failure - None of the expected response records can be returned. One or more non-surrogate diagnostic records is returned + */ + public static final int E_success = 0; + public static final int E_partial_1 = 1; + public static final int E_partial_2 = 2; + public static final int E_partial_3 = 3; + public static final int E_partial_4 = 4; + public static final int E_failure = 5; + public ASN1Integer value; + /** + * Constructor for a PresentStatus from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public PresentStatus(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + if (checkTag) { + if (ber.tagGet() != 27 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("PresentStatus: bad BER: tag=" + ber.tagGet() + " expected 27\n"); + } + } + + value = new ASN1Integer(ber, false); + } + + /** + * Returns a BER encoding of the PresentStatus. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 27); + } + + /** + * Returns a BER encoding of PresentStatus, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the PresentStatus. + */ + + public String toString() { + return value.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ProtocolVersion.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ProtocolVersion.java new file mode 100644 index 0000000..4ac403a --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ProtocolVersion.java @@ -0,0 +1,92 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1BitString; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a ProtocolVersion from Z39-50-APDU-1995. + *
+ * ProtocolVersion ::=
+ * [3] IMPLICIT BIT STRING
+ * 
+ */ +public final class ProtocolVersion extends ASN1Any { + public ASN1BitString value; + + /** + * Default constructor for a ProtocolVersion. + */ + public ProtocolVersion() { + } + + /** + * Constructor for a ProtocolVersion from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ProtocolVersion(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // Check tag matches + + if (checkTag) { + if (ber.tagGet() != 3 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("ProtocolVersion: bad BER: tag=" + ber.tagGet() + " expected 3\n"); + } + } + + value = new ASN1BitString(ber, false); + } + + /** + * Returns a BER encoding of the ProtocolVersion. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 3); + } + + /** + * Returns a BER encoding of ProtocolVersion, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the ProtocolVersion. + */ + public String toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ProximityOperator.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ProximityOperator.java new file mode 100644 index 0000000..44334b3 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ProximityOperator.java @@ -0,0 +1,297 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Boolean; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a ProximityOperator from Z39-50-APDU-1995. + *
+ * ProximityOperator ::=
+ * SEQUENCE {
+ *   exclusion [1] IMPLICIT BOOLEAN OPTIONAL
+ *   distance [2] IMPLICIT INTEGER
+ *   ordered [3] IMPLICIT BOOLEAN
+ *   relationType [4] IMPLICIT INTEGER
+ *   proximityUnitCode [5] EXPLICIT ProximityOperator_proximityUnitCode
+ * }
+ * 
+ */ +public final class ProximityOperator extends ASN1Any { + // Enumerated constants for relationType + public static final int E_lessThan = 1; + public static final int E_lessThanOrEqual = 2; + public static final int E_equal = 3; + public static final int E_greaterThanOrEqual = 4; + public static final int E_greaterThan = 5; + public static final int E_notEqual = 6; + public ASN1Boolean s_exclusion; // optional + public ASN1Integer s_distance; + public ASN1Boolean s_ordered; + public ASN1Integer s_relationType; + public ProximityOperatorProximityUnitCode s_proximityUnitCode; + /** + * Constructor for a ProximityOperator from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ProximityOperator(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // ProximityOperator should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("ProximityOperator: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + + // Decoding: exclusion [1] IMPLICIT BOOLEAN OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ProximityOperator: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 1 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_exclusion = new ASN1Boolean(p, false); + part++; + } + + // Decoding: distance [2] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ProximityOperator: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 2 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("ProximityOperator: bad tag in s_distance\n"); + } + + s_distance = new ASN1Integer(p, false); + part++; + + // Decoding: ordered [3] IMPLICIT BOOLEAN + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ProximityOperator: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 3 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("ProximityOperator: bad tag in s_ordered\n"); + } + + s_ordered = new ASN1Boolean(p, false); + part++; + + // Decoding: relationType [4] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ProximityOperator: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 4 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("ProximityOperator: bad tag in s_relationType\n"); + } + + s_relationType = new ASN1Integer(p, false); + part++; + + // Decoding: proximityUnitCode [5] EXPLICIT ProximityOperator_proximityUnitCode + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ProximityOperator: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 5 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("ProximityOperator: bad tag in s_proximityUnitCode\n"); + } + + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("ProximityOperator: bad BER encoding: s_proximityUnitCode tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException + ("ProximityOperator: bad BER encoding: s_proximityUnitCode tag bad\n"); + } + + s_proximityUnitCode = new ProximityOperatorProximityUnitCode(tagged.elementAt(0), true); + part++; + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("ProximityOperator: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ProximityOperator. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ProximityOperator, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 4; // number of mandatories + if (s_exclusion != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + + // Encoding s_exclusion: BOOLEAN OPTIONAL + + if (s_exclusion != null) { + fields[x++] = s_exclusion.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding s_distance: INTEGER + + fields[x++] = s_distance.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + + // Encoding s_ordered: BOOLEAN + + fields[x++] = s_ordered.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 3); + + // Encoding s_relationType: INTEGER + + fields[x++] = s_relationType.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 4); + + // Encoding s_proximityUnitCode: ProximityOperator_proximityUnitCode + + enc = new BEREncoding[1]; + enc[0] = s_proximityUnitCode.berEncode(); + fields[x] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 5, enc); + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ProximityOperator. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_exclusion != null) { + str.append("exclusion "); + str.append(s_exclusion); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("distance "); + str.append(s_distance); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("ordered "); + str.append(s_ordered); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("relationType "); + str.append(s_relationType); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("proximityUnitCode "); + str.append(s_proximityUnitCode); + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ProximityOperatorProximityUnitCode.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ProximityOperatorProximityUnitCode.java new file mode 100644 index 0000000..4f90a11 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ProximityOperatorProximityUnitCode.java @@ -0,0 +1,169 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a ProximityOperator_proximityUnitCode from Z39-50-APDU-1995. + *
+ * ProximityOperator_proximityUnitCode ::=
+ * CHOICE {
+ *   known [1] IMPLICIT KnownProximityUnit
+ *   private [2] IMPLICIT INTEGER
+ * }
+ * 
+ */ +public final class ProximityOperatorProximityUnitCode extends ASN1Any { + + public KnownProximityUnit c_known; + public ASN1Integer c_private; + + + /** + * Constructor for a ProximityOperator_proximityUnitCode from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ProximityOperatorProximityUnitCode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Null out all choices + + c_known = null; + c_private = null; + + // Try choice known + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_known = new KnownProximityUnit(ber, false); + return; + } + + // Try choice private + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_private = new ASN1Integer(ber, false); + return; + } + + throw new ASN1Exception("ProximityOperator_proximityUnitCode: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of ProximityOperator_proximityUnitCode. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + // Encoding choice: c_known + if (c_known != null) { + chosen = c_known.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding choice: c_private + if (c_private != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_private.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("ProximityOperator_proximityUnitCode: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the ProximityOperator_proximityUnitCode. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + + boolean found = false; + + if (c_known != null) { + found = true; + str.append("known "); + str.append(c_known); + } + + if (c_private != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("private "); + str.append(c_private); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Query.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Query.java new file mode 100644 index 0000000..9c92fb0 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Query.java @@ -0,0 +1,333 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1OctetString; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a Query from Z39-50-APDU-1995. + *
+ * Query ::=
+ * CHOICE {
+ *   type-0 [0] EXPLICIT ANY
+ *   type-1 [1] IMPLICIT RPNQuery
+ *   type-2 [2] EXPLICIT OCTET STRING
+ *   type-100 [100] EXPLICIT OCTET STRING
+ *   type-101 [101] IMPLICIT RPNQuery
+ *   type-102 [102] EXPLICIT OCTET STRING
+ * }
+ * 
+ */ +public final class Query extends ASN1Any { + + public ASN1Any c_type_0; + public RPNQuery c_type_1; + public ASN1OctetString c_type_2; + public ASN1OctetString c_type_100; + public RPNQuery c_type_101; + public ASN1OctetString c_type_102; + + /** + * Default constructor for a Query. + */ + + public Query() { + } + /** + * Constructor for a Query from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Query(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + BERConstructed tagwrapper; + + // Null out all choices + + c_type_0 = null; + c_type_1 = null; + c_type_2 = null; + c_type_100 = null; + c_type_101 = null; + c_type_102 = null; + + // Try choice type-0 + if (ber.tagGet() == 0 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("Query: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException("Query: bad BER form\n"); + } + c_type_0 = new ASN1Any(tagwrapper.elementAt(0), true); + return; + } + + // Try choice type-1 + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_type_1 = new RPNQuery(ber, false); + return; + } + + // Try choice type-2 + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Query: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("Query: bad BER form\n"); + } + c_type_2 = new ASN1OctetString(tagwrapper.elementAt(0), true); + return; + } + + // Try choice type-100 + if (ber.tagGet() == 100 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Query: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("Query: bad BER form\n"); + } + c_type_100 = new ASN1OctetString(tagwrapper.elementAt(0), true); + return; + } + + // Try choice type-101 + if (ber.tagGet() == 101 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_type_101 = new RPNQuery(ber, false); + return; + } + + // Try choice type-102 + if (ber.tagGet() == 102 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Query: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("Query: bad BER form\n"); + } + c_type_102 = new ASN1OctetString(tagwrapper.elementAt(0), true); + return; + } + + throw new ASN1Exception("Query: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of Query. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + BEREncoding enc[]; + + // Encoding choice: c_type_0 + if (c_type_0 != null) { + enc = new BEREncoding[1]; + enc[0] = c_type_0.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 0, enc); + } + + // Encoding choice: c_type_1 + if (c_type_1 != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_type_1.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding choice: c_type_2 + if (c_type_2 != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + enc = new BEREncoding[1]; + enc[0] = c_type_2.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 2, enc); + } + + // Encoding choice: c_type_100 + if (c_type_100 != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + enc = new BEREncoding[1]; + enc[0] = c_type_100.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 100, enc); + } + + // Encoding choice: c_type_101 + if (c_type_101 != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_type_101.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 101); + } + + // Encoding choice: c_type_102 + if (c_type_102 != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + enc = new BEREncoding[1]; + enc[0] = c_type_102.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 102, enc); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("Query: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the Query. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + + boolean found = false; + + if (c_type_0 != null) { + found = true; + str.append("type-0 "); + str.append(c_type_0); + } + + if (c_type_1 != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("type-1 "); + str.append(c_type_1); + } + + if (c_type_2 != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("type-2 "); + str.append(c_type_2); + } + + if (c_type_100 != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("type-100 "); + str.append(c_type_100); + } + + if (c_type_101 != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("type-101 "); + str.append(c_type_101); + } + + if (c_type_102 != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("type-102 "); + str.append(c_type_102); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/RPNQuery.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/RPNQuery.java new file mode 100644 index 0000000..fbfeb84 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/RPNQuery.java @@ -0,0 +1,126 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a RPNQuery from Z39-50-APDU-1995. + *
+ * RPNQuery ::=
+ * SEQUENCE {
+ *   attributeSet AttributeSetId
+ *   rpn RPNStructure
+ * }
+ * 
+ */ +public final class RPNQuery extends ASN1Any { + public AttributeSetId s_attributeSet; + public RPNStructure s_rpn; + + /** + * Default constructor for a RPNQuery. + */ + public RPNQuery() { + } + + /** + * Constructor for a RPNQuery from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public RPNQuery(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("RPNQuery: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("RPNQuery: incomplete"); + } + p = berConstructed.elementAt(part); + s_attributeSet = new AttributeSetId(p, true); + part++; + if (numParts <= part) { + throw new ASN1Exception("RPNQuery: incomplete"); + } + p = berConstructed.elementAt(part); + s_rpn = new RPNStructure(p, true); + part++; + if (part < numParts) { + throw new ASN1Exception("RPNQuery: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the RPNQuery. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of RPNQuery, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 2; + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + fields[x++] = s_attributeSet.berEncode(); + fields[x] = s_rpn.berEncode(); + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the RPNQuery. + */ + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + str.append("attributeSet "); + str.append(s_attributeSet); + outputted++; + if (0 < outputted) { + str.append(", "); + } + str.append("rpn "); + str.append(s_rpn); + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/RPNStructure.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/RPNStructure.java new file mode 100644 index 0000000..c640586 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/RPNStructure.java @@ -0,0 +1,161 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a RPNStructure from Z39-50-APDU-1995. + *
+ * RPNStructure ::=
+ * CHOICE {
+ *   op [0] EXPLICIT Operand
+ *   rpnRpnOp [1] IMPLICIT RPNStructure_rpnRpnOp
+ * }
+ * 
+ */ +public final class RPNStructure extends ASN1Any { + + public Operand c_op; + public RPNStructureRpnRpnOp c_rpnRpnOp; + + /** + * Default constructor for a RPNStructure. + */ + public RPNStructure() { + } + + /** + * Constructor for a RPNStructure from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public RPNStructure(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed tagwrapper; + c_op = null; + c_rpnRpnOp = null; + if (ber.tagGet() == 0 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("RPNStructure: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException + ("RPNStructure: bad BER form\n"); + } + c_op = new Operand(tagwrapper.elementAt(0), true); + return; + } + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_rpnRpnOp = new RPNStructureRpnRpnOp(ber, false); + return; + } + throw new ASN1Exception("RPNStructure: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of RPNStructure. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + + BEREncoding enc[]; + + // Encoding choice: c_op + if (c_op != null) { + enc = new BEREncoding[1]; + enc[0] = c_op.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 0, enc); + } + + // Encoding choice: c_rpnRpnOp + if (c_rpnRpnOp != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_rpnRpnOp.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("RPNStructure: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the RPNStructure. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (c_op != null) { + found = true; + str.append("op "); + str.append(c_op); + } + if (c_rpnRpnOp != null) { + if (found) { + str.append(" "); + } + str.append("rpnRpnOp "); + str.append(c_rpnRpnOp); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/RPNStructureRpnRpnOp.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/RPNStructureRpnRpnOp.java new file mode 100644 index 0000000..23a11b3 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/RPNStructureRpnRpnOp.java @@ -0,0 +1,197 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a RPNStructure_rpnRpnOp from Z39-50-APDU-1995. + *
+ * RPNStructure_rpnRpnOp ::=
+ * SEQUENCE {
+ *   rpn1 RPNStructure
+ *   rpn2 RPNStructure
+ *   op Operator
+ * }
+ * 
+ */ +public final class RPNStructureRpnRpnOp extends ASN1Any { + + public RPNStructure s_rpn1; + public RPNStructure s_rpn2; + public Operator s_op; + + + /** + * Default constructor for a RPNStructure_rpnRpnOp. + */ + + public RPNStructureRpnRpnOp() { + } + + /** + * Constructor for a RPNStructure_rpnRpnOp from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public RPNStructureRpnRpnOp(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // RPNStructure_rpnRpnOp should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("RPNStructure_rpnRpnOp: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: rpn1 RPNStructure + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("RPNStructure_rpnRpnOp: incomplete"); + } + p = berConstructed.elementAt(part); + + s_rpn1 = new RPNStructure(p, true); + part++; + + // Decoding: rpn2 RPNStructure + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("RPNStructure_rpnRpnOp: incomplete"); + } + p = berConstructed.elementAt(part); + + s_rpn2 = new RPNStructure(p, true); + part++; + + // Decoding: op Operator + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("RPNStructure_rpnRpnOp: incomplete"); + } + p = berConstructed.elementAt(part); + + s_op = new Operator(p, true); + part++; + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception(" RPNStructure_rpnRpnOp: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the RPNStructure_rpnRpnOp. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of RPNStructure_rpnRpnOp, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 3; // number of mandatories + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_rpn1: RPNStructure + + fields[x++] = s_rpn1.berEncode(); + + // Encoding s_rpn2: RPNStructure + + fields[x++] = s_rpn2.berEncode(); + + // Encoding s_op: Operator + + fields[x] = s_op.berEncode(); + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the RPNStructure_rpnRpnOp. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + str.append("rpn1 "); + str.append(s_rpn1); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("rpn2 "); + str.append(s_rpn2); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("op "); + str.append(s_op); + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Range.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Range.java new file mode 100644 index 0000000..f1f63cb --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Range.java @@ -0,0 +1,180 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a Range from Z39-50-APDU-1995. + *
+ * Range ::=
+ * SEQUENCE {
+ *   startingPosition [1] IMPLICIT INTEGER
+ *   numberOfRecords [2] IMPLICIT INTEGER
+ * }
+ * 
+ */ +public final class Range extends ASN1Any { + public ASN1Integer s_startingPosition; + public ASN1Integer s_numberOfRecords; + + + /** + * Constructor for a Range from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Range(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Range should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Range: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: startingPosition [1] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("Range: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 1 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("Range: bad tag in s_startingPosition\n"); + } + + s_startingPosition = new ASN1Integer(p, false); + part++; + + // Decoding: numberOfRecords [2] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("Range: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 2 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("Range: bad tag in s_numberOfRecords\n"); + } + + s_numberOfRecords = new ASN1Integer(p, false); + part++; + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("Range: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the Range. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of Range, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 2; // number of mandatories + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_startingPosition: INTEGER + + fields[x++] = s_startingPosition.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + + // Encoding s_numberOfRecords: INTEGER + + fields[x++] = s_numberOfRecords.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the Range. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + str.append("startingPosition "); + str.append(s_startingPosition); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("numberOfRecords "); + str.append(s_numberOfRecords); + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Records.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Records.java new file mode 100644 index 0000000..95c3c54 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Records.java @@ -0,0 +1,249 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a Records from Z39-50-APDU-1995. + *
+ * Records ::=
+ * CHOICE {
+ *   responseRecords [28] IMPLICIT SEQUENCE OF NamePlusRecord
+ *   nonSurrogateDiagnostic [130] IMPLICIT DefaultDiagFormat
+ *   multipleNonSurDiagnostics [205] IMPLICIT SEQUENCE OF DiagRec
+ * }
+ * 
+ */ +public final class Records extends ASN1Any { + public NamePlusRecord c_responseRecords[]; + public DefaultDiagFormat c_nonSurrogateDiagnostic; + public DiagRec c_multipleNonSurDiagnostics[]; + + + /** + * Constructor for a Records from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Records(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Null out all choices + + c_responseRecords = null; + c_nonSurrogateDiagnostic = null; + c_multipleNonSurDiagnostics = null; + + // Try choice responseRecords + if (ber.tagGet() == 28 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + BEREncoding ber_data; + ber_data = ber; + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber_data; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Records: bad BER form\n"); + } + + int numParts = berConstructed.numberComponents(); + int p; + + c_responseRecords = new NamePlusRecord[numParts]; + + for (p = 0; p < numParts; p++) { + c_responseRecords[p] = new NamePlusRecord(berConstructed.elementAt(p), true); + } + return; + } + + // Try choice nonSurrogateDiagnostic + if (ber.tagGet() == 130 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_nonSurrogateDiagnostic = new DefaultDiagFormat(ber, false); + return; + } + + // Try choice multipleNonSurDiagnostics + if (ber.tagGet() == 205 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + BEREncoding ber_data; + ber_data = ber; + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber_data; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Records: bad BER form\n"); + } + + int numParts = berConstructed.numberComponents(); + int p; + + c_multipleNonSurDiagnostics = new DiagRec[numParts]; + + for (p = 0; p < numParts; p++) { + c_multipleNonSurDiagnostics[p] = new DiagRec(berConstructed.elementAt(p), true); + } + return; + } + + throw new ASN1Exception("Records: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of Records. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + BEREncoding f2[]; + int p; + // Encoding choice: c_responseRecords + if (c_responseRecords != null) { + f2 = new BEREncoding[c_responseRecords.length]; + + for (p = 0; p < c_responseRecords.length; p++) { + f2[p] = c_responseRecords[p].berEncode(); + } + + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 28, f2); + } + + // Encoding choice: c_nonSurrogateDiagnostic + if (c_nonSurrogateDiagnostic != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_nonSurrogateDiagnostic.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 130); + } + + // Encoding choice: c_multipleNonSurDiagnostics + if (c_multipleNonSurDiagnostics != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + f2 = new BEREncoding[c_multipleNonSurDiagnostics.length]; + + for (p = 0; p < c_multipleNonSurDiagnostics.length; p++) { + f2[p] = c_multipleNonSurDiagnostics[p].berEncode(); + } + + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 205, f2); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("Records: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the Records. + */ + + public String + toString() { + int p; + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (c_responseRecords != null) { + found = true; + str.append("responseRecords "); + str.append("{"); + for (p = 0; p < c_responseRecords.length; p++) { + str.append(c_responseRecords[p]); + } + str.append("}"); + } + + if (c_nonSurrogateDiagnostic != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("nonSurrogateDiagnostic "); + str.append(c_nonSurrogateDiagnostic); + } + + if (c_multipleNonSurDiagnostics != null) { + if (found) { + str.append(" "); + } + str.append("multipleNonSurDiagnostics "); + str.append("{"); + for (p = 0; p < c_multipleNonSurDiagnostics.length; p++) { + str.append(c_multipleNonSurDiagnostics[p]); + } + str.append("}"); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ReferenceId.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ReferenceId.java new file mode 100644 index 0000000..cc773fc --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ReferenceId.java @@ -0,0 +1,113 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1OctetString; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a ReferenceId from Z39-50-APDU-1995. + *
+ * ReferenceId ::=
+ * [2] IMPLICIT OCTET STRING
+ * 
+ */ +public final class ReferenceId extends ASN1Any { + + public ASN1OctetString value; + + /** + * Default constructor for a ReferenceId. + */ + + public ReferenceId() { + } + + + /** + * Constructor for a ReferenceId from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ReferenceId(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Check tag matches + + if (checkTag) { + if (ber.tagGet() != 2 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("ReferenceId: bad BER: tag=" + ber.tagGet() + " expected 2\n"); + } + } + + value = new ASN1OctetString(ber, false); + } + + /** + * Returns a BER encoding of the ReferenceId. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + } + + /** + * Returns a BER encoding of ReferenceId, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + +/* + * Internal variables for class. + */ + + /** + * Returns a new String object containing a text representing + * of the ReferenceId. + */ + + public String + toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceControlRequest.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceControlRequest.java new file mode 100644 index 0000000..45893a6 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceControlRequest.java @@ -0,0 +1,387 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Boolean; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ResourceControlRequest from Z39-50-APDU-1995. + *
+ * ResourceControlRequest ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   suspendedFlag [39] IMPLICIT BOOLEAN OPTIONAL
+ *   resourceReport [40] EXPLICIT ResourceReport OPTIONAL
+ *   partialResultsAvailable [41] IMPLICIT INTEGER OPTIONAL
+ *   responseRequired [42] IMPLICIT BOOLEAN
+ *   triggeredRequestFlag [43] IMPLICIT BOOLEAN OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class ResourceControlRequest extends ASN1Any { + + // Enumerated constants for partialResultsAvailable + public static final int E_subset = 1; + public static final int E_interim = 2; + public static final int E_none = 3; + public ReferenceId s_referenceId; // optional + public ASN1Boolean s_suspendedFlag; // optional + public ResourceReport s_resourceReport; // optional + public ASN1Integer s_partialResultsAvailable; // optional + public ASN1Boolean s_responseRequired; + public ASN1Boolean s_triggeredRequestFlag; // optional + public OtherInformation s_otherInfo; // optional + /** + * Default constructor for a ResourceControlRequest. + */ + + public ResourceControlRequest() { + } + /** + * Constructor for a ResourceControlRequest from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ResourceControlRequest(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // ResourceControlRequest should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("ResourceControlRequest: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ResourceControlRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: suspendedFlag [39] IMPLICIT BOOLEAN OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ResourceControlRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 39 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_suspendedFlag = new ASN1Boolean(p, false); + part++; + } + + // Decoding: resourceReport [40] EXPLICIT ResourceReport OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ResourceControlRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 40 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("ResourceControlRequest: bad BER encoding: s_resourceReport tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException + ("ResourceControlRequest: bad BER encoding: s_resourceReport tag bad\n"); + } + + s_resourceReport = new ResourceReport(tagged.elementAt(0), true); + part++; + } + + // Decoding: partialResultsAvailable [41] IMPLICIT INTEGER OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ResourceControlRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 41 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_partialResultsAvailable = new ASN1Integer(p, false); + part++; + } + + // Decoding: responseRequired [42] IMPLICIT BOOLEAN + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ResourceControlRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 42 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("ResourceControlRequest: bad tag in s_responseRequired\n"); + } + + s_responseRequired = new ASN1Boolean(p, false); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_triggeredRequestFlag = null; + s_otherInfo = null; + + // Decoding: triggeredRequestFlag [43] IMPLICIT BOOLEAN OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 43 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_triggeredRequestFlag = new ASN1Boolean(p, false); + part++; + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("ResourceControlRequest: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ResourceControlRequest. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ResourceControlRequest, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 1; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_suspendedFlag != null) { + numFields++; + } + if (s_resourceReport != null) { + numFields++; + } + if (s_partialResultsAvailable != null) { + numFields++; + } + if (s_triggeredRequestFlag != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_suspendedFlag: BOOLEAN OPTIONAL + + if (s_suspendedFlag != null) { + fields[x++] = s_suspendedFlag.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 39); + } + + // Encoding s_resourceReport: ResourceReport OPTIONAL + + if (s_resourceReport != null) { + enc = new BEREncoding[1]; + enc[0] = s_resourceReport.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 40, enc); + } + + // Encoding s_partialResultsAvailable: INTEGER OPTIONAL + + if (s_partialResultsAvailable != null) { + fields[x++] = s_partialResultsAvailable.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 41); + } + + // Encoding s_responseRequired: BOOLEAN + + fields[x++] = s_responseRequired.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 42); + + // Encoding s_triggeredRequestFlag: BOOLEAN OPTIONAL + + if (s_triggeredRequestFlag != null) { + fields[x++] = s_triggeredRequestFlag.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 43); + } + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ResourceControlRequest. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (s_suspendedFlag != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("suspendedFlag "); + str.append(s_suspendedFlag); + outputted++; + } + + if (s_resourceReport != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("resourceReport "); + str.append(s_resourceReport); + outputted++; + } + + if (s_partialResultsAvailable != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("partialResultsAvailable "); + str.append(s_partialResultsAvailable); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("responseRequired "); + str.append(s_responseRequired); + outputted++; + + if (s_triggeredRequestFlag != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("triggeredRequestFlag "); + str.append(s_triggeredRequestFlag); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + outputted++; + } + + str.append("}"); + + return str.toString(); + } + +} \ No newline at end of file diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceControlResponse.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceControlResponse.java new file mode 100644 index 0000000..dac71de --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceControlResponse.java @@ -0,0 +1,261 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Boolean; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ResourceControlResponse from Z39-50-APDU-1995. + *
+ * ResourceControlResponse ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   continueFlag [44] IMPLICIT BOOLEAN
+ *   resultSetWanted [45] IMPLICIT BOOLEAN OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class ResourceControlResponse extends ASN1Any { + + public ReferenceId s_referenceId; // optional + public ASN1Boolean s_continueFlag; + public ASN1Boolean s_resultSetWanted; // optional + public OtherInformation s_otherInfo; // optional + + /** + * Default constructor for a ResourceControlResponse. + */ + + public ResourceControlResponse() { + } + + /** + * Constructor for a ResourceControlResponse from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ResourceControlResponse(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // ResourceControlResponse should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("ResourceControlResponse: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ResourceControlResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: continueFlag [44] IMPLICIT BOOLEAN + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ResourceControlResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 44 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("ResourceControlResponse: bad tag in s_continueFlag\n"); + } + + s_continueFlag = new ASN1Boolean(p, false); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_resultSetWanted = null; + s_otherInfo = null; + + // Decoding: resultSetWanted [45] IMPLICIT BOOLEAN OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 45 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_resultSetWanted = new ASN1Boolean(p, false); + part++; + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("ResourceControlResponse: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ResourceControlResponse. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ResourceControlResponse, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 1; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_resultSetWanted != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_continueFlag: BOOLEAN + + fields[x++] = s_continueFlag.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 44); + + // Encoding s_resultSetWanted: BOOLEAN OPTIONAL + + if (s_resultSetWanted != null) { + fields[x++] = s_resultSetWanted.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 45); + } + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ResourceControlResponse. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("continueFlag "); + str.append(s_continueFlag); + outputted++; + + if (s_resultSetWanted != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("resultSetWanted "); + str.append(s_resultSetWanted); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + + str.append("}"); + + return str.toString(); + } + +} \ No newline at end of file diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReport.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReport.java new file mode 100644 index 0000000..7170038 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReport.java @@ -0,0 +1,79 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ResourceReport from Z39-50-APDU-1995. + *
+ * ResourceReport ::=
+ * EXTERNAL
+ * 
+ */ +public final class ResourceReport extends ASN1Any { + + public ASN1External value; + + /** + * Constructor for a ResourceReport from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ResourceReport(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + value = new ASN1External(ber, checkTag); + } + + /** + * Returns a BER encoding of the ResourceReport. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return value.berEncode(); + } + + /** + * Returns a BER encoding of ResourceReport, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the ResourceReport. + */ + + public String toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportId.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportId.java new file mode 100644 index 0000000..2b872c7 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportId.java @@ -0,0 +1,86 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a ResourceReportId from Z39-50-APDU-1995. + *
+ * ResourceReportId ::=
+ * OBJECT IDENTIFIER
+ * 
+ */ +public final class ResourceReportId extends ASN1Any { + + public ASN1ObjectIdentifier value; + + + /** + * Constructor for a ResourceReportId from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ResourceReportId(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + value = new ASN1ObjectIdentifier(ber, checkTag); + } + + /** + * Returns a BER encoding of the ResourceReportId. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return value.berEncode(); + } + + /** + * Returns a BER encoding of ResourceReportId, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the ResourceReportId. + */ + public String toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportRequest.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportRequest.java new file mode 100644 index 0000000..cfeb60e --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportRequest.java @@ -0,0 +1,262 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ResourceReportRequest from Z39-50-APDU-1995 + *
+ * ResourceReportRequest ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   opId [210] IMPLICIT ReferenceId OPTIONAL
+ *   prefResourceReportFormat [49] IMPLICIT ResourceReportId OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class ResourceReportRequest extends ASN1Any { + + public ReferenceId s_referenceId; // optional + public ReferenceId s_opId; // optional + public ResourceReportId s_prefResourceReportFormat; // optional + public OtherInformation s_otherInfo; // optional + + + /** + * Constructor for a ResourceReportRequest from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ResourceReportRequest(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // ResourceReportRequest should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("ResourceReportRequest: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_referenceId = null; + s_opId = null; + s_prefResourceReportFormat = null; + s_otherInfo = null; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: opId [210] IMPLICIT ReferenceId OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 210 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_opId = new ReferenceId(p, false); + part++; + } + + // Decoding: prefResourceReportFormat [49] IMPLICIT ResourceReportId OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 49 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_prefResourceReportFormat = new ResourceReportId(p, false); + part++; + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("ResourceReportRequest: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ResourceReportRequest. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ResourceReportRequest, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 0; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_opId != null) { + numFields++; + } + if (s_prefResourceReportFormat != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_opId: ReferenceId OPTIONAL + + if (s_opId != null) { + fields[x++] = s_opId.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 210); + } + + // Encoding s_prefResourceReportFormat: ResourceReportId OPTIONAL + + if (s_prefResourceReportFormat != null) { + fields[x++] = s_prefResourceReportFormat.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 49); + } + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x++] = s_otherInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ResourceReportRequest. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (s_opId != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("opId "); + str.append(s_opId); + outputted++; + } + + if (s_prefResourceReportFormat != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("prefResourceReportFormat "); + str.append(s_prefResourceReportFormat); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportResponse.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportResponse.java new file mode 100644 index 0000000..0b1d2a9 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResourceReportResponse.java @@ -0,0 +1,269 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ResourceReportResponse from Z39-50-APDU-1995. + *
+ * ResourceReportResponse ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   resourceReportStatus [50] IMPLICIT INTEGER
+ *   resourceReport [51] EXPLICIT ResourceReport OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class ResourceReportResponse extends ASN1Any { + + // Enumerated constants for resourceReportStatus + public static final int E_success = 0; + public static final int E_partial = 1; + public static final int E_failure_1 = 2; + public static final int E_failure_2 = 3; + public static final int E_failure_3 = 4; + public static final int E_failure_4 = 5; + public static final int E_failure_5 = 6; + public static final int E_failure_6 = 7; + public ReferenceId s_referenceId; // optional + public ASN1Integer s_resourceReportStatus; + public ResourceReport s_resourceReport; // optional + public OtherInformation s_otherInfo; // optional + /** + * Default constructor for a ResourceReportResponse. + */ + + public ResourceReportResponse() { + } + /** + * Constructor for a ResourceReportResponse from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ResourceReportResponse(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // ResourceReportResponse should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("ResourceReportResponse: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ResourceReportResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: resourceReportStatus [50] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ResourceReportResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 50 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("ResourceReportResponse: bad tag in s_resourceReportStatus\n"); + } + + s_resourceReportStatus = new ASN1Integer(p, false); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_resourceReport = null; + s_otherInfo = null; + + // Decoding: resourceReport [51] EXPLICIT ResourceReport OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 51 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException("ResourceReportResponse: bad BER encoding: s_resourceReport tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException("ResourceReportResponse: bad BER encoding: s_resourceReport tag bad\n"); + } + + s_resourceReport = new ResourceReport(tagged.elementAt(0), true); + part++; + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("ResourceReportResponse: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ResourceReportResponse. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ResourceReportResponse, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 1; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_resourceReport != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_resourceReportStatus: INTEGER + + fields[x++] = s_resourceReportStatus.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 50); + + // Encoding s_resourceReport: ResourceReport OPTIONAL + + if (s_resourceReport != null) { + enc = new BEREncoding[1]; + enc[0] = s_resourceReport.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 51, enc); + } + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("resourceReportStatus "); + str.append(s_resourceReportStatus); + outputted++; + + if (s_resourceReport != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("resourceReport "); + str.append(s_resourceReport); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + + str.append("}"); + + return str.toString(); + } + +} \ No newline at end of file diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ResultSetId.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResultSetId.java new file mode 100644 index 0000000..206414d --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResultSetId.java @@ -0,0 +1,100 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ResultSetId from Z39-50-APDU-1995 + *
+ * ResultSetId ::=
+ * [31] IMPLICIT InternationalString
+ * 
+ */ +public final class ResultSetId extends ASN1Any { + + public InternationalString value; + + /** + * Default constructor for a ResultSetId. + */ + public ResultSetId() { + } + + + /** + * Constructor for a ResultSetId from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ResultSetId(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Check tag matches + + if (checkTag) { + if (ber.tagGet() != 31 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("ResultSetId: bad BER: tag=" + ber.tagGet() + " expected 31\n"); + } + } + + value = new InternationalString(ber, false); + } + + /** + * Returns a BER encoding of the ResultSetId. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 31); + } + + /** + * Returns a BER encoding of ResultSetId, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + return value.berEncode(tagType, tag); + } + + /** + * Returns a new String object containing a text representing + * of the ResultSetId. + */ + public String toString() { + return value.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ResultSetPlusAttributes.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResultSetPlusAttributes.java new file mode 100644 index 0000000..5e2c058 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ResultSetPlusAttributes.java @@ -0,0 +1,127 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a ResultSetPlusAttributes from Z39-50-APDU-1995. + *
+ * ResultSetPlusAttributes ::=
+ * [214] IMPLICIT SEQUENCE {
+ *   resultSet ResultSetId
+ *   attributes AttributeList
+ * }
+ * 
+ */ +public final class ResultSetPlusAttributes extends ASN1Any { + + public ResultSetId s_resultSet; + public AttributeList s_attributes; + + /** + * Constructor for a ResultSetPlusAttributes from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public ResultSetPlusAttributes(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + if (checkTag) { + if (ber.tagGet() != 214 || + ber.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("ResultSetPlusAttributes: bad BER: tag=" + ber.tagGet() + " expected 214\n"); + } + } + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("ResultSetPlusAttributes: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("ResultSetPlusAttributes: incomplete"); + } + p = berConstructed.elementAt(part); + s_resultSet = new ResultSetId(p, true); + part++; + if (numParts <= part) { + throw new ASN1Exception("ResultSetPlusAttributes: incomplete"); + } + p = berConstructed.elementAt(part); + s_attributes = new AttributeList(p, true); + part++; + if (part < numParts) { + throw new ASN1Exception("ResultSetPlusAttributes: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ResultSetPlusAttributes. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 214); + } + + /** + * Returns a BER encoding of ResultSetPlusAttributes, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 2; + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + fields[x++] = s_resultSet.berEncode(); + fields[x] = s_attributes.berEncode(); + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ResultSetPlusAttributes. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + str.append("resultSet "); + str.append(s_resultSet); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("attributes "); + str.append(s_attributes); + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ScanRequest.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ScanRequest.java new file mode 100644 index 0000000..6f67c07 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ScanRequest.java @@ -0,0 +1,297 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a ScanRequest from Z39-50-APDU-1995 + *
+ * ScanRequest ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   databaseNames [3] IMPLICIT SEQUENCE OF DatabaseName
+ *   attributeSet AttributeSetId OPTIONAL
+ *   termListAndStartPoint AttributesPlusTerm
+ *   stepSize [5] IMPLICIT INTEGER OPTIONAL
+ *   numberOfTermsRequested [6] IMPLICIT INTEGER
+ *   preferredPositionInResponse [7] IMPLICIT INTEGER OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class ScanRequest extends ASN1Any { + public ReferenceId s_referenceId; // optional + public DatabaseName s_databaseNames[]; + public AttributeSetId s_attributeSet; // optional + public AttributesPlusTerm s_termListAndStartPoint; + public ASN1Integer s_stepSize; // optional + public ASN1Integer s_numberOfTermsRequested; + public ASN1Integer s_preferredPositionInResponse; // optional + public OtherInformation s_otherInfo; // optional + /** + * Constructor for a ScanRequest from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public ScanRequest(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("ScanRequest: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("ScanRequest: incomplete"); + } + p = berConstructed.elementAt(part); + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + if (numParts <= part) { + throw new ASN1Exception("ScanRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 3 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("ScanRequest: bad tag in s_databaseNames\n"); + } + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + s_databaseNames = new DatabaseName[parts]; + int n; + for (n = 0; n < parts; n++) { + s_databaseNames[n] = new DatabaseName(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + if (numParts <= part) { + throw new ASN1Exception("ScanRequest: incomplete"); + } + p = berConstructed.elementAt(part); + try { + s_attributeSet = new AttributeSetId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_attributeSet = null; // no, not present + } + if (numParts <= part) { + throw new ASN1Exception("ScanRequest: incomplete"); + } + p = berConstructed.elementAt(part); + s_termListAndStartPoint = new AttributesPlusTerm(p, true); + part++; + if (numParts <= part) { + throw new ASN1Exception("ScanRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 5 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_stepSize = new ASN1Integer(p, false); + part++; + } + if (numParts <= part) { + throw new ASN1Exception("ScanRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 6 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("ScanRequest: bad tag in s_numberOfTermsRequested\n"); + } + s_numberOfTermsRequested = new ASN1Integer(p, false); + part++; + s_preferredPositionInResponse = null; + s_otherInfo = null; + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 7 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_preferredPositionInResponse = new ASN1Integer(p, false); + part++; + } + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + if (part < numParts) { + throw new ASN1Exception("ScanRequest: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ScanRequest. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ScanRequest, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 3; + if (s_referenceId != null) { + numFields++; + } + if (s_attributeSet != null) { + numFields++; + } + if (s_stepSize != null) { + numFields++; + } + if (s_preferredPositionInResponse != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + f2 = new BEREncoding[s_databaseNames.length]; + for (p = 0; p < s_databaseNames.length; p++) { + f2[p] = s_databaseNames[p].berEncode(); + } + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 3, f2); + if (s_attributeSet != null) { + fields[x++] = s_attributeSet.berEncode(); + } + fields[x++] = s_termListAndStartPoint.berEncode(); + if (s_stepSize != null) { + fields[x++] = s_stepSize.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 5); + } + fields[x++] = s_numberOfTermsRequested.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 6); + if (s_preferredPositionInResponse != null) { + fields[x++] = s_preferredPositionInResponse.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 7); + } + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ScanRequest. + */ + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("databaseNames "); + str.append("{"); + for (p = 0; p < s_databaseNames.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(s_databaseNames[p]); + } + str.append("}"); + outputted++; + if (s_attributeSet != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("attributeSet "); + str.append(s_attributeSet); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("termListAndStartPoint "); + str.append(s_termListAndStartPoint); + outputted++; + if (s_stepSize != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("stepSize "); + str.append(s_stepSize); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("numberOfTermsRequested "); + str.append(s_numberOfTermsRequested); + outputted++; + if (s_preferredPositionInResponse != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("preferredPositionInResponse "); + str.append(s_preferredPositionInResponse); + outputted++; + } + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + str.append("}"); + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/ScanResponse.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/ScanResponse.java new file mode 100644 index 0000000..24bc841 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/ScanResponse.java @@ -0,0 +1,386 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a ScanResponse from Z39-50-APDU-1995. + *
+ * ScanResponse ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   stepSize [3] IMPLICIT INTEGER OPTIONAL
+ *   scanStatus [4] IMPLICIT INTEGER
+ *   numberOfEntriesReturned [5] IMPLICIT INTEGER
+ *   positionOfTerm [6] IMPLICIT INTEGER OPTIONAL
+ *   entries [7] IMPLICIT ListEntries OPTIONAL
+ *   attributeSet [8] IMPLICIT AttributeSetId OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class ScanResponse extends ASN1Any { + + // Enumerated constants for scanStatus + public static final int E_success = 0; + public static final int E_partial_1 = 1; + public static final int E_partial_2 = 2; + public static final int E_partial_3 = 3; + public static final int E_partial_4 = 4; + public static final int E_partial_5 = 5; + public static final int E_failure = 6; + public ReferenceId s_referenceId; // optional + public ASN1Integer s_stepSize; // optional + public ASN1Integer s_scanStatus; + public ASN1Integer s_numberOfEntriesReturned; + public ASN1Integer s_positionOfTerm; // optional + public ListEntries s_entries; // optional + public AttributeSetId s_attributeSet; // optional + public OtherInformation s_otherInfo; // optional + /** + * Constructor for a ScanResponse from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public ScanResponse(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // ScanResponse should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("ScanResponse: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ScanResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: stepSize [3] IMPLICIT INTEGER OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ScanResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 3 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_stepSize = new ASN1Integer(p, false); + part++; + } + + // Decoding: scanStatus [4] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ScanResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 4 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("ScanResponse: bad tag in s_scanStatus\n"); + } + + s_scanStatus = new ASN1Integer(p, false); + part++; + + // Decoding: numberOfEntriesReturned [5] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("ScanResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 5 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("ScanResponse: bad tag in s_numberOfEntriesReturned\n"); + } + + s_numberOfEntriesReturned = new ASN1Integer(p, false); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_positionOfTerm = null; + s_entries = null; + s_attributeSet = null; + s_otherInfo = null; + + // Decoding: positionOfTerm [6] IMPLICIT INTEGER OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 6 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_positionOfTerm = new ASN1Integer(p, false); + part++; + } + + // Decoding: entries [7] IMPLICIT ListEntries OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 7 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_entries = new ListEntries(p, false); + part++; + } + + // Decoding: attributeSet [8] IMPLICIT AttributeSetId OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 8 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_attributeSet = new AttributeSetId(p, false); + part++; + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("ScanResponse: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the ScanResponse. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of ScanResponse, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 2; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_stepSize != null) { + numFields++; + } + if (s_positionOfTerm != null) { + numFields++; + } + if (s_entries != null) { + numFields++; + } + if (s_attributeSet != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_stepSize: INTEGER OPTIONAL + + if (s_stepSize != null) { + fields[x++] = s_stepSize.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 3); + } + + // Encoding s_scanStatus: INTEGER + + fields[x++] = s_scanStatus.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 4); + + // Encoding s_numberOfEntriesReturned: INTEGER + + fields[x++] = s_numberOfEntriesReturned.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 5); + + // Encoding s_positionOfTerm: INTEGER OPTIONAL + + if (s_positionOfTerm != null) { + fields[x++] = s_positionOfTerm.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 6); + } + + // Encoding s_entries: ListEntries OPTIONAL + + if (s_entries != null) { + fields[x++] = s_entries.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 7); + } + + // Encoding s_attributeSet: AttributeSetId OPTIONAL + + if (s_attributeSet != null) { + fields[x++] = s_attributeSet.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 8); + } + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the ScanResponse. + */ + + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (s_stepSize != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("stepSize "); + str.append(s_stepSize); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("scanStatus "); + str.append(s_scanStatus); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("numberOfEntriesReturned "); + str.append(s_numberOfEntriesReturned); + outputted++; + + if (s_positionOfTerm != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("positionOfTerm "); + str.append(s_positionOfTerm); + outputted++; + } + + if (s_entries != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("entries "); + str.append(s_entries); + outputted++; + } + + if (s_attributeSet != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("attributeSet "); + str.append(s_attributeSet); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/SearchRequest.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/SearchRequest.java new file mode 100644 index 0000000..696b34b --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/SearchRequest.java @@ -0,0 +1,461 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Boolean; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a SearchRequest from Z39-50-APDU-1995. + *
+ * SearchRequest ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   smallSetUpperBound [13] IMPLICIT INTEGER
+ *   largeSetLowerBound [14] IMPLICIT INTEGER
+ *   mediumSetPresentNumber [15] IMPLICIT INTEGER
+ *   replaceIndicator [16] IMPLICIT BOOLEAN
+ *   resultSetName [17] IMPLICIT InternationalString
+ *   databaseNames [18] IMPLICIT SEQUENCE OF DatabaseName
+ *   smallSetElementSetNames [100] EXPLICIT ElementSetNames OPTIONAL
+ *   mediumSetElementSetNames [101] EXPLICIT ElementSetNames OPTIONAL
+ *   preferredRecordSyntax [104] IMPLICIT OBJECT IDENTIFIER OPTIONAL
+ *   query [21] EXPLICIT Query
+ *   additionalSearchInfo [203] IMPLICIT OtherInformation OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class SearchRequest extends ASN1Any { + public ReferenceId s_referenceId; // optional + public ASN1Integer s_smallSetUpperBound; + public ASN1Integer s_largeSetLowerBound; + public ASN1Integer s_mediumSetPresentNumber; + public ASN1Boolean s_replaceIndicator; + public InternationalString s_resultSetName; + public DatabaseName s_databaseNames[]; + public ElementSetNames s_smallSetElementSetNames; // optional + public ElementSetNames s_mediumSetElementSetNames; // optional + public ASN1ObjectIdentifier s_preferredRecordSyntax; // optional + public Query s_query; + public OtherInformation s_additionalSearchInfo; // optional + public OtherInformation s_otherInfo; // optional + /** + * Default constructor for a SearchRequest. + */ + public SearchRequest() { + } + /** + * Constructor for a SearchRequest from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public SearchRequest(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // SearchRequest should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("SearchRequest: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + if (numParts <= part) { + throw new ASN1Exception("SearchRequest: incomplete"); + } + p = berConstructed.elementAt(part); + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + if (numParts <= part) { + throw new ASN1Exception("SearchRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 13 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SearchRequest: bad tag in s_smallSetUpperBound\n"); + } + s_smallSetUpperBound = new ASN1Integer(p, false); + part++; + if (numParts <= part) { + throw new ASN1Exception("SearchRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 14 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SearchRequest: bad tag in s_largeSetLowerBound\n"); + } + s_largeSetLowerBound = new ASN1Integer(p, false); + part++; + if (numParts <= part) { + throw new ASN1Exception("SearchRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 15 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SearchRequest: bad tag in s_mediumSetPresentNumber\n"); + } + s_mediumSetPresentNumber = new ASN1Integer(p, false); + part++; + if (numParts <= part) { + throw new ASN1Exception("SearchRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 16 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SearchRequest: bad tag in s_replaceIndicator\n"); + } + s_replaceIndicator = new ASN1Boolean(p, false); + part++; + if (numParts <= part) { + throw new ASN1Exception("SearchRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 17 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SearchRequest: bad tag in s_resultSetName\n"); + } + s_resultSetName = new InternationalString(p, false); + part++; + if (numParts <= part) { + throw new ASN1Exception("SearchRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 18 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SearchRequest: bad tag in s_databaseNames\n"); + } + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + s_databaseNames = new DatabaseName[parts]; + int n; + for (n = 0; n < parts; n++) { + s_databaseNames[n] = new DatabaseName(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + if (numParts <= part) { + throw new ASN1Exception("SearchRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 100 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException("SearchRequest: bad BER encoding: s_smallSetElementSetNames tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException("SearchRequest: bad BER encoding: s_smallSetElementSetNames tag bad\n"); + } + s_smallSetElementSetNames = new ElementSetNames(tagged.elementAt(0), true); + part++; + } + if (numParts <= part) { + throw new ASN1Exception("SearchRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 101 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException("SearchRequest: bad BER encoding: s_mediumSetElementSetNames tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException("SearchRequest: bad BER encoding: s_mediumSetElementSetNames tag bad\n"); + } + s_mediumSetElementSetNames = new ElementSetNames(tagged.elementAt(0), true); + part++; + } + if (numParts <= part) { + throw new ASN1Exception("SearchRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 104 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_preferredRecordSyntax = new ASN1ObjectIdentifier(p, false); + part++; + } + if (numParts <= part) { + throw new ASN1Exception("SearchRequest: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 21 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SearchRequest: bad tag in s_query\n"); + } + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException("SearchRequest: bad BER encoding: s_query tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException("SearchRequest: bad BER encoding: s_query tag bad\n"); + } + s_query = new Query(tagged.elementAt(0), true); + part++; + s_additionalSearchInfo = null; + s_otherInfo = null; + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 203 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_additionalSearchInfo = new OtherInformation(p, false); + part++; + } + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + if (part < numParts) { + throw new ASN1Exception("SearchRequest: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the SearchRequest. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of SearchRequest, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 7; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_smallSetElementSetNames != null) { + numFields++; + } + if (s_mediumSetElementSetNames != null) { + numFields++; + } + if (s_preferredRecordSyntax != null) { + numFields++; + } + if (s_additionalSearchInfo != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + BEREncoding enc[]; + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + fields[x++] = s_smallSetUpperBound.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 13); + fields[x++] = s_largeSetLowerBound.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 14); + fields[x++] = s_mediumSetPresentNumber.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 15); + fields[x++] = s_replaceIndicator.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 16); + fields[x++] = s_resultSetName.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 17); + f2 = new BEREncoding[s_databaseNames.length]; + for (p = 0; p < s_databaseNames.length; p++) { + f2[p] = s_databaseNames[p].berEncode(); + } + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 18, f2); + if (s_smallSetElementSetNames != null) { + enc = new BEREncoding[1]; + enc[0] = s_smallSetElementSetNames.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 100, enc); + } + if (s_mediumSetElementSetNames != null) { + enc = new BEREncoding[1]; + enc[0] = s_mediumSetElementSetNames.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 101, enc); + } + if (s_preferredRecordSyntax != null) { + fields[x++] = s_preferredRecordSyntax.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 104); + } + enc = new BEREncoding[1]; + enc[0] = s_query.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 21, enc); + if (s_additionalSearchInfo != null) { + fields[x++] = s_additionalSearchInfo.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 203); + } + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the SearchRequest. + */ + + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("smallSetUpperBound "); + str.append(s_smallSetUpperBound); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("largeSetLowerBound "); + str.append(s_largeSetLowerBound); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("mediumSetPresentNumber "); + str.append(s_mediumSetPresentNumber); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("replaceIndicator "); + str.append(s_replaceIndicator); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("resultSetName "); + str.append(s_resultSetName); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("databaseNames "); + str.append("{"); + for (p = 0; p < s_databaseNames.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(s_databaseNames[p]); + } + str.append("}"); + outputted++; + + if (s_smallSetElementSetNames != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("smallSetElementSetNames "); + str.append(s_smallSetElementSetNames); + outputted++; + } + + if (s_mediumSetElementSetNames != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("mediumSetElementSetNames "); + str.append(s_mediumSetElementSetNames); + outputted++; + } + + if (s_preferredRecordSyntax != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("preferredRecordSyntax "); + str.append(s_preferredRecordSyntax); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("query "); + str.append(s_query); + outputted++; + + if (s_additionalSearchInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("additionalSearchInfo "); + str.append(s_additionalSearchInfo); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/SearchResponse.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/SearchResponse.java new file mode 100644 index 0000000..a99776f --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/SearchResponse.java @@ -0,0 +1,401 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Boolean; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a SearchResponse from Z39-50-APDU-1995. + *
+ * SearchResponse ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   resultCount [23] IMPLICIT INTEGER
+ *   numberOfRecordsReturned [24] IMPLICIT INTEGER
+ *   nextResultSetPosition [25] IMPLICIT INTEGER
+ *   searchStatus [22] IMPLICIT BOOLEAN
+ *   resultSetStatus [26] IMPLICIT INTEGER OPTIONAL
+ *   presentStatus PresentStatus OPTIONAL
+ *   records Records OPTIONAL
+ *   additionalSearchInfo [203] IMPLICIT OtherInformation OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class SearchResponse extends ASN1Any { + + // Enumerated constants for resultSetStatus + public static final int E_subset = 1; + public static final int E_interim = 2; + public static final int E_none = 3; + public ReferenceId s_referenceId; // optional + public ASN1Integer s_resultCount; + public ASN1Integer s_numberOfRecordsReturned; + public ASN1Integer s_nextResultSetPosition; + public ASN1Boolean s_searchStatus; + public ASN1Integer s_resultSetStatus; // optional + public PresentStatus s_presentStatus; // optional + public Records s_records; // optional + public OtherInformation s_additionalSearchInfo; // optional + public OtherInformation s_otherInfo; // optional + /** + * Constructor for a SearchResponse from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public SearchResponse(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("SearchResponse: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("SearchResponse: incomplete"); + } + p = berConstructed.elementAt(part); + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + if (numParts <= part) { + throw new ASN1Exception("SearchResponse: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 23 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SearchResponse: bad tag in s_resultCount\n"); + } + s_resultCount = new ASN1Integer(p, false); + part++; + if (numParts <= part) { + throw new ASN1Exception("SearchResponse: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 24 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SearchResponse: bad tag in s_numberOfRecordsReturned\n"); + } + s_numberOfRecordsReturned = new ASN1Integer(p, false); + part++; + if (numParts <= part) { + throw new ASN1Exception("SearchResponse: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 25 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SearchResponse: bad tag in s_nextResultSetPosition\n"); + } + s_nextResultSetPosition = new ASN1Integer(p, false); + part++; + if (numParts <= part) { + throw new ASN1Exception("SearchResponse: incomplete"); + } + p = berConstructed.elementAt(part); + if (p.tagGet() != 22 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SearchResponse: bad tag in s_searchStatus\n"); + } + s_searchStatus = new ASN1Boolean(p, false); + part++; + s_resultSetStatus = null; + s_presentStatus = null; + s_records = null; + s_additionalSearchInfo = null; + s_otherInfo = null; + if (numParts <= part) { + return; + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 26 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_resultSetStatus = new ASN1Integer(p, false); + part++; + } + + // Decoding: presentStatus PresentStatus OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_presentStatus = new PresentStatus(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_presentStatus = null; // no, not present + } + + // Decoding: records Records OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_records = new Records(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_records = null; // no, not present + } + + // Decoding: additionalSearchInfo [203] IMPLICIT OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 203 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_additionalSearchInfo = new OtherInformation(p, false); + part++; + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("SearchResponse: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the SearchResponse. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of SearchResponse, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + int numFields = 4; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_resultSetStatus != null) { + numFields++; + } + if (s_presentStatus != null) { + numFields++; + } + if (s_records != null) { + numFields++; + } + if (s_additionalSearchInfo != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_resultCount: INTEGER + + fields[x++] = s_resultCount.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 23); + + // Encoding s_numberOfRecordsReturned: INTEGER + + fields[x++] = s_numberOfRecordsReturned.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 24); + + // Encoding s_nextResultSetPosition: INTEGER + + fields[x++] = s_nextResultSetPosition.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 25); + + // Encoding s_searchStatus: BOOLEAN + + fields[x++] = s_searchStatus.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 22); + + // Encoding s_resultSetStatus: INTEGER OPTIONAL + + if (s_resultSetStatus != null) { + fields[x++] = s_resultSetStatus.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 26); + } + + // Encoding s_presentStatus: PresentStatus OPTIONAL + + if (s_presentStatus != null) { + fields[x++] = s_presentStatus.berEncode(); + } + + // Encoding s_records: Records OPTIONAL + + if (s_records != null) { + fields[x++] = s_records.berEncode(); + } + + // Encoding s_additionalSearchInfo: OtherInformation OPTIONAL + + if (s_additionalSearchInfo != null) { + fields[x++] = s_additionalSearchInfo.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 203); + } + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the SearchResponse. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("resultCount "); + str.append(s_resultCount); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("numberOfRecordsReturned "); + str.append(s_numberOfRecordsReturned); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("nextResultSetPosition "); + str.append(s_nextResultSetPosition); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("searchStatus "); + str.append(s_searchStatus); + outputted++; + + if (s_resultSetStatus != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("resultSetStatus "); + str.append(s_resultSetStatus); + outputted++; + } + + if (s_presentStatus != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("presentStatus "); + str.append(s_presentStatus); + outputted++; + } + + if (s_records != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("records "); + str.append(s_records); + outputted++; + } + + if (s_additionalSearchInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("additionalSearchInfo "); + str.append(s_additionalSearchInfo); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Segment.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Segment.java new file mode 100644 index 0000000..c1c7291 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Segment.java @@ -0,0 +1,270 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a Segment from Z39-50-APDU-1995. + *
+ * Segment ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   numberOfRecordsReturned [24] IMPLICIT INTEGER
+ *   segmentRecords [0] IMPLICIT SEQUENCE OF NamePlusRecord
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class Segment extends ASN1Any { + + public ReferenceId s_referenceId; // optional + public ASN1Integer s_numberOfRecordsReturned; + public NamePlusRecord s_segmentRecords[]; + public OtherInformation s_otherInfo; // optional + + /** + * Constructor for a Segment from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Segment(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Segment should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Segment: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("Segment: incomplete"); + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: numberOfRecordsReturned [24] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("Segment: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 24 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("Segment: bad tag in s_numberOfRecordsReturned\n"); + } + + s_numberOfRecordsReturned = new ASN1Integer(p, false); + part++; + + // Decoding: segmentRecords [0] IMPLICIT SEQUENCE OF NamePlusRecord + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("Segment: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 0 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("Segment: bad tag in s_segmentRecords\n"); + } + + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + s_segmentRecords = new NamePlusRecord[parts]; + int n; + for (n = 0; n < parts; n++) { + s_segmentRecords[n] = new NamePlusRecord(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_otherInfo = null; + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("Segment: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the Segment. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of Segment, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 2; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_numberOfRecordsReturned: INTEGER + + fields[x++] = s_numberOfRecordsReturned.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 24); + + // Encoding s_segmentRecords: SEQUENCE OF + + f2 = new BEREncoding[s_segmentRecords.length]; + + for (p = 0; p < s_segmentRecords.length; p++) { + f2[p] = s_segmentRecords[p].berEncode(); + } + + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 0, f2); + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the Segment. + */ + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("numberOfRecordsReturned "); + str.append(s_numberOfRecordsReturned); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("segmentRecords "); + str.append("{"); + for (p = 0; p < s_segmentRecords.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(s_segmentRecords[p]); + } + str.append("}"); + outputted++; + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/SortElement.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortElement.java new file mode 100644 index 0000000..635d2a7 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortElement.java @@ -0,0 +1,208 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a SortElement from Z39-50-APDU-1995 + *
+ * SortElement ::=
+ * CHOICE {
+ *   generic [1] EXPLICIT SortKey
+ *   datbaseSpecific [2] IMPLICIT SEQUENCE OF SortElement_datbaseSpecific
+ * }
+ * 
+ */ +public final class SortElement extends ASN1Any { + + public SortKey c_generic; + public SortElementDatabaseSpecific c_datbaseSpecific[]; + + + /** + * Constructor for a SortElement from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public SortElement(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + BERConstructed tagwrapper; + + // Null out all choices + + c_generic = null; + c_datbaseSpecific = null; + + // Try choice generic + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagwrapper = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("SortElement: bad BER form\n"); + } + if (tagwrapper.numberComponents() != 1) { + throw new ASN1EncodingException("SortElement: bad BER form\n"); + } + c_generic = new SortKey(tagwrapper.elementAt(0), true); + return; + } + + // Try choice datbaseSpecific + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + BEREncoding ber_data; + ber_data = ber; + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber_data; + } catch (ClassCastException e) { + throw new ASN1EncodingException("SortElement: bad BER form\n"); + } + + int numParts = berConstructed.numberComponents(); + int p; + + c_datbaseSpecific = new SortElementDatabaseSpecific[numParts]; + + for (p = 0; p < numParts; p++) { + c_datbaseSpecific[p] = new SortElementDatabaseSpecific(berConstructed.elementAt(p), true); + } + return; + } + + throw new ASN1Exception("SortElement: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of SortElement. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + BEREncoding f2[]; + int p; + BEREncoding enc[]; + + // Encoding choice: c_generic + if (c_generic != null) { + enc = new BEREncoding[1]; + enc[0] = c_generic.berEncode(); + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 1, enc); + } + + // Encoding choice: c_datbaseSpecific + if (c_datbaseSpecific != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + f2 = new BEREncoding[c_datbaseSpecific.length]; + + for (p = 0; p < c_datbaseSpecific.length; p++) { + f2[p] = c_datbaseSpecific[p].berEncode(); + } + + chosen = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 2, f2); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("SortElement: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the SortElement. + */ + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (c_generic != null) { + found = true; + str.append("generic "); + str.append(c_generic); + } + + if (c_datbaseSpecific != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("datbaseSpecific "); + str.append("{"); + for (p = 0; p < c_datbaseSpecific.length; p++) { + str.append(c_datbaseSpecific[p]); + } + str.append("}"); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/SortElementDatabaseSpecific.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortElementDatabaseSpecific.java new file mode 100644 index 0000000..3beae4e --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortElementDatabaseSpecific.java @@ -0,0 +1,155 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a SortElement_datbaseSpecific from Z39-50-APDU-1995. + *
+ * SortElement_datbaseSpecific ::=
+ * SEQUENCE {
+ *   databaseName DatabaseName
+ *   dbSort SortKey
+ * }
+ * 
+ */ +public final class SortElementDatabaseSpecific extends ASN1Any { + + public DatabaseName s_databaseName; + public SortKey s_dbSort; + + /** + * Constructor for a SortElement_datbaseSpecific from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public SortElementDatabaseSpecific(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // SortElement_datbaseSpecific should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("SortElement_datbaseSpecific: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: databaseName DatabaseName + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("SortElement_datbaseSpecific: incomplete"); + } + p = berConstructed.elementAt(part); + + s_databaseName = new DatabaseName(p, true); + part++; + + // Decoding: dbSort SortKey + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("SortElement_datbaseSpecific: incomplete"); + } + p = berConstructed.elementAt(part); + + s_dbSort = new SortKey(p, true); + part++; + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("SortElement_datbaseSpecific: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the SortElement_datbaseSpecific. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of SortElement_datbaseSpecific, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 2; // number of mandatories + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_databaseName: DatabaseName + + fields[x++] = s_databaseName.berEncode(); + + // Encoding s_dbSort: SortKey + + fields[x] = s_dbSort.berEncode(); + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the SortElement_datbaseSpecific. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + str.append("databaseName "); + str.append(s_databaseName); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("dbSort "); + str.append(s_dbSort); + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKey.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKey.java new file mode 100644 index 0000000..d89d46d --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKey.java @@ -0,0 +1,175 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a SortKey from Z39-50-APDU-1995. + *
+ * SortKey ::=
+ * CHOICE {
+ *   sortfield [0] IMPLICIT InternationalString
+ *   elementSpec [1] IMPLICIT Specification
+ *   sortAttributes [2] IMPLICIT SortKey_sortAttributes
+ * }
+ * 
+ */ +public final class SortKey extends ASN1Any { + + public InternationalString c_sortfield; + public Specification c_elementSpec; + public SortKeySortAttributes c_sortAttributes; + + /** + * Constructor for a SortKey from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public SortKey(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + c_sortfield = null; + c_elementSpec = null; + c_sortAttributes = null; + if (ber.tagGet() == 0 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_sortfield = new InternationalString(ber, false); + return; + } + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_elementSpec = new Specification(ber, false); + return; + } + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_sortAttributes = new SortKeySortAttributes(ber, false); + return; + } + throw new ASN1Exception("SortKey: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of SortKey. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + // Encoding choice: c_sortfield + if (c_sortfield != null) { + chosen = c_sortfield.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 0); + } + + // Encoding choice: c_elementSpec + if (c_elementSpec != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_elementSpec.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding choice: c_sortAttributes + if (c_sortAttributes != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_sortAttributes.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("SortKey: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the SortKey. + */ + + public String toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (c_sortfield != null) { + found = true; + str.append("sortfield "); + str.append(c_sortfield); + } + + if (c_elementSpec != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("elementSpec "); + str.append(c_elementSpec); + } + + if (c_sortAttributes != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("sortAttributes "); + str.append(c_sortAttributes); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySortAttributes.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySortAttributes.java new file mode 100644 index 0000000..90ddcaa --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySortAttributes.java @@ -0,0 +1,124 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a SortKey_sortAttributes from Z39-50-APDU-1995. + *
+ * SortKey_sortAttributes ::=
+ * SEQUENCE {
+ *   id AttributeSetId
+ *   list AttributeList
+ * }
+ * 
+ */ +public final class SortKeySortAttributes extends ASN1Any { + + public AttributeSetId s_id; + public AttributeList s_list; + + + /** + * Constructor for a SortKey_sortAttributes from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public SortKeySortAttributes(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("SortKey_sortAttributes: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + throw new ASN1Exception("SortKey_sortAttributes: incomplete"); + } + p = berConstructed.elementAt(part); + s_id = new AttributeSetId(p, true); + part++; + if (numParts <= part) { + throw new ASN1Exception("SortKey_sortAttributes: incomplete"); + } + p = berConstructed.elementAt(part); + s_list = new AttributeList(p, true); + part++; + if (part < numParts) { + throw new ASN1Exception("SortKey_sortAttributes: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the SortKey_sortAttributes. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of SortKey_sortAttributes, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 2; // number of mandatories + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + fields[x++] = s_id.berEncode(); + fields[x] = s_list.berEncode(); + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the SortKey_sortAttributes. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + str.append("id "); + str.append(s_id); + outputted++; + if (0 < outputted) { + str.append(", "); + } + str.append("list "); + str.append(s_list); + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySpec.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySpec.java new file mode 100644 index 0000000..7387105 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySpec.java @@ -0,0 +1,230 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a SortKeySpec from Z39-50-APDU-1995. + *
+ * SortKeySpec ::=
+ * SEQUENCE {
+ *   sortElement SortElement
+ *   sortRelation [1] IMPLICIT INTEGER
+ *   caseSensitivity [2] IMPLICIT INTEGER
+ *   missingValueAction [3] EXPLICIT SortKeySpec_missingValueAction OPTIONAL
+ * }
+ * 
+ */ +public final class SortKeySpec extends ASN1Any { + + + public static final int E_ascending = 0; + public static final int E_descending = 1; + public static final int E_ascendingByFrequency = 3; + public static final int E_descendingByfrequency = 4; + public static final int E_caseSensitive = 0; + public static final int E_caseInsensitive = 1; + public SortElement s_sortElement; + public ASN1Integer s_sortRelation; + public ASN1Integer s_caseSensitivity; + public SortKeySpecMissingValueAction s_missingValueAction; // optional + /** + * Constructor for a SortKeySpec from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public SortKeySpec(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // SortKeySpec should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("SortKeySpec: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + + // Decoding: sortElement SortElement + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("SortKeySpec: incomplete"); + } + p = berConstructed.elementAt(part); + + s_sortElement = new SortElement(p, true); + part++; + + // Decoding: sortRelation [1] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("SortKeySpec: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 1 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SortKeySpec: bad tag in s_sortRelation\n"); + } + + s_sortRelation = new ASN1Integer(p, false); + part++; + + // Decoding: caseSensitivity [2] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("SortKeySpec: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 2 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("SortKeySpec: bad tag in s_caseSensitivity\n"); + } + + s_caseSensitivity = new ASN1Integer(p, false); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_missingValueAction = null; + + // Decoding: missingValueAction [3] EXPLICIT SortKeySpec_missingValueAction OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 3 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException("SortKeySpec: bad BER encoding: s_missingValueAction tag bad"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException("SortKeySpec: bad BER encoding: s_missingValueAction tag bad"); + } + + s_missingValueAction = new SortKeySpecMissingValueAction(tagged.elementAt(0), true); + part++; + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("SortKeySpec: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the SortKeySpec. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of SortKeySpec, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 3; // number of mandatories + if (s_missingValueAction != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + fields[x++] = s_sortElement.berEncode(); + fields[x++] = s_sortRelation.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + fields[x++] = s_caseSensitivity.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + if (s_missingValueAction != null) { + enc = new BEREncoding[1]; + enc[0] = s_missingValueAction.berEncode(); + fields[x] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 3, enc); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the SortKeySpec. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + str.append("sortElement "); + str.append(s_sortElement); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("sortRelation "); + str.append(s_sortRelation); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("caseSensitivity "); + str.append(s_caseSensitivity); + outputted++; + + if (s_missingValueAction != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("missingValueAction "); + str.append(s_missingValueAction); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySpecMissingValueAction.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySpecMissingValueAction.java new file mode 100644 index 0000000..7bf2109 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortKeySpecMissingValueAction.java @@ -0,0 +1,192 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Null; +import org.xbib.asn1.ASN1OctetString; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a SortKeySpec_missingValueAction from Z39-50-APDU-1995. + *
+ * SortKeySpec_missingValueAction ::=
+ * CHOICE {
+ *   abort [1] IMPLICIT NULL
+ *   null [2] IMPLICIT NULL
+ *   missingValueData [3] IMPLICIT OCTET STRING
+ * }
+ * 
+ */ +public final class SortKeySpecMissingValueAction extends ASN1Any { + + public ASN1Null c_abort; + public ASN1Null c_null; + public ASN1OctetString c_missingValueData; + + + /** + * Constructor for a SortKeySpec_missingValueAction from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public SortKeySpecMissingValueAction(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Null out all choices + + c_abort = null; + c_null = null; + c_missingValueData = null; + + // Try choice abort + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_abort = new ASN1Null(ber, false); + return; + } + + // Try choice null + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_null = new ASN1Null(ber, false); + return; + } + + // Try choice missingValueData + if (ber.tagGet() == 3 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_missingValueData = new ASN1OctetString(ber, false); + return; + } + + throw new ASN1Exception("SortKeySpec_missingValueAction: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of SortKeySpec_missingValueAction. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + // Encoding choice: c_abort + if (c_abort != null) { + chosen = c_abort.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding choice: c_null + if (c_null != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_null.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + } + + // Encoding choice: c_missingValueData + if (c_missingValueData != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_missingValueData.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 3); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("SortKeySpec_missingValueAction: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the SortKeySpec_missingValueAction. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (c_abort != null) { + found = true; + str.append("abort "); + str.append(c_abort); + } + + if (c_null != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("null "); + str.append(c_null); + } + + if (c_missingValueData != null) { + if (found) { + str.append(" "); + } + str.append("missingValueData "); + str.append(c_missingValueData); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/SortRequest.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortRequest.java new file mode 100644 index 0000000..f9a78e0 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortRequest.java @@ -0,0 +1,300 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a SortRequest from Z39-50-APDU-1995. + *
+ * SortRequest ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   inputResultSetNames [3] IMPLICIT SEQUENCE OF InternationalString
+ *   sortedResultSetName [4] IMPLICIT InternationalString
+ *   sortSequence [5] IMPLICIT SEQUENCE OF SortKeySpec
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class SortRequest extends ASN1Any { + public ReferenceId s_referenceId; // optional + public InternationalString s_inputResultSetNames[]; + public InternationalString s_sortedResultSetName; + public SortKeySpec s_sortSequence[]; + public OtherInformation s_otherInfo; // optional + + /** + * Constructor for a SortRequest from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + public SortRequest(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // SortRequest should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("SortRequest: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("SortRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: inputResultSetNames [3] IMPLICIT SEQUENCE OF InternationalString + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("SortRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 3 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("SortRequest: bad tag in s_inputResultSetNames\n"); + } + + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + s_inputResultSetNames = new InternationalString[parts]; + int n; + for (n = 0; n < parts; n++) { + s_inputResultSetNames[n] = new InternationalString(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + + // Decoding: sortedResultSetName [4] IMPLICIT InternationalString + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("SortRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 4 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("SortRequest: bad tag in s_sortedResultSetName\n"); + } + + s_sortedResultSetName = new InternationalString(p, false); + part++; + + // Decoding: sortSequence [5] IMPLICIT SEQUENCE OF SortKeySpec + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("SortRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 5 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("SortRequest: bad tag in s_sortSequence\n"); + } + + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + s_sortSequence = new SortKeySpec[parts]; + int n; + for (n = 0; n < parts; n++) { + s_sortSequence[n] = new SortKeySpec(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_otherInfo = null; + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("SortRequest: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the SortRequest. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of SortRequest, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 3; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + f2 = new BEREncoding[s_inputResultSetNames.length]; + for (p = 0; p < s_inputResultSetNames.length; p++) { + f2[p] = s_inputResultSetNames[p].berEncode(); + } + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 3, f2); + fields[x++] = s_sortedResultSetName.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 4); + f2 = new BEREncoding[s_sortSequence.length]; + for (p = 0; p < s_sortSequence.length; p++) { + f2[p] = s_sortSequence[p].berEncode(); + } + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 5, f2); + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the SortRequest. + */ + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("inputResultSetNames "); + str.append("{"); + for (p = 0; p < s_inputResultSetNames.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(s_inputResultSetNames[p]); + } + str.append("}"); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("sortedResultSetName "); + str.append(s_sortedResultSetName); + outputted++; + + if (0 < outputted) { + str.append(", "); + } + str.append("sortSequence "); + str.append("{"); + for (p = 0; p < s_sortSequence.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(s_sortSequence[p]); + } + str.append("}"); + outputted++; + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/SortResponse.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortResponse.java new file mode 100644 index 0000000..8298c8d --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/SortResponse.java @@ -0,0 +1,278 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a SortResponse from Z39-50-APDU-1995. + *
+ * SortResponse ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   sortStatus [3] IMPLICIT INTEGER
+ *   resultSetStatus [4] IMPLICIT INTEGER OPTIONAL
+ *   diagnostics [5] IMPLICIT SEQUENCE OF DiagRec OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class SortResponse extends ASN1Any { + + public static final int E_success = 0; + public static final int E_partial_1 = 1; + public static final int E_failure = 2; + public static final int E_empty = 1; + public static final int E_interim = 2; + public static final int E_unchanged = 3; + public static final int E_none = 4; + public ReferenceId s_referenceId; // optional + public ASN1Integer s_sortStatus; + public ASN1Integer s_resultSetStatus; // optional + public DiagRec s_diagnostics[]; // optional + public OtherInformation s_otherInfo; // optional + /** + * Constructor for a SortResponse from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public SortResponse(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // SortResponse should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("SortResponse: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("SortResponse: incomplete"); + } + p = berConstructed.elementAt(part); + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("SortResponse: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 3 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException + ("SortResponse: bad tag in s_sortStatus\n"); + } + + s_sortStatus = new ASN1Integer(p, false); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_resultSetStatus = null; + s_diagnostics = null; + s_otherInfo = null; + + // Decoding: resultSetStatus [4] IMPLICIT INTEGER OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 4 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_resultSetStatus = new ASN1Integer(p, false); + part++; + } + + // Decoding: diagnostics [5] IMPLICIT SEQUENCE OF DiagRec OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 5 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + s_diagnostics = new DiagRec[parts]; + int n; + for (n = 0; n < parts; n++) { + s_diagnostics[n] = new DiagRec(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("SortResponse: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the SortResponse. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of SortResponse, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + int numFields = 1; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_resultSetStatus != null) { + numFields++; + } + if (s_diagnostics != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + fields[x++] = s_sortStatus.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 3); + if (s_resultSetStatus != null) { + fields[x++] = s_resultSetStatus.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 4); + } + if (s_diagnostics != null) { + f2 = new BEREncoding[s_diagnostics.length]; + for (p = 0; p < s_diagnostics.length; p++) { + f2[p] = s_diagnostics[p].berEncode(); + } + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 5, f2); + } + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the SortResponse. + */ + public String toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + if (0 < outputted) { + str.append(", "); + } + str.append("sortStatus "); + str.append(s_sortStatus); + outputted++; + if (s_resultSetStatus != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("resultSetStatus "); + str.append(s_resultSetStatus); + outputted++; + } + if (s_diagnostics != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("diagnostics "); + str.append("{"); + for (p = 0; p < s_diagnostics.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(s_diagnostics[p]); + } + str.append("}"); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Specification.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Specification.java new file mode 100644 index 0000000..1d54fb6 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Specification.java @@ -0,0 +1,204 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a Specification from Z39-50-APDU-1995. + *
+ * Specification ::=
+ * SEQUENCE {
+ *   schema [1] IMPLICIT OBJECT IDENTIFIER OPTIONAL
+ *   elementSpec [2] EXPLICIT Specification_elementSpec OPTIONAL
+ * }
+ * 
+ */ +public final class Specification extends ASN1Any { + + public ASN1ObjectIdentifier s_schema; // optional + public SpecificationElementSpec s_elementSpec; // optional + + + /** + * Constructor for a Specification from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Specification(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Specification should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Specification: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_schema = null; + s_elementSpec = null; + + // Decoding: schema [1] IMPLICIT OBJECT IDENTIFIER OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 1 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_schema = new ASN1ObjectIdentifier(p, false); + part++; + } + + // Decoding: elementSpec [2] EXPLICIT Specification_elementSpec OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 2 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException("Specification: bad BER encoding: s_elementSpec tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException("Specification: bad BER encoding: s_elementSpec tag bad\n"); + } + + s_elementSpec = new SpecificationElementSpec(tagged.elementAt(0), true); + part++; + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("Specification: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the Specification. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of Specification, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 0; // number of mandatories + if (s_schema != null) { + numFields++; + } + if (s_elementSpec != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + + // Encoding s_schema: OBJECT IDENTIFIER OPTIONAL + + if (s_schema != null) { + fields[x++] = s_schema.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding s_elementSpec: Specification_elementSpec OPTIONAL + + if (s_elementSpec != null) { + enc = new BEREncoding[1]; + enc[0] = s_elementSpec.berEncode(); + fields[x] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 2, enc); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the Specification. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + if (s_schema != null) { + str.append("schema "); + str.append(s_schema); + outputted++; + } + + if (s_elementSpec != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("elementSpec "); + str.append(s_elementSpec); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/SpecificationElementSpec.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/SpecificationElementSpec.java new file mode 100644 index 0000000..b5ca142 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/SpecificationElementSpec.java @@ -0,0 +1,159 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a Specification_elementSpec from Z39-50-APDU-1995. + *
+ * Specification_elementSpec ::=
+ * CHOICE {
+ *   elementSetName [1] IMPLICIT InternationalString
+ *   externalEspec [2] IMPLICIT EXTERNAL
+ * }
+ * 
+ */ +public final class SpecificationElementSpec extends ASN1Any { + public InternationalString c_elementSetName; + public ASN1External c_externalEspec; + + + /** + * Constructor for a Specification_elementSpec from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public SpecificationElementSpec(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Null out all choices + + c_elementSetName = null; + c_externalEspec = null; + + // Try choice elementSetName + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_elementSetName = new InternationalString(ber, false); + return; + } + + // Try choice externalEspec + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_externalEspec = new ASN1External(ber, false); + return; + } + + throw new ASN1Exception("Specification_elementSpec: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of Specification_elementSpec. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + BEREncoding chosen = null; + + // Encoding choice: c_elementSetName + if (c_elementSetName != null) { + chosen = c_elementSetName.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding choice: c_externalEspec + if (c_externalEspec != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_externalEspec.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("Specification_elementSpec: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the Specification_elementSpec. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (c_elementSetName != null) { + found = true; + str.append("elementSetName "); + str.append(c_elementSetName); + } + if (c_externalEspec != null) { + if (found) { + str.append(" "); + } + str.append("externalEspec "); + str.append(c_externalEspec); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/StringOrNumeric.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/StringOrNumeric.java new file mode 100644 index 0000000..8eb4a37 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/StringOrNumeric.java @@ -0,0 +1,156 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.BEREncoding; + + +/** + * Class for representing a StringOrNumeric from Z39-50-APDU-1995. + *
+ * StringOrNumeric ::=
+ * CHOICE {
+ *   string [1] IMPLICIT InternationalString
+ *   numeric [2] IMPLICIT INTEGER
+ * }
+ * 
+ */ +public final class StringOrNumeric extends ASN1Any { + public InternationalString c_string; + public ASN1Integer c_numeric; + + + /** + * Constructor for a StringOrNumeric from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public StringOrNumeric(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // Null out all choices + + c_string = null; + c_numeric = null; + + // Try choice string + if (ber.tagGet() == 1 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_string = new InternationalString(ber, false); + return; + } + + // Try choice numeric + if (ber.tagGet() == 2 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_numeric = new ASN1Integer(ber, false); + return; + } + + throw new ASN1Exception("StringOrNumeric: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of StringOrNumeric. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + + // Encoding choice: c_string + if (c_string != null) { + chosen = c_string.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 1); + } + + // Encoding choice: c_numeric + if (c_numeric != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_numeric.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("StringOrNumeric: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the StringOrNumeric. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + boolean found = false; + if (c_string != null) { + found = true; + str.append("string "); + str.append(c_string); + } + if (c_numeric != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("numeric "); + str.append(c_numeric); + } + + str.append("}"); + + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Term.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Term.java new file mode 100644 index 0000000..b1d2775 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Term.java @@ -0,0 +1,329 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1External; +import org.xbib.asn1.ASN1GeneralizedTime; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Null; +import org.xbib.asn1.ASN1ObjectIdentifier; +import org.xbib.asn1.ASN1OctetString; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a Term from Z39-50-APDU-1995. + *
+ * Term ::=
+ * CHOICE {
+ *   general [45] IMPLICIT OCTET STRING
+ *   numeric [215] IMPLICIT INTEGER
+ *   characterString [216] IMPLICIT InternationalString
+ *   oid [217] IMPLICIT OBJECT IDENTIFIER
+ *   dateTime [218] IMPLICIT GeneralizedTime
+ *   external [219] IMPLICIT EXTERNAL
+ *   integerAndUnit [220] IMPLICIT IntUnit
+ *   null [221] IMPLICIT NULL
+ * }
+ * 
+ */ +public final class Term extends ASN1Any { + + public ASN1OctetString c_general; + public ASN1Integer c_numeric; + public InternationalString c_characterString; + public ASN1ObjectIdentifier c_oid; + public ASN1GeneralizedTime c_dateTime; + public ASN1External c_external; + public IntUnit c_integerAndUnit; + public ASN1Null c_null; + public Term() { + } + /** + * Constructor for a Term from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Term(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // Null out all choices + + c_general = null; + c_numeric = null; + c_characterString = null; + c_oid = null; + c_dateTime = null; + c_external = null; + c_integerAndUnit = null; + c_null = null; + + // Try choice general + if (ber.tagGet() == 45 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_general = new ASN1OctetString(ber, false); + return; + } + + // Try choice numeric + if (ber.tagGet() == 215 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_numeric = new ASN1Integer(ber, false); + return; + } + + // Try choice characterString + if (ber.tagGet() == 216 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_characterString = new InternationalString(ber, false); + return; + } + + // Try choice oid + if (ber.tagGet() == 217 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_oid = new ASN1ObjectIdentifier(ber, false); + return; + } + + // Try choice dateTime + if (ber.tagGet() == 218 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_dateTime = new ASN1GeneralizedTime(ber, false); + return; + } + + // Try choice external + if (ber.tagGet() == 219 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_external = new ASN1External(ber, false); + return; + } + + // Try choice integerAndUnit + if (ber.tagGet() == 220 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_integerAndUnit = new IntUnit(ber, false); + return; + } + if (ber.tagGet() == 221 && + ber.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + c_null = new ASN1Null(ber, false); + return; + } + throw new ASN1Exception("Term: bad BER encoding: choice not matched"); + } + + /** + * Returns a BER encoding of Term. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + BEREncoding chosen = null; + + // Encoding choice: c_general + if (c_general != null) { + chosen = c_general.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 45); + } + + // Encoding choice: c_numeric + if (c_numeric != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_numeric.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 215); + } + + // Encoding choice: c_characterString + if (c_characterString != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_characterString.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 216); + } + + // Encoding choice: c_oid + if (c_oid != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_oid.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 217); + } + + // Encoding choice: c_dateTime + if (c_dateTime != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_dateTime.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 218); + } + + // Encoding choice: c_external + if (c_external != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_external.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 219); + } + + // Encoding choice: c_integerAndUnit + if (c_integerAndUnit != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_integerAndUnit.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 220); + } + + // Encoding choice: c_null + if (c_null != null) { + if (chosen != null) { + throw new ASN1Exception("CHOICE multiply set"); + } + chosen = c_null.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 221); + } + + // Check for error of having none of the choices set + if (chosen == null) { + throw new ASN1Exception("CHOICE not set"); + } + + return chosen; + } + + /** + * Generating a BER encoding of the object + * and implicitly tagging it. + * This method is for internal use only. You should use + * the berEncode method that does not take a parameter. + * This function should never be used, because this + * production is a CHOICE. + * It must never have an implicit tag. + * An exception will be thrown if it is called. + * + * @param tagType the type of the tag. + * @param tag the tag. + * @throws ASN1Exception if it cannot be BER encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // This method must not be called! + + // Method is not available because this is a basic CHOICE + // which does not have an explicit tag on it. So it is not + // permitted to allow something else to apply an implicit + // tag on it, otherwise the tag identifying which CHOICE + // it is will be overwritten and lost. + + throw new ASN1EncodingException("Term: cannot implicitly tag"); + } + + /** + * Returns a new String object containing a text representing + * of the Term. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + + boolean found = false; + + if (c_general != null) { + found = true; + str.append("general "); + str.append(c_general); + } + + if (c_numeric != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("numeric "); + str.append(c_numeric); + } + + if (c_characterString != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("characterString "); + str.append(c_characterString); + } + + if (c_oid != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("oid "); + str.append(c_oid); + } + + if (c_dateTime != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("dateTime "); + str.append(c_dateTime); + } + + if (c_external != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("external "); + str.append(c_external); + } + + if (c_integerAndUnit != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("integerAndUnit "); + str.append(c_integerAndUnit); + } + + if (c_null != null) { + if (found) { + str.append(" "); + } + found = true; + str.append("null "); + str.append(c_null); + } + + str.append("}"); + + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/TermInfo.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/TermInfo.java new file mode 100644 index 0000000..d5628e4 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/TermInfo.java @@ -0,0 +1,386 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a TermInfo from Z39-50-APDU-1995. + *
+ * TermInfo ::=
+ * SEQUENCE {
+ *   term Term
+ *   displayTerm [0] IMPLICIT InternationalString OPTIONAL
+ *   suggestedAttributes AttributeList OPTIONAL
+ *   alternativeTerm [4] IMPLICIT SEQUENCE OF AttributesPlusTerm OPTIONAL
+ *   globalOccurrences [2] IMPLICIT INTEGER OPTIONAL
+ *   byAttributes [3] IMPLICIT OccurrenceByAttributes OPTIONAL
+ *   otherTermInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ + +public final class TermInfo extends ASN1Any { + + public Term s_term; + public InternationalString s_displayTerm; // optional + public AttributeList s_suggestedAttributes; // optional + public AttributesPlusTerm s_alternativeTerm[]; // optional + public ASN1Integer s_globalOccurrences; // optional + public OccurrenceByAttributes s_byAttributes; // optional + public OtherInformation s_otherTermInfo; // optional + /** + * Default constructor for a TermInfo. + */ + + public TermInfo() { + } + /** + * Constructor for a TermInfo from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public TermInfo(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public void + berDecode(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + // TermInfo should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("TermInfo: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: term Term + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("TermInfo: incomplete"); + } + p = berConstructed.elementAt(part); + + s_term = new Term(p, true); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_displayTerm = null; + s_suggestedAttributes = null; + s_alternativeTerm = null; + s_globalOccurrences = null; + s_byAttributes = null; + s_otherTermInfo = null; + + // Decoding: displayTerm [0] IMPLICIT InternationalString OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 0 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_displayTerm = new InternationalString(p, false); + part++; + } + + // Decoding: suggestedAttributes AttributeList OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_suggestedAttributes = new AttributeList(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_suggestedAttributes = null; // no, not present + } + + // Decoding: alternativeTerm [4] IMPLICIT SEQUENCE OF AttributesPlusTerm OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 4 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + BERConstructed cons = (BERConstructed) p; + int parts = cons.numberComponents(); + s_alternativeTerm = new AttributesPlusTerm[parts]; + int n; + for (n = 0; n < parts; n++) { + s_alternativeTerm[n] = new AttributesPlusTerm(cons.elementAt(n), true); + } + } catch (ClassCastException e) { + throw new ASN1EncodingException("Bad BER"); + } + part++; + } + + // Decoding: globalOccurrences [2] IMPLICIT INTEGER OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 2 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_globalOccurrences = new ASN1Integer(p, false); + part++; + } + + // Decoding: byAttributes [3] IMPLICIT OccurrenceByAttributes OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 3 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_byAttributes = new OccurrenceByAttributes(p, false); + part++; + } + + // Decoding: otherTermInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherTermInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherTermInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("TermInfo: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the TermInfo. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of TermInfo, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 1; // number of mandatories + if (s_displayTerm != null) { + numFields++; + } + if (s_suggestedAttributes != null) { + numFields++; + } + if (s_alternativeTerm != null) { + numFields++; + } + if (s_globalOccurrences != null) { + numFields++; + } + if (s_byAttributes != null) { + numFields++; + } + if (s_otherTermInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding f2[]; + int p; + + // Encoding s_term: Term + + fields[x++] = s_term.berEncode(); + + // Encoding s_displayTerm: InternationalString OPTIONAL + + if (s_displayTerm != null) { + fields[x++] = s_displayTerm.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 0); + } + + // Encoding s_suggestedAttributes: AttributeList OPTIONAL + + if (s_suggestedAttributes != null) { + fields[x++] = s_suggestedAttributes.berEncode(); + } + + // Encoding s_alternativeTerm: SEQUENCE OF OPTIONAL + + if (s_alternativeTerm != null) { + f2 = new BEREncoding[s_alternativeTerm.length]; + + for (p = 0; p < s_alternativeTerm.length; p++) { + f2[p] = s_alternativeTerm[p].berEncode(); + } + + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 4, f2); + } + + // Encoding s_globalOccurrences: INTEGER OPTIONAL + + if (s_globalOccurrences != null) { + fields[x++] = s_globalOccurrences.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 2); + } + + // Encoding s_byAttributes: OccurrenceByAttributes OPTIONAL + + if (s_byAttributes != null) { + fields[x++] = s_byAttributes.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 3); + } + + // Encoding s_otherTermInfo: OtherInformation OPTIONAL + + if (s_otherTermInfo != null) { + fields[x] = s_otherTermInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the TermInfo. + */ + + public String + toString() { + int p; + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + str.append("term "); + str.append(s_term); + outputted++; + + if (s_displayTerm != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("displayTerm "); + str.append(s_displayTerm); + outputted++; + } + + if (s_suggestedAttributes != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("suggestedAttributes "); + str.append(s_suggestedAttributes); + outputted++; + } + + if (s_alternativeTerm != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("alternativeTerm "); + str.append("{"); + for (p = 0; p < s_alternativeTerm.length; p++) { + if (p != 0) { + str.append(", "); + } + str.append(s_alternativeTerm[p]); + } + str.append("}"); + outputted++; + } + + if (s_globalOccurrences != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("globalOccurrences "); + str.append(s_globalOccurrences); + outputted++; + } + + if (s_byAttributes != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("byAttributes "); + str.append(s_byAttributes); + outputted++; + } + + if (s_otherTermInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherTermInfo "); + str.append(s_otherTermInfo); + } + + str.append("}"); + + return str.toString(); + } + +} \ No newline at end of file diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/TriggerResourceControlRequest.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/TriggerResourceControlRequest.java new file mode 100644 index 0000000..69e1924 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/TriggerResourceControlRequest.java @@ -0,0 +1,285 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1Boolean; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a TriggerResourceControlRequest from Z39-50-APDU-1995. + *
+ * TriggerResourceControlRequest ::=
+ * SEQUENCE {
+ *   referenceId ReferenceId OPTIONAL
+ *   requestedAction [46] IMPLICIT INTEGER
+ *   prefResourceReportFormat [47] IMPLICIT ResourceReportId OPTIONAL
+ *   resultSetWanted [48] IMPLICIT BOOLEAN OPTIONAL
+ *   otherInfo OtherInformation OPTIONAL
+ * }
+ * 
+ */ +public final class TriggerResourceControlRequest extends ASN1Any { + + // Enumerated constants for requestedAction + public static final int E_resourceReport = 1; + public static final int E_resourceControl = 2; + public static final int E_cancel = 3; + public ReferenceId s_referenceId; // optional + public ASN1Integer s_requestedAction; + public ResourceReportId s_prefResourceReportFormat; // optional + public ASN1Boolean s_resultSetWanted; // optional + public OtherInformation s_otherInfo; // optional + /** + * Constructor for a TriggerResourceControlRequest from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public TriggerResourceControlRequest(BEREncoding ber, boolean checkTag) + throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + // TriggerResourceControlRequest should be encoded by a constructed BER + + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("TriggerResourceControlRequest: bad BER form\n"); + } + + // Prepare to decode the components + + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + + // Decoding: referenceId ReferenceId OPTIONAL + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("TriggerResourceControlRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + try { + s_referenceId = new ReferenceId(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_referenceId = null; // no, not present + } + + // Decoding: requestedAction [46] IMPLICIT INTEGER + + if (numParts <= part) { + // End of record, but still more elements to get + throw new ASN1Exception("TriggerResourceControlRequest: incomplete"); + } + p = berConstructed.elementAt(part); + + if (p.tagGet() != 46 || + p.tagTypeGet() != BEREncoding.CONTEXT_SPECIFIC_TAG) { + throw new ASN1EncodingException("TriggerResourceControlRequest: bad tag in s_requestedAction\n"); + } + + s_requestedAction = new ASN1Integer(p, false); + part++; + + // Remaining elements are optional, set variables + // to null (not present) so can return at endStream of BER + + s_prefResourceReportFormat = null; + s_resultSetWanted = null; + s_otherInfo = null; + + // Decoding: prefResourceReportFormat [47] IMPLICIT ResourceReportId OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 47 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_prefResourceReportFormat = new ResourceReportId(p, false); + part++; + } + + // Decoding: resultSetWanted [48] IMPLICIT BOOLEAN OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 48 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_resultSetWanted = new ASN1Boolean(p, false); + part++; + } + + // Decoding: otherInfo OtherInformation OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + try { + s_otherInfo = new OtherInformation(p, true); + part++; // yes, consumed + } catch (ASN1Exception e) { + s_otherInfo = null; // no, not present + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("TriggerResourceControlRequest: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the TriggerResourceControlRequest. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + public BEREncoding berEncode() throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of TriggerResourceControlRequest, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + public BEREncoding berEncode(int tagType, int tag) throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 1; // number of mandatories + if (s_referenceId != null) { + numFields++; + } + if (s_prefResourceReportFormat != null) { + numFields++; + } + if (s_resultSetWanted != null) { + numFields++; + } + if (s_otherInfo != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + + // Encoding s_referenceId: ReferenceId OPTIONAL + + if (s_referenceId != null) { + fields[x++] = s_referenceId.berEncode(); + } + + // Encoding s_requestedAction: INTEGER + + fields[x++] = s_requestedAction.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 46); + + // Encoding s_prefResourceReportFormat: ResourceReportId OPTIONAL + + if (s_prefResourceReportFormat != null) { + fields[x++] = s_prefResourceReportFormat.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 47); + } + + // Encoding s_resultSetWanted: BOOLEAN OPTIONAL + + if (s_resultSetWanted != null) { + fields[x++] = s_resultSetWanted.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 48); + } + + // Encoding s_otherInfo: OtherInformation OPTIONAL + + if (s_otherInfo != null) { + fields[x] = s_otherInfo.berEncode(); + } + + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the TriggerResourceControlRequest. + */ + + public String + toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_referenceId != null) { + str.append("referenceId "); + str.append(s_referenceId); + outputted++; + } + + if (0 < outputted) { + str.append(", "); + } + str.append("requestedAction "); + str.append(s_requestedAction); + outputted++; + + if (s_prefResourceReportFormat != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("prefResourceReportFormat "); + str.append(s_prefResourceReportFormat); + outputted++; + } + + if (s_resultSetWanted != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("resultSetWanted "); + str.append(s_resultSetWanted); + outputted++; + } + + if (s_otherInfo != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("otherInfo "); + str.append(s_otherInfo); + } + + str.append("}"); + + return str.toString(); + } +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/Unit.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/Unit.java new file mode 100644 index 0000000..79f54f5 --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/Unit.java @@ -0,0 +1,278 @@ +package org.xbib.io.iso23950.v3; + +import org.xbib.asn1.ASN1Any; +import org.xbib.asn1.ASN1EncodingException; +import org.xbib.asn1.ASN1Exception; +import org.xbib.asn1.ASN1Integer; +import org.xbib.asn1.ASN1Sequence; +import org.xbib.asn1.BERConstructed; +import org.xbib.asn1.BEREncoding; + +/** + * Class for representing a Unit from Z39-50-APDU-1995. + *
+ * Unit ::=
+ * SEQUENCE {
+ *   unitSystem [1] EXPLICIT InternationalString OPTIONAL
+ *   unitType [2] EXPLICIT StringOrNumeric OPTIONAL
+ *   unit [3] EXPLICIT StringOrNumeric OPTIONAL
+ *   scaleFactor [4] IMPLICIT INTEGER OPTIONAL
+ * }
+ * 
+ */ +public final class Unit extends ASN1Any { + public InternationalString s_unitSystem; // optional + public StringOrNumeric s_unitType; // optional + public StringOrNumeric s_unit; // optional + public ASN1Integer s_scaleFactor; // optional + + /** + * Constructor for a Unit from a BER encoding. + * + * @param ber the BER encoding. + * @param checkTag will check tag if true, use false + * if the BER has been implicitly tagged. You should + * usually be passing true. + * @throws ASN1Exception if the BER encoding is bad. + */ + + public Unit(BEREncoding ber, boolean checkTag) throws ASN1Exception { + super(ber, checkTag); + } + + /** + * Initializing object from a BER encoding. + * This method is for internal use only. You should use + * the constructor that takes a BEREncoding. + * + * @param ber the BER to decode. + * @param checkTag if the tag should be checked. + * @throws ASN1Exception if the BER encoding is bad. + */ + public void berDecode(BEREncoding ber, boolean checkTag) throws ASN1Exception { + BERConstructed berConstructed; + try { + berConstructed = (BERConstructed) ber; + } catch (ClassCastException e) { + throw new ASN1EncodingException("Unit: bad BER form\n"); + } + int numParts = berConstructed.numberComponents(); + int part = 0; + BEREncoding p; + BERConstructed tagged; + s_unitSystem = null; + s_unitType = null; + s_unit = null; + s_scaleFactor = null; + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + if (p.tagGet() == 1 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Unit: bad BER encoding: s_unitSystem tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException + ("Unit: bad BER encoding: s_unitSystem tag bad\n"); + } + + s_unitSystem = new InternationalString(tagged.elementAt(0), true); + part++; + } + + // Decoding: unitType [2] EXPLICIT StringOrNumeric OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 2 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Unit: bad BER encoding: s_unitType tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException + ("Unit: bad BER encoding: s_unitType tag bad\n"); + } + + s_unitType = new StringOrNumeric(tagged.elementAt(0), true); + part++; + } + + // Decoding: unit [3] EXPLICIT StringOrNumeric OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 3 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + try { + tagged = (BERConstructed) p; + } catch (ClassCastException e) { + throw new ASN1EncodingException + ("Unit: bad BER encoding: s_unit tag bad\n"); + } + if (tagged.numberComponents() != 1) { + throw new ASN1EncodingException + ("Unit: bad BER encoding: s_unit tag bad\n"); + } + + s_unit = new StringOrNumeric(tagged.elementAt(0), true); + part++; + } + + // Decoding: scaleFactor [4] IMPLICIT INTEGER OPTIONAL + + if (numParts <= part) { + return; // no more data, but ok (rest is optional) + } + p = berConstructed.elementAt(part); + + if (p.tagGet() == 4 && + p.tagTypeGet() == BEREncoding.CONTEXT_SPECIFIC_TAG) { + s_scaleFactor = new ASN1Integer(p, false); + part++; + } + + // Should not be any more parts + + if (part < numParts) { + throw new ASN1Exception("Unit: bad BER: extra data " + part + "/" + numParts + " processed"); + } + } + + /** + * Returns a BER encoding of the Unit. + * + * @return The BER encoding. + * @throws ASN1Exception Invalid or cannot be encoded. + */ + + public BEREncoding + berEncode() + throws ASN1Exception { + return berEncode(BEREncoding.UNIVERSAL_TAG, ASN1Sequence.SEQUENCE_TAG); + } + + /** + * Returns a BER encoding of Unit, implicitly tagged. + * + * @param tagType The type of the implicit tag. + * @param tag The implicit tag. + * @return The BER encoding of the object. + * @throws ASN1Exception When invalid or cannot be encoded. + */ + + public BEREncoding + berEncode(int tagType, int tag) + throws ASN1Exception { + // Calculate the number of fields in the encoding + + int numFields = 0; // number of mandatories + if (s_unitSystem != null) { + numFields++; + } + if (s_unitType != null) { + numFields++; + } + if (s_unit != null) { + numFields++; + } + if (s_scaleFactor != null) { + numFields++; + } + + // Encode it + + BEREncoding fields[] = new BEREncoding[numFields]; + int x = 0; + BEREncoding enc[]; + + // Encoding s_unitSystem: InternationalString OPTIONAL + + if (s_unitSystem != null) { + enc = new BEREncoding[1]; + enc[0] = s_unitSystem.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 1, enc); + } + + // Encoding s_unitType: StringOrNumeric OPTIONAL + + if (s_unitType != null) { + enc = new BEREncoding[1]; + enc[0] = s_unitType.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 2, enc); + } + + // Encoding s_unit: StringOrNumeric OPTIONAL + + if (s_unit != null) { + enc = new BEREncoding[1]; + enc[0] = s_unit.berEncode(); + fields[x++] = new BERConstructed(BEREncoding.CONTEXT_SPECIFIC_TAG, 3, enc); + } + + // Encoding s_scaleFactor: INTEGER OPTIONAL + + if (s_scaleFactor != null) { + fields[x] = s_scaleFactor.berEncode(BEREncoding.CONTEXT_SPECIFIC_TAG, 4); + } + return new BERConstructed(tagType, tag, fields); + } + + /** + * Returns a new String object containing a text representing + * of the Unit. + */ + public String toString() { + StringBuilder str = new StringBuilder("{"); + int outputted = 0; + + if (s_unitSystem != null) { + str.append("unitSystem "); + str.append(s_unitSystem); + outputted++; + } + + if (s_unitType != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("unitType "); + str.append(s_unitType); + outputted++; + } + + if (s_unit != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("unit "); + str.append(s_unit); + outputted++; + } + + if (s_scaleFactor != null) { + if (0 < outputted) { + str.append(", "); + } + str.append("scaleFactor "); + str.append(s_scaleFactor); + } + str.append("}"); + return str.toString(); + } + +} diff --git a/z3950/src/main/java/org/xbib/io/iso23950/v3/package-info.java b/z3950/src/main/java/org/xbib/io/iso23950/v3/package-info.java new file mode 100644 index 0000000..4e64c6a --- /dev/null +++ b/z3950/src/main/java/org/xbib/io/iso23950/v3/package-info.java @@ -0,0 +1,4 @@ +/** + * + */ +package org.xbib.io.iso23950.v3; diff --git a/z3950/src/main/jflex/org/xbib/io/iso23950/pqf/PQF.jflex b/z3950/src/main/jflex/org/xbib/io/iso23950/pqf/PQF.jflex new file mode 100755 index 0000000..5f14a1a --- /dev/null +++ b/z3950/src/main/jflex/org/xbib/io/iso23950/pqf/PQF.jflex @@ -0,0 +1,172 @@ +package org.xbib.io.iso23950.pqf; + +import java.io.*; + +%% +%class PQFLexer +%implements PQFTokens +%unicode +%integer +%eofval{ + return 0; +%eofval} +%line +%column + +%{ + private Object yylval; + private int token; + private StringBuilder sb = new StringBuilder(); + + public int getToken() { + return token; + } + + public int nextToken() { + try { + token = yylex(); + return token; + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + + public Object getSemantic() { + return yylval; + } + + public int getLine() { + return yyline; + } + + public int getColumn() { + return yycolumn; + } + +%} +NL = \n | \r | \r\n +AND = "@and" +OR = "@or" +NOT = "@not" +ATTR = "@attr" +ATTRSET = "@attrset" +TERM = "@term" +SET = "@set" +VOID = "void" +KNOWN = "known" +PRIVATE = "private" +CHARSTRING1 = [^ .\t\"()=<>\\]+ +CHARSTRING2 = [^\"] +INTEGER = [0-9]+ +EQUALS = "=" +OPERATORS = "=" | ">" | "<" | ">=" | "<=" | "<>" +TERMTYPE = "general" | "numeric" | "string" | "oid" | "datetime" | "null" + +%state STRING2 + +%% + +\" { + yybegin(STRING2); + sb.setLength(0); + } + + { + +\\\" { + sb.append("\""); + } +{CHARSTRING2} { + sb.append(yytext()); + } +\" { + yybegin(YYINITIAL); + yylval = sb.toString(); + return CHARSTRING2; + } +} + +{NL} { + return NL; + } + +" "|\t { + } + +{EQUALS} { + yylval = yytext(); + return EQUALS; + } + +{OPERATORS} { + yylval = yytext(); + return OPERATORS; + } + +{INTEGER} { + yylval = Integer.parseInt(yytext()); + return INTEGER; + } + +{AND} { + yylval = yytext(); + return AND; + } + +{OR} { + yylval = yytext(); + return OR; + } + +{NOT} { + yylval = yytext(); + return NOT; + } + +{ATTR} { + yylval = yytext(); + return ATTR; + } + +{ATTRSET} { + yylval = yytext(); + return ATTRSET; + } + +{TERM} { + yylval = yytext(); + return TERM; + } + +{SET} { + yylval = yytext(); + return SET; + } + +{VOID} { + yylval = yytext(); + return VOID; + } + +{KNOWN} { + yylval = yytext(); + return KNOWN; + } + +{PRIVATE} { + yylval = yytext(); + return PRIVATE; + } + +{TERMTYPE} { + yylval = yytext(); + return TERMTYPE; + } + +{CHARSTRING1} { + yylval = yytext(); + return CHARSTRING1; + } + + diff --git a/z3950/src/main/resources/xsl/isodis25577-sru-response.xsl b/z3950/src/main/resources/xsl/isodis25577-sru-response.xsl new file mode 100644 index 0000000..c79f66e --- /dev/null +++ b/z3950/src/main/resources/xsl/isodis25577-sru-response.xsl @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + info:srw/schema/9/marcxchange + xml + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/z3950/src/test/java/org/xbib/io/iso23950/Bib1Test.java b/z3950/src/test/java/org/xbib/io/iso23950/Bib1Test.java new file mode 100644 index 0000000..9225d23 --- /dev/null +++ b/z3950/src/test/java/org/xbib/io/iso23950/Bib1Test.java @@ -0,0 +1,26 @@ +package org.xbib.io.iso23950; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.ResourceBundle; + +/** + * + */ +public class Bib1Test { + + @Test + public void testBibUse() { + ResourceBundle bundle = ResourceBundle.getBundle("org.xbib.io.iso23950.bib-1"); + ArrayList values = new ArrayList<>(); + for (String key : bundle.keySet()) { + values.add(bundle.getString(key) + "=" + key); + } + Collections.sort(values); + for (Object v : values) { + //logger.info(v.toString()); + } + } +} diff --git a/z3950/src/test/java/org/xbib/io/iso23950/ParserTest.java b/z3950/src/test/java/org/xbib/io/iso23950/ParserTest.java new file mode 100644 index 0000000..225bbee --- /dev/null +++ b/z3950/src/test/java/org/xbib/io/iso23950/ParserTest.java @@ -0,0 +1,39 @@ +package org.xbib.io.iso23950; + +import org.junit.Assert; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; + +/** + * + */ +public abstract class ParserTest extends Assert { + + /** + * Helper method for reading a text file with queries. + * + * @param path the path + * + * @return a string iterable + * + * @throws IOException if the text file can not be read + */ + protected Iterable readFromResource(String path) + throws IOException { + final ArrayList lines = new ArrayList<>(); + InputStream in = getClass().getClassLoader().getResourceAsStream(path); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String line; + while ((line = br.readLine()) != null) { + if (line.length() > 0) { + lines.add(line); + } + } + br.close(); + return lines; + } +} diff --git a/z3950/src/test/java/org/xbib/io/iso23950/SearchTest.java b/z3950/src/test/java/org/xbib/io/iso23950/SearchTest.java new file mode 100644 index 0000000..2038137 --- /dev/null +++ b/z3950/src/test/java/org/xbib/io/iso23950/SearchTest.java @@ -0,0 +1,42 @@ +package org.xbib.io.iso23950; + +import org.junit.Test; +import org.xbib.io.iso23950.exceptions.MessageSizeTooSmallException; +import org.xbib.io.iso23950.exceptions.NoRecordsReturnedException; + +import java.util.Collections; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + */ +public class SearchTest { + + private static final Logger logger = Logger.getLogger(SearchTest.class.getName()); + + @Test + public void testCopac() throws Exception { + String host = "z3950.copac.ac.uk"; + int port = 210; + String database = "COPAC"; + String query = "@attr 1=1 smith"; + String preferredRecordSyntax = "1.2.840.10003.5.109.10"; // xml // "1.2.840.10003.5.10"; // MARC + int from = 1; + int length = 1; + try { + ZClient client = ZClient.builder() + .setHost(host) + .setPort(port) + .setDatabases(Collections.singletonList(database)) + .setPreferredRecordSyntax(preferredRecordSyntax) + .build(); + client.executePQF(query, from, length, + (status, recordCount, elapsedMillis) -> logger.log(Level.INFO, "records = " + recordCount), + record -> logger.log(Level.INFO, "found record " + record)); + client.close(); + } catch (NoRecordsReturnedException | MessageSizeTooSmallException e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } +} diff --git a/z3950/src/test/java/org/xbib/io/iso23950/ZClientTest.java b/z3950/src/test/java/org/xbib/io/iso23950/ZClientTest.java new file mode 100644 index 0000000..326ab72 --- /dev/null +++ b/z3950/src/test/java/org/xbib/io/iso23950/ZClientTest.java @@ -0,0 +1,56 @@ +package org.xbib.io.iso23950; + +import org.junit.Test; + +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + */ +public class ZClientTest { + + private static final Logger logger = Logger.getLogger(ZClientTest.class.getName()); + + @Test + public void testCQL() { + for (String serviceName : Arrays.asList("LIBRIS", "SWB")) { + String query = "bib.identifierISSN = 00280836"; + int from = 1; + int size = 10; + try (ZClient client = ZClient.newZClient(serviceName)) { + logger.log(Level.INFO, "executing CQL " + serviceName); + int count = client.executeCQL(query, from, size, + (status, recordCount, elapsedMillis) -> + logger.log(Level.INFO, serviceName + " results = " + recordCount), + record -> + logger.log(Level.INFO, "record = " + record)); + logger.log(Level.INFO, "returned records = " + count); + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + } + + @Test + public void testPQF() { + for (String serviceName : Arrays.asList("LIBRIS", "SWB")) { + String query = "@attr 1=8 \"00280836\""; + int from = 1; + int size = 10; + try (ZClient client = ZClient.newZClient(serviceName)) { + logger.log(Level.INFO, "executing PQF " + serviceName); + int count = client.executePQF(query, from, size, + (status, recordCount, elapsedMillis) -> + logger.log(Level.INFO, serviceName + " status = " + status + " results = " + recordCount), + record -> + logger.log(Level.INFO, "record = " + record.toString(Charset.forName(client.getEncoding())))); + logger.log(Level.INFO, "returned records = " + count); + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + } +} diff --git a/z3950/src/test/java/org/xbib/io/iso23950/cql/CQL2RPNTest.java b/z3950/src/test/java/org/xbib/io/iso23950/cql/CQL2RPNTest.java new file mode 100644 index 0000000..1a98d53 --- /dev/null +++ b/z3950/src/test/java/org/xbib/io/iso23950/cql/CQL2RPNTest.java @@ -0,0 +1,21 @@ +package org.xbib.io.iso23950.cql; + +import org.junit.Test; +import org.xbib.cql.CQLParser; + +/** + * + */ +public class CQL2RPNTest { + + @Test + public void testCQL2RPN() { + String cql = "dc.title = Test"; + CQLParser parser = new CQLParser(cql); + parser.parse(); + CQLRPNGenerator generator = new CQLRPNGenerator(); + parser.getCQLQuery().accept(generator); + String q = generator.getQueryResult().toString(); + System.err.println("cql2rpn = " + q); + } +} diff --git a/z3950/src/test/java/org/xbib/io/iso23950/cql/package-info.java b/z3950/src/test/java/org/xbib/io/iso23950/cql/package-info.java new file mode 100644 index 0000000..ac6aa8f --- /dev/null +++ b/z3950/src/test/java/org/xbib/io/iso23950/cql/package-info.java @@ -0,0 +1,4 @@ +/** + * + */ +package org.xbib.io.iso23950.cql; diff --git a/z3950/src/test/java/org/xbib/io/iso23950/package-info.java b/z3950/src/test/java/org/xbib/io/iso23950/package-info.java new file mode 100644 index 0000000..d679460 --- /dev/null +++ b/z3950/src/test/java/org/xbib/io/iso23950/package-info.java @@ -0,0 +1,4 @@ +/** + * + */ +package org.xbib.io.iso23950; diff --git a/z3950/src/test/java/org/xbib/io/iso23950/pqf/PQFParserTest.java b/z3950/src/test/java/org/xbib/io/iso23950/pqf/PQFParserTest.java new file mode 100644 index 0000000..ee491f2 --- /dev/null +++ b/z3950/src/test/java/org/xbib/io/iso23950/pqf/PQFParserTest.java @@ -0,0 +1,36 @@ +package org.xbib.io.iso23950.pqf; + +import org.junit.Test; +import org.xbib.io.iso23950.ParserTest; + +import java.io.IOException; +import java.io.StringReader; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + */ +public class PQFParserTest extends ParserTest { + + private static final Logger logger = Logger.getLogger(PQFParserTest.class.getName()); + + @Test + public void testSucceed() throws SyntaxException, IOException { + int ok = 0; + int errors = 0; + for (String q : readFromResource("org/xbib/io/iso23950/pqf/pqf-must-succeed")) { + PQFParser parser = new PQFParser(new StringReader(q)); + try { + parser.parse(); + ok++; + } catch (Exception e) { + logger.log(Level.SEVERE,"failed: " + q, e); + errors++; + } + } + assertEquals(errors, 0); + assertEquals(ok, 17); + } + +} diff --git a/z3950/src/test/java/org/xbib/io/iso23950/pqf/package-info.java b/z3950/src/test/java/org/xbib/io/iso23950/pqf/package-info.java new file mode 100644 index 0000000..251e741 --- /dev/null +++ b/z3950/src/test/java/org/xbib/io/iso23950/pqf/package-info.java @@ -0,0 +1,4 @@ +/** + * + */ +package org.xbib.io.iso23950.pqf; diff --git a/z3950/src/test/resources/log4j2.xml b/z3950/src/test/resources/log4j2.xml new file mode 100644 index 0000000..f71aced --- /dev/null +++ b/z3950/src/test/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/z3950/src/test/resources/org/xbib/io/iso23950/pqf/pqf-must-succeed b/z3950/src/test/resources/org/xbib/io/iso23950/pqf/pqf-must-succeed new file mode 100644 index 0000000..4f3784b --- /dev/null +++ b/z3950/src/test/resources/org/xbib/io/iso23950/pqf/pqf-must-succeed @@ -0,0 +1,17 @@ +dylan +"bob dylan" +@or "dylan" "zimmerman" +@and @or dylan zimmerman when +@and when @or dylan zimmerman +@set Result-1 +@and @set seta @set setb +@attr 1=4 computer +@attr 1=12 @attr 5=1 "abc1234567" +@attr 1=4 @attr 4=1 "self portrait" +@attrset exp1 @attr 1=1 CategoryList +@attr gils 1=2008 Copenhagen +@attr 1=/book/title computer +@term string "a UTF-8 string, maybe?" +@or @and bob dylan @set Result-1 +@attr 4=1 @and @attr 1=1 "bob dylan" @attr 1=4 "slow train coming" +@and @attr 2=4 @attr gils 1=2038 -114 @attr 2=2 @attr gils 1=2039 -109 \ No newline at end of file