01: package org.geotools.data.gml;
02:
03: import java.io.IOException;
04: import java.io.InputStream;
05: import java.util.Iterator;
06:
07: import org.geotools.feature.Feature;
08: import org.geotools.xml.StreamingParser;
09:
10: public class GMLIterator implements Iterator {
11:
12: /**
13: * type entry
14: */
15: GMLTypeEntry entry;
16: /**
17: * The parser + input
18: */
19: InputStream input;
20: StreamingParser parser;
21:
22: /**
23: * The next feature
24: */
25: Feature feature;
26:
27: GMLIterator(GMLTypeEntry entry) throws IOException {
28:
29: this .entry = entry;
30:
31: try {
32: input = entry.parent().document();
33: parser = new StreamingParser(
34: entry.parent().configuration(), input, "//"
35: + entry.getTypeName());
36: } catch (Exception e) {
37: throw (IOException) new IOException().initCause(e);
38: }
39: }
40:
41: public Object next() {
42: return feature;
43: }
44:
45: public boolean hasNext() {
46: feature = (Feature) parser.parse();
47: return feature != null;
48: }
49:
50: public void remove() {
51: throw new UnsupportedOperationException();
52: }
53:
54: public void close() throws IOException {
55: input.close();
56: input = null;
57: parser = null;
58: feature = null;
59: }
60: }
|