Permalink
Browse files

AbstractFeatureCollectionTypeBinding parse is demanding an implementa…

…tion of Collection
  • Loading branch information...
1 parent 647f226 commit f778502fd0c7b9442c63ee55525037bd0b08b0b0 @jodygarnett jodygarnett committed Oct 30, 2012
@@ -16,9 +16,13 @@
*/
package org.geotools.gml3.bindings;
+import java.util.Collection;
+import java.util.List;
+
import javax.xml.namespace.QName;
import org.geotools.data.simple.SimpleFeatureCollection;
+import org.geotools.feature.DefaultFeatureCollection;
import org.geotools.feature.DefaultFeatureCollections;
import org.geotools.feature.FeatureCollection;
import org.geotools.gml3.GML;
@@ -87,19 +91,34 @@ public Object parse(ElementInstance instance, Node node, Object value)
SimpleFeatureCollection featureCollection =
(SimpleFeatureCollection) node.getChildValue(FeatureCollection.class);
if (featureCollection == null) {
- featureCollection = DefaultFeatureCollections.newCollection();
+ featureCollection = new DefaultFeatureCollection();
}
//<element maxOccurs="unbounded" minOccurs="0" ref="gml:featureMember"/>
- featureCollection.addAll(node.getChildValues(SimpleFeature.class));
+ List childValues = node.getChildValues(SimpleFeature.class);
+
+ if( featureCollection instanceof Collection){
+ // example DefaultFeatureCollections or ListFeatureCollection
+ ((Collection)featureCollection).addAll(childValues);
+ }
+ else {
+ throw new IllegalStateException("DefaultFeatureCollection or ListFeatureCollection required");
+ }
//<element minOccurs="0" ref="gml:featureMembers"/>
SimpleFeature[] featureMembers = (SimpleFeature[]) node.getChildValue(SimpleFeature[].class);
- if (featureMembers != null) {
- for (int i = 0; i < featureMembers.length; i++) {
- featureCollection.add(featureMembers[i]);
+ if( featureCollection instanceof Collection){
+ // example DefaultFeatureCollections or ListFeatureCollection
+ if (featureMembers != null) {
+ for (int i = 0; i < featureMembers.length; i++) {
+ ((Collection)featureCollection).add(featureMembers[i]);
+ }
}
+
+ }
+ else {
+ throw new IllegalStateException("DefaultFeatureCollection or ListFeatureCollection required");
}
return featureCollection;
@@ -16,10 +16,12 @@
*/
package org.geotools.gml3.bindings;
+import java.util.Collection;
import java.util.List;
import javax.xml.namespace.QName;
+import org.geotools.feature.DefaultFeatureCollection;
import org.geotools.feature.DefaultFeatureCollections;
import org.geotools.feature.FeatureCollection;
import org.geotools.gml3.GML;
@@ -86,8 +88,8 @@ public Object parse(ElementInstance instance, Node node, Object value)
}
List features = node.getChildValues(SimpleFeature.class);
- fc = DefaultFeatureCollections.newCollection();
- fc.addAll(features);
+ fc = new DefaultFeatureCollection();
+ ((Collection)fc).addAll(features);
return fc;
}
@@ -16,9 +16,8 @@
*/
package org.geotools.gml3.bindings;
-import java.util.Iterator;
-
import org.geotools.data.simple.SimpleFeatureCollection;
+import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.gml3.GML;
import org.geotools.gml3.GML3TestSupport;
import org.geotools.xml.Configuration;
@@ -60,12 +59,16 @@ public void testFeatureMember() throws Exception {
assertEquals(2, fc.size());
- Iterator i = fc.iterator();
- SimpleFeature f = (SimpleFeature) i.next();
- assertEquals("fid.1", f.getID());
-
- f = (SimpleFeature) i.next();
- assertEquals("fid.2", f.getID());
+ SimpleFeatureIterator i = fc.features();
+ try {
+ SimpleFeature f = (SimpleFeature) i.next();
+ assertEquals("fid.1", f.getID());
+
+ f = (SimpleFeature) i.next();
+ assertEquals("fid.2", f.getID());
+ } finally {
+ i.close();
+ }
}
public void testFeatureMembers() throws Exception {
@@ -85,11 +88,15 @@ public void testFeatureMembers() throws Exception {
assertEquals(2, fc.size());
- Iterator i = fc.iterator();
- SimpleFeature f = (SimpleFeature) i.next();
- assertEquals("fid.1", f.getID());
-
- f = (SimpleFeature) i.next();
- assertEquals("fid.2", f.getID());
+ SimpleFeatureIterator i = fc.features();
+ try {
+ SimpleFeature f = (SimpleFeature) i.next();
+ assertEquals("fid.1", f.getID());
+
+ f = (SimpleFeature) i.next();
+ assertEquals("fid.2", f.getID());
+ } finally {
+ i.close();
+ }
}
}
@@ -77,20 +77,23 @@ public void testParseFeatureCollection() throws Exception {
assertEquals( 3, features.size() );
FeatureIterator fi = features.features();
-
- for ( int i = 0; i < 3; i++ ) {
- assertTrue( fi.hasNext() );
-
- SimpleFeature f = (SimpleFeature) fi.next();
- assertTrue( f.getDefaultGeometry() instanceof Point );
-
- Point point = (Point) f.getDefaultGeometry();
- assertEquals( i/1d, point.getX(), 0.1 );
- assertEquals( i/1d, point.getX(), 0.1 );
+ try {
+ for ( int i = 0; i < 3; i++ ) {
+ assertTrue( fi.hasNext() );
+
+ SimpleFeature f = (SimpleFeature) fi.next();
+ assertTrue( f.getDefaultGeometry() instanceof Point );
- assertEquals( i, f.getAttribute( "count" ) );
+ Point point = (Point) f.getDefaultGeometry();
+ assertEquals( i/1d, point.getX(), 0.1 );
+ assertEquals( i/1d, point.getX(), 0.1 );
+
+ assertEquals( i, f.getAttribute( "count" ) );
+ }
+ }
+ finally {
+ fi.close();
}
- features.close( fi );
}
/**

0 comments on commit f778502

Please sign in to comment.