01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-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.postgis;
17:
18: import java.io.IOException;
19: import java.util.NoSuchElementException;
20:
21: import org.geotools.data.FeatureReader;
22: import org.geotools.data.postgis.fidmapper.VersionedFIDMapper;
23: import org.geotools.feature.Feature;
24: import org.geotools.feature.FeatureType;
25: import org.geotools.feature.IllegalAttributeException;
26:
27: /**
28: * A feature reader for versioned features. It assumes the internal reader has
29: * already been configured not to return versioning columns, so simply handles
30: * FID mutation.
31: *
32: * @author aaime
33: * @since 2.4
34: *
35: */
36: class VersionedFeatureReader implements FeatureReader {
37:
38: private FeatureReader wrapped;
39:
40: private VersionedFIDMapper fidMapper;
41:
42: public VersionedFeatureReader(FeatureReader wrapped,
43: VersionedFIDMapper fidMapper) {
44: this .wrapped = wrapped;
45: this .fidMapper = fidMapper;
46: }
47:
48: public void close() throws IOException {
49: wrapped.close();
50: }
51:
52: public FeatureType getFeatureType() {
53: return wrapped.getFeatureType();
54: }
55:
56: public boolean hasNext() throws IOException {
57: return wrapped.hasNext();
58: }
59:
60: public Feature next() throws IOException,
61: IllegalAttributeException, NoSuchElementException {
62: Feature feature = wrapped.next();
63: FeatureType featureType = wrapped.getFeatureType();
64: String id = feature.getID();
65:
66: return featureType.create(feature
67: .getAttributes(new Object[featureType
68: .getAttributeCount()]), fidMapper
69: .getUnversionedFid(id));
70: }
71: }
|