01: /*
02: * Geotools2 - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package org.geotools.feature;
18:
19: import java.io.IOException;
20: import java.util.Iterator;
21: import java.util.NoSuchElementException;
22:
23: import org.geotools.data.FeatureReader;
24:
25: /**
26: * An iterator that wraps around a FeatureReader.
27: * The Iterator's hasNext() will return false if the wrapped feature reader's
28: * hasNext method throws an exception. If next() throws an exeption a NoSuchElementException
29: * will be thrown.
30: *
31: * @author jeichar
32: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/feature/FeatureReaderIterator.java $
33: */
34: public class FeatureReaderIterator implements Iterator {
35:
36: private FeatureReader reader;
37:
38: /**
39: *
40: */
41: public FeatureReaderIterator(FeatureReader reader) {
42: this .reader = reader;
43: }
44:
45: /* (non-Javadoc)
46: * @see java.util.Iterator#hasNext()
47: */
48: public boolean hasNext() {
49: try {
50: return reader.hasNext();
51: } catch (Exception e) {
52: return false;
53: }
54: }
55:
56: /* (non-Javadoc)
57: * @see java.util.Iterator#next()
58: */
59: public Object next() {
60: try {
61: return reader.next();
62: } catch (Exception e) {
63: throw new NoSuchElementException(
64: "Exception raised during next: "
65: + e.getLocalizedMessage());
66: }
67: }
68:
69: /* (non-Javadoc)
70: * @see java.util.Iterator#remove()
71: */
72: public void remove() {
73: throw new UnsupportedOperationException("Iterator is read only");
74: }
75:
76: public void close() {
77: try {
78: reader.close();
79: } catch (IOException e) {
80: e.printStackTrace();
81: }
82: }
83:
84: }
|