01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.vfny.geoserver.global;
06:
07: import org.geotools.data.DataSourceException;
08: import org.geotools.data.DefaultQuery;
09: import org.geotools.data.Query;
10: import org.geotools.data.VersioningFeatureSource;
11: import org.geotools.data.VersioningFeatureStore;
12: import org.geotools.data.postgis.FeatureDiffReader;
13: import org.geotools.feature.FeatureCollection;
14: import org.geotools.feature.FeatureType;
15: import org.opengis.filter.Filter;
16: import org.opengis.referencing.crs.CoordinateReferenceSystem;
17: import java.io.IOException;
18:
19: public class GeoServerVersioningFeatureStore extends
20: GeoServerFeatureStore implements VersioningFeatureStore {
21: GeoServerVersioningFeatureStore(VersioningFeatureStore store,
22: FeatureType schema, Filter definitionQuery,
23: CoordinateReferenceSystem declaredCRS, int srsHandling) {
24: super (store, schema, definitionQuery, declaredCRS, srsHandling);
25: }
26:
27: public void rollback(String toVersion, Filter filter, String[] users)
28: throws IOException {
29: ((VersioningFeatureStore) source).rollback(toVersion, filter,
30: users);
31: }
32:
33: public FeatureDiffReader getDifferences(String fromVersion,
34: String toVersion, Filter filter, String[] users)
35: throws IOException {
36: // TODO: if we are bound to a smaller schema, we should remove the
37: // hidden attributes from the differences
38: return ((VersioningFeatureSource) source).getDifferences(
39: fromVersion, toVersion, filter, users);
40: }
41:
42: public FeatureCollection getLog(String fromVersion,
43: String toVersion, Filter filter, String[] users,
44: int maxFeatures) throws IOException {
45: return ((VersioningFeatureSource) source).getLog(fromVersion,
46: toVersion, filter, users, maxFeatures);
47: }
48:
49: public FeatureCollection getVersionedFeatures(Query query)
50: throws IOException {
51: final VersioningFeatureSource versioningSource = ((VersioningFeatureSource) source);
52: Query newQuery = adaptQuery(query, versioningSource
53: .getVersionedFeatures().getSchema());
54:
55: CoordinateReferenceSystem targetCRS = query
56: .getCoordinateSystemReproject();
57: try {
58: //this is the raw "unprojected" feature collection
59:
60: FeatureCollection fc = versioningSource
61: .getVersionedFeatures(newQuery);
62:
63: return reprojectFeatureCollection(targetCRS, fc);
64: } catch (Exception e) {
65: throw new DataSourceException(e);
66: }
67: }
68:
69: public FeatureCollection getVersionedFeatures(Filter filter)
70: throws IOException {
71: return getFeatures(new DefaultQuery(schema.getTypeName(),
72: filter));
73: }
74:
75: public FeatureCollection getVersionedFeatures() throws IOException {
76: return getFeatures(Query.ALL);
77: }
78: }
|