fixing RdfContentParameter generic type settings

This commit is contained in:
Jörg Prante 2016-11-13 22:55:51 +01:00
parent df3205ee0f
commit 8d157d9192
20 changed files with 58 additions and 53 deletions

View file

@ -14,7 +14,7 @@ ext {
allprojects {
group = 'org.xbib'
version = '1.0.4'
version = '1.0.5'
apply plugin: 'java'
apply plugin: 'maven'

View file

@ -13,6 +13,5 @@ public interface RdfContent<P extends RdfContentParams> {
RdfContentGenerator<P> createGenerator(OutputStream out) throws IOException;
RdfContentParser createParser(InputStream in) throws IOException;
RdfContentParser<P> createParser(InputStream in) throws IOException;
}

View file

@ -5,10 +5,10 @@ import java.io.IOException;
/**
*
*/
public interface RdfContentParser {
public interface RdfContentParser<R extends RdfContentParams> {
RdfContentType contentType();
RdfContentParser parse() throws IOException;
RdfContentParser<R> parse() throws IOException;
}

View file

@ -33,7 +33,7 @@ public class RdfXContent implements RdfContent<RdfXContentParams> {
}
@Override
public RdfContentParser createParser(InputStream in) throws IOException {
public RdfContentParser<RdfXContentParams> createParser(InputStream in) throws IOException {
throw new UnsupportedOperationException();
}
}

View file

@ -14,7 +14,7 @@ public class RouteRdfXContent implements RdfContent<RouteRdfXContentParams> {
private RouteRdfXContent() {
}
public static final RouteRdfXContent routeRdfXContent() {
public static RouteRdfXContent routeRdfXContent() {
return ROUTE_RDF_X_CONTENT;
}
@ -33,8 +33,8 @@ public class RouteRdfXContent implements RdfContent<RouteRdfXContentParams> {
}
@Override
public RdfContentParser createParser(InputStream in) throws IOException {
return null;
public RdfContentParser<RouteRdfXContentParams> createParser(InputStream in) throws IOException {
throw new UnsupportedOperationException();
}
/**

View file

@ -44,7 +44,7 @@ public class JsonContent implements RdfContent<JsonContentParams> {
}
@Override
public RdfContentParser createParser(InputStream in) throws IOException {
return new JsonContentParser(in);
public RdfContentParser<JsonContentParams> createParser(InputStream in) throws IOException {
return new JsonContentParser<>(in);
}
}

View file

@ -1,6 +1,7 @@
package org.xbib.content.rdf.io.json;
import org.xbib.content.rdf.RdfContentBuilder;
import org.xbib.content.rdf.RdfContentParams;
import org.xbib.content.rdf.RdfContentParser;
import org.xbib.content.rdf.RdfContentType;
import org.xbib.content.rdf.StandardRdfContentType;
@ -18,14 +19,15 @@ import javax.xml.namespace.QName;
/**
* A parser for generic JSON (not JSON-LD) via JSON SaX adapter.
* @param <R> parameterized type
*/
public class JsonContentParser implements RdfContentParser {
public class JsonContentParser<R extends RdfContentParams> implements RdfContentParser<R> {
private final Reader reader;
private XmlHandler<JsonContentParams> handler;
private XmlHandler<R> handler;
private RdfContentBuilder<JsonContentParams> builder;
private RdfContentBuilder<R> builder;
private QName root;
@ -42,27 +44,27 @@ public class JsonContentParser implements RdfContentParser {
return StandardRdfContentType.JSON;
}
public XmlHandler<JsonContentParams> getHandler() {
public XmlHandler<R> getHandler() {
return handler;
}
public JsonContentParser setHandler(XmlHandler<JsonContentParams> handler) {
public JsonContentParser<R> setHandler(XmlHandler<R> handler) {
this.handler = handler;
return this;
}
public JsonContentParser root(QName root) {
public JsonContentParser<R> root(QName root) {
this.root = root;
return this;
}
public JsonContentParser builder(RdfContentBuilder<JsonContentParams> builder) {
public JsonContentParser<R> builder(RdfContentBuilder<R> builder) {
this.builder = builder;
return this;
}
@Override
public JsonContentParser parse() throws IOException {
public JsonContentParser<R> parse() throws IOException {
if (handler != null) {
if (builder != null) {
handler.setBuilder(builder);

View file

@ -44,7 +44,7 @@ public class NTripleContent implements RdfContent<NTripleContentParams> {
}
@Override
public RdfContentParser createParser(InputStream in) throws IOException {
return new NTripleContentParser(in);
public RdfContentParser<NTripleContentParams> createParser(InputStream in) throws IOException {
return new NTripleContentParser<>(in);
}
}

View file

@ -1,6 +1,7 @@
package org.xbib.content.rdf.io.ntriple;
import org.xbib.content.rdf.RdfContentBuilder;
import org.xbib.content.rdf.RdfContentParams;
import org.xbib.content.rdf.RdfContentParser;
import org.xbib.content.rdf.RdfContentType;
import org.xbib.content.rdf.Resource;
@ -24,8 +25,9 @@ import java.util.regex.PatternSyntaxException;
* Parser for NTriple RDF format.
* See also the <a href="http://www.w3.org/TR/rdf-testcases/#convert">NTriple
* specification</a>.
* @param <R> RDF content parameter type
*/
public class NTripleContentParser implements RdfContentParser {
public class NTripleContentParser<R extends RdfContentParams> implements RdfContentParser<R> {
private static final Resource resource = new DefaultAnonymousResource();
@ -48,7 +50,7 @@ public class NTripleContentParser implements RdfContentParser {
private boolean eof;
private RdfContentBuilder<NTripleContentParams> builder;
private RdfContentBuilder<R> builder;
public NTripleContentParser(InputStream in) throws IOException {
this(new InputStreamReader(in, StandardCharsets.UTF_8));
@ -63,13 +65,13 @@ public class NTripleContentParser implements RdfContentParser {
return StandardRdfContentType.NTRIPLE;
}
public NTripleContentParser setBuilder(RdfContentBuilder<NTripleContentParams> builder) {
public NTripleContentParser<R> setBuilder(RdfContentBuilder<R> builder) {
this.builder = builder;
return this;
}
@Override
public NTripleContentParser parse() throws IOException {
public NTripleContentParser<R> parse() throws IOException {
this.eof = false;
try (BufferedReader br = new BufferedReader(reader)) {
while (!eof) {

View file

@ -44,7 +44,7 @@ public class RdfXmlContent implements RdfContent<RdfXmlContentParams> {
}
@Override
public RdfContentParser createParser(InputStream in) throws IOException {
return new RdfXmlContentParser<RdfXmlContentParams>(in);
public RdfContentParser<RdfXmlContentParams> createParser(InputStream in) throws IOException {
return new RdfXmlContentParser<>(in);
}
}

View file

@ -52,7 +52,7 @@ import java.util.logging.Logger;
* Note that the XMLLiteral datatype is not fully supported.
* @param <R> parameter type
*/
public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConstants, RdfContentParser {
public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConstants, RdfContentParser<R> {
private static final Logger logger = Logger.getLogger(RdfXmlContentParser.class.getName());

View file

@ -44,8 +44,8 @@ public class TurtleContent implements RdfContent<TurtleContentParams> {
}
@Override
public RdfContentParser createParser(InputStream inputStream) throws IOException {
return new TurtleContentParser(inputStream);
public RdfContentParser<TurtleContentParams> createParser(InputStream inputStream) throws IOException {
return new TurtleContentParser<>(inputStream);
}
}

View file

@ -4,6 +4,7 @@ import org.xbib.content.rdf.Literal;
import org.xbib.content.rdf.RdfContentBuilder;
import org.xbib.content.rdf.RdfContentBuilderHandler;
import org.xbib.content.rdf.RdfContentBuilderProvider;
import org.xbib.content.rdf.RdfContentParams;
import org.xbib.content.rdf.RdfContentParser;
import org.xbib.content.rdf.RdfContentType;
import org.xbib.content.rdf.Resource;
@ -36,8 +37,9 @@ import java.util.logging.Logger;
*
* @see <a href="http://www.w3.org/TeamSubmission/turtle/">Turtle - Terse RDF
* Triple Language</a>
* @param <R> RDF content type parameter
*/
public class TurtleContentParser implements RdfContentParser {
public class TurtleContentParser<R extends RdfContentParams> implements RdfContentParser<R> {
private static final Logger logger = Logger.getLogger(TurtleContentParser.class.getName());
@ -45,11 +47,11 @@ public class TurtleContentParser implements RdfContentParser {
private final HashMap<String, Node> bnodes = new HashMap<>();
private RdfContentBuilderProvider<TurtleContentParams> provider;
private RdfContentBuilderProvider<R> provider;
private RdfContentBuilderHandler<TurtleContentParams> rdfContentBuilderHandler;
private RdfContentBuilderHandler<R> rdfContentBuilderHandler;
private RdfContentBuilder<TurtleContentParams> builder;
private RdfContentBuilder<R> builder;
/**
* The base IRI.
@ -136,29 +138,29 @@ public class TurtleContentParser implements RdfContentParser {
return StandardRdfContentType.TURTLE;
}
public TurtleContentParser setRdfContentBuilderProvider(RdfContentBuilderProvider<TurtleContentParams> provider) {
public TurtleContentParser<R> setRdfContentBuilderProvider(RdfContentBuilderProvider<R> provider) {
this.provider = provider;
return this;
}
public TurtleContentParser setRdfContentBuilderHandler(RdfContentBuilderHandler<TurtleContentParams>
public TurtleContentParser<R> setRdfContentBuilderHandler(RdfContentBuilderHandler<R>
rdfContentBuilderHandler) {
this.rdfContentBuilderHandler = rdfContentBuilderHandler;
return this;
}
public TurtleContentParser setBaseIRI(IRI baseIRI) {
public TurtleContentParser<R> setBaseIRI(IRI baseIRI) {
this.baseIRI = baseIRI;
return this;
}
public TurtleContentParser context(XmlNamespaceContext context) {
public TurtleContentParser<R> context(XmlNamespaceContext context) {
this.context = context;
return this;
}
@Override
public TurtleContentParser parse() throws IOException {
public TurtleContentParser<R> parse() throws IOException {
if (provider != null) {
builder = provider.newContentBuilder();
builder.startStream();
@ -218,7 +220,7 @@ public class TurtleContentParser implements RdfContentParser {
* relative URIs. It takes, itself, a relative URI, so it can be used to
* change the base URI relative to the previous one.
*
* @throws IOException
* @throws IOException if directive could not be parsed
*/
private void parseDirective() throws IOException {
String directive;

View file

@ -44,7 +44,7 @@ public class XmlContent implements RdfContent<XmlContentParams> {
}
@Override
public RdfContentParser createParser(InputStream inputStream) throws IOException {
public RdfContentParser<XmlContentParams> createParser(InputStream inputStream) throws IOException {
return new XmlContentParser<>(inputStream);
}
}

View file

@ -20,7 +20,7 @@ import java.nio.charset.StandardCharsets;
* An XML reader for parsing XML into triples.
* @param <P> parameter type
*/
public class XmlContentParser<P extends RdfContentParams> implements RdfContentParser {
public class XmlContentParser<P extends RdfContentParams> implements RdfContentParser<P> {
private final Reader reader;

View file

@ -66,7 +66,7 @@ public class JsonReaderTest extends StreamTester {
};
RdfContentBuilder<JsonContentParams> builder = jsonBuilder();
jsonHandler.setBuilder(builder);
new JsonContentParser(in)
new JsonContentParser<JsonContentParams>(in)
.setHandler(jsonHandler)
.root(new QName("http://purl.org/dc/elements/1.1/", "root", "dc"))
.parse();

View file

@ -22,7 +22,7 @@ public class NTripleReaderTest extends StreamTester {
throw new IOException("file " + filename + " not found");
}
RdfContentBuilder<NTripleContentParams> builder = ntripleBuilder();
NTripleContentParser reader = new NTripleContentParser(in);
NTripleContentParser<NTripleContentParams> reader = new NTripleContentParser<>(in);
reader.setBuilder(builder);
reader.parse();
//assertStream(getClass().getResource("rdfxml.ttl").openStream(),

View file

@ -22,7 +22,7 @@ public class TurtleConformanceTest extends StreamTester {
for (int n = 0; n < 30; n++) {
String testNum = String.format("%02d", n);
InputStream in = getClass().getResource("/turtle/test-" + testNum + ".ttl").openStream();
TurtleContentParser turtleParser = new TurtleContentParser(in)
TurtleContentParser<TurtleContentParams> turtleParser = new TurtleContentParser<TurtleContentParams>(in)
.setBaseIRI(IRI.create("http://example/base/"));
turtleParser.setRdfContentBuilderProvider(RdfContentFactory::turtleBuilder);
turtleParser.setRdfContentBuilderHandler(b -> {

View file

@ -29,7 +29,7 @@ public class TurtleTest extends StreamTester {
IRINamespaceContext context = IRINamespaceContext.newInstance();
context.addNamespace("gnd", "http://d-nb.info/gnd/");
InputStream in = getClass().getResourceAsStream("GND.ttl");
TurtleContentParser reader = new TurtleContentParser(in)
TurtleContentParser<TurtleContentParams> reader = new TurtleContentParser<TurtleContentParams>(in)
.setBaseIRI(IRI.create("http://d-nb.info/gnd/"))
.context(context);
reader.parse();
@ -40,7 +40,7 @@ public class TurtleTest extends StreamTester {
public void testTurtleGND2() throws Exception {
IRINamespaceContext context = IRINamespaceContext.newInstance();
InputStream in = getClass().getResourceAsStream("gnd2.ttl");
TurtleContentParser reader = new TurtleContentParser(in)
TurtleContentParser<TurtleContentParams> reader = new TurtleContentParser<TurtleContentParams>(in)
.setBaseIRI(IRI.create("http://d-nb.info/gnd/"))
.context(context);
reader.parse();
@ -51,7 +51,7 @@ public class TurtleTest extends StreamTester {
public void testTurtleGND3() throws Exception {
IRINamespaceContext context = IRINamespaceContext.newInstance();
InputStream in = getClass().getResourceAsStream("gnd2.ttl");
TurtleContentParser reader = new TurtleContentParser(in)
TurtleContentParser<TurtleContentParams> reader = new TurtleContentParser<TurtleContentParams>(in)
.setBaseIRI(IRI.create("http://d-nb.info/gnd/"))
.context(context);
reader.setRdfContentBuilderProvider(RdfContentFactory::turtleBuilder);

View file

@ -1,12 +1,12 @@
package org.xbib.content.rdf.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
*
*/