use of net.opengis.sensorML.x101.CharacteristicsDocument.Characteristics in project arctic-sea by 52North.
the class SensorMLEncoderv101 method addAbstractProcessValues.
// TODO refactor/rename
private void addAbstractProcessValues(final AbstractProcessType abstractProcess, final AbstractProcess sosAbstractProcess) throws EncodingException {
if (sosAbstractProcess.isSetGmlID()) {
abstractProcess.setId(sosAbstractProcess.getGmlId());
}
if (sosAbstractProcess.isSetCapabilities()) {
final Capabilities[] existing = abstractProcess.getCapabilitiesArray();
final Set<String> names = Sets.newHashSetWithExpectedSize(existing.length);
for (final Capabilities element : existing) {
if (element.getName() != null) {
names.add(element.getName());
}
}
for (final SmlCapabilities sosCapability : sosAbstractProcess.getCapabilities()) {
final Capabilities c = createCapability(sosCapability);
// replace existing capability with the same name
if (names.contains(c.getName())) {
removeCapability(abstractProcess, c);
}
abstractProcess.addNewCapabilities().set(c);
}
}
// set description
if (sosAbstractProcess.isSetDescription() && !abstractProcess.isSetDescription()) {
abstractProcess.addNewDescription().setStringValue(sosAbstractProcess.getDescription());
}
if (sosAbstractProcess.isSetName() && CollectionHelper.isNullOrEmpty(abstractProcess.getNameArray())) {
// TODO check if override existing names
addNamesToAbstractProcess(abstractProcess, sosAbstractProcess.getNames());
}
// set identification
if (sosAbstractProcess.isSetIdentifications()) {
abstractProcess.setIdentificationArray(createIdentification(sosAbstractProcess.getIdentifications()));
}
// set classification
if (sosAbstractProcess.isSetClassifications()) {
abstractProcess.setClassificationArray(createClassification(sosAbstractProcess.getClassifications()));
}
// set characteristics
if (sosAbstractProcess.isSetCharacteristics()) {
abstractProcess.setCharacteristicsArray(createCharacteristics(sosAbstractProcess.getCharacteristics()));
}
// set documentation
if (sosAbstractProcess.isSetDocumentation() && CollectionHelper.isNullOrEmpty(abstractProcess.getDocumentationArray())) {
abstractProcess.setDocumentationArray(createDocumentationArray(sosAbstractProcess.getDocumentation()));
}
// process
if (sosAbstractProcess.isSetContact() && CollectionHelper.isNullOrEmpty(abstractProcess.getContactArray())) {
ContactList contactList = createContactList(sosAbstractProcess.getContact());
if (contactList != null && contactList.getMemberArray().length > 0) {
abstractProcess.addNewContact().setContactList(contactList);
}
}
// set keywords
if (sosAbstractProcess.isSetKeywords()) {
final List<String> keywords = sosAbstractProcess.getKeywords();
final int length = abstractProcess.getKeywordsArray().length;
for (int i = 0; i < length; ++i) {
abstractProcess.removeKeywords(i);
}
abstractProcess.addNewKeywords().addNewKeywordList().setKeywordArray(keywords.toArray(new String[keywords.size()]));
}
if (sosAbstractProcess.isSetValidTime()) {
if (abstractProcess.isSetValidTime()) {
// remove existing validTime element
final XmlCursor newCursor = abstractProcess.getValidTime().newCursor();
newCursor.removeXml();
newCursor.dispose();
}
final Time time = sosAbstractProcess.getMergedValidTime();
final XmlObject xbtime = encodeObjectToXml(GmlConstants.NS_GML, time);
if (time instanceof TimeInstant) {
abstractProcess.addNewValidTime().addNewTimeInstant().set(xbtime);
} else if (time instanceof TimePeriod) {
abstractProcess.addNewValidTime().addNewTimePeriod().set(xbtime);
}
}
}
use of net.opengis.sensorML.x101.CharacteristicsDocument.Characteristics in project arctic-sea by 52North.
the class SensorMLEncoderv101 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 = Lists.newArrayListWithExpectedSize(smlCharacteristics.size());
for (final SmlCharacteristics sosSMLCharacteristics : smlCharacteristics) {
final Characteristics xbCharacteristics = Characteristics.Factory.newInstance(getXmlOptions());
if (sosSMLCharacteristics.isSetName()) {
xbCharacteristics.setName(sosSMLCharacteristics.getName());
}
if (sosSMLCharacteristics.isSetAbstractDataRecord()) {
if (sosSMLCharacteristics.getDataRecord() instanceof SweSimpleDataRecord) {
final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) xbCharacteristics.addNewAbstractDataRecord().substitute(SweConstants.QN_SIMPLEDATARECORD_SWE_101, SimpleDataRecordType.type);
if (sosSMLCharacteristics.isSetTypeDefinition()) {
xbSimpleDataRecord.setDefinition(sosSMLCharacteristics.getTypeDefinition());
}
if (sosSMLCharacteristics.getDataRecord().isSetFields()) {
for (final SweField field : sosSMLCharacteristics.getDataRecord().getFields()) {
final AnyScalarPropertyType xbField = xbSimpleDataRecord.addNewField();
xbField.setName(field.getName().getValue());
addSweSimpleTypeToField(xbField, field.getElement());
}
}
} else if (sosSMLCharacteristics.getDataRecord() instanceof SweDataRecord) {
throw unsupportedCharacteristicsType(SweAggregateType.DataRecord);
} else {
throw unsupportedCharacteristicsType(sosSMLCharacteristics.getDataRecord().getClass().getName());
}
} else if (sosSMLCharacteristics.isSetHref()) {
if (sosSMLCharacteristics.isSetName()) {
xbCharacteristics.setName(sosSMLCharacteristics.getName());
}
xbCharacteristics.setHref(sosSMLCharacteristics.getHref());
if (sosSMLCharacteristics.isSetTitle()) {
xbCharacteristics.setTitle(sosSMLCharacteristics.getTitle());
}
}
characteristicsList.add(xbCharacteristics);
}
return characteristicsList.toArray(new Characteristics[characteristicsList.size()]);
}
Aggregations