use of org.n52.shetland.ogc.swe.simpleType.SweCount in project arctic-sea by 52North.
the class SweCommonDecoderV20 method parseValues.
private List<List<String>> parseValues(final SweCount elementCount, final SweAbstractDataComponent elementType, final SweAbstractEncoding encoding, final EncodedValuesPropertyType encodedValuesPropertyType) throws DecodingException {
if (checkParameterTypes(elementType, encoding)) {
// Get swe values String via cursor as String
String values;
// TODO replace XmlCursor
/*
* if (encodedValuesPropertyType.schemaType() == XmlString.type) {
* XmlString xbString
*/
// @see SosDecoderv20#parseResultValues
XmlCursor xbCursor = encodedValuesPropertyType.newCursor();
xbCursor.toFirstContentToken();
if (xbCursor.isText()) {
values = xbCursor.getTextValue().trim();
xbCursor.dispose();
if (values != null && !values.isEmpty()) {
SweTextEncoding textEncoding = (SweTextEncoding) encoding;
String[] blocks = values.split(textEncoding.getBlockSeparator());
List<List<String>> resultValues = new ArrayList<>(blocks.length);
for (String block : blocks) {
String[] tokens = block.split(textEncoding.getTokenSeparator());
List<String> tokenList = Arrays.asList(tokens);
resultValues.add(tokenList);
}
return resultValues;
}
}
}
return null;
}
use of org.n52.shetland.ogc.swe.simpleType.SweCount in project arctic-sea by 52North.
the class AbstractGmlDecoderv321 method parseNamedValueValue.
protected NamedValue<?> parseNamedValueValue(XmlObject xml) throws DecodingException {
XmlObject xmlObject = xml;
if (xmlObject.schemaType() == XmlAnyTypeImpl.type) {
try {
xmlObject = XmlObject.Factory.parse(xml.xmlText().trim());
} catch (XmlException e) {
LOGGER.error("Error while parsing NamedValueValue", e);
}
}
Object value;
if (XmlBoolean.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlBoolean) xmlObject).getBooleanValue();
} else if (XmlString.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlString) xmlObject).getStringValue();
} else if (XmlInt.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlInt) xmlObject).getIntValue();
} else if (XmlInteger.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlInteger) xmlObject).getBigIntegerValue().intValue();
} else if (XmlDouble.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlDouble) xmlObject).getDoubleValue();
} else {
value = decodeXmlObject(xmlObject);
}
if (value instanceof BooleanValue) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue((BooleanValue) value);
return namedValue;
} else if (value instanceof SweBoolean) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue(new BooleanValue(((SweBoolean) value).getValue()));
return namedValue;
} else if (value instanceof Boolean) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue(new BooleanValue((Boolean) value));
return namedValue;
} else if (value instanceof CategoryValue) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue((CategoryValue) value);
return namedValue;
} else if (value instanceof SweCategory) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new CategoryValue(((SweCategory) value).getValue(), ((SweCategory) value).getCodeSpace()));
return namedValue;
} else if (value instanceof CountValue) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue((CountValue) value);
return namedValue;
} else if (value instanceof SweCount) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue(new CountValue(((SweCount) value).getValue()));
return namedValue;
} else if (value instanceof Integer) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue(new CountValue((Integer) value));
return namedValue;
} else if (value instanceof GeometryValue) {
NamedValue<Geometry> namedValue = new NamedValue<>();
namedValue.setValue((GeometryValue) value);
return namedValue;
} else if (value instanceof QuantityValue) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue((QuantityValue) value);
return namedValue;
} else if (value instanceof GmlMeasureType) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue(((GmlMeasureType) value).getValue(), ((GmlMeasureType) value).getUnit()));
return namedValue;
} else if (value instanceof SweQuantity) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue(((SweQuantity) value).getValue(), ((SweQuantity) value).getUom()));
return namedValue;
} else if (value instanceof Double) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue((Double) value));
return namedValue;
} else if (value instanceof TextValue) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue((TextValue) value);
return namedValue;
} else if (value instanceof SweText) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new TextValue(((SweText) value).getValue()));
return namedValue;
} else if (value instanceof String) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new TextValue((String) value));
return namedValue;
} else if (value instanceof AbstractGeometry) {
NamedValue<Geometry> namedValue = new NamedValue<>();
namedValue.setValue(new GeometryValue((AbstractGeometry) value));
return namedValue;
} else if (value instanceof org.n52.shetland.ogc.gml.ReferenceType) {
NamedValue<org.n52.shetland.ogc.gml.ReferenceType> namedValue = new NamedValue<>();
namedValue.setValue(new ReferenceValue((org.n52.shetland.ogc.gml.ReferenceType) value));
return namedValue;
} else if (value instanceof W3CHrefAttribute) {
NamedValue<W3CHrefAttribute> namedValue = new NamedValue<>();
namedValue.setValue(new HrefAttributeValue((W3CHrefAttribute) value));
return namedValue;
} else {
throw new UnsupportedDecoderInputException(this, xmlObject);
}
}
use of org.n52.shetland.ogc.swe.simpleType.SweCount in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_count_with_quality_Category.
@Test
public void should_encode_count_with_quality_Category() throws EncodingException {
final String qualityCategoryValue = "quality-category-value";
final SweCount sosCount = (SweCount) new SweCount().setQuality(Lists.newArrayList((SweQuality) new SweCategory().setValue(qualityCategoryValue)));
final XmlObject encode = sweCommonEncoderv101.encode(sosCount);
assertThat(encode, instanceOf(Count.class));
final Count xbCount = (Count) encode;
assertThat(xbCount.getQualityArray(), is(not(nullValue())));
assertThat(xbCount.getQualityArray().length, is(1));
assertThat(xbCount.getQualityArray(0).isSetCategory(), is(true));
assertThat(xbCount.getQualityArray(0).getCategory().getValue(), is(qualityCategoryValue));
}
use of org.n52.shetland.ogc.swe.simpleType.SweCount in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldCount.
@Test
public void should_encode_Datarecord_with_fieldCount() throws EncodingException {
final String field1Name = "test-name";
final int field1Value = 52;
final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweCount().setValue(field1Value))));
assertThat(encode, is(instanceOf(DataRecordType.class)));
final DataRecordType xbDataRecord = (DataRecordType) encode;
final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
assertThat(xbDataRecord.getFieldArray().length, is(1));
assertThat(field1.isSetCount(), is(TRUE));
assertThat(field1.getName(), is(field1Name));
assertThat(field1.getCount().getValue(), is(BigInteger.valueOf(field1Value)));
}
use of org.n52.shetland.ogc.swe.simpleType.SweCount in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_count_with_quality_QuantityRange.
@Test
public void should_encode_count_with_quality_QuantityRange() throws EncodingException {
final RangeValue<BigDecimal> qualityQuantityRangeValue = new RangeValue<>(BigDecimal.valueOf(1.0), BigDecimal.valueOf(2.0));
final SweCount sosCount = (SweCount) new SweCount().setQuality(Lists.newArrayList((SweQuality) new SweQuantityRange().setValue(qualityQuantityRangeValue)));
final XmlObject encode = sweCommonEncoderv101.encode(sosCount);
assertThat(encode, instanceOf(Count.class));
final Count xbCount = (Count) encode;
assertThat(xbCount.getQualityArray(), is(not(nullValue())));
assertThat(xbCount.getQualityArray().length, is(1));
assertThat(xbCount.getQualityArray(0).isSetQuantityRange(), is(true));
assertThat(BigDecimal.valueOf((Double) xbCount.getQualityArray(0).getQuantityRange().getValue().get(0)), is(qualityQuantityRangeValue.getRangeStart()));
assertThat(BigDecimal.valueOf((Double) xbCount.getQualityArray(0).getQuantityRange().getValue().get(1)), is(qualityQuantityRangeValue.getRangeEnd()));
}
Aggregations