01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2005-2006, 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: package org.geotools.data.collection;
17:
18: import java.io.IOException;
19: import java.util.NoSuchElementException;
20:
21: import org.geotools.data.DataSourceException;
22: import org.geotools.data.FeatureReader;
23: import org.geotools.feature.Feature;
24: import org.geotools.feature.FeatureIterator;
25: import org.geotools.feature.FeatureType;
26: import org.geotools.feature.IllegalAttributeException;
27:
28: /**
29: * A FeatureReader that wraps up a normal FeatureIterator.
30: * <p>
31: * This class is useful for faking (and testing) the Resource based
32: * API against in memory datastructures. You are warned that to
33: * complete the illusion that Resource based IO is occuring content
34: * will be duplicated.
35: * </p>
36: * @author Jody Garnett, Refractions Research, Inc.
37: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/data/collection/DelegateFeatureReader.java $
38: */
39: public class DelegateFeatureReader implements FeatureReader {
40: FeatureIterator delegate;
41: FeatureType schema;
42:
43: public DelegateFeatureReader(FeatureType featureType,
44: FeatureIterator features) {
45: this .schema = featureType;
46: this .delegate = features;
47: }
48:
49: public FeatureType getFeatureType() {
50: return schema;
51: }
52:
53: public Feature next() throws IOException,
54: IllegalAttributeException, NoSuchElementException {
55: if (delegate == null) {
56: throw new IOException("Feature Reader has been closed");
57: }
58: try {
59: Feature feature = delegate.next();
60: // obj = schema.duplicate( obj );
61: return feature;
62: } catch (NoSuchElementException end) {
63: throw new DataSourceException("There are no more Features",
64: end);
65: }
66: }
67:
68: public boolean hasNext() throws IOException {
69: return delegate != null && delegate.hasNext();
70: }
71:
72: public void close() throws IOException {
73: if (delegate != null)
74: delegate.close();
75: delegate = null;
76: schema = null;
77: }
78:
79: }
|