Search in sources :

Example 1 with SweAbstractSimpleType

use of org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType in project arctic-sea by 52North.

the class SosOffering method from.

/**
 * Creates a set of {@literal SosOffering}s from SWE simple type.
 *
 * @param type
 *            the type (may be {@literal null})
 *
 * @return the set (never {@literal null})
 */
public static SosOffering from(SweAbstractSimpleType<?> type) {
    if (type == null) {
        return null;
    }
    String identifer = type.getValue().toString();
    CodeType name = type.getName();
    SosOffering offering = new SosOffering(identifer, name);
    if (type.isSetDescription()) {
        offering.setDescription(type.getDescription());
    }
    return offering;
}
Also used : CodeType(org.n52.shetland.ogc.gml.CodeType)

Example 2 with SweAbstractSimpleType

use of org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType 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 3 with SweAbstractSimpleType

use of org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType 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 4 with SweAbstractSimpleType

use of org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType in project arctic-sea by 52North.

the class SweCommonEncoderv101 method createSimpleType.

private AbstractDataComponentType createSimpleType(SweAbstractSimpleType<?> sosSimpleType, EncodingContext additionalValues) throws EncodingException {
    AbstractDataComponentType abstractDataComponentType = null;
    if (sosSimpleType instanceof SweBoolean) {
        abstractDataComponentType = createBoolean((SweBoolean) sosSimpleType);
    } else if (sosSimpleType instanceof SweCategory) {
        abstractDataComponentType = createCategory((SweCategory) sosSimpleType);
    } else if (sosSimpleType instanceof SweCount) {
        abstractDataComponentType = createCount((SweCount) sosSimpleType);
    } else if (sosSimpleType instanceof SweCountRange) {
        abstractDataComponentType = createCountRange((SweCountRange) sosSimpleType);
    } else if (sosSimpleType instanceof SweObservableProperty) {
        abstractDataComponentType = createObservableProperty((SweObservableProperty) sosSimpleType);
    } else if (sosSimpleType instanceof SweQuantity) {
        abstractDataComponentType = createQuantity((SweQuantity) sosSimpleType);
    } else if (sosSimpleType instanceof SweQuantityRange) {
        abstractDataComponentType = createQuantityRange((SweQuantityRange) sosSimpleType);
    } else if (sosSimpleType instanceof SweText) {
        abstractDataComponentType = createText((SweText) sosSimpleType);
    } else if (sosSimpleType instanceof SweTimeRange) {
        abstractDataComponentType = createTimeRange((SweTimeRange) sosSimpleType);
    } else if (sosSimpleType instanceof SweTime) {
        abstractDataComponentType = createTime((SweTime) sosSimpleType);
    } else {
        throw new NotYetSupportedEncodingException(SweAbstractSimpleType.class.getSimpleName(), sosSimpleType);
    }
    addAbstractDataComponentValues(abstractDataComponentType, sosSimpleType);
    return abstractDataComponentType;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) AbstractDataComponentType(net.opengis.swe.x101.AbstractDataComponentType) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) SweCountRange(org.n52.shetland.ogc.swe.simpleType.SweCountRange) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SweObservableProperty(org.n52.shetland.ogc.swe.simpleType.SweObservableProperty)

Example 5 with SweAbstractSimpleType

use of org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType 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

DataRecordType (net.opengis.swe.x101.DataRecordType)2 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)2 XmlObject (org.apache.xmlbeans.XmlObject)2 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)2 SweAbstractSimpleType (org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType)2 EncodingException (org.n52.svalbard.encode.exception.EncodingException)2 NotYetSupportedEncodingException (org.n52.svalbard.encode.exception.NotYetSupportedEncodingException)2 InputList (net.opengis.sensorML.x101.InputsDocument.Inputs.InputList)1 IoComponentPropertyType (net.opengis.sensorML.x101.IoComponentPropertyType)1 OutputList (net.opengis.sensorML.x101.OutputsDocument.Outputs.OutputList)1 SensorMLDocument (net.opengis.sensorML.x101.SensorMLDocument)1 SystemType (net.opengis.sensorML.x101.SystemType)1 AbstractDataComponentType (net.opengis.swe.x101.AbstractDataComponentType)1 DataArrayType (net.opengis.swe.x101.DataArrayType)1 DataRecordDocument (net.opengis.swe.x101.DataRecordDocument)1 Test (org.junit.Test)1 CodeType (org.n52.shetland.ogc.gml.CodeType)1 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)1 AbstractProcess (org.n52.shetland.ogc.sensorML.AbstractProcess)1 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)1