use of net.opengis.gml.FeatureCollectionDocument2 in project arctic-sea by 52North.
the class GmlEncoderv311 method createFeatureCollection.
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH")
private XmlObject createFeatureCollection(FeatureCollection sosFeatureCollection) throws EncodingException {
Map<String, AbstractFeature> members = sosFeatureCollection.getMembers();
XmlObject xmlObject = null;
if (sosFeatureCollection.isSetMembers()) {
if (members.size() == 1) {
for (Entry<String, AbstractFeature> entry : members.entrySet()) {
String member = entry.getKey();
if (members.get(member) instanceof SamplingFeature) {
return createFeature((SamplingFeature) members.get(member));
} else {
throw missingFeatureEncoder();
}
}
} else {
FeatureCollectionDocument2 xbFeatureColllectionDoc = FeatureCollectionDocument2.Factory.newInstance(getXmlOptions());
AbstractFeatureCollectionType xbFeatCol = xbFeatureColllectionDoc.addNewFeatureCollection();
StringBuilder builder = new StringBuilder();
builder.append("sfc_");
builder.append(JavaHelper.generateID(Long.toString(System.currentTimeMillis())));
xbFeatCol.setId(builder.toString());
for (Entry<String, AbstractFeature> entry : members.entrySet()) {
String member = entry.getKey();
if (members.get(member) instanceof SamplingFeature) {
XmlObject xmlFeature = createFeature((SamplingFeature) members.get(member));
xbFeatCol.addNewFeatureMember().set(xmlFeature);
} else {
throw missingFeatureEncoder();
}
}
xmlObject = xbFeatureColllectionDoc;
}
} else {
FeatureCollectionDocument2 xbFeatColDoc = FeatureCollectionDocument2.Factory.newInstance(getXmlOptions());
xbFeatColDoc.addNewFeatureCollection();
xmlObject = xbFeatColDoc;
}
XmlCursor cursor = xmlObject.newCursor();
boolean isAFC = cursor.toChild(new QName(GmlConstants.NS_GML, GmlConstants.EN_ABSTRACT_FEATURE_COLLECTION));
if (isAFC) {
cursor.setName(new QName(GmlConstants.NS_GML, GmlConstants.EN_FEATURE_COLLECTION));
}
cursor.dispose();
return xmlObject;
}
Aggregations