use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class ObservationEncoder method encodeSweDataArrayValue.
private JsonNode encodeSweDataArrayValue(Value<?> value) throws EncodingException {
SweDataArrayValue sweDataArrayValue = (SweDataArrayValue) value;
ObjectNode result = nodeFactory().objectNode();
ArrayNode jfields = result.putArray(JSONConstants.FIELDS);
ArrayNode jvalues = result.putArray(JSONConstants.VALUES);
List<SweField> fields = ((SweDataRecord) sweDataArrayValue.getValue().getElementType()).getFields();
List<List<String>> values = sweDataArrayValue.getValue().getValues();
TokenConverter[] conv = new TokenConverter[fields.size()];
int i = 0;
for (SweField field : fields) {
try {
conv[i++] = TokenConverter.forField(field);
} catch (IllegalArgumentException e) {
throw new UnsupportedEncoderInputException(this, field);
}
jfields.add(encodeObjectToJson(field));
}
for (List<String> block : values) {
ArrayNode jblock = jvalues.addArray();
i = 0;
for (String token : block) {
jblock.add(conv[i++].convert(token));
}
}
return result;
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class ObservationEncoder method encodeComplexValue.
private JsonNode encodeComplexValue(Value<?> value) throws EncodingException {
ArrayNode result = nodeFactory().arrayNode();
ComplexValue complexValue = (ComplexValue) value;
SweAbstractDataRecord sweDataRecord = complexValue.getValue();
for (SweField field : sweDataRecord.getFields()) {
result.add(encodeObjectToJson(field));
}
return result;
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class ObservationEncoder method getFieldForValue.
private SweField getFieldForValue(String phenomenon, Value<?> value) throws EncodingException {
final SweAbstractDataComponent def;
if (value instanceof BooleanValue) {
def = new SweBoolean();
} else if (value instanceof CategoryValue) {
SweCategory sweCategory = new SweCategory();
CategoryValue categoryValue = (CategoryValue) value;
sweCategory.setCodeSpace(categoryValue.getUnit());
def = sweCategory;
} else if (value instanceof CountValue) {
def = new SweCount();
} else if (value instanceof QuantityValue) {
SweQuantity sweQuantity = new SweQuantity();
QuantityValue quantityValue = (QuantityValue) value;
sweQuantity.setUom(quantityValue.getUnit());
def = sweQuantity;
} else if (value instanceof TextValue) {
def = new SweText();
} else if (value instanceof NilTemplateValue) {
def = new SweText();
} else if (value instanceof BooleanValue) {
def = new SweBoolean();
} else if (value instanceof GeometryValue) {
def = new SweText();
} else {
throw new UnsupportedEncoderInputException(this, value);
}
def.setDefinition(phenomenon);
return new SweField(phenomenon, def);
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createSimpleDataRecord.
private SimpleDataRecordType createSimpleDataRecord(SweSimpleDataRecord simpleDataRecord) throws EncodingException {
SimpleDataRecordType xbSimpleDataRecord = SimpleDataRecordType.Factory.newInstance(getXmlOptions());
if (simpleDataRecord.isSetDefinition()) {
xbSimpleDataRecord.setDefinition(simpleDataRecord.getDefinition());
}
if (simpleDataRecord.isSetDescription()) {
StringOrRefType xbSoR = StringOrRefType.Factory.newInstance();
xbSoR.setStringValue(simpleDataRecord.getDefinition());
xbSimpleDataRecord.setDescription(xbSoR);
}
if (simpleDataRecord.isSetFields()) {
AnyScalarPropertyType[] xbFields = new AnyScalarPropertyType[simpleDataRecord.getFields().size()];
int xbFieldIndex = 0;
for (SweField sweField : simpleDataRecord.getFields()) {
AnyScalarPropertyType xbField = createFieldForSimpleDataRecord(sweField);
xbFields[xbFieldIndex] = xbField;
xbFieldIndex++;
}
xbSimpleDataRecord.setFieldArray(xbFields);
}
return xbSimpleDataRecord;
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createFieldForSimpleDataRecord.
private AnyScalarPropertyType createFieldForSimpleDataRecord(SweField sweField) throws EncodingException {
SweAbstractDataComponent sosElement = sweField.getElement();
AnyScalarPropertyType xbField = AnyScalarPropertyType.Factory.newInstance(getXmlOptions());
if (sweField.isSetName()) {
xbField.setName(sweField.getName().getValue());
}
AbstractDataComponentType xbDCD;
if (sosElement instanceof SweBoolean) {
xbDCD = xbField.addNewBoolean();
xbDCD.set(createSimpleType((SweBoolean) sosElement));
} else if (sosElement instanceof SweCategory) {
xbDCD = xbField.addNewCategory();
xbDCD.set(createSimpleType((SweCategory) sosElement));
} else if (sosElement instanceof SweCount) {
xbDCD = xbField.addNewCount();
xbDCD.set(createSimpleType((SweCount) sosElement));
} else if (sosElement instanceof SweQuantity) {
xbDCD = xbField.addNewQuantity();
xbDCD.set(createSimpleType((SweQuantity) sosElement));
} else if (sosElement instanceof SweText) {
xbDCD = xbField.addNewText();
xbDCD.set(createSimpleType((SweText) sosElement));
} else if (sosElement instanceof SweTime) {
xbDCD = xbField.addNewTime();
xbDCD.set(createSimpleType((SweTime) sosElement));
} else {
throw new EncodingException("The element type '%s' of the received %s is not supported by this encoder '%s'.", new Object[] { sosElement != null ? sosElement.getClass().getName() : null, sweField.getClass().getName(), getClass().getName() });
}
return xbField;
}
Aggregations