001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.global;
006:
007: import org.geotools.data.DataSourceException;
008: import org.geotools.data.DefaultQuery;
009: import org.geotools.data.Query;
010: import org.geotools.data.VersioningFeatureLocking;
011: import org.geotools.data.VersioningFeatureSource;
012: import org.geotools.data.VersioningFeatureStore;
013: import org.geotools.data.postgis.FeatureDiffReader;
014: import org.geotools.feature.FeatureCollection;
015: import org.geotools.feature.FeatureType;
016: import org.opengis.filter.Filter;
017: import org.opengis.referencing.crs.CoordinateReferenceSystem;
018: import java.io.IOException;
019:
020: /**
021: * Versioning wrapper that preserves the versioning nature of a feature source
022: *
023: * @TODO: once the experiment is over, move this back to the main module
024: * @author Andrea Aime, TOPP
025: *
026: */
027: public class GeoServerVersioningFeatureSource extends
028: GeoServerFeatureSource implements VersioningFeatureSource {
029: GeoServerVersioningFeatureSource(VersioningFeatureSource source,
030: FeatureType schema, Filter definitionQuery,
031: CoordinateReferenceSystem declaredCRS, int srsHandling) {
032: super (source, schema, definitionQuery, declaredCRS, srsHandling);
033: }
034:
035: public FeatureDiffReader getDifferences(String fromVersion,
036: String toVersion, Filter filter, String[] users)
037: throws IOException {
038: // TODO: if we are bound to a smaller schema, we should remove the
039: // hidden attributes from the differences
040: return ((VersioningFeatureSource) source).getDifferences(
041: fromVersion, toVersion, filter, users);
042: }
043:
044: public FeatureCollection getLog(String fromVersion,
045: String toVersion, Filter filter, String[] users,
046: int maxFeatures) throws IOException {
047: return ((VersioningFeatureSource) source).getLog(fromVersion,
048: toVersion, filter, users, maxFeatures);
049: }
050:
051: /**
052: * Factory that make the correct decorator for the provided featureSource.
053: *
054: * <p>
055: * This factory method is public and will be used to create all required
056: * subclasses. By comparison the constructors for this class have package
057: * visibiliy.
058: * </p>
059: *
060: * @param featureSource
061: * @param schema
062: * @param definitionQuery
063: * @param declaredCRS
064: *
065: *
066: * @return
067: */
068: public static GeoServerFeatureSource create(
069: VersioningFeatureSource featureSource, FeatureType schema,
070: Filter definitionQuery,
071: CoordinateReferenceSystem declaredCRS, int srsHandling) {
072: if (featureSource instanceof VersioningFeatureLocking) {
073: return new GeoServerVersioningFeatureLocking(
074: (VersioningFeatureLocking) featureSource, schema,
075: definitionQuery, declaredCRS, srsHandling);
076: } else if (featureSource instanceof VersioningFeatureStore) {
077: return new GeoServerVersioningFeatureStore(
078: (VersioningFeatureStore) featureSource, schema,
079: definitionQuery, declaredCRS, srsHandling);
080: }
081:
082: return new GeoServerVersioningFeatureSource(featureSource,
083: schema, definitionQuery, declaredCRS, srsHandling);
084: }
085:
086: public FeatureCollection getVersionedFeatures(Query query)
087: throws IOException {
088: final VersioningFeatureSource versioningSource = ((VersioningFeatureSource) source);
089: Query newQuery = adaptQuery(query, versioningSource
090: .getVersionedFeatures().getSchema());
091:
092: CoordinateReferenceSystem targetCRS = query
093: .getCoordinateSystemReproject();
094: try {
095: //this is the raw "unprojected" feature collection
096:
097: FeatureCollection fc = versioningSource
098: .getVersionedFeatures(newQuery);
099:
100: return reprojectFeatureCollection(targetCRS, fc);
101: } catch (Exception e) {
102: throw new DataSourceException(e);
103: }
104: }
105:
106: public FeatureCollection getVersionedFeatures(Filter filter)
107: throws IOException {
108: return getFeatures(new DefaultQuery(schema.getTypeName(),
109: filter));
110: }
111:
112: public FeatureCollection getVersionedFeatures() throws IOException {
113: return getFeatures(Query.ALL);
114: }
115: }
|