use of org.n52.shetland.ogc.sensorML.SensorML 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;
}
use of org.n52.shetland.ogc.sensorML.SensorML in project arctic-sea by 52North.
the class SensorMLDecoderV20 method parseCapabilities.
/**
* Parses the capabilities, processing and removing special insertion
* metadata
*
* @param abstractProcess
* The AbstractProcess to which capabilities and insertion
* metadata are added
* @param capabilitiesArray
* XML capabilities
*
* @throws DecodingException
* * if an error occurs
*/
private void parseCapabilities(final AbstractProcess abstractProcess, final Capabilities[] capabilitiesArray) throws DecodingException {
for (final Capabilities cs : capabilitiesArray) {
final SmlCapabilities capabilities = new SmlCapabilities(cs.getName());
if (cs.isSetCapabilityList()) {
CapabilityListType cl = cs.getCapabilityList();
if (CollectionHelper.isNotNullOrEmpty(cl.getCapabilityArray())) {
for (Capability c : cl.getCapabilityArray()) {
final SmlCapability capability = new SmlCapability(c.getName());
if (c.isSetAbstractDataComponent()) {
final Object o = decodeXmlElement(c.getAbstractDataComponent());
if (o instanceof SweAbstractDataComponent) {
capability.setAbstractDataComponent((SweAbstractDataComponent) o);
capabilities.addCapability(capability);
} else {
throw new DecodingException(XmlHelper.getLocalName(cs), "Error while parsing the capabilities of " + "the SensorML (the capabilities data record " + "is not of type DataRecordPropertyType)!");
}
} else if (c.isSetHref()) {
capability.setHref(c.getHref());
if (c.isSetTitle()) {
capability.setTitle(c.getTitle());
}
}
}
}
}
abstractProcess.addCapabilities(capabilities);
}
}
use of org.n52.shetland.ogc.sensorML.SensorML 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);
}
use of org.n52.shetland.ogc.sensorML.SensorML in project arctic-sea by 52North.
the class SensorMLEncoderv101 method createPosition.
/**
* Creates the position section of the SensorML description.
*
* @param position
* SOS position
*
* @return XML Position element
*
* @throws EncodingException
* if an error occurs
*/
private Position createPosition(final SmlPosition position) throws EncodingException {
Position xbPosition = Position.Factory.newInstance(getXmlOptions());
if (position.isSetName()) {
xbPosition.setName(position.getName().getValue());
} else {
xbPosition.setName("position");
}
PositionType xbSwePosition = xbPosition.addNewPosition();
xbSwePosition.setFixed(position.isFixed());
xbSwePosition.setReferenceFrame(position.getReferenceFrame());
final VectorType xbVector = xbSwePosition.addNewLocation().addNewVector();
for (SweCoordinate<?> coordinate : position.getPosition()) {
if (coordinate.getValue().getValue() != null && (!coordinate.getValue().isSetValue() || !coordinate.getValue().getValue().equals(Double.NaN))) {
// FIXME: SWE Common NS
xbVector.addNewCoordinate().set(encodeObjectToXml(SweConstants.NS_SWE_101, coordinate));
}
}
return xbPosition;
}
use of org.n52.shetland.ogc.sensorML.SensorML in project arctic-sea by 52North.
the class SensorMLEncoderv101 method createComponents.
/**
* Creates the components section of the SensorML description.
*
* @param sosComponents
* SOS SWE representation.
*
* @return encoded sml:components
*
* @throws EncodingException
* if the encoding fails
*/
private Components createComponents(List<SmlComponent> sosComponents) throws EncodingException {
Components components = Components.Factory.newInstance(getXmlOptions());
ComponentList componentList = components.addNewComponentList();
for (SmlComponent sosSMLComponent : sosComponents) {
Component component = componentList.addNewComponent();
if (sosSMLComponent.getName() != null) {
component.setName(sosSMLComponent.getName());
}
if (sosSMLComponent.getHref() != null) {
component.setHref(sosSMLComponent.getHref());
if (sosSMLComponent.getTitle() != null) {
component.setTitle(sosSMLComponent.getTitle());
}
} else if (sosSMLComponent.getProcess() != null) {
XmlObject xmlObject = null;
if (sosSMLComponent.getProcess().isSetXml()) {
try {
xmlObject = XmlObject.Factory.parse(sosSMLComponent.getProcess().getXml());
} catch (XmlException xmle) {
throw new EncodingException("Error while encoding SensorML child procedure description " + "from stored SensorML encoded sensor description with XMLBeans", xmle);
}
} else {
if (sosSMLComponent.getProcess() instanceof SensorML) {
xmlObject = createSensorDescriptionFromObject(((SensorML) sosSMLComponent.getProcess()).getMembers().iterator().next());
} else if (sosSMLComponent.getProcess() instanceof AbstractProcess) {
xmlObject = createSensorDescriptionFromObject(sosSMLComponent.getProcess());
}
}
if (xmlObject != null) {
AbstractProcessType xbProcess = null;
if (xmlObject instanceof SensorMLDocument) {
final SensorMLDocument smlDoc = (SensorMLDocument) xmlObject;
for (final Member member : smlDoc.getSensorML().getMemberArray()) {
xbProcess = member.getProcess();
break;
}
} else if (xmlObject instanceof AbstractProcessType) {
xbProcess = (AbstractProcessType) xmlObject;
}
if (xbProcess == null) {
throw new EncodingException("The sensor type is not supported by this SOS");
}
// TODO add feature/parentProcs/childProcs to component - is
// this already done?
SchemaType schemaType = xbProcess.schemaType();
component.addNewProcess().substitute(getQnameForType(schemaType), schemaType).set(xbProcess);
}
}
}
return components;
}
Aggregations