01: package org.ontoware.rdfreactor.runtime;
02:
03: import org.ontoware.aifbcommons.collection.ClosableIterator;
04: import org.ontoware.rdf2go.model.QueryRow;
05:
06: /**
07: * Wrapper class to iterate over an array of elements returned from a SPARQL
08: * Query.
09: *
10: * @author mvo
11: */
12: class SparqlIterator implements ClosableIterator<OOQueryRow> {
13:
14: private OOQueryResultTableImpl ooQueryResultTable;
15: private ClosableIterator<QueryRow> rdf2goIterator;
16:
17: /**
18: * Constructor for the wrapper class over the results of a SPARQL Query.
19: */
20: public SparqlIterator(OOQueryResultTableImpl impl,
21: ClosableIterator<QueryRow> it) {
22: this .ooQueryResultTable = impl;
23: this .rdf2goIterator = it;
24: }
25:
26: public boolean hasNext() {
27: return rdf2goIterator.hasNext();
28: }
29:
30: public OOQueryRow next() {
31: if (hasNext()) {
32: QueryRow rdf2go = rdf2goIterator.next();
33: OOQueryRow ooRow = new OOQueryRowImpl(ooQueryResultTable,
34: rdf2go);
35: return ooRow;
36: } else {
37: rdf2goIterator.close();
38: rdf2goIterator = null;
39: return null;
40: }
41: }
42:
43: public void remove() {
44: rdf2goIterator.remove();
45: }
46:
47: public void close() {
48: rdf2goIterator.close();
49: }
50:
51: }
|