01: package org.ontoware.rdf2go.impl.jena24;
02:
03: import org.ontoware.aifbcommons.collection.ClosableIterator;
04: import org.ontoware.rdf2go.exception.ModelRuntimeException;
05: import org.ontoware.rdf2go.model.QueryRow;
06: import org.ontoware.rdf2go.model.impl.QueryRowImpl;
07:
08: import com.hp.hpl.jena.query.QuerySolution;
09: import com.hp.hpl.jena.query.ResultSet;
10: import com.hp.hpl.jena.rdf.model.RDFNode;
11:
12: public class QueryIterator implements ClosableIterator<QueryRow> {
13:
14: private ResultSet resultSet;
15:
16: private QueryResultTableImpl table;
17:
18: public QueryIterator(QueryResultTableImpl table, ResultSet results) {
19: this .resultSet = results;
20: this .table = table;
21: }
22:
23: public boolean hasNext() {
24: return this .resultSet.hasNext();
25: }
26:
27: public QueryRow next() {
28: QuerySolution qs = this .resultSet.nextSolution();
29: QueryRowImpl row = new QueryRowImpl();
30: for (String v : table.getVariables()) {
31: RDFNode node = qs.get(v);
32: assert node != null : "null node for varname " + v
33: + ". Do you have unbound variables in the query?";
34: try {
35: row.put(v, TypeConversion.toRDF2Go(node.asNode()));
36: } catch (ModelRuntimeException e) {
37: throw new ModelRuntimeException(e);
38: }
39: }
40: return row;
41: }
42:
43: public void remove() {
44: this .resultSet.remove();
45: }
46:
47: public void close() {
48: }
49:
50: }
|