/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { FeatureCollection fc = (FeatureCollection) node.getChildValue(FeatureCollection.class); if (fc != null) { return fc; } List features = node.getChildValues(SimpleFeature.class); fc = new DelayedSchemaFeatureCollection(); ((Collection) fc).addAll(features); return fc; }
@Override public SimpleFeatureType getSchema() { if (schema == null) { if (isEmpty()) { return PLACEHOLDER; } else { schema = list.get(0).getFeatureType(); } } return schema; }
@Test public void testEmpty() { DelayedSchemaFeatureCollection fc = new DelayedSchemaFeatureCollection(); assertEquals(DelayedSchemaFeatureCollection.PLACEHOLDER, fc.getSchema()); assertTrue(fc.getBounds().isEmpty()); fc.add(riverFeatures[0]); assertFalse(fc.getBounds().isEmpty()); assertEquals(riverType, fc.getSchema()); }
@Test public void testTwoTypes() { DelayedSchemaFeatureCollection fc = new DelayedSchemaFeatureCollection(); fc.add(riverFeatures[0]); fc.add(lakeFeatures[0]); // the type is the one of the first feature assertEquals(riverType, fc.getSchema()); // but we can get both un-modified try (SimpleFeatureIterator it = fc.features()) { assertEquals(riverFeatures[0], it.next()); assertEquals(lakeFeatures[0], it.next()); assertFalse(it.hasNext()); } } }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { SimpleFeatureCollection featureCollection = (SimpleFeatureCollection) node.getChildValue(FeatureCollection.class); if (featureCollection == null) { featureCollection = new DelayedSchemaFeatureCollection(); } // <element maxOccurs="unbounded" minOccurs="0" ref="gml:featureMember"/> List<SimpleFeature> childValues = node.getChildValues(SimpleFeature.class); // example DefaultFeatureCollections or ListFeatureCollection Collection<SimpleFeature> collection = DataUtilities.collectionCast(featureCollection); collection.addAll(childValues); // <element minOccurs="0" ref="gml:featureMembers"/> SimpleFeature[] featureMembers = (SimpleFeature[]) node.getChildValue(SimpleFeature[].class); if (featureMembers != null) { for (int i = 0; i < featureMembers.length; i++) { collection.add(featureMembers[i]); } } return featureCollection; }