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.geoserver.wfsv;
06:
07: import java.io.IOException;
08: import java.math.BigInteger;
09: import java.util.Calendar;
10: import java.util.List;
11:
12: import net.opengis.wfs.FeatureCollectionType;
13: import net.opengis.wfs.GetFeatureType;
14: import net.opengis.wfsv.VersionedFeatureCollectionType;
15: import net.opengis.wfsv.WfsvFactory;
16:
17: import org.geoserver.wfs.GetFeature;
18: import org.geoserver.wfs.WFS;
19: import org.geoserver.wfs.WFSException;
20: import org.geotools.data.FeatureSource;
21: import org.geotools.data.Query;
22: import org.geotools.data.VersioningFeatureSource;
23: import org.geotools.feature.FeatureCollection;
24: import org.vfny.geoserver.global.Data;
25:
26: /**
27: * An extension of {@link GetFeature} returning collection of versioned features
28: * @author Administrator
29: *
30: */
31: public class VersionedGetFeature extends GetFeature {
32:
33: public VersionedGetFeature(WFS wfs, Data catalog) {
34: super (wfs, catalog);
35: }
36:
37: protected FeatureCollection getFeatures(GetFeatureType request,
38: FeatureSource source, Query gtQuery) throws IOException {
39: if (!(source instanceof VersioningFeatureSource))
40: throw new WFSException(source.getSchema().getTypeName()
41: + " is not versioned, cannot "
42: + "execute a GetVersionedFeature on it");
43: return ((VersioningFeatureSource) source)
44: .getVersionedFeatures(gtQuery);
45: }
46:
47: /**
48: * Allows subclasses to alter the result generation
49: * @param count
50: * @param results
51: * @param lockId
52: * @return
53: */
54: protected FeatureCollectionType buildResults(int count,
55: List results, String lockId) {
56: VersionedFeatureCollectionType result = WfsvFactory.eINSTANCE
57: .createVersionedFeatureCollectionType();
58: result.setNumberOfFeatures(BigInteger.valueOf(count));
59: result.setTimeStamp(Calendar.getInstance());
60: result.setLockId(lockId);
61: result.getFeature().addAll(results);
62: result.setVersion("xxx");
63: return result;
64: }
65:
66: }
|