use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class ExiEncoder method encode.
@Override
public EXIObject<XmlObject> encode(T response) throws EncodingException {
Encoder<Object, T> encoder = getEncoder(response);
Object encode = encoder.encode(response);
if (encode != null && encode instanceof XmlObject) {
return new EXIObject<XmlObject>((XmlObject) encode);
} else {
throw new UnsupportedEncoderInputException(encoder, response);
}
}
use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException 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.svalbard.encode.exception.UnsupportedEncoderInputException 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.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class AbstractOmEncoderv20 method encode.
@Override
public XmlObject encode(Object element, EncodingContext additionalValues) throws EncodingException {
XmlObject encodedObject = null;
if (element instanceof OmObservation) {
encodedObject = encodeOmObservation((OmObservation) element, additionalValues);
} else if (element instanceof NamedValue) {
NamedValueType nvt = createNamedValue((NamedValue<?>) element);
if (additionalValues.has(XmlBeansEncodingFlags.DOCUMENT)) {
NamedValueDocument nvd = NamedValueDocument.Factory.newInstance();
nvd.setNamedValue(nvt);
encodedObject = nvd;
} else if (additionalValues.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
NamedValuePropertyType nvpt = NamedValuePropertyType.Factory.newInstance();
nvpt.setNamedValue(nvt);
encodedObject = nvpt;
} else {
encodedObject = nvt;
}
} else if (element instanceof AbstractFeature) {
encodedObject = encodeFeatureOfInterest((AbstractFeature) element);
} else if (element instanceof SosProcedureDescription) {
encodedObject = encodeProcedureDescription((SosProcedureDescription<?>) element);
} else {
throw new UnsupportedEncoderInputException(this, element);
}
// XmlHelper.validateDocument(encodedObject));
return encodedObject;
}
use of org.n52.svalbard.encode.exception.UnsupportedEncoderInputException in project arctic-sea by 52North.
the class OmEncoderv100 method encode.
@Override
public XmlObject encode(Object element, EncodingContext additionalValues) throws EncodingException {
XmlObject encodedObject = null;
if (element instanceof OmObservation) {
encodedObject = createObservation((OmObservation) element, additionalValues);
} else if (element instanceof GetObservationResponse) {
GetObservationResponse response = (GetObservationResponse) element;
encodedObject = createObservationCollection(response.getObservationCollection(), response.getResultModel());
} else if (element instanceof GetObservationByIdResponse) {
GetObservationByIdResponse response = (GetObservationByIdResponse) element;
encodedObject = createObservationCollection(response.getObservationCollection(), response.getResultModel());
} else {
throw new UnsupportedEncoderInputException(this, element);
}
XmlHelper.validateDocument(encodedObject, EncodingException::new);
return encodedObject;
}
Aggregations