use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.
the class GetObservationResponseEncoder method createResponse.
@Override
protected XmlObject createResponse(ObservationEncoder<XmlObject, OmObservation> encoder, GetObservationResponse response) throws EncodingException {
try {
GetObservationResponseDocument doc = GetObservationResponseDocument.Factory.newInstance(getXmlOptions());
GetObservationResponseType xbResponse = doc.addNewGetObservationResponse();
ObservationStream observationCollection = response.getObservationCollection();
while (observationCollection.hasNext()) {
xbResponse.addNewObservationData().addNewOMObservation().set(encoder.encode(observationCollection.next()));
}
// in a single observation the gml:ids must be unique
XmlHelper.makeGmlIdsUnique(doc.getDomNode());
return doc;
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
}
use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.
the class AbstractXmlResponseEncoder method create.
/**
* Override this method in concrete response encoder if streaming is supported for this operations.
*
* @param response Implementation of {@link OwsServiceResponse}
* @param outputStream {@link OutputStream} to write
* @param encodingValues {@link EncodingValues} with additional indicators for encoding
*
* @throws EncodingException If an error occurs during encoding/writing to stream
*/
protected void create(T response, OutputStream outputStream, EncodingContext encodingValues) throws EncodingException {
try {
XmlOptions xmlOptions;
if (encodingValues.has(StreamingEncoderFlags.EMBEDDED)) {
xmlOptions = new XmlOptions(getXmlOptions());
xmlOptions.setSaveNoXmlDecl();
} else {
xmlOptions = getXmlOptions();
}
XmlObject xmlObject = create(response);
setSchemaLocations(xmlObject);
xmlObject.save(outputStream, xmlOptions);
} catch (IOException ioe) {
throw new EncodingException("Error while writing element to stream!", ioe);
}
}
use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.
the class SamplingEncoderv20 method encodeShape.
private void encodeShape(ShapeType xbShape, AbstractSamplingFeature sampFeat) throws EncodingException {
Encoder<XmlObject, Geometry> encoder = getEncoder(GmlConstants.NS_GML_32, sampFeat.getGeometry());
if (encoder != null) {
XmlObject xmlObject = encoder.encode(sampFeat.getGeometry(), EncodingContext.of(XmlBeansEncodingFlags.GMLID, sampFeat.getGmlId()));
if (xbShape.isSetAbstractGeometry()) {
xbShape.getAbstractGeometry().set(xmlObject);
} else {
xbShape.addNewAbstractGeometry().set(xmlObject);
}
XmlHelper.substituteElement(xbShape.getAbstractGeometry(), xmlObject);
} else {
throw new EncodingException("Error while encoding geometry for feature, needed encoder is missing!");
}
}
use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createFieldForSimpleDataRecord.
private AnyScalarPropertyType createFieldForSimpleDataRecord(SweField sweField) throws EncodingException {
SweAbstractDataComponent sosElement = sweField.getElement();
AnyScalarPropertyType xbField = AnyScalarPropertyType.Factory.newInstance(getXmlOptions());
if (sweField.isSetName()) {
xbField.setName(sweField.getName().getValue());
}
AbstractDataComponentType xbDCD;
if (sosElement instanceof SweBoolean) {
xbDCD = xbField.addNewBoolean();
xbDCD.set(createSimpleType((SweBoolean) sosElement));
} else if (sosElement instanceof SweCategory) {
xbDCD = xbField.addNewCategory();
xbDCD.set(createSimpleType((SweCategory) sosElement));
} else if (sosElement instanceof SweCount) {
xbDCD = xbField.addNewCount();
xbDCD.set(createSimpleType((SweCount) sosElement));
} else if (sosElement instanceof SweQuantity) {
xbDCD = xbField.addNewQuantity();
xbDCD.set(createSimpleType((SweQuantity) sosElement));
} else if (sosElement instanceof SweText) {
xbDCD = xbField.addNewText();
xbDCD.set(createSimpleType((SweText) sosElement));
} else if (sosElement instanceof SweTime) {
xbDCD = xbField.addNewTime();
xbDCD.set(createSimpleType((SweTime) sosElement));
} else {
throw new EncodingException("The element type '%s' of the received %s is not supported by this encoder '%s'.", new Object[] { sosElement != null ? sosElement.getClass().getName() : null, sweField.getClass().getName(), getClass().getName() });
}
return xbField;
}
use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.
the class InsertObservationRequestEncoderTest method shouldThrowExceptionIfOfferingsAreMissing.
@Test
public void shouldThrowExceptionIfOfferingsAreMissing() throws EncodingException {
thrown.expect(UnsupportedEncoderInputException.class);
thrown.expectMessage(Is.is("Encoder " + InsertObservationRequestEncoder.class.getSimpleName() + " can not encode 'missing offering(s)'"));
encoder.create(new InsertObservationRequest("SOS", "2.0.0"));
}
Aggregations