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.VersioningFeatureLocking;
11: import org.geotools.data.VersioningFeatureSource;
12: import org.geotools.data.VersioningFeatureStore;
13: import org.geotools.data.postgis.FeatureDiffReader;
14: import org.geotools.feature.FeatureCollection;
15: import org.geotools.feature.FeatureType;
16: import org.opengis.filter.Filter;
17: import org.opengis.referencing.crs.CoordinateReferenceSystem;
18: import java.io.IOException;
19:
20: /**
21: * Versioning wrapper that preserves the versioning nature of a feature locking
22: *
23: * @TODO: once the experiment is over, move this back to the main module
24: * @author Andrea Aime, TOPP
25: *
26: */
27: public class GeoServerVersioningFeatureLocking extends
28: GeoServerFeatureLocking implements VersioningFeatureLocking {
29: GeoServerVersioningFeatureLocking(VersioningFeatureLocking locking,
30: FeatureType schema, Filter definitionQuery,
31: CoordinateReferenceSystem declaredCRS, int srsHandling) {
32: super (locking, schema, definitionQuery, declaredCRS,
33: srsHandling);
34: }
35:
36: public void rollback(String toVersion, Filter filter, String[] users)
37: throws IOException {
38: ((VersioningFeatureStore) source).rollback(toVersion, filter,
39: users);
40: }
41:
42: public FeatureDiffReader getDifferences(String fromVersion,
43: String toVersion, Filter filter, String[] users)
44: throws IOException {
45: // TODO: if we are bound to a smaller schema, we should remove the
46: // hidden attributes from the differences
47: return ((VersioningFeatureSource) source).getDifferences(
48: fromVersion, toVersion, filter, users);
49: }
50:
51: public FeatureCollection getLog(String fromVersion,
52: String toVersion, Filter filter, String[] users,
53: int maxFeatures) throws IOException {
54: return ((VersioningFeatureSource) source).getLog(fromVersion,
55: toVersion, filter, users, maxFeatures);
56: }
57:
58: public FeatureCollection getVersionedFeatures(Query query)
59: throws IOException {
60: final VersioningFeatureSource versioningSource = ((VersioningFeatureSource) source);
61: Query newQuery = adaptQuery(query, versioningSource
62: .getVersionedFeatures().getSchema());
63:
64: CoordinateReferenceSystem targetCRS = query
65: .getCoordinateSystemReproject();
66: try {
67: //this is the raw "unprojected" feature collection
68:
69: FeatureCollection fc = versioningSource
70: .getVersionedFeatures(newQuery);
71:
72: return reprojectFeatureCollection(targetCRS, fc);
73: } catch (Exception e) {
74: throw new DataSourceException(e);
75: }
76: }
77:
78: public FeatureCollection getVersionedFeatures(Filter filter)
79: throws IOException {
80: return getFeatures(new DefaultQuery(schema.getTypeName(),
81: filter));
82: }
83:
84: public FeatureCollection getVersionedFeatures() throws IOException {
85: return getFeatures(Query.ALL);
86: }
87: }
|