Permalink
Browse files

Updates for GeoTools FeatureCollection api changes

  • Loading branch information...
jdeolive
jdeolive committed Nov 3, 2012
1 parent 06bc9c7 commit bd8840dc637d5acf83e92fc072310faf5bde1352
Showing with 166 additions and 461 deletions.
  1. +1 −1 src/extension/excel/src/main/java/org/geoserver/wfs/response/ExcelOutputFormat.java
  2. +4 −3 .../imagemap/src/main/java/org/vfny/geoserver/wms/responses/map/htmlimagemap/HTMLImageMapWriter.java
  3. +7 −32 src/main/src/main/java/org/geoserver/feature/CompositeFeatureCollection.java
  4. +4 −21 src/main/src/main/java/org/geoserver/feature/ReprojectingFeatureCollection.java
  5. +8 −20 src/main/src/main/java/org/geoserver/feature/RetypingFeatureCollection.java
  6. +0 −5 src/main/src/main/java/org/geoserver/security/decorators/CheckAttributesFeatureCollection.java
  7. +0 −3 src/main/src/main/java/org/geoserver/security/decorators/DefaultSecureDataFactory.java
  8. +0 −137 src/main/src/main/java/org/geoserver/security/decorators/SecuredFeatureCollection.java
  9. +2 −0 src/main/src/main/java/org/geoserver/security/decorators/SecuredIterator.java
  10. +6 −1 src/main/src/main/java/org/geoserver/security/decorators/SecuredSimpleFeatureIterator.java
  11. +61 −83 src/main/src/test/java/org/geoserver/security/decorators/SecuredFeatureCollectionTest.java
  12. +2 −2 src/main/src/test/java/org/geoserver/template/FeatureWrapperTest.java
  13. +3 −2 src/web/demo/src/main/java/org/geoserver/web/crs/CRSAreaOfValidityMapBuilder.java
  14. +2 −2 src/wfs/src/main/java/org/geoserver/wfs/InsertElementHandler.java
  15. +4 −11 src/wfs/src/main/java/org/geoserver/wfs/LockFeature.java
  16. +3 −10 src/wfs/src/main/java/org/geoserver/wfs/UpdateElementHandler.java
  17. +1 −5 src/wfs/src/main/java/org/geoserver/wfs/response/CSVOutputFormat.java
  18. +1 −1 src/wfs/src/main/java/org/geoserver/wfs/response/GeoJSONOutputFormat.java
  19. +7 −23 src/wfs/src/main/java/org/geoserver/wfs/response/RemappingFeatureCollection.java
  20. +3 −2 src/wfs/src/test/java/org/geoserver/wfs/response/ShapeZipTest.java
  21. +5 −1 src/wfs/src/test/java/org/geoserver/wfs/v1_1/TransactionTest.java
  22. +32 −26 src/wms/src/main/java/org/geoserver/kml/KMLRasterTransformer.java
  23. +1 −1 src/wms/src/main/java/org/geoserver/kml/KMLVectorTransformer.java
  24. +0 −58 src/wms/src/main/java/org/geoserver/wms/featureinfo/FeatureCollectionDecorator.java
  25. +1 −1 src/wms/src/main/java/org/geoserver/wms/georss/AtomGeoRSSTransformer.java
  26. +1 −1 src/wms/src/main/java/org/geoserver/wms/georss/RSSGeoRSSTransformer.java
  27. +6 −8 src/wms/src/test/java/org/geoserver/wms/featureinfo/FeatureTemplateTest.java
  28. +1 −1 src/wms/src/test/java/org/geoserver/wms/featureinfo/FeatureTimeTemplateTest.java
@@ -167,7 +167,7 @@ protected void write(FeatureCollectionResponse featureCollection, OutputStream o
}
}
} finally {
- fc.close(i);
+ i.close();
}
}
@@ -195,9 +195,10 @@ public void writeFeatures(SimpleFeatureCollection fColl, FeatureTypeStyle[] ftsL
} catch (NoSuchElementException ex) {
throw new DataSourceException(ex.getMessage(), ex);
} finally {
- if(iter!=null)
- //make sure we always close
- fColl.close(iter);
+ if(iter!=null) {
+ //make sure we always close
+ iter.close();
+ }

This comment has been minimized.

Show comment Hide comment
@jodygarnett

jodygarnett Nov 7, 2012

Member

There is a DataUtilities.close( iterator ) that aaime requested, it does allow you to avoid null checks

@jodygarnett

jodygarnett Nov 7, 2012

Member

There is a DataUtilities.close( iterator ) that aaime requested, it does allow you to avoid null checks

}
}
@@ -13,6 +13,7 @@
import org.geotools.data.DataUtilities;
import org.geotools.data.store.DataFeatureCollection;
import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.FeatureIterator;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.identity.FeatureId;
@@ -64,7 +65,7 @@ public int getCount() throws IOException {
class CompositeIterator implements Iterator {
int index;
- Iterator iterator;
+ FeatureIterator iterator;
public CompositeIterator() {
index = 0;
@@ -83,11 +84,11 @@ public boolean hasNext() {
while (index < collections.size()) {
//close current before we move to next
if (iterator != null) {
- ((FeatureCollection) collections.get(index - 1)).close(iterator);
+ iterator.close();
}
//grap next
- iterator = ((FeatureCollection) collections.get(index++)).iterator();
+ iterator = ((FeatureCollection) collections.get(index++)).features();
if (iterator.hasNext()) {
return true;
@@ -97,7 +98,7 @@ public boolean hasNext() {
//no more
if (iterator != null) {
//close the last iterator
- ((FeatureCollection) collections.get(collections.size() - 1)).close(iterator);
+ iterator.close();
}
return false;
@@ -108,43 +109,17 @@ public Object next() {
}
}
- public boolean addAll(Collection arg0) {
- throw new RuntimeException("Can't add to a composite featurecollection; you need to add to one of the constituent collections direclty.");
- }
-
- public boolean removeAll(Collection arg0) {
- Iterator it = collections.iterator();
- boolean result = false;
- while (it.hasNext()){
- FeatureCollection col = (FeatureCollection)it.next();
- result |= col.removeAll(arg0);
- }
- return result;
- }
-
- public boolean retainAll(Collection arg0) {
- boolean result = false;
-
- Iterator it = collections.iterator();
- while (it.hasNext()){
- FeatureCollection col = (FeatureCollection)it.next();
- result |= col.removeAll(arg0);
- }
-
- return result;
- }
-
public Object[] toArray(Object[] arg0) {
List list = new ArrayList();
Iterator it = collections.iterator();
while(it.hasNext()){
FeatureCollection col = (FeatureCollection)it.next();
- Iterator it2 = col.iterator();
+ FeatureIterator it2 = col.features();
while (it2.hasNext()){

This comment has been minimized.

Show comment Hide comment
@jodygarnett

jodygarnett Nov 7, 2012

Member

I have been doing the try / finally thing to ensure iterator is closed

@jodygarnett

jodygarnett Nov 7, 2012

Member

I have been doing the try / finally thing to ensure iterator is closed

list.add(it.next());
}
- col.close(it2);
+ it2.close();
}
return list.toArray(arg0);
@@ -120,7 +120,7 @@ public void accepts(FeatureVisitor visitor, ProgressListener progress) {
visitor.visit(it.next());
}
} finally {
- close(it);
+ it.close();
}
}
@@ -132,24 +132,6 @@ public SimpleFeatureIterator features() {
return new ReprojectingFeatureIterator(delegate.features());
}
- public Iterator iterator() {
- return new ReprojectingIterator(delegate.iterator());
- }
-
- public void close(SimpleFeatureIterator iterator) {
- if (iterator instanceof ReprojectingFeatureIterator) {
- delegate.close(((ReprojectingFeatureIterator) iterator).getDelegate());
- }
-
- iterator.close();
- }
-
- public void close(Iterator iterator) {
- if (iterator instanceof ReprojectingIterator) {
- delegate.close(((ReprojectingIterator) iterator).getDelegate());
- }
- }
-
public SimpleFeatureType getFeatureType() {
return schema;
}
@@ -218,7 +200,7 @@ public SimpleFeatureCollection subCollection(Filter filter) {
public ReferencedEnvelope getBounds() {
ReferencedEnvelope bounds = null;
- Iterator i = iterator();
+ SimpleFeatureIterator i = features();
try {
if (!i.hasNext()) {
@@ -237,7 +219,7 @@ public ReferencedEnvelope getBounds() {
return bounds;
} finally {
- close(i);
+ i.close();
}
}
@@ -339,6 +321,7 @@ public SimpleFeature next() throws NoSuchElementException {
}
public void close() {
+ if (delegate != null) delegate.close();
delegate = null;
}
}
@@ -12,6 +12,7 @@
import org.geotools.data.FeatureWriter;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
+import org.geotools.feature.FeatureIterator;
import org.geotools.feature.IllegalAttributeException;
import org.geotools.feature.collection.DelegateSimpleFeatureIterator;
import org.geotools.feature.simple.SimpleFeatureBuilder;
@@ -40,22 +41,8 @@ public SimpleFeatureType getSchema() {
return target;
}
- public Iterator<SimpleFeature> iterator() {
- return new RetypingIterator(delegate.iterator(), target);
- }
-
- public void close(Iterator<SimpleFeature> iterator) {
- RetypingIterator retyping = (RetypingIterator) iterator;
- delegate.close(retyping.delegate);
- }
-
public SimpleFeatureIterator features() {
- return new DelegateSimpleFeatureIterator(this, iterator());
- }
-
- public void close(SimpleFeatureIterator iterator) {
- DelegateSimpleFeatureIterator delegate = (DelegateSimpleFeatureIterator) iterator;
- delegate.close();
+ return new RetypingIterator(delegate.features(), target);
}
static SimpleFeature retype(SimpleFeature source, SimpleFeatureBuilder builder)
@@ -102,11 +89,11 @@ public static FeatureId reTypeId(FeatureId sourceId, SimpleFeatureType original,
return sourceId;
}
- public static class RetypingIterator implements Iterator<SimpleFeature> {
+ public static class RetypingIterator implements SimpleFeatureIterator {
SimpleFeatureBuilder builder;
- Iterator<SimpleFeature> delegate;
+ SimpleFeatureIterator delegate;
- public RetypingIterator(Iterator<SimpleFeature> delegate, SimpleFeatureType target) {
+ public RetypingIterator(SimpleFeatureIterator delegate, SimpleFeatureType target) {
this.delegate = delegate;
this.builder = new SimpleFeatureBuilder(target);
}
@@ -123,8 +110,9 @@ public SimpleFeature next() {
}
}
- public void remove() {
- delegate.remove();
+ @Override
+ public void close() {
+ delegate.close();
}
}
@@ -43,11 +43,6 @@ public SimpleFeatureIterator features() {
return new CheckAttributesFeatureIterator(delegate.features(), writableAttributes);
}
- @Override
- public Iterator iterator() {
- return new FeatureIteratorIterator<SimpleFeature>(features());
- }
-
public class CheckAttributesFeatureIterator implements SimpleFeatureIterator {
SimpleFeatureIterator delegate;
@@ -49,7 +49,6 @@ public boolean canSecure(Class clazz) {
|| FeatureStore.class.isAssignableFrom(clazz)
|| FeatureLocking.class.isAssignableFrom(clazz)
|| FeatureCollection.class.isAssignableFrom(clazz)
- || Iterator.class.isAssignableFrom(clazz)
|| FeatureIterator.class.isAssignableFrom(clazz)
|| AbstractGridCoverage2DReader.class.isAssignableFrom(clazz)
|| AbstractGridFormat.class.isAssignableFrom(clazz)
@@ -109,8 +108,6 @@ public Object secure(Object object, WrapperPolicy policy) {
return new SecuredSimpleFeatureCollection((SimpleFeatureCollection) object, policy);
} else if (FeatureCollection.class.isAssignableFrom(clazz)) {
return new SecuredFeatureCollection((FeatureCollection) object, policy);
- } else if (Iterator.class.isAssignableFrom(clazz)) {
- return new SecuredIterator((Iterator) object, policy);
} else if (SimpleFeatureIterator.class.isAssignableFrom(clazz)) {
return new SecuredSimpleFeatureIterator((SimpleFeatureIterator) object);
} else if (FeatureIterator.class.isAssignableFrom(clazz)) {
Oops, something went wrong.

0 comments on commit bd8840d

Please sign in to comment.