Search in sources :

Example 6 with DataArrayType

use of net.opengis.swe.x101.DataArrayType in project arctic-sea by 52North.

the class SweCommonDecoderV20 method parseDataArray.

private SweDataArray parseDataArray(DataArrayType xbDataArray) throws DecodingException {
    SweDataArray sosSweDataArray = new SweDataArray();
    CountPropertyType elementCount = xbDataArray.getElementCount();
    if (elementCount != null) {
        sosSweDataArray.setElementCount(parseElementCount(elementCount));
    }
    // parse data record to elementType
    DataArrayType.ElementType xbElementType = xbDataArray.getElementType();
    if (xbElementType != null && xbElementType.getAbstractDataComponent() != null) {
        sosSweDataArray.setElementType(parseAbstractDataComponent(xbElementType.getAbstractDataComponent()));
    }
    if (xbDataArray.isSetEncoding()) {
        sosSweDataArray.setEncoding(parseEncoding(xbDataArray.getEncoding().getAbstractEncoding()));
    }
    // parse values
    if (xbDataArray.isSetValues()) {
        sosSweDataArray.setValues(parseValues(sosSweDataArray.getElementCount(), sosSweDataArray.getElementType(), sosSweDataArray.getEncoding(), xbDataArray.getValues()));
    }
    // set XML
    DataArrayDocument dataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
    dataArrayDoc.setDataArray1(xbDataArray);
    sosSweDataArray.setXml(dataArrayDoc.xmlText(getXmlOptions()));
    return sosSweDataArray;
}
Also used : CountPropertyType(net.opengis.swe.x20.CountPropertyType) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) DataArrayType(net.opengis.swe.x20.DataArrayType) DataArrayDocument(net.opengis.swe.x20.DataArrayDocument)

Example 7 with DataArrayType

use of net.opengis.swe.x101.DataArrayType in project arctic-sea by 52North.

the class SensorMLDecoderV101Test method should_decode_io_from_sml.

@Test
public void should_decode_io_from_sml() throws DecodingException {
    SensorMLDocument xbSmlDoc = getSensorMLDoc();
    SystemType xbSystem = (SystemType) xbSmlDoc.getSensorML().addNewMember().addNewProcess().substitute(SensorMLConstants.SYSTEM_QNAME, SystemType.type);
    InputList xbInputList = xbSystem.addNewInputs().addNewInputList();
    OutputList xbOutputList = xbSystem.addNewOutputs().addNewOutputList();
    IoComponentPropertyType input1 = xbInputList.addNewInput();
    input1.setName("input1");
    input1.addNewBoolean();
    IoComponentPropertyType input2 = xbInputList.addNewInput();
    input2.setName("input2");
    input2.addNewCount();
    IoComponentPropertyType output1 = xbOutputList.addNewOutput();
    output1.setName("output1");
    output1.addNewQuantity();
    IoComponentPropertyType output2 = xbOutputList.addNewOutput();
    output2.setName("output2");
    DataArrayType dataArray = getDataArray();
    output2.setAbstractDataArray1(dataArray);
    XmlHelper.substituteElement(output2.getAbstractDataArray1(), dataArray);
    IoComponentPropertyType output3 = xbOutputList.addNewOutput();
    output3.setName("output3");
    DataRecordType dataRecord = DataRecordType.Factory.newInstance();
    output3.setAbstractDataRecord(dataRecord);
    XmlHelper.substituteElement(output3.getAbstractDataRecord(), dataRecord);
    AbstractProcess absProcess = decodeAbstractProcess(xbSmlDoc);
    assertThat(absProcess.getInputs().get(0).getIoValue().getDataComponentType(), is(SweDataComponentType.Boolean));
    // assertThat(
    // ((SweAbstractSimpleType)absProcess.getInputs().get(0).getIoValue()).getDataComponentType(),
    // is (SweDataComponentType.Boolean));
    assertThat(absProcess.getInputs().get(1).getIoValue().getDataComponentType(), is(SweDataComponentType.Count));
    // assertThat(
    // ((SweAbstractSimpleType)absProcess.getInputs().get(1).getIoValue()).getDataComponentType(),
    // is (SweDataComponentType.Count));
    assertThat(absProcess.getOutputs().get(0).getIoValue().getDataComponentType(), is(SweDataComponentType.Quantity));
    // assertThat(
    // ((SweAbstractSimpleType)absProcess.getOutputs().get(0).getIoValue()).getDataComponentType(),
    // is (SweDataComponentType.Quantity));
    assertThat(absProcess.getOutputs().get(1).getIoValue().getDataComponentType(), is(SweDataComponentType.DataArray));
    assertThat(absProcess.getOutputs().get(2).getIoValue().getDataComponentType(), is(SweDataComponentType.DataRecord));
}
Also used : SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) DataRecordType(net.opengis.swe.x101.DataRecordType) InputList(net.opengis.sensorML.x101.InputsDocument.Inputs.InputList) SensorMLDocument(net.opengis.sensorML.x101.SensorMLDocument) AbstractProcess(org.n52.shetland.ogc.sensorML.AbstractProcess) SystemType(net.opengis.sensorML.x101.SystemType) IoComponentPropertyType(net.opengis.sensorML.x101.IoComponentPropertyType) OutputList(net.opengis.sensorML.x101.OutputsDocument.Outputs.OutputList) DataArrayType(net.opengis.swe.x101.DataArrayType) Test(org.junit.Test)

Example 8 with DataArrayType

use of net.opengis.swe.x101.DataArrayType in project arctic-sea by 52North.

the class SweCommonEncoderv101 method createDataArray.

private DataArrayDocument createDataArray(SweDataArray sosDataArray) throws EncodingException {
    if (sosDataArray != null) {
        if (sosDataArray.isSetElementTyp()) {
            DataArrayDocument xbDataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
            DataArrayType xbDataArray = xbDataArrayDoc.addNewDataArray1();
            // set element count
            if (sosDataArray.isSetElementCount()) {
                xbDataArray.addNewElementCount().addNewCount().set(createCount(sosDataArray.getElementCount()));
            }
            if (sosDataArray.isSetElementTyp()) {
                DataComponentPropertyType xbElementType = xbDataArray.addNewElementType();
                xbElementType.setName("Components");
                // FIXME use visitor pattern
                if (sosDataArray.getElementType() instanceof SweBoolean) {
                    xbElementType.addNewBoolean().set(createSimpleType((SweBoolean) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweCategory) {
                    xbElementType.addNewCategory().set(createSimpleType((SweCategory) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweCount) {
                    xbElementType.addNewCount().set(createSimpleType((SweCount) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweQuantity) {
                    xbElementType.addNewQuantity().set(createSimpleType((SweQuantity) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweText) {
                    xbElementType.addNewText().set(createSimpleType((SweText) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweTimeRange) {
                    xbElementType.addNewTimeRange().set(createSimpleType((SweTimeRange) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweTime) {
                    xbElementType.addNewTime().set(createSimpleType((SweTime) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweEnvelope) {
                    xbElementType.addNewAbstractDataRecord().set(createEnvelope((SweEnvelope) sosDataArray.getElementType()));
                    xbElementType.getAbstractDataRecord().substitute(SweConstants.QN_ENVELOPE_SWE_101, EnvelopeType.type);
                } else if (sosDataArray.getElementType() instanceof SweDataRecord) {
                    xbElementType.addNewAbstractDataRecord().set(createDataRecord((SweDataRecord) sosDataArray.getElementType()));
                    xbElementType.getAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataRecordType.type);
                } else if (sosDataArray.getElementType() instanceof SweDataArray) {
                    xbElementType.addNewAbstractDataArray1().set(createDataArray((SweDataArray) sosDataArray.getElementType()).getDataArray1());
                    xbElementType.getAbstractDataArray1().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataArrayType.type);
                } else {
                    throw new UnsupportedEncoderInputException(this, sosDataArray.getElementType());
                }
            }
            if (sosDataArray.isSetEncoding()) {
                BlockEncodingPropertyType xbEncoding = xbDataArray.addNewEncoding();
                xbEncoding.set(createBlockEncoding(sosDataArray.getEncoding()));
            // xbDataArray.getEncoding().substitute(
            // new QName(SWEConstants.NS_SWE_101,
            // SWEConstants.EN_TEXT_ENCODING,
            // SWEConstants.NS_SWE_PREFIX), TextBlock.type);
            }
            // }
            if (sosDataArray.isSetValues()) {
                xbDataArray.addNewValues().set(createValues(sosDataArray.getValues(), sosDataArray.getEncoding()));
            }
            return xbDataArrayDoc;
        } else if (sosDataArray.isSetXml()) {
            try {
                XmlObject xmlObject = XmlObject.Factory.parse(sosDataArray.getXml().trim());
                if (xmlObject instanceof DataArrayDocument) {
                    return (DataArrayDocument) xmlObject;
                } else {
                    DataArrayDocument xbDataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
                    xbDataArrayDoc.setDataArray1(DataArrayType.Factory.parse(sosDataArray.getXml().trim()));
                    return xbDataArrayDoc;
                }
            } catch (XmlException e) {
                throw new EncodingException("Error while encoding SweDataArray!", e);
            }
        }
    }
    return null;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) BlockEncodingPropertyType(net.opengis.swe.x101.BlockEncodingPropertyType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) DataArrayDocument(net.opengis.swe.x101.DataArrayDocument) DataArrayType(net.opengis.swe.x101.DataArrayType)

Example 9 with DataArrayType

use of net.opengis.swe.x101.DataArrayType 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;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) DataRecordType(net.opengis.swe.x101.DataRecordType) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) EnvelopeType(net.opengis.swe.x101.EnvelopeType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) SweCountRange(org.n52.shetland.ogc.swe.simpleType.SweCountRange) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) DataArrayType(net.opengis.swe.x101.DataArrayType)

Aggregations

DataArrayType (net.opengis.swe.x101.DataArrayType)4 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)4 DataArrayType (net.opengis.swe.x20.DataArrayType)4 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)4 NotYetSupportedEncodingException (org.n52.svalbard.encode.exception.NotYetSupportedEncodingException)4 BooleanType (net.opengis.swe.x20.BooleanType)3 CategoryType (net.opengis.swe.x20.CategoryType)3 CountRangeType (net.opengis.swe.x20.CountRangeType)3 CountType (net.opengis.swe.x20.CountType)3 DataArrayDocument (net.opengis.swe.x20.DataArrayDocument)3 DataRecordType (net.opengis.swe.x20.DataRecordType)3 QuantityRangeType (net.opengis.swe.x20.QuantityRangeType)3 QuantityType (net.opengis.swe.x20.QuantityType)3 TextType (net.opengis.swe.x20.TextType)3 TimeRangeType (net.opengis.swe.x20.TimeRangeType)3 TimeType (net.opengis.swe.x20.TimeType)3 VectorType (net.opengis.swe.x20.VectorType)3 DataArrayDocument (net.opengis.swe.x101.DataArrayDocument)2 DataRecordType (net.opengis.swe.x101.DataRecordType)2 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)2