use of org.apache.sis.storage.IllegalFeatureTypeException in project sis by apache.
the class Writer method write.
/**
* Writes the given feature.
*
* @param feature the feature to write, or {@code null} if none.
* @throws DataStoreException if the given feature is not a recognized type.
* @throws XMLStreamException if underlying STAX writer encounter an error.
* @throws JAXBException if underlying JAXB marshaller encounter an error.
*/
@Override
public void write(final AbstractFeature feature) throws DataStoreException, XMLStreamException, JAXBException {
if (feature != null) {
final Types types = ((Store) owner).types;
final DefaultFeatureType type = feature.getType();
if (types.wayPoint.isAssignableFrom(type)) {
writeWayPoint(feature, Tags.WAY_POINT);
} else {
final boolean isRoute = types.route.isAssignableFrom(type);
if (!isRoute && !types.track.isAssignableFrom(type)) {
throw new IllegalFeatureTypeException(owner.getLocale(), owner.getFormatName(), type.getName());
}
writer.writeStartElement(isRoute ? Tags.ROUTES : Tags.TRACKS);
writeSingleValue(Tags.NAME, feature.getPropertyValue(Tags.NAME));
writeSingleValue(Tags.COMMENT, feature.getPropertyValue(Tags.COMMENT));
writeSingleValue(Tags.DESCRIPTION, feature.getPropertyValue(Tags.DESCRIPTION));
writeSingleValue(Tags.SOURCE, feature.getPropertyValue(Tags.SOURCE));
writeLinks((Collection<?>) feature.getPropertyValue(Tags.LINK));
writeSingleValue(Tags.NUMBER, feature.getPropertyValue(Tags.NUMBER));
if (version != 0) {
writeSingleValue(Tags.TYPE, feature.getPropertyValue(Tags.TYPE));
}
if (isRoute) {
for (Object prop : (Collection<?>) feature.getPropertyValue(Tags.ROUTE_POINTS)) {
writeWayPoint((AbstractFeature) prop, Tags.ROUTE_POINTS);
}
} else {
for (Object segment : (Collection<?>) feature.getPropertyValue(Tags.TRACK_SEGMENTS)) {
if (segment != null) {
writer.writeStartElement(Tags.TRACK_SEGMENTS);
for (Object prop : (Collection<?>) ((AbstractFeature) segment).getPropertyValue(Tags.TRACK_POINTS)) {
writeWayPoint((AbstractFeature) prop, Tags.TRACK_POINTS);
}
writer.writeEndElement();
}
}
}
writer.writeEndElement();
}
}
}
Aggregations