@Override
public void createServiceDescription(RDFWriter writer, String requestURL, boolean isUpdate) throws RDFHandlerException {
try {
writer.startRDF();
final ValueFactory vf = new ValueFactoryImpl();
writer.handleNamespace(SPARQL_SD.PREFIX, SPARQL_SD.NAMESPACE);
writer.handleNamespace("formats", "http://www.w3.org/ns/formats/");
writer.handleNamespace("void", "http://rdfs.org/ns/void#");
final BNode sd = vf.createBNode();
writer.handleStatement(vf.createStatement(sd, RDF.TYPE, SPARQL_SD.Service));
writer.handleStatement(vf.createStatement(sd, SPARQL_SD.endpoint, vf.createURI(requestURL)));
writer.handleStatement(vf.createStatement(sd, SPARQL_SD.supportedLanguage, isUpdate?SPARQL_SD.SPARQL11Update:SPARQL_SD.SPARQL11Query));
if (!isUpdate) {
// FIXME: really? these types?
final Set<FileFormat> formats = new HashSet<>();
formats.addAll(RDFWriterRegistry.getInstance().getKeys());
formats.addAll(TupleQueryResultFormat.values());
for (FileFormat f: formats) {
final String formatUri = w3cFormatID.get(f);
if (StringUtils.isNotBlank(formatUri)) {
writer.handleStatement(vf.createStatement(sd, SPARQL_SD.resultFormat, vf.createURI(formatUri)));
} else {
final BNode fNode = vf.createBNode();
writer.handleStatement(vf.createStatement(sd, SPARQL_SD.resultFormat, fNode));
writer.handleStatement(vf.createStatement(fNode, RDF.TYPE, vf.createURI("http://www.w3.org/ns/formats/Format")));
writer.handleStatement(vf.createStatement(fNode, vf.createURI("http://www.w3.org/ns/formats/media_type"), vf.createLiteral(f.getDefaultMIMEType())));
writer.handleStatement(vf.createStatement(fNode, vf.createURI("http://www.w3.org/ns/formats/preferred_suffix"), vf.createLiteral("."+f.getDefaultFileExtension())));
}
}
}
final BNode dataset = vf.createBNode();
writer.handleStatement(vf.createStatement(sd, SPARQL_SD.defaultDataset, dataset));
writer.handleStatement(vf.createStatement(dataset, RDF.TYPE, SPARQL_SD.Dataset));
final RepositoryConnection kiwiCon = sesameService.getConnection();
try {
kiwiCon.begin();
// FIXME: Default graph, in KiWi this is all - is it not?
final BNode defaultGraph = vf.createBNode();
writer.handleStatement(vf.createStatement(dataset, SPARQL_SD.defaultGraph, defaultGraph));
writer.handleStatement(vf.createStatement(defaultGraph, RDF.TYPE, SPARQL_SD.Graph));
// TODO: Number of triples here? This can be expensive!
writer.handleStatement(vf.createStatement(defaultGraph, vf.createURI("http://rdfs.org/ns/void#triples"), vf.createLiteral(kiwiCon.size())));
final RepositoryResult<Resource> cID = kiwiCon.getContextIDs();
try {
while (cID.hasNext()) {
final Resource c = cID.next();
if (c instanceof URI) {
// A named graph
final BNode ng = vf.createBNode();
writer.handleStatement(vf.createStatement(dataset, SPARQL_SD.namedGraph, ng));
writer.handleStatement(vf.createStatement(ng, RDF.TYPE, SPARQL_SD.NamedGraph));
writer.handleStatement(vf.createStatement(ng, SPARQL_SD.name, c));
final BNode g = vf.createBNode();
writer.handleStatement(vf.createStatement(ng, SPARQL_SD.graph, g));
writer.handleStatement(vf.createStatement(g, RDF.TYPE, SPARQL_SD.Graph));
// TODO: Number of triples here? This can be expensive!
writer.handleStatement(vf.createStatement(g, vf.createURI("http://rdfs.org/ns/void#triples"), vf.createLiteral(kiwiCon.size(c))));
}
}
} finally {
cID.close();