use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.
the class DescribeSensorV2RequestEncoderTest method shouldThrowExceptionIfVersionIsMissing.
@Test
public void shouldThrowExceptionIfVersionIsMissing() throws EncodingException {
thrown.expect(UnsupportedEncoderInputException.class);
thrown.expectMessage(Is.is("Encoder " + DescribeSensorV2RequestEncoder.class.getSimpleName() + " can not encode 'missing version'"));
new DescribeSensorV2RequestEncoder().create(new DescribeSensorRequest("service", ""));
}
use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createField.
private DataComponentPropertyType createField(SweField sweField) throws EncodingException {
SweAbstractDataComponent sosElement = sweField.getElement();
DataComponentPropertyType xbField = DataComponentPropertyType.Factory.newInstance(getXmlOptions());
if (sweField.isSetName()) {
xbField.setName(sweField.getName().getValue());
}
if (sosElement instanceof SweBoolean) {
xbField.addNewBoolean().set(createSimpleType((SweBoolean) sosElement));
} else if (sosElement instanceof SweCategory) {
xbField.addNewCategory().set(createSimpleType((SweCategory) sosElement));
} else if (sosElement instanceof SweCount) {
xbField.addNewCount().set(createSimpleType((SweCount) sosElement));
} else if (sosElement instanceof SweCountRange) {
xbField.addNewCount().set(createSimpleType((SweCountRange) sosElement));
} else if (sosElement instanceof SweQuantity) {
xbField.addNewQuantity().set(createSimpleType((SweQuantity) sosElement));
} else if (sosElement instanceof SweQuantityRange) {
xbField.addNewQuantity().set(createSimpleType((SweQuantityRange) sosElement));
} else if (sosElement instanceof SweText) {
xbField.addNewText().set(createSimpleType((SweText) sosElement));
} else if (sosElement instanceof SweTimeRange) {
xbField.addNewTimeRange().set(createSimpleType((SweTimeRange) sosElement));
} else if (sosElement instanceof SweTime) {
xbField.addNewTime().set(createSimpleType((SweTime) sosElement));
} else if (sosElement instanceof SweEnvelope) {
EnvelopeType xbEnvelope = (EnvelopeType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_ENVELOPE_SWE_101, EnvelopeType.type);
xbEnvelope.set(createEnvelope((SweEnvelope) sosElement));
} else if (sosElement instanceof SweDataRecord) {
DataRecordType xbEnvelope = (DataRecordType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataRecordType.type);
xbEnvelope.set(createDataRecord((SweDataRecord) sosElement));
} else if (sosElement instanceof SweDataArray) {
DataArrayType xbEnvelope = (DataArrayType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataArrayType.type);
xbEnvelope.set(createDataArray((SweDataArray) sosElement).getDataArray1());
} 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 SensorMLEncoderv101 method addSweSimpleTypeToField.
/**
* Adds a SOS SWE simple type to a XML SWE field.
*
* @param xbField
* XML SWE field
* @param sosSweData
* SOS field element content
*
* @throws EncodingException
* if an error occurs
*/
private void addSweSimpleTypeToField(AnyScalarPropertyType xbField, SweAbstractDataComponent sosSweData) throws EncodingException {
Encoder<?, SweAbstractDataComponent> encoder = getEncoder(new XmlEncoderKey(SweConstants.NS_SWE_101, SweDataArray.class));
if (encoder == null) {
throw new EncodingException("The %s is not supported by this SOS for SWE fields!", sosSweData.getClass().getSimpleName());
}
XmlObject encoded = (XmlObject) encoder.encode(sosSweData);
if (!(sosSweData instanceof SweAbstractSimpleType)) {
throw new EncodingException("The SosSweAbstractDataComponent '%s' is not supported by this SOS SensorML encoder!", sosSweData);
}
SweAbstractSimpleType<?> sosSweSimpleType = (SweAbstractSimpleType<?>) sosSweData;
sosSweSimpleType.accept(new ScalarSweDataComponentAdder(xbField)).orElseThrow(() -> new EncodingException("The SWE simpleType '%s' is not supported by this SOS SensorML encoder!", sosSweSimpleType.getDataComponentType().name())).set(encoded);
}
Aggregations