Search in sources :

Example 1 with XmlEncoderKey

use of org.n52.svalbard.encode.XmlEncoderKey in project arctic-sea by 52North.

the class SoapBinding method encodeSoapResponse.

private Object encodeSoapResponse(SoapChain chain) throws OwsExceptionReport, NoEncoderForKeyException {
    EncoderKey key = new XmlEncoderKey(chain.getSoapResponse().getSoapNamespace(), chain.getSoapResponse().getClass());
    Encoder<?, SoapResponse> encoder = getEncoder(key);
    if (encoder != null) {
        try {
            return encoder.encode(chain.getSoapResponse());
        } catch (OwsEncodingException ex) {
            throw ex.getCause();
        } catch (EncodingException ex) {
            throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
        }
    } else {
        NoEncoderForKeyException cause = new NoEncoderForKeyException(key);
        throw new NoApplicableCodeException().withMessage(cause.getMessage()).causedBy(cause);
    }
}
Also used : NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) SoapResponse(org.n52.shetland.w3c.soap.SoapResponse) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OwsEncodingException(org.n52.iceland.coding.encode.OwsEncodingException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) EncoderKey(org.n52.svalbard.encode.EncoderKey) XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) OwsEncodingException(org.n52.iceland.coding.encode.OwsEncodingException)

Example 2 with XmlEncoderKey

use of org.n52.svalbard.encode.XmlEncoderKey in project arctic-sea by 52North.

the class AbstractOmV20XmlStreamWriter method writeParameter.

/**
 * Write om:parameter to stream
 *
 * @throws XMLStreamException
 *             If an error occurs when writing to stream
 * @throws EncodingException
 *             If an error occurs when creating elements to be written
 */
protected void writeParameter() throws XMLStreamException, EncodingException {
    XmlEncoderKey key = new XmlEncoderKey(OmConstants.NS_OM_2, NamedValue.class);
    Encoder<XmlObject, NamedValue<?>> encoder = getEncoder(key);
    if (encoder != null) {
        for (NamedValue<?> namedValue : getElement().getParameter()) {
            start(OmConstants.QN_OM_20_PARAMETER);
            writeXmlObject(encoder.encode(namedValue), OmConstants.QN_OM_20_NAMED_VALUE);
            end(OmConstants.QN_OM_20_PARAMETER);
        }
    }
}
Also used : XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) XmlObject(org.apache.xmlbeans.XmlObject) NamedValue(org.n52.shetland.ogc.om.NamedValue)

Example 3 with XmlEncoderKey

use of org.n52.svalbard.encode.XmlEncoderKey in project arctic-sea by 52North.

the class DescribeSensorResponseEncoderTest method should_return_correct_encoder_keys.

@Test
public void should_return_correct_encoder_keys() {
    Set<EncoderKey> returnedKeySet = new DescribeSensorResponseEncoder().getKeys();
    assertThat(returnedKeySet.size(), is(3));
    assertThat(returnedKeySet, hasItem(new XmlEncoderKey(SwesConstants.NS_SWES_20, DescribeSensorResponse.class)));
    assertThat(returnedKeySet, hasItem(new OperationResponseEncoderKey(SosConstants.SOS, Sos2Constants.SERVICEVERSION, SosConstants.Operations.DescribeSensor, MediaTypes.TEXT_XML)));
    assertThat(returnedKeySet, hasItem(new OperationResponseEncoderKey(SosConstants.SOS, Sos2Constants.SERVICEVERSION, SosConstants.Operations.DescribeSensor, MediaTypes.APPLICATION_XML)));
}
Also used : EncoderKey(org.n52.svalbard.encode.EncoderKey) OperationResponseEncoderKey(org.n52.svalbard.encode.OperationResponseEncoderKey) XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) OperationResponseEncoderKey(org.n52.svalbard.encode.OperationResponseEncoderKey) DescribeSensorResponseEncoder(org.n52.svalbard.encode.DescribeSensorResponseEncoder) Test(org.junit.Test)

Example 4 with XmlEncoderKey

use of org.n52.svalbard.encode.XmlEncoderKey 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);
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) SweAbstractSimpleType(org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) XmlObject(org.apache.xmlbeans.XmlObject) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray)

Aggregations

XmlEncoderKey (org.n52.svalbard.encode.XmlEncoderKey)3 XmlObject (org.apache.xmlbeans.XmlObject)2 EncoderKey (org.n52.svalbard.encode.EncoderKey)2 EncodingException (org.n52.svalbard.encode.exception.EncodingException)2 Test (org.junit.Test)1 OwsEncodingException (org.n52.iceland.coding.encode.OwsEncodingException)1 NamedValue (org.n52.shetland.ogc.om.NamedValue)1 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)1 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)1 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)1 SweAbstractSimpleType (org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType)1 SoapResponse (org.n52.shetland.w3c.soap.SoapResponse)1 DescribeSensorResponseEncoder (org.n52.svalbard.encode.DescribeSensorResponseEncoder)1 OperationResponseEncoderKey (org.n52.svalbard.encode.OperationResponseEncoderKey)1 NoEncoderForKeyException (org.n52.svalbard.encode.exception.NoEncoderForKeyException)1