001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package org.geotools.data.feature.adapter;
018:
019: import java.io.IOException;
020: import java.net.URI;
021: import java.util.Collection;
022: import java.util.Collections;
023: import java.util.Set;
024:
025: import org.geotools.catalog.GeoResourceInfo;
026: import org.geotools.data.DataStore;
027: import org.geotools.data.DefaultQuery;
028: import org.geotools.data.FeatureListener;
029: import org.geotools.data.FeatureSource;
030: import org.geotools.data.Query;
031: import org.geotools.data.Transaction;
032: import org.geotools.data.feature.FeatureSource2;
033: import org.geotools.feature.FeatureCollection;
034: import org.geotools.feature.FeatureType;
035: import org.geotools.feature.iso.Types;
036: import org.geotools.feature.iso.type.TypeFactoryImpl;
037: import org.opengis.feature.simple.SimpleFeatureFactory;
038: import org.opengis.feature.simple.SimpleFeatureType;
039: import org.opengis.feature.type.AttributeDescriptor;
040: import org.opengis.feature.type.Name;
041: import org.opengis.feature.type.TypeFactory;
042: import org.opengis.filter.Filter;
043: import org.opengis.filter.capability.FilterCapabilities;
044:
045: import com.vividsolutions.jts.geom.Envelope;
046:
047: /**
048: *
049: * @author Gabriel Roldan, Axios Engineering
050: * @version $Id: FeatureSource2Adapter.java 26649 2007-08-22 09:55:31Z groldan $
051: * @source $URL:
052: * http://svn.geotools.org/geotools/branches/2.4.x/modules/unsupported/community-schemas/community-schema-ds/src/main/java/org/geotools/data/feature/adapter/FeatureSource2Adapter.java $
053: * @since 2.4
054: */
055: public class FeatureSource2Adapter implements FeatureSource2 {
056:
057: private FeatureSource source;
058:
059: private FeatureAccessAdapter dataStore;
060:
061: private AttributeDescriptor descriptor;
062:
063: private SimpleFeatureType isoFeatureType;
064:
065: private SimpleFeatureFactory attributeFactory;
066:
067: public FeatureSource2Adapter(FeatureAccessAdapter dataStore,
068: FeatureSource featureSource,
069: SimpleFeatureFactory attributeFactory) {
070: this .dataStore = dataStore;
071: this .source = featureSource;
072: this .attributeFactory = attributeFactory;
073:
074: isoFeatureType = new ISOFeatureTypeAdapter(source.getSchema());
075: TypeFactory tf = new TypeFactoryImpl();
076: descriptor = tf.createAttributeDescriptor(isoFeatureType,
077: isoFeatureType.getName(), 0, Integer.MAX_VALUE, true,
078: null);
079: }
080:
081: public void addFeatureListener(FeatureListener listener) {
082: source.addFeatureListener(listener);
083: }
084:
085: public Envelope getBounds() throws IOException {
086: return source.getBounds();
087: }
088:
089: public Envelope getBounds(Query query) throws IOException {
090: return source.getBounds(query);
091: }
092:
093: public int getCount(Query query) throws IOException {
094: return source.getCount(query);
095: }
096:
097: public DataStore getDataStore() {
098: return this .dataStore;
099: }
100:
101: public FeatureCollection getFeatures(Query query)
102: throws IOException {
103: return source.getFeatures(query);
104: }
105:
106: public FeatureCollection getFeatures(Filter filter)
107: throws IOException {
108: return source.getFeatures(filter);
109: }
110:
111: public FeatureCollection getFeatures() throws IOException {
112: return source.getFeatures();
113: }
114:
115: public FeatureType getSchema() {
116: return source.getSchema();
117: }
118:
119: public void removeFeatureListener(FeatureListener listener) {
120: source.removeFeatureListener(listener);
121: }
122:
123: // ////////////////////////////////////////
124:
125: public Collection content() {
126: return content(Filter.INCLUDE);
127: }
128:
129: public Collection content(String query, String queryLanguage) {
130: throw new UnsupportedOperationException();
131: }
132:
133: public Collection content(Filter filter) {
134: return content(filter, Integer.MAX_VALUE);
135: }
136:
137: public Collection content(Filter filter, int countLimit) {
138: FeatureCollection features;
139: try {
140: DefaultQuery query = new DefaultQuery(source.getSchema()
141: .getTypeName());
142: query.setFilter(filter);
143: query.setMaxFeatures(countLimit);
144: features = source.getFeatures(query);
145: } catch (IOException e) {
146: throw (RuntimeException) new RuntimeException()
147: .initCause(e);
148: }
149: Collection isoFeatures = new FeatureCollectionAdapter(
150: isoFeatureType, features, attributeFactory);
151: return isoFeatures;
152: }
153:
154: public Object describe() {
155: return descriptor;
156: }
157:
158: public void dispose() {
159: // TODO: what to do?
160: }
161:
162: public FilterCapabilities getFilterCapabilities() {
163: throw new UnsupportedOperationException("Not yet implemented");
164: }
165:
166: public GeoResourceInfo getInfo() {
167: throw new UnsupportedOperationException("Not yet implemented");
168: }
169:
170: public Name getName() {
171: FeatureType gtType = source.getSchema();
172: URI namespace = gtType.getNamespace();
173: String nsUri = namespace == null ? null : namespace.toString();
174: String name = gtType.getTypeName();
175:
176: Name typeName = Types.typeName(nsUri, name);
177: return typeName;
178: }
179:
180: public void setTransaction(Transaction t) {
181: // DO NOTHING BY NOW
182: }
183:
184: public Set getSupportedHints() {
185: return Collections.EMPTY_SET;
186: }
187:
188: }
|