001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package org.geotools.data.wfs;
016:
017: import java.io.IOException;
018: import java.util.Iterator;
019: import java.util.List;
020:
021: import org.geotools.data.DefaultQuery;
022: import org.geotools.data.FeatureReader;
023: import org.geotools.data.Query;
024: import org.geotools.data.Transaction;
025: import org.geotools.data.ows.FeatureSetDescription;
026: import org.geotools.factory.CommonFactoryFinder;
027: import org.geotools.feature.FeatureType;
028: import org.geotools.filter.IllegalFilterException;
029: import org.opengis.filter.Filter;
030: import org.opengis.filter.FilterFactory;
031: import org.opengis.filter.spatial.BBOX;
032:
033: import com.vividsolutions.jts.geom.Envelope;
034:
035: /**
036: * This strategy addresses a bug in most MapServer implementations where a filter is required in order for all the features to
037: * be returned. So if the Filter is Filter.NONE or Query.ALL then a BBox Filter is constructed that is the entire layer.
038: *
039: * @author Jesse
040: * @since 1.1.0
041: */
042: public class MapServerWFSStrategy extends StrictWFSStrategy implements
043: WFSStrategy {
044:
045: public MapServerWFSStrategy(WFSDataStore store) {
046: super (store);
047: }
048:
049: protected FeatureReader createFeatureReader(
050: Transaction transaction, Query query) throws IOException {
051: return new MapServerWFSFeatureReader(transaction, query,
052: COMPLIANCE_LEVEL);
053: }
054:
055: protected class MapServerWFSFeatureReader extends
056: StrictFeatureReader {
057:
058: public MapServerWFSFeatureReader(Transaction transaction,
059: Query query, Integer level) throws IOException {
060: super (transaction, query, level);
061: }
062:
063: protected void init(Transaction transaction, Query query,
064: Integer level) throws IOException {
065: Filter filter = query.getFilter();
066: Query query2;
067: if (filter == Filter.INCLUDE) {
068: FilterFactory fac = CommonFactoryFinder
069: .getFilterFactory(null);
070: try {
071: FeatureType schema = store.getSchema(query
072: .getTypeName());
073: String attName = schema.getDefaultGeometry()
074: .getName();
075:
076: List fts = store.capabilities.getFeatureTypes(); // FeatureSetDescription
077: Iterator i = fts.iterator();
078: String desiredType = query.getTypeName().substring(
079: query.getTypeName().indexOf(":") + 1);
080:
081: Envelope bbox = null;
082: while (i.hasNext()) {
083: FeatureSetDescription fsd = (FeatureSetDescription) i
084: .next();
085: String fsdName = (fsd.getName() == null) ? null
086: : fsd.getName().substring(
087: fsd.getName().indexOf(":") + 1);
088:
089: if (desiredType.equals(fsdName)) {
090: bbox = fsd.getLatLongBoundingBox();
091:
092: }
093: }
094:
095: if (bbox == null) {
096: query2 = query;
097: } else {
098: BBOX newFilter = fac
099: .bbox(attName, bbox.getMinX(), bbox
100: .getMinY(), bbox.getMaxX(),
101: bbox.getMaxY(), "EPSG:4326");
102:
103: query2 = new DefaultQuery(query.getTypeName(),
104: query.getNamespace(), newFilter, query
105: .getMaxFeatures(), query
106: .getPropertyNames(), query
107: .getHandle());
108: }
109: } catch (IllegalFilterException e) {
110: query2 = query;
111: }
112: } else
113: query2 = query;
114: super.init(transaction, query2, level);
115: }
116:
117: }
118:
119: }
|