use of org.jvnet.ogc.gml.v_3_1_1.jts.MarshallerImpl in project ddf by codice.
the class CswFilterFactory method convertGeometry.
@SuppressWarnings("unchecked")
private JAXBElement<? extends AbstractGeometryType> convertGeometry(Geometry geometry) {
geometry.setUserData(CswConstants.SRS_NAME);
JAXBElement<? extends AbstractGeometryType> abstractGeometry = null;
try {
Map<String, String> geoConverterProps = new HashMap<String, String>();
geoConverterProps.put(CswJTSToGML311GeometryConverter.USE_POS_LIST_GEO_CONVERTER_PROP_KEY, String.valueOf(this.isSetUsePosList));
JTSToGML311GeometryConverter converter = new CswJTSToGML311GeometryConverter(geoConverterProps);
Marshaller marshaller = new MarshallerImpl(JAXB_CONTEXT.createMarshaller(), converter);
StringWriter writer = new StringWriter();
marshaller.marshal(geometry, writer);
String xmlGeo = writer.toString();
LOGGER.debug("Geometry as XML: {}", xmlGeo);
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(xmlGeo));
Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
Object object = unmarshaller.unmarshal(xmlStreamReader);
LOGGER.debug("Unmarshalled as => {}", object);
if (object instanceof JAXBElement) {
abstractGeometry = (JAXBElement<? extends AbstractGeometryType>) object;
} else {
LOGGER.debug("Unable to cast to JAXBElement<? extends AbstractGeometryType>. Object is of type [{}].", object.getClass().getName());
}
} catch (JAXBException | XMLStreamException e) {
LOGGER.debug("Unable to unmarshal geometry [{}]", geometry.getClass().getName(), e);
}
return abstractGeometry;
}
Aggregations