Search in sources :

Example 11 with DataComponentPropertyType

use of org.geotoolkit.swe.xml.v100.DataComponentPropertyType 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 SweSimpleDataRecord) {
                    xbElementType.addNewAbstractDataRecord().set(createSimpleDataRecord((SweSimpleDataRecord) sosDataArray.getElementType()));
                    xbElementType.getAbstractDataRecord().substitute(SweConstants.QN_SIMPLEDATARECORD_SWE_101, SimpleDataRecordType.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) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) 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 12 with DataComponentPropertyType

use of org.geotoolkit.swe.xml.v100.DataComponentPropertyType in project arctic-sea by 52North.

the class SweCommonDecoderV101 method parseSweDataArrayType.

private SweDataArray parseSweDataArrayType(DataArrayType xbDataArray) throws DecodingException {
    if (!xbDataArray.getElementType().isSetAbstractDataRecord()) {
        throw new DecodingException("The swe:DataArray contains a not yet supported elementType element. " + "Currently only 'swe:DataRecord' is supported as elementType element.");
    }
    final SweDataArray dataArray = new SweDataArray();
    if (xbDataArray.getElementCount() != null) {
        dataArray.setElementCount(parseElementCount(xbDataArray.getElementCount()));
    }
    // parse data record to elementType
    DataComponentPropertyType elementType = xbDataArray.getElementType();
    if (elementType != null) {
        dataArray.setElementType(parseDataComponentProperty(elementType));
    }
    if (xbDataArray.isSetEncoding()) {
        dataArray.setEncoding(parseEncoding(xbDataArray.getEncoding()));
    }
    // parse values
    // if (xbDataArray.isSetValues()) {
    // // TODO implement full support
    // // dataArray.setValues(parseValues(dataArray.getElementCount(),
    // // dataArray.getElementType(),
    // // dataArray.getEncoding(), xbDataArray.getValues()));
    // }
    DataArrayDocument xbDataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
    xbDataArrayDoc.setDataArray1(xbDataArray);
    dataArray.setXml(xbDataArrayDoc.xmlText(getXmlOptions()));
    return dataArray;
}
Also used : NotYetSupportedDecodingException(org.n52.svalbard.decode.exception.NotYetSupportedDecodingException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) DataArrayDocument(net.opengis.swe.x101.DataArrayDocument)

Example 13 with DataComponentPropertyType

use of org.geotoolkit.swe.xml.v100.DataComponentPropertyType in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldBoolean.

@Test
public void should_encode_Datarecord_with_fieldBoolean() throws EncodingException {
    final String field1Name = "test-name";
    final boolean field1Value = true;
    final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweBoolean().setValue(field1Value))));
    assertThat(encode, is(instanceOf(DataRecordType.class)));
    final DataRecordType xbDataRecord = (DataRecordType) encode;
    final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
    assertThat(xbDataRecord.getFieldArray().length, is(1));
    assertThat(field1.isSetBoolean(), is(TRUE));
    assertThat(field1.getName(), is(field1Name));
    assertThat(field1.getBoolean().getValue(), is(field1Value));
}
Also used : SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) DataRecordType(net.opengis.swe.x101.DataRecordType) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) XmlObject(org.apache.xmlbeans.XmlObject) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) Test(org.junit.jupiter.api.Test)

Example 14 with DataComponentPropertyType

use of org.geotoolkit.swe.xml.v100.DataComponentPropertyType in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldCount.

@Test
public void should_encode_Datarecord_with_fieldCount() throws EncodingException {
    final String field1Name = "test-name";
    final int field1Value = 52;
    final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweCount().setValue(field1Value))));
    assertThat(encode, is(instanceOf(DataRecordType.class)));
    final DataRecordType xbDataRecord = (DataRecordType) encode;
    final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
    assertThat(xbDataRecord.getFieldArray().length, is(1));
    assertThat(field1.isSetCount(), is(TRUE));
    assertThat(field1.getName(), is(field1Name));
    assertThat(field1.getCount().getValue(), is(BigInteger.valueOf(field1Value)));
}
Also used : SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) DataRecordType(net.opengis.swe.x101.DataRecordType) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) XmlObject(org.apache.xmlbeans.XmlObject) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) Test(org.junit.jupiter.api.Test)

Example 15 with DataComponentPropertyType

use of org.geotoolkit.swe.xml.v100.DataComponentPropertyType in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldTime.

@Test
public void should_encode_Datarecord_with_fieldTime() throws EncodingException {
    final String field1Name = "test-name";
    final DateTime field1Value = new DateTime(System.currentTimeMillis());
    final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweTime().setValue(field1Value))));
    assertThat(encode, is(instanceOf(DataRecordType.class)));
    final DataRecordType xbDataRecord = (DataRecordType) encode;
    final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
    assertThat(xbDataRecord.getFieldArray().length, is(1));
    assertThat(field1.isSetTime(), is(TRUE));
    assertThat(field1.getName(), is(field1Name));
    final DateTime xbTime = new DateTime(((XmlCalendar) field1.getTime().getValue()).getTimeInMillis(), DateTimeZone.UTC);
    assertThat(xbTime.toDateTime(field1Value.getZone()), is(field1Value));
}
Also used : SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) DataRecordType(net.opengis.swe.x101.DataRecordType) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) XmlObject(org.apache.xmlbeans.XmlObject) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Aggregations

DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)13 XmlObject (org.apache.xmlbeans.XmlObject)10 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)10 DataRecordType (net.opengis.swe.x101.DataRecordType)9 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)9 ArrayList (java.util.ArrayList)8 SweField (org.n52.shetland.ogc.swe.SweField)8 Test (org.junit.jupiter.api.Test)7 InputStream (java.io.InputStream)4 DataComponentPropertyType (org.geotoolkit.swe.xml.v101.DataComponentPropertyType)4 DataRecordType (org.geotoolkit.swe.xml.v101.DataRecordType)4 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)4 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)4 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)4 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)4 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)4 StringWriter (java.io.StringWriter)3 SweEnvelope (org.n52.shetland.ogc.swe.SweEnvelope)3 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)3 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)3