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.geoserver.feature.RetypingFeatureCollection;
008: import org.geotools.data.FeatureReader;
009: import org.geotools.data.FeatureStore;
010: import org.geotools.data.Transaction;
011: import org.geotools.feature.AttributeType;
012: import org.geotools.feature.FeatureCollection;
013: import org.geotools.feature.FeatureType;
014: import org.opengis.filter.Filter;
015: import org.opengis.referencing.crs.CoordinateReferenceSystem;
016: import java.io.IOException;
017: import java.util.Set;
018:
019: /**
020: * GeoServer wrapper for backend Geotools2 DataStore.
021: *
022: * <p>
023: * Support FeatureSource decorator for FeatureTypeInfo that takes care of
024: * mapping the FeatureTypeInfo's FeatureSource with the schema and definition
025: * query configured for it.
026: * </p>
027: *
028: * <p>
029: * Because GeoServer requires that attributes always be returned in the same
030: * order we need a way to smoothly inforce this. Could we use this class to do
031: * so? It would need to support writing and locking though.
032: * </p>
033: *
034: * @author Gabriel Rold?n
035: * @version $Id: GeoServerFeatureStore.java 7265 2007-07-18 12:51:13Z aaime $
036: */
037: public class GeoServerFeatureStore extends GeoServerFeatureSource
038: implements FeatureStore {
039: /**
040: * Creates a new DEFQueryFeatureLocking object.
041: *
042: * @param store GeoTools2 FeatureSource
043: * @param schema FeatureType served by source
044: * @param definitionQuery Filter that constrains source
045: * @param declaredCRS Geometries will be forced to this CRS (or null, if no forcing is needed)
046: * @param srsHandling
047: */
048: GeoServerFeatureStore(FeatureStore store, FeatureType schema,
049: Filter definitionQuery,
050: CoordinateReferenceSystem declaredCRS, int srsHandling) {
051: super (store, schema, definitionQuery, declaredCRS, srsHandling);
052: }
053:
054: /**
055: * FeatureStore access (to save casting)
056: *
057: * @return DOCUMENT ME!
058: */
059: FeatureStore store() {
060: return (FeatureStore) source;
061: }
062:
063: /**
064: * see interface for details.
065: * @param fc
066: * @return
067: * @throws IOException
068: */
069: public Set addFeatures(FeatureCollection fc) throws IOException {
070: FeatureStore store = store();
071:
072: //check if the feature collection needs to be retyped
073: if (!store.getSchema().equals(fc.getSchema())) {
074: fc = new RetypingFeatureCollection(fc, store.getSchema());
075: }
076:
077: return store().addFeatures(fc);
078: }
079:
080: /**
081: * DOCUMENT ME!
082: *
083: * @param filter DOCUMENT ME!
084: *
085: * @throws IOException DOCUMENT ME!
086: */
087: public void removeFeatures(Filter filter) throws IOException {
088: filter = makeDefinitionFilter(filter);
089:
090: store().removeFeatures(filter);
091: }
092:
093: /**
094: * DOCUMENT ME!
095: *
096: * @param type DOCUMENT ME!
097: * @param value DOCUMENT ME!
098: * @param filter DOCUMENT ME!
099: *
100: * @throws IOException DOCUMENT ME!
101: *
102: * @task REVISIT: should we check that non exposed attributes are requiered
103: * in <code>type</code>?
104: */
105: public void modifyFeatures(AttributeType[] type, Object[] value,
106: Filter filter) throws IOException {
107: filter = makeDefinitionFilter(filter);
108:
109: store().modifyFeatures(type, value, filter);
110: }
111:
112: /**
113: * DOCUMENT ME!
114: *
115: * @param type DOCUMENT ME!
116: * @param value DOCUMENT ME!
117: * @param filter DOCUMENT ME!
118: *
119: * @throws IOException DOCUMENT ME!
120: */
121: public void modifyFeatures(AttributeType type, Object value,
122: Filter filter) throws IOException {
123: filter = makeDefinitionFilter(filter);
124:
125: store().modifyFeatures(type, value, filter);
126: }
127:
128: /**
129: * DOCUMENT ME!
130: *
131: * @param reader DOCUMENT ME!
132: *
133: * @throws IOException DOCUMENT ME!
134: */
135: public void setFeatures(FeatureReader reader) throws IOException {
136: FeatureStore store = store();
137:
138: //check if the feature reader needs to be retyped
139: if (!store.getSchema().equals(reader.getFeatureType())) {
140: reader = new RetypingFeatureCollection.RetypingFeatureReader(
141: reader, store.getSchema());
142: }
143:
144: store().setFeatures(reader);
145: }
146:
147: /**
148: * DOCUMENT ME!
149: *
150: * @param transaction DOCUMENT ME!
151: */
152: public void setTransaction(Transaction transaction) {
153: store().setTransaction(transaction);
154: }
155:
156: /**
157: * DOCUMENT ME!
158: *
159: * @return DOCUMENT ME!
160: */
161: public Transaction getTransaction() {
162: return store().getTransaction();
163: }
164: }
|