use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class SensorMLEncoderv101 method createSensorMLDescription.
protected SensorMLDocument createSensorMLDescription(final SensorML smlSensorDesc) throws EncodingException {
final SensorMLDocument sensorMLDoc = SensorMLDocument.Factory.newInstance(getXmlOptions());
final net.opengis.sensorML.x101.SensorMLDocument.SensorML xbSensorML = sensorMLDoc.addNewSensorML();
xbSensorML.setVersion(SensorMLConstants.VERSION_V101);
if (smlSensorDesc.isSetMembers()) {
for (final AbstractProcess sml : smlSensorDesc.getMembers()) {
if (sml instanceof System) {
final SystemType xbSystem = (SystemType) xbSensorML.addNewMember().addNewProcess().substitute(new QName(SensorMLConstants.NS_SML, SensorMLConstants.EN_SYSTEM), SystemType.type);
final System smlSystem = (System) sml;
addAbstractProcessValues(xbSystem, smlSystem);
addSystemValues(xbSystem, smlSystem);
} else if (sml instanceof ProcessModel) {
final ProcessModelType xbProcessModel = (ProcessModelType) xbSensorML.addNewMember().addNewProcess().substitute(new QName(SensorMLConstants.NS_SML, SensorMLConstants.EN_PROCESS_MODEL), ProcessModelType.type);
final ProcessModel smlProcessModel = (ProcessModel) sml;
addAbstractProcessValues(xbProcessModel, smlProcessModel);
addProcessModelValues(xbProcessModel, smlProcessModel);
} else if (sml instanceof org.n52.shetland.ogc.sensorML.Component) {
final ComponentType xbCompontent = (ComponentType) xbSensorML.addNewMember().addNewProcess().substitute(new QName(SensorMLConstants.NS_SML, SensorMLConstants.EN_COMPONENT), ComponentType.type);
final org.n52.shetland.ogc.sensorML.Component smlComponent = (org.n52.shetland.ogc.sensorML.Component) sml;
addAbstractProcessValues(xbCompontent, smlComponent);
addComponentValues(xbCompontent, smlComponent);
}
}
}
return sensorMLDoc;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class SensorMLEncoderv101 method createOutputs.
/**
* Creates the outputs section of the SensorML description.
*
* @param sosOutputs
* SOS SWE representation.
*
* @return XML Outputs element
*
* @throws EncodingException
* if the encoding fails
*/
private Outputs createOutputs(final List<SmlIo> sosOutputs) throws EncodingException {
Outputs outputs = Outputs.Factory.newInstance(getXmlOptions());
OutputList outputList = outputs.addNewOutputList();
Set<String> definitions = Sets.newHashSet();
int counter = 1;
Set<String> outputNames = Sets.newHashSet();
for (SmlIo sosSMLIo : sosOutputs) {
if (sosSMLIo.isSetValue() && !definitions.contains(sosSMLIo.getIoValue().getDefinition())) {
if (!sosSMLIo.isSetName() || outputNames.contains(sosSMLIo.getIoName())) {
sosSMLIo.setIoName(getValidOutputName(counter++, outputNames));
}
outputNames.add(sosSMLIo.getIoName());
addIoComponentPropertyType(outputList.addNewOutput(), sosSMLIo);
definitions.add(sosSMLIo.getIoValue().getDefinition());
}
}
return outputs;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class SensorMLEncoderv20 method createComponents.
/**
* Creates the components section of the SensorML description.
*
* @param sosComponents
* SOS SWE representation.
*
* @return encoded sml:components
*
* @throws EncodingException
* if the process encoding fails
*/
private ComponentListPropertyType createComponents(final List<SmlComponent> sosComponents) throws EncodingException {
ComponentListPropertyType clpt = ComponentListPropertyType.Factory.newInstance(getXmlOptions());
final ComponentListType clt = clpt.addNewComponentList();
for (final SmlComponent sosSMLComponent : sosComponents) {
final Component component = clt.addNewComponent();
if (sosSMLComponent.isSetName()) {
component.setName(sosSMLComponent.getName());
}
if (sosSMLComponent.isSetHref()) {
component.setHref(sosSMLComponent.getHref());
if (sosSMLComponent.isSetTitle()) {
component.setTitle(sosSMLComponent.getTitle());
}
} else if (sosSMLComponent.isSetProcess()) {
XmlObject xmlObject = encode(sosSMLComponent.getProcess(), EncodingContext.of(XmlBeansEncodingFlags.TYPE));
// }
if (xmlObject != null) {
// AbstractProcessType xbProcess = null;
// if (xmlObject instanceof AbstractProcessType) {
// xbProcess = (AbstractProcessType) xmlObject;
// } else {
// throw new NoApplicableCodeException()
// .withMessage("The sensor type is not supported by this
// SOS");
// }
// TODO add feature/parentProcs/childProcs to component - is
// this already done?
// XmlObject substituteElement =
// XmlHelper.substituteElement(component.addNewAbstractProcess(),
// xmlObject);
// substituteElement.set(xmlObject);
substitute(component.addNewAbstractProcess(), xmlObject);
}
}
}
return clpt;
}
use of org.n52.svalbard.encode.exception.EncodingException 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()]);
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class SensorMLEncoderv20 method createCapability.
private Capabilities createCapability(final SmlCapabilities capabilities) throws EncodingException {
Capabilities xbCapabilities = null;
if (capabilities.isSetAbstractDataComponents()) {
xbCapabilities = Capabilities.Factory.newInstance(getXmlOptions());
if (capabilities.isSetName()) {
xbCapabilities.setName(capabilities.getName());
}
CapabilityListType capabilityList = xbCapabilities.addNewCapabilityList();
if (capabilities.isSetCapabilities()) {
for (SmlCapability capability : capabilities.getCapabilities()) {
XmlObject encodeObjectToXml = encodeObjectToXmlSwe20(capability.getAbstractDataComponent());
Capability c = capabilityList.addNewCapability();
if (capability.isSetName()) {
c.setName(NcName.makeValid(capability.getName()));
} else if (capability.getAbstractDataComponent().isSetName()) {
capability.setName(NcName.makeValid(capability.getAbstractDataComponent().getName().getValue()));
} else {
capability.setName(NcName.makeValid(capability.getAbstractDataComponent().getDefinition()));
}
XmlObject substituteElement = XmlHelper.substituteElement(c.addNewAbstractDataComponent(), encodeObjectToXml);
substituteElement.set(encodeObjectToXml);
}
} else if (capabilities.isSetAbstractDataComponents()) {
for (SweAbstractDataComponent component : capabilities.getAbstractDataComponents()) {
XmlObject encodeObjectToXml = encodeObjectToXmlSwe20(component);
Capability capability = capabilityList.addNewCapability();
if (component.isSetName()) {
capability.setName(NcName.makeValid(component.getName().getValue()));
} else {
capability.setName(NcName.makeValid(component.getDefinition()));
}
XmlObject substituteElement = XmlHelper.substituteElement(capability.addNewAbstractDataComponent(), encodeObjectToXml);
substituteElement.set(encodeObjectToXml);
}
}
}
return xbCapabilities;
}
Aggregations