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.util.Iterator;
021: import java.util.List;
022:
023: import org.geotools.feature.Feature;
024: import org.geotools.feature.FeatureCollection;
025: import org.geotools.feature.FeatureIterator;
026: import org.geotools.feature.iso.Types;
027: import org.geotools.feature.iso.collection.AbstractSimpleFeatureCollection;
028: import org.geotools.feature.iso.type.AttributeDescriptorImpl;
029: import org.opengis.feature.simple.SimpleFeatureFactory;
030: import org.opengis.feature.simple.SimpleFeatureType;
031: import org.opengis.feature.type.AttributeDescriptor;
032: import org.opengis.feature.type.Name;
033:
034: /**
035: *
036: * @author Gabriel Roldan, Axios Engineering
037: * @version $Id: FeatureCollectionAdapter.java 26649 2007-08-22 09:55:31Z groldan $
038: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/community-schemas/community-schema-ds/src/main/java/org/geotools/data/feature/adapter/FeatureCollectionAdapter.java $
039: * @since 2.4
040: */
041: public class FeatureCollectionAdapter extends
042: AbstractSimpleFeatureCollection {
043:
044: private FeatureCollection gtFeatures;
045:
046: private SimpleFeatureType isoType;
047:
048: private SimpleFeatureFactory attributeFactory;
049:
050: private int maxFeatures = Integer.MAX_VALUE;
051:
052: private AttributeDescriptor featureDescriptor;
053:
054: public FeatureCollectionAdapter(SimpleFeatureType isoType,
055: FeatureCollection features,
056: SimpleFeatureFactory attributeFactory) {
057: super (null, null);
058: this .isoType = isoType;
059: this .gtFeatures = features;
060:
061: Name typeName = isoType.getName();
062: Name name = Types.typeName(typeName.getNamespaceURI(), typeName
063: .getLocalPart());
064: featureDescriptor = new AttributeDescriptorImpl(isoType, name,
065: 0, Integer.MAX_VALUE, true, null);
066: }
067:
068: // public Iterator iterator() {
069: // final Iterator gtFeatureIterator = gtFeatures.iterator();
070: //
071: // Iterator isoFeatures = new Iterator() {
072: // int featureCount = 0;
073: // public boolean hasNext() {
074: // return featureCount <= maxFeatures && gtFeatureIterator.hasNext();
075: // }
076: //
077: // public Object next() {
078: // featureCount++;
079: // Feature gtFeature = (Feature) gtFeatureIterator.next();
080: // org.opengis.feature.Feature isoFeature;
081: // isoFeature = new ISOFeatureAdapter(gtFeature, isoType, attributeFactory, featureDescriptor);
082: // return isoFeature;
083: // }
084: //
085: // public void remove() {
086: // gtFeatureIterator.remove();
087: // }
088: //
089: // };
090: // return isoFeatures;
091: // }
092:
093: public int size() {
094: return gtFeatures.size();
095: }
096:
097: public int getMaxFeatures() {
098: return maxFeatures;
099: }
100:
101: public void setMaxFeatures(int maxFeatures) {
102: this .maxFeatures = maxFeatures;
103: }
104:
105: protected void closeIterator(Iterator close) throws IOException {
106: FeatureIteratorWrapper wrapper = (FeatureIteratorWrapper) close;
107: wrapper.close();
108: }
109:
110: protected Iterator openIterator() throws IOException {
111: final FeatureIterator gtFeatureIterator = gtFeatures.features();
112: final FeatureIteratorWrapper wrapper = new FeatureIteratorWrapper(
113: gtFeatureIterator);
114: return wrapper;
115: }
116:
117: public Object operation(Name arg0, List arg1) {
118: return null;
119: }
120:
121: private class FeatureIteratorWrapper implements Iterator {
122: final FeatureIterator gtFeatureIterator;
123: int featureCount = 0;
124:
125: public FeatureIteratorWrapper(FeatureIterator gtFeatureIterator) {
126: this .gtFeatureIterator = gtFeatureIterator;
127: }
128:
129: public boolean hasNext() {
130: return featureCount <= maxFeatures
131: && gtFeatureIterator.hasNext();
132: }
133:
134: public Object next() {
135: featureCount++;
136: Feature gtFeature = (Feature) gtFeatureIterator.next();
137: org.opengis.feature.Feature isoFeature;
138: isoFeature = new ISOFeatureAdapter(gtFeature, isoType,
139: attributeFactory, featureDescriptor);
140: return isoFeature;
141: }
142:
143: public void remove() {
144: throw new UnsupportedOperationException();
145: }
146:
147: public void close() {
148: this .gtFeatureIterator.close();
149: }
150:
151: }
152:
153: public List get(Name name) {
154: throw new UnsupportedOperationException("not implemented yet");
155: }
156: }
|