01: /**
02: *
03: */package org.ontoware.rdfreactor.runtime;
04:
05: import java.util.Iterator;
06:
07: import org.ontoware.rdf2go.exception.ModelRuntimeException;
08: import org.ontoware.rdf2go.model.Model;
09: import org.ontoware.rdf2go.model.node.Node;
10:
11: /**
12: * Wrapper class for an Iterator over URI or BlankNode or Literal objects,
13: * which are objects of triples in the model.
14: * Only RDF Reactor compatible subjects can be extracted from the Iterator.
15: *
16: * @author $Author: xamde $
17: * @version $Id: ObjectResultIterator.java,v 1.7 2006/10/16 17:31:58 xamde Exp $
18: *
19: */
20:
21: public class ObjectResultIterator<E> implements Iterator<E> {
22:
23: private Iterator<Node> it;
24:
25: private Class<?> returnType;
26:
27: private Model m;
28:
29: /**
30: * Constrcutor for the wrapper around an Iterator over URI or BlankNode or Literal triple objects.
31: *
32: * @param m -
33: * the underlying RDF2Go model
34: * @param it -
35: * Iterator over Statements
36: * @param returnType -
37: * the desired Java return type for extracting objects from the Iterator
38: */
39: public ObjectResultIterator(Model m, Iterator<Node> it,
40: Class<?> returnType) {
41: this .it = it;
42: this .returnType = returnType;
43: this .m = m;
44: }
45:
46: public boolean hasNext() {
47: return it.hasNext();
48: }
49:
50: @SuppressWarnings(value="unchecked")
51: public E next() {
52: Node node = it.next();
53: Object typedObject;
54: try {
55: typedObject = RDFReactorRuntime.node2javatype(this .m, node,
56: returnType);
57: // TODO: can this be done better in Java 1.5?
58: return (E) typedObject;
59: } catch (ModelRuntimeException e) {
60: throw new ModelRuntimeException(e);
61: }
62: }
63:
64: public void remove() {
65: it.remove();
66: }
67:
68: }
|