Search in sources :

Example 86 with EncodingException

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

the class SweCommonEncoderv101 method createDataRecord.

// TODO check types for SWE101
private DataRecordType createDataRecord(SweDataRecord sosDataRecord) throws EncodingException {
    List<SweField> sosFields = sosDataRecord.getFields();
    DataRecordType xbDataRecord = DataRecordType.Factory.newInstance(getXmlOptions());
    if (sosDataRecord.isSetDefinition()) {
        xbDataRecord.setDefinition(sosDataRecord.getDefinition());
    }
    if (sosDataRecord.isSetFields()) {
        DataComponentPropertyType[] xbFields = new DataComponentPropertyType[sosFields.size()];
        int xbFieldIndex = 0;
        for (SweField sosSweField : sosFields) {
            DataComponentPropertyType xbField = createField(sosSweField);
            xbFields[xbFieldIndex] = xbField;
            xbFieldIndex++;
        }
        xbDataRecord.setFieldArray(xbFields);
    }
    return xbDataRecord;
}
Also used : DataRecordType(net.opengis.swe.x101.DataRecordType) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) SweField(org.n52.shetland.ogc.swe.SweField) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType)

Example 87 with EncodingException

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

the class SweCommonEncoderv101 method encode.

@Override
public XmlObject encode(Object element, EncodingContext context) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof SweAbstractSimpleType) {
        encodedObject = createSimpleType((SweAbstractSimpleType<?>) element, context);
    // }
    // if (element instanceof SweBoolean) {
    // encodedObject = createBoolean((SweBoolean) element);
    // } else if (element instanceof SweCategory) {
    // encodedObject = createCategory((SweCategory) element);
    // } else if (element instanceof SweCount) {
    // encodedObject = createCount((SweCount) element);
    // } else if (element instanceof SweObservableProperty) {
    // encodedObject = createObservableProperty((SweObservableProperty)
    // element);
    // } else if (element instanceof SweQuantity) {
    // encodedObject = createQuantity((SweQuantity) element);
    // } else if (element instanceof SweQuantityRange) {
    // encodedObject = createQuantityRange((SweQuantityRange) element);
    // } else if (element instanceof SweText) {
    // encodedObject = createText((SweText) element);
    // } else if (element instanceof SweTime) {
    // encodedObject = createTime((SweTime) element);
    // } else if (element instanceof SweTimeRange) {
    // encodedObject = createTimeRange((SweTimeRange) element);
    } else if (element instanceof SweCoordinate) {
        encodedObject = createCoordinate((SweCoordinate<?>) element);
    } else if (element instanceof SweDataArray) {
        encodedObject = createDataArray((SweDataArray) element);
    } else if (element instanceof SweDataRecord) {
        DataRecordType drt = createDataRecord((SweDataRecord) element);
        if (context.has(XmlBeansEncodingFlags.DOCUMENT)) {
            DataRecordDocument drd = DataRecordDocument.Factory.newInstance(getXmlOptions());
            drd.setDataRecord(drt);
            encodedObject = drd;
        } else {
            encodedObject = drt;
        }
    } else if (element instanceof SweEnvelope) {
        encodedObject = createEnvelope((SweEnvelope) element);
    } else if (element instanceof SweSimpleDataRecord) {
        encodedObject = createSimpleDataRecord((SweSimpleDataRecord) element);
    } else if (element instanceof TimePeriod) {
        encodedObject = createTimeGeometricPrimitivePropertyType((TimePeriod) element);
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : DataRecordType(net.opengis.swe.x101.DataRecordType) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) SweAbstractSimpleType(org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) XmlObject(org.apache.xmlbeans.XmlObject) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) DataRecordDocument(net.opengis.swe.x101.DataRecordDocument) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 88 with EncodingException

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

the class SweCommonEncoderv20 method createCoordinate.

private Coordinate createCoordinate(SweCoordinate<?> coordinate) throws EncodingException {
    Coordinate xbCoordinate = Coordinate.Factory.newInstance(getXmlOptions());
    xbCoordinate.setName(coordinate.getName());
    xbCoordinate.setQuantity((QuantityType) createAbstractDataComponent(coordinate.getValue(), EncodingContext.empty()));
    return xbCoordinate;
}
Also used : Coordinate(net.opengis.swe.x20.VectorType.Coordinate) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate)

Example 89 with EncodingException

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

the class SweCommonEncoderv20 method createField.

private DataRecordType.Field createField(SweField field) throws EncodingException {
    SweAbstractDataComponent element = field.getElement();
    DataRecordType.Field xmlField = DataRecordType.Field.Factory.newInstance(getXmlOptions());
    if (field.isSetName()) {
        xmlField.setName(NcName.makeValid(field.getName().getValue()));
    }
    XmlObject encodeObjectToXml = createAbstractDataComponent(element, EncodingContext.empty());
    XmlObject substituteElement = XmlHelper.substituteElement(xmlField.addNewAbstractDataComponent(), encodeObjectToXml);
    substituteElement.set(encodeObjectToXml);
    return xmlField;
}
Also used : DataRecordType(net.opengis.swe.x20.DataRecordType) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) Field(net.opengis.swe.x20.DataRecordType.Field) XmlObject(org.apache.xmlbeans.XmlObject)

Example 90 with EncodingException

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

the class SweCommonEncoderv20 method createQuality.

private QualityPropertyType[] createQuality(final Collection<SweQuality> quality) throws EncodingException {
    if (!quality.isEmpty()) {
        final ArrayList<QualityPropertyType> xbQualities = Lists.newArrayListWithCapacity(quality.size());
        for (final SweQuality sweQuality : quality) {
            final QualityPropertyType xbQuality = QualityPropertyType.Factory.newInstance();
            if (sweQuality instanceof SweText) {
                xbQuality.addNewText().set(((SweText) sweQuality).accept(new SweDataComponentVisitorImpl()));
            } else if (sweQuality instanceof SweCategory) {
                xbQuality.addNewCategory().set(((SweCategory) sweQuality).accept(new SweDataComponentVisitorImpl()));
            } else if (sweQuality instanceof SweQuantity) {
                xbQuality.addNewQuantity().set(((SweQuantity) sweQuality).accept(new SweDataComponentVisitorImpl()));
            } else if (sweQuality instanceof SweQuantityRange) {
                xbQuality.addNewQuantityRange().set(((SweQuantityRange) sweQuality).accept(new SweDataComponentVisitorImpl()));
            }
            xbQualities.add(xbQuality);
        }
        return xbQualities.toArray(new QualityPropertyType[xbQualities.size()]);
    }
    final QualityPropertyType[] result = { QualityPropertyType.Factory.newInstance() };
    return result;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweQuality(org.n52.shetland.ogc.swe.simpleType.SweQuality) QualityPropertyType(net.opengis.swe.x20.QualityPropertyType) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)124 Test (org.junit.Test)93 EncodingException (org.n52.svalbard.encode.exception.EncodingException)60 SweField (org.n52.shetland.ogc.swe.SweField)29 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)29 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)22 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)21 XmlException (org.apache.xmlbeans.XmlException)20 DateTime (org.joda.time.DateTime)19 OmObservation (org.n52.shetland.ogc.om.OmObservation)19 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)17 Time (org.n52.shetland.ogc.gml.time.Time)15 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)15 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)13 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)13 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)12 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)12 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)12 SystemType (net.opengis.sensorML.x101.SystemType)11 DataRecordType (net.opengis.swe.x101.DataRecordType)11