use of org.eclipse.rdf4j.query.parser.sparql.ast.ASTDatasetClause in project rdf4j by eclipse.
the class DatasetDeclProcessor method process.
/**
* Extracts a SPARQL {@link Dataset} from an ASTQueryContainer, if one is contained. Returns null
* otherwise.
*
* @param qc
* The query model to resolve relative URIs in.
* @throws MalformedQueryException
* If DatasetClause does not contain a valid URI.
*/
public static Dataset process(ASTOperationContainer qc) throws MalformedQueryException {
SimpleDataset dataset = null;
ASTOperation op = qc.getOperation();
if (op != null) {
List<ASTDatasetClause> datasetClauses = op.getDatasetClauseList();
if (!datasetClauses.isEmpty()) {
dataset = new SimpleDataset();
for (ASTDatasetClause dc : datasetClauses) {
ASTIRI astIri = dc.jjtGetChild(ASTIRI.class);
try {
IRI uri = SESAME.NIL;
if (astIri != null) {
uri = SimpleValueFactory.getInstance().createIRI(astIri.getValue());
}
boolean withClause = false;
if (op instanceof ASTModify) {
if (dc.equals(((ASTModify) op).getWithClause())) {
withClause = true;
dataset.setDefaultInsertGraph(uri);
dataset.addDefaultRemoveGraph(uri);
}
}
// clauses.
if (!withClause || datasetClauses.size() == 1) {
if (dc.isNamed()) {
dataset.addNamedGraph(uri);
} else {
dataset.addDefaultGraph(uri);
}
}
} catch (IllegalArgumentException e) {
throw new MalformedQueryException(e.getMessage(), e);
}
}
}
}
return dataset;
}
Aggregations