reorganize package structure for fine grained dependencies

This commit is contained in:
Jörg Prante 2019-03-15 13:45:07 +01:00
parent d0c91568a8
commit b2df8b14ba
208 changed files with 618 additions and 454 deletions

View file

@ -1,5 +1,5 @@
plugins {
id "com.github.spotbugs" version "1.6.2"
id "com.github.spotbugs" version "1.6.9"
id "org.sonarqube" version '2.6.1'
id "io.codearte.nexus-staging" version "0.11.0"
}
@ -18,22 +18,14 @@ printf "Host: %s\nOS: %s %s %s\nJVM: %s %s %s %s\nGradle: %s Groovy: %s Java: %s
GroovySystem.getVersion(),
JavaVersion.current()
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'jacoco'
apply plugin: "com.github.spotbugs"
apply from: "${rootProject.projectDir}/gradle/ext.gradle"
apply from: "${rootProject.projectDir}/gradle/sonarqube.gradle"
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: "com.github.spotbugs"
configurations {
wagon
@ -63,8 +55,9 @@ subprojects {
}
test {
systemProperty 'java.util.logging.config.file', project.file('src/test/resources/logging.properties')
testLogging {
showStandardStreams = false
showStandardStreams = true
exceptionFormat = 'full'
}
}
@ -87,6 +80,16 @@ subprojects {
sign configurations.archives
}
}
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'
}
apply from: "${rootProject.projectDir}/gradle/publish.gradle"
apply from: "${rootProject.projectDir}/gradle/sonarqube.gradle"
}

View file

@ -1,9 +1,9 @@
group = org.xbib
name = z3950
version = 1.2.1
version = 1.3.0
xbib-cql.version = 1.2.0
netty.version = 4.1.29.Final
netty.version = 4.1.34.Final
junit.version = 4.12
wagon.version = 3.0.0

View file

@ -1,8 +0,0 @@
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'
}

View file

@ -1,5 +1,4 @@
spotbugs {
toolVersion = '3.1.3'
sourceSets = [sourceSets.main]
@ -7,14 +6,17 @@ spotbugs {
effort = "max"
reportLevel = "high"
}
spotbugsMain.reports {
xml.enabled = false
html.enabled = true
}
spotbugsTest.reports {
xml.enabled = false
html.enabled = true
}
tasks.withType(Pmd) {
ignoreFailures = true
reports {
@ -31,20 +33,12 @@ tasks.withType(Checkstyle) {
}
}
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/"
}
}

Binary file not shown.

View file

@ -1,6 +1,6 @@
#Fri Sep 07 18:47:56 CEST 2018
#Thu Mar 14 15:23:27 CET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip

2
gradlew vendored
View file

@ -28,7 +28,7 @@ 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=""
DEFAULT_JVM_OPTS='"-Xmx64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

2
gradlew.bat vendored
View file

@ -14,7 +14,7 @@ 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=
set DEFAULT_JVM_OPTS="-Xmx64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

View file

@ -1,2 +1,6 @@
include 'asn1'
include 'z3950'
include 'z3950-asn1'
include 'z3950-api'
include 'z3950-common'
include 'z3950-client'
include 'z3950-client-netty'
include 'z3950-sru'

3
z3950-api/build.gradle Normal file
View file

@ -0,0 +1,3 @@
dependencies {
compile project(':z3950-asn1')
}

View file

@ -0,0 +1,44 @@
package org.xbib.z3950.api;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
public interface Client extends Closeable {
int searchCQL(String query, int offset, int length,
SearchListener searchListener,
RecordListener recordListener) throws IOException;
int searchPQF(String query, int offset, int length,
SearchListener searchListener,
RecordListener recordListener) throws IOException;
void scanPQF(String query, int nTerms, int step, int position,
ScanListener scanListener) throws IOException;
String getHost();
int getPort();
String getUser();
String getPass();
long getTimeout();
String getPreferredRecordSyntax();
String getResultSetName();
String getElementSetName();
String getEncoding();
String getFormat();
String getType();
List<String> getDatabases();
}

View file

@ -0,0 +1,6 @@
package org.xbib.z3950.api;
public interface ClientProvider<C extends Client> {
C getClient();
}

View file

@ -1,4 +1,4 @@
package org.xbib.io.iso23950;
package org.xbib.z3950.api;
/**
*

View file

@ -0,0 +1,13 @@
package org.xbib.z3950.api;
import java.io.InputStream;
import java.nio.charset.Charset;
public interface Record {
int getNumber();
InputStream asStream();
String toString(Charset charset);
}

View file

@ -1,4 +1,4 @@
package org.xbib.io.iso23950;
package org.xbib.z3950.api;
/**
*

View file

@ -1,4 +1,4 @@
package org.xbib.io.iso23950;
package org.xbib.z3950.api;
import org.xbib.asn1.BEREncoding;

View file

@ -1,4 +1,4 @@
package org.xbib.io.iso23950;
package org.xbib.z3950.api;
import java.io.IOException;

View file

@ -0,0 +1,5 @@
dependencies {
compile project(':z3950-common')
compile "io.netty:netty-handler:${project.property('netty.version')}"
compile "io.netty:netty-transport:${project.property('netty.version')}"
}

View file

@ -1,4 +1,4 @@
package org.xbib.io.iso23950.netty;
package org.xbib.z3950.client.netty;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
@ -42,7 +42,6 @@ public class NettyZClient {
}
public void shutdown() throws InterruptedException {
group.shutdownGracefully().sync();
}

View file

@ -0,0 +1,3 @@
dependencies {
compile project(':z3950-common')
}

View file

@ -1,12 +1,17 @@
package org.xbib.io.iso23950;
package org.xbib.z3950.client;
import org.xbib.asn1.io.InputStreamBERReader;
import org.xbib.asn1.io.OutputStreamBERWriter;
import org.xbib.io.iso23950.operations.CloseOperation;
import org.xbib.io.iso23950.operations.InitOperation;
import org.xbib.io.iso23950.operations.PresentOperation;
import org.xbib.io.iso23950.operations.ScanOperation;
import org.xbib.io.iso23950.operations.SearchOperation;
import org.xbib.z3950.common.operations.CloseOperation;
import org.xbib.z3950.common.operations.InitOperation;
import org.xbib.z3950.common.operations.PresentOperation;
import org.xbib.z3950.common.operations.ScanOperation;
import org.xbib.z3950.common.operations.SearchOperation;
import org.xbib.z3950.api.Client;
import org.xbib.z3950.api.InitListener;
import org.xbib.z3950.api.RecordListener;
import org.xbib.z3950.api.ScanListener;
import org.xbib.z3950.api.SearchListener;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@ -27,9 +32,9 @@ import java.util.logging.Logger;
/**
* Default Z client.
*/
public class ZClient implements AutoCloseable {
public class DefaultClient implements Client {
private static final Logger logger = Logger.getLogger(ZClient.class.getName());
private static final Logger logger = Logger.getLogger(DefaultClient.class.getName());
private final String host;
@ -67,16 +72,16 @@ public class ZClient implements AutoCloseable {
private OutputStreamBERWriter berWriter;
private ZClient(String host, int port, String user, String pass, long timeout,
String preferredRecordSyntax,
String resultSetName,
String elementSetName,
String encoding,
String format,
String type,
List<String> databases,
Integer preferredMessageSize,
InitListener initListener) {
private DefaultClient(String host, int port, String user, String pass, long timeout,
String preferredRecordSyntax,
String resultSetName,
String elementSetName,
String encoding,
String format,
String type,
List<String> databases,
Integer preferredMessageSize,
InitListener initListener) {
this.host = host;
this.port = port;
this.user = user;
@ -127,6 +132,7 @@ public class ZClient implements AutoCloseable {
}
}
@Override
public int searchCQL(String query, int offset, int length,
SearchListener searchListener,
RecordListener recordListener) throws IOException {
@ -167,6 +173,7 @@ public class ZClient implements AutoCloseable {
}
}
@Override
public int searchPQF(String query, int offset, int length,
SearchListener searchListener,
RecordListener recordListener) throws IOException {
@ -208,6 +215,7 @@ public class ZClient implements AutoCloseable {
}
}
@Override
public void scanPQF(String query, int nTerms, int step, int position,
ScanListener scanListener) throws IOException {
ensureConnected();
@ -220,73 +228,68 @@ public class ZClient implements AutoCloseable {
}
}
@Override
public String getHost() {
return host;
}
@Override
public int getPort() {
return port;
}
@Override
public String getUser() {
return user;
}
@Override
public String getPass() {
return pass;
}
@Override
public long getTimeout() {
return timeout;
}
@Override
public String getPreferredRecordSyntax() {
return preferredRecordSyntax;
}
@Override
public String getResultSetName() {
return resultSetName;
}
@Override
public String getElementSetName() {
return elementSetName;
}
@Override
public String getEncoding() {
return encoding;
}
@Override
public String getFormat() {
return format;
}
@Override
public String getType() {
return type;
}
@Override
public List<String> getDatabases() {
return databases;
}
private void connect() throws IOException {
try {
lock.lock();
Socket socket = new Socket();
socket.connect(new InetSocketAddress(host, port), (int) timeout);
socket.setSoTimeout((int) timeout * 1000);
this.socket = socket;
InputStream src = new BufferedInputStream(socket.getInputStream());
OutputStream dest = new BufferedOutputStream(socket.getOutputStream());
this.berReader = new InputStreamBERReader(src);
this.berWriter = new OutputStreamBERWriter(dest);
InitOperation initOperation = new InitOperation(berReader, berWriter, user, pass);
if (initOperation.execute(preferredMessageSize, initListener)) {
throw new IOException("could not initiate connection");
}
logger.log(Level.INFO, initOperation.getTargetInfo());
} finally {
lock.unlock();
}
}
private boolean isConnected() {
@ -295,7 +298,24 @@ public class ZClient implements AutoCloseable {
private void ensureConnected() throws IOException {
if (!isConnected()) {
connect();
try {
lock.lock();
Socket socket = new Socket();
socket.connect(new InetSocketAddress(host, port), (int) timeout);
socket.setSoTimeout((int) timeout * 1000);
this.socket = socket;
InputStream src = new BufferedInputStream(socket.getInputStream());
OutputStream dest = new BufferedOutputStream(socket.getOutputStream());
this.berReader = new InputStreamBERReader(src);
this.berWriter = new OutputStreamBERWriter(dest);
InitOperation initOperation = new InitOperation(berReader, berWriter, user, pass);
if (initOperation.execute(preferredMessageSize, initListener)) {
throw new IOException("could not initiate connection");
}
logger.log(Level.INFO, initOperation.getTargetInfo());
} finally {
lock.unlock();
}
}
}
@ -331,7 +351,7 @@ public class ZClient implements AutoCloseable {
public static class Builder {
private static final ResourceBundle recordSyntaxBundle =
ResourceBundle.getBundle("org.xbib.io.iso23950.recordsyntax");
ResourceBundle.getBundle("org.xbib.z3950.common.recordsyntax");
private String host;
@ -434,8 +454,8 @@ public class ZClient implements AutoCloseable {
return this;
}
public ZClient build() {
return new ZClient(host, port, user, pass, timeout,
public DefaultClient build() {
return new DefaultClient(host, port, user, pass, timeout,
preferredRecordSyntax,
resultSetName,
elementSetName,

View file

@ -1,6 +1,7 @@
package org.xbib.io.iso23950;
package org.xbib.z3950.client.test;
import org.junit.Test;
import org.xbib.z3950.client.DefaultClient;
import java.io.IOException;
import java.io.InputStream;
@ -14,9 +15,9 @@ import java.util.logging.Logger;
/**
*
*/
public class ZClientTest {
public class DefaultClientTest {
private static final Logger logger = Logger.getLogger(ZClientTest.class.getName());
private static final Logger logger = Logger.getLogger(DefaultClientTest.class.getName());
@Test
public void testCQL() {
@ -24,7 +25,7 @@ public class ZClientTest {
String query = "bib.identifierISSN = 00280836";
int from = 1;
int size = 10;
try (ZClient client = newZClient(serviceName)) {
try (DefaultClient client = newZClient(serviceName)) {
logger.log(Level.INFO, "executing CQL " + serviceName);
int count = client.searchCQL(query, from, size,
(status, total, returned, elapsedMillis) ->
@ -37,31 +38,13 @@ public class ZClientTest {
}
}
@Test
public void testGBV() {
String serviceName = "GBV";
String query = "gbv.controlNumberZDB = 1413423-8";
int from = 1;
int size = 2;
try (ZClient client = newZClient(serviceName)) {
logger.log(Level.INFO, "executing CQL " + query);
int count = client.searchCQL(query, from, size,
(status, total, returned, elapsedMillis) ->
logger.log(Level.INFO, serviceName + " total results = " + total),
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 = newZClient(serviceName)) {
try (DefaultClient client = newZClient(serviceName)) {
logger.log(Level.INFO, "executing PQF " + serviceName);
int count = client.searchPQF(query, from, size,
(status, total, returned, elapsedMillis) ->
@ -74,21 +57,20 @@ public class ZClientTest {
}
}
private static ZClient newZClient(String name) throws IOException {
private DefaultClient newZClient(String name) throws IOException {
return newZClient(getProperties(name));
}
private static Properties getProperties(String name) throws IOException {
private Properties getProperties(String name) throws IOException {
Properties properties = new Properties();
try (InputStream inputStream =
ZClient.class.getResourceAsStream("/org/xbib/io/iso23950/service/" + name + ".properties")) {
try (InputStream inputStream = getClass().getResourceAsStream(name + ".properties")) {
properties.load(inputStream);
}
return properties;
}
private static ZClient newZClient(Properties properties) {
ZClient.Builder builder = ZClient.builder();
private static DefaultClient newZClient(Properties properties) {
DefaultClient.Builder builder = DefaultClient.builder();
if (properties.containsKey("host")) {
builder.setHost(properties.getProperty("host"));
}

View file

@ -0,0 +1,110 @@
package org.xbib.z3950.client.test;
import org.junit.Test;
import org.xbib.z3950.client.DefaultClient;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.junit.Assert.assertEquals;
/**
* GBV test.
*/
public class GBVZClientTest {
private static final Logger logger = Logger.getLogger(GBVZClientTest.class.getName());
@Test
public void testGBV() {
String query = "@attr 1=4 linux";
int from = 1;
int size = 10;
try (DefaultClient client = newZClient("GBV")) {
logger.log(Level.INFO, "executing PQF " + query);
int count = client.searchPQF(query, from, size,
(status, total, returned, elapsedMillis) ->
logger.log(Level.INFO, "total results = " + total + " millis = " + elapsedMillis),
record -> logger.log(Level.INFO, "record = " + record.toString(StandardCharsets.UTF_8)));
logger.log(Level.INFO, "record count = " + count);
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
}
@Test
public void testControlNumberZDB() {
String serviceName = "GBV";
String query = "bib.controlNumberZDB = 1413423-8";
int from = 1;
int size = 2;
try (DefaultClient client = newZClient(serviceName)) {
logger.log(Level.INFO, "executing CQL " + query);
int count = client.searchCQL(query, from, size,
(status, total, returned, elapsedMillis) ->
logger.log(Level.INFO, serviceName + " total results = " + total),
record -> logger.log(Level.INFO, "record = " + record));
logger.log(Level.INFO, "returned records = " + count);
assertEquals(1, count);
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
}
private DefaultClient newZClient(String name) throws IOException {
return newZClient(getProperties(name));
}
private Properties getProperties(String name) throws IOException {
Properties properties = new Properties();
try (InputStream inputStream = getClass().getResourceAsStream(name + ".properties")) {
properties.load(inputStream);
}
return properties;
}
private static DefaultClient newZClient(Properties properties) {
DefaultClient.Builder builder = DefaultClient.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();
}
}

View file

@ -4,8 +4,6 @@ plugins {
}
dependencies {
compile project(':asn1')
compile project(':z3950-api')
compile "org.xbib:cql-common:${project.property('xbib-cql.version')}"
compile "io.netty:netty-handler:${project.property('netty.version')}"
compile "io.netty:netty-transport:${project.property('netty.version')}"
}

View file

@ -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.z3950.common.pqf %token NL %token <String> OR %token <String> AND %token <String> NOT %token <String> ATTR %token <String> ATTRSET %token <String> TERM %token <String> SET %token <String> VOID %token <String> KNOWN %token <String> PRIVATE %token <String> TERMTYPE %token <String> CHARSTRING1 %token <String> CHARSTRING2 %token <String> OPERATORS %token <String> EQUALS %token <Integer> INTEGER %left AND %left OR %left NOT %type <PQF> pqf %type <Query> querystruct %type <Expression> expression %type <AttrStr> attrstr %type <Term> term %type <Setname> 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; }

View file

@ -1,4 +1,6 @@
package org.xbib.io.iso23950;
package org.xbib.z3950.common;
import org.xbib.z3950.api.Record;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
@ -7,7 +9,7 @@ import java.nio.charset.Charset;
/**
* A record for Z39.50 presentations.
*/
public class Record {
public class DefaultRecord implements Record {
private final int number;
@ -15,20 +17,23 @@ public class Record {
private final ByteArrayInputStream stream;
public Record(int number, byte[] content) {
public DefaultRecord(int number, byte[] content) {
this.number = number;
this.content = content;
this.stream = new ByteArrayInputStream(content);
}
@Override
public int getNumber() {
return number;
}
@Override
public InputStream asStream() {
return stream;
}
@Override
public String toString(Charset charset) {
return new String(content, charset);
}

View file

@ -0,0 +1,38 @@
package org.xbib.z3950.common;
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.z3950.common.diagnostics");
private static final long serialVersionUID = -899201811019819079L;
private int diagCode;
private String message;
public Diagnostics(int diagCode, String message) {
super("" + diagCode + " " + bundle.getString(Integer.toString(diagCode)) + " " + message);
this.diagCode = diagCode;
this.message = message;
}
public int getDiagCode() {
return diagCode;
}
public String getPlainText() {
return message;
}
@Override
public String toString() {
return message;
}
}

View file

@ -1,9 +1,9 @@
package org.xbib.io.iso23950;
package org.xbib.z3950.common;
/**
*
*/
public class ErrorRecord extends Record {
public class ErrorRecord extends DefaultRecord {
public ErrorRecord(int number, byte[] content) {
super(number, content);

View file

@ -1,4 +1,4 @@
package org.xbib.io.iso23950.cql;
package org.xbib.z3950.common.cql;
import org.xbib.asn1.ASN1Any;
import org.xbib.asn1.ASN1Integer;
@ -22,16 +22,16 @@ 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 org.xbib.z3950.common.v3.AttributeElement;
import org.xbib.z3950.common.v3.AttributeElementAttributeValue;
import org.xbib.z3950.common.v3.AttributeList;
import org.xbib.z3950.common.v3.AttributeSetId;
import org.xbib.z3950.common.v3.AttributesPlusTerm;
import org.xbib.z3950.common.v3.Operand;
import org.xbib.z3950.common.v3.Operator;
import org.xbib.z3950.common.v3.RPNQuery;
import org.xbib.z3950.common.v3.RPNStructure;
import org.xbib.z3950.common.v3.RPNStructureRpnRpnOp;
import java.util.HashMap;
import java.util.Map;
@ -52,9 +52,9 @@ public final class CQLRPNGenerator implements Visitor {
private final Map<String, ResourceBundle> contexts = new HashMap<String, ResourceBundle>() {
private static final long serialVersionUID = 8199395368653216950L;
{
put("bib", ResourceBundle.getBundle("org.xbib.io.iso23950.cql.bib-1"));
put("dc", ResourceBundle.getBundle("org.xbib.io.iso23950.cql.dc"));
put("gbv", ResourceBundle.getBundle("org.xbib.io.iso23950.cql.gbv"));
put("bib", ResourceBundle.getBundle("org.xbib.z3950.common.cql.bib-1"));
put("dc", ResourceBundle.getBundle("org.xbib.z3950.common.cql.dc"));
put("gbv", ResourceBundle.getBundle("org.xbib.z3950.common.cql.gbv"));
}
};
private Stack<ASN1Any> result;
@ -182,7 +182,7 @@ public final class CQLRPNGenerator implements Visitor {
}
Operand operand = new Operand();
operand.attrTerm = new AttributesPlusTerm();
operand.attrTerm.term = new org.xbib.io.iso23950.v3.Term();
operand.attrTerm.term = new org.xbib.z3950.common.v3.Term();
operand.attrTerm.term.c_general = new ASN1OctetString(node.getTerm().getValue());
Stack<AttributeElement> attrs = new Stack<>();
ASN1Any any = !result.isEmpty() && result.peek() instanceof AttributeElement ? result.pop() : null;

View file

@ -1,4 +1,4 @@
package org.xbib.io.iso23950.cql;
package org.xbib.z3950.common.cql;
/**
* Syntax exception.

View file

@ -0,0 +1,4 @@
/**
*
*/
package org.xbib.z3950.common.cql;

View file

@ -1,4 +1,4 @@
package org.xbib.io.iso23950.exceptions;
package org.xbib.z3950.common.exceptions;
import java.io.IOException;

View file

@ -0,0 +1,4 @@
/**
*
*/
package org.xbib.z3950.common.exceptions;

View file

@ -1,19 +1,19 @@
package org.xbib.io.iso23950.operations;
package org.xbib.z3950.common.operations;
import org.xbib.asn1.ASN1Any;
import org.xbib.asn1.ASN1Exception;
import org.xbib.asn1.BEREncoding;
import org.xbib.asn1.io.BERReader;
import org.xbib.asn1.io.BERWriter;
import org.xbib.io.iso23950.v3.Close;
import org.xbib.io.iso23950.v3.InitializeRequest;
import org.xbib.io.iso23950.v3.InitializeResponse;
import org.xbib.io.iso23950.v3.PresentRequest;
import org.xbib.io.iso23950.v3.PresentResponse;
import org.xbib.io.iso23950.v3.ScanRequest;
import org.xbib.io.iso23950.v3.ScanResponse;
import org.xbib.io.iso23950.v3.SearchRequest;
import org.xbib.io.iso23950.v3.SearchResponse;
import org.xbib.z3950.common.v3.Close;
import org.xbib.z3950.common.v3.InitializeRequest;
import org.xbib.z3950.common.v3.InitializeResponse;
import org.xbib.z3950.common.v3.PresentRequest;
import org.xbib.z3950.common.v3.PresentResponse;
import org.xbib.z3950.common.v3.ScanRequest;
import org.xbib.z3950.common.v3.ScanResponse;
import org.xbib.z3950.common.v3.SearchRequest;
import org.xbib.z3950.common.v3.SearchResponse;
import java.io.IOException;

View file

@ -1,15 +1,19 @@
package org.xbib.io.iso23950.operations;
package org.xbib.z3950.common.operations;
import org.xbib.asn1.ASN1Integer;
import org.xbib.asn1.io.BERReader;
import org.xbib.asn1.io.BERWriter;
import org.xbib.io.iso23950.v3.Close;
import org.xbib.io.iso23950.v3.CloseReason;
import org.xbib.z3950.common.v3.Close;
import org.xbib.z3950.common.v3.CloseReason;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class CloseOperation extends AbstractOperation<Close, Close> {
private static final Logger logger = Logger.getLogger(CloseOperation.class.getName());
public CloseOperation(BERReader reader, BERWriter writer) {
super(reader, writer);
}
@ -19,6 +23,9 @@ public class CloseOperation extends AbstractOperation<Close, Close> {
close.closeReason = new CloseReason();
close.closeReason.value = new ASN1Integer(reason);
close.referenceId = null;
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, close.toString());
}
write(close);
// do not wait, it may hang
//waitClosePDU();

View file

@ -1,20 +1,21 @@
package org.xbib.io.iso23950.operations;
package org.xbib.z3950.common.operations;
import org.xbib.asn1.ASN1BitString;
import org.xbib.asn1.ASN1GeneralString;
import org.xbib.asn1.ASN1Integer;
import org.xbib.asn1.io.BERReader;
import org.xbib.asn1.io.BERWriter;
import org.xbib.io.iso23950.InitListener;
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.ProtocolVersion;
import org.xbib.z3950.common.v3.IdAuthentication;
import org.xbib.z3950.common.v3.IdAuthenticationIdPass;
import org.xbib.z3950.common.v3.InitializeRequest;
import org.xbib.z3950.common.v3.InitializeResponse;
import org.xbib.z3950.common.v3.InternationalString;
import org.xbib.z3950.common.v3.Options;
import org.xbib.z3950.common.v3.ProtocolVersion;
import org.xbib.z3950.api.InitListener;
import java.io.IOException;