Search in sources :

Example 1 with SmlCharacteristic

use of org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic in project arctic-sea by 52North.

the class SensorMLEncoderv20 method createCharacteristics.

/**
 * Creates the characteristics section of the SensorML description.
 *
 * @param smlCharacteristics
 *            SOS characteristics list
 *
 * @return XML Characteristics array
 *
 * @throws EncodingException
 *             If an error occurs
 */
private Characteristics[] createCharacteristics(final List<SmlCharacteristics> smlCharacteristics) throws EncodingException {
    final List<Characteristics> characteristicsList = new ArrayList<>(smlCharacteristics.size());
    for (final SmlCharacteristics sosSMLCharacteristics : smlCharacteristics) {
        Characteristics xbCharacteristics = Characteristics.Factory.newInstance(getXmlOptions());
        if (sosSMLCharacteristics.isSetName()) {
            xbCharacteristics.setName(sosSMLCharacteristics.getName());
        } else {
            xbCharacteristics.setName("characteristics_" + smlCharacteristics.lastIndexOf(sosSMLCharacteristics));
        }
        CharacteristicListType characteristicList = xbCharacteristics.addNewCharacteristicList();
        if (sosSMLCharacteristics.isSetCharacteristics()) {
            for (SmlCharacteristic characteristic : sosSMLCharacteristics.getCharacteristic()) {
                Characteristic c = characteristicList.addNewCharacteristic();
                c.setName(NcName.makeValid(characteristic.getName()));
                if (characteristic.isSetAbstractDataComponent()) {
                    XmlObject encodeObjectToXml = encodeObjectToXml(SweConstants.NS_SWE_20, characteristic.getAbstractDataComponent());
                    XmlObject substituteElement = XmlHelper.substituteElement(c.addNewAbstractDataComponent(), encodeObjectToXml);
                    substituteElement.set(encodeObjectToXml);
                } else if (characteristic.isSetHref()) {
                    c.setHref(characteristic.getHref());
                    if (characteristic.isSetTitle()) {
                        c.setTitle(characteristic.getTitle());
                    }
                }
            }
        }
        if (sosSMLCharacteristics.isSetAbstractDataComponents()) {
            if (sosSMLCharacteristics.isSetAbstractDataComponents()) {
                for (SweAbstractDataComponent component : sosSMLCharacteristics.getAbstractDataComponents()) {
                    XmlObject encodeObjectToXml = encodeObjectToXml(SweConstants.NS_SWE_20, component);
                    Characteristic c = characteristicList.addNewCharacteristic();
                    c.setName(NcName.makeValid(component.getName().getValue()));
                    XmlObject substituteElement = XmlHelper.substituteElement(c.addNewAbstractDataComponent(), encodeObjectToXml);
                    substituteElement.set(encodeObjectToXml);
                }
            }
        }
        characteristicsList.add(xbCharacteristics);
    }
    return characteristicsList.toArray(new Characteristics[characteristicsList.size()]);
}
Also used : SmlCharacteristics(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristics) Characteristics(net.opengis.sensorml.x20.DescribedObjectType.Characteristics) SmlCharacteristics(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristics) SmlCharacteristic(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic) SmlCharacteristic(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic) Characteristic(net.opengis.sensorml.x20.CharacteristicListType.Characteristic) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ArrayList(java.util.ArrayList) CharacteristicListType(net.opengis.sensorml.x20.CharacteristicListType) XmlObject(org.apache.xmlbeans.XmlObject)

Example 2 with SmlCharacteristic

use of org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic in project arctic-sea by 52North.

the class SmlCharacteristics method getCharacteristic.

/**
 * @return the characteristics
 */
public List<SmlCharacteristic> getCharacteristic() {
    if (!hasCharacteristics() && isSetAbstractDataComponents()) {
        List<SmlCharacteristic> c = Lists.newArrayList();
        for (SweAbstractDataComponent component : getAbstractDataComponents()) {
            SmlCharacteristic smlCharacteristic = new SmlCharacteristic(component.getName().getValue());
            smlCharacteristic.setAbstractDataComponent(component);
            c.add(smlCharacteristic);
        }
        return c;
    }
    return this.characteristics;
}
Also used : SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent)

Example 3 with SmlCharacteristic

use of org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic in project arctic-sea by 52North.

the class SensorMLDecoderV20 method parseCharacteristics.

/**
 * Parses the characteristics
 *
 * @param clpts
 *            XML characteristics
 * @return SOS characteristics
 *
 * @throws DecodingException
 *             * if an error occurs
 */
private List<SmlCharacteristics> parseCharacteristics(final CharacteristicListPropertyType[] clpts) throws DecodingException {
    final List<SmlCharacteristics> sosCharacteristicsList = new ArrayList<>(clpts.length);
    for (final CharacteristicListPropertyType clpt : clpts) {
        final SmlCharacteristics sosCharacteristics = new SmlCharacteristics();
        if (clpt.isSetCharacteristicList()) {
            CharacteristicListType clt = clpt.getCharacteristicList();
            if (CollectionHelper.isNotNullOrEmpty(clt.getCharacteristicArray())) {
                for (Characteristic c : clt.getCharacteristicArray()) {
                    final SmlCharacteristic characteristic = new SmlCharacteristic(c.getName());
                    if (c.isSetAbstractDataComponent()) {
                        final Object o = decodeXmlElement(c.getAbstractDataComponent());
                        if (o instanceof SweAbstractDataComponent) {
                            characteristic.setAbstractDataComponent((SweAbstractDataComponent) o);
                        } else {
                            throw new DecodingException(XmlHelper.getLocalName(clpt), "Error while parsing the characteristics of the SensorML " + "(the characteristics' data record is not of " + "type DataRecordPropertyType)!");
                        }
                    } else if (c.isSetHref()) {
                        characteristic.setHref(c.getHref());
                        if (c.isSetTitle()) {
                            characteristic.setTitle(c.getTitle());
                        }
                    }
                    sosCharacteristics.addCharacteristic(characteristic);
                }
            }
        }
        sosCharacteristicsList.add(sosCharacteristics);
    }
    return sosCharacteristicsList;
}
Also used : SmlCharacteristics(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristics) CharacteristicListPropertyType(net.opengis.sensorml.x20.CharacteristicListPropertyType) SmlCharacteristic(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic) SmlCharacteristic(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic) Characteristic(net.opengis.sensorml.x20.CharacteristicListType.Characteristic) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ArrayList(java.util.ArrayList) CharacteristicListType(net.opengis.sensorml.x20.CharacteristicListType) DescribedObject(org.n52.shetland.ogc.sensorML.v20.DescribedObject) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException)

Aggregations

SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)3 ArrayList (java.util.ArrayList)2 CharacteristicListType (net.opengis.sensorml.x20.CharacteristicListType)2 Characteristic (net.opengis.sensorml.x20.CharacteristicListType.Characteristic)2 XmlObject (org.apache.xmlbeans.XmlObject)2 SmlCharacteristic (org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic)2 SmlCharacteristics (org.n52.shetland.ogc.sensorML.elements.SmlCharacteristics)2 CharacteristicListPropertyType (net.opengis.sensorml.x20.CharacteristicListPropertyType)1 Characteristics (net.opengis.sensorml.x20.DescribedObjectType.Characteristics)1 DescribedObject (org.n52.shetland.ogc.sensorML.v20.DescribedObject)1 DecodingException (org.n52.svalbard.decode.exception.DecodingException)1