use of org.geotoolkit.gml.xml.FeatureCollection in project geotoolkit by Geomatys.
the class AbstractComplexInputConverter method fromXml.
private static Stream<FeatureSet> fromXml(final Data source) {
final XmlFeatureReader fcollReader;
try {
fcollReader = WPSIO.getFeatureReader(source.getSchema());
} catch (MalformedURLException ex) {
throw new UnconvertibleObjectException("Unable to reach the schema url.", ex);
}
List<Object> content = new ArrayList<>();
// extract feature nodes from gml unmarshalled feature collection
for (Object o : source.getContent()) {
if (o instanceof JAXBElement) {
o = ((JAXBElement) o).getValue();
}
if (o instanceof FeatureCollection) {
FeatureCollection fc = (FeatureCollection) o;
for (FeatureProperty fp : fc.getFeatureMember()) {
if (fp.getUnknowFeature() != null) {
content.add(fp.getUnknowFeature());
} else {
throw new UnconvertibleObjectException("Unabel to read feature from XML.");
}
}
} else {
content.add(o);
}
}
final Stream<FeatureSet> result = content.stream().map(in -> {
try {
return fcollReader.read(in);
} catch (XMLStreamException | IOException ex) {
throw new UnconvertibleObjectException("Unable to read feature from nodes.", ex);
}
}).map(ReferenceToFeatureCollectionConverter::castOrWrap);
return result.onClose(() -> fcollReader.dispose());
}
Aggregations