use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class OmDecoderv20 method getResult.
private ObservationValue<?> getResult(OMObservationType omObservation) throws DecodingException {
XmlObject xbResult = omObservation.getResult();
if (xbResult.schemaType() == XmlAnyTypeImpl.type) {
// Template observation for InsertResultTemplate operation
if (!xbResult.getDomNode().hasChildNodes()) {
return new SingleObservationValue<>(new NilTemplateValue());
} else {
try {
xbResult = XmlObject.Factory.parse(xbResult.xmlText().trim());
} catch (XmlException e) {
LOGGER.error("Error while parsing NamedValueValue", e);
}
}
}
if (xbResult.schemaType() == XmlBoolean.type) {
// TruthObservation
XmlBoolean xbBoolean = (XmlBoolean) xbResult;
BooleanValue booleanValue = new BooleanValue(xbBoolean.getBooleanValue());
return new SingleObservationValue<>(booleanValue);
} else if (xbResult.schemaType() == XmlInteger.type) {
// CountObservation
XmlInteger xbInteger = (XmlInteger) xbResult;
CountValue countValue = new CountValue(Integer.parseInt(xbInteger.getBigIntegerValue().toString()));
return new SingleObservationValue<>(countValue);
} else if (xbResult.schemaType() == XmlString.type) {
// TextObservation
XmlString xbString = (XmlString) xbResult;
TextValue stringValue = new TextValue(xbString.getStringValue());
return new SingleObservationValue<>(stringValue);
} else {
// result elements with other encoding like SWE_ARRAY_OBSERVATION
Object decodedObject = decodeXmlObject(xbResult);
if (decodedObject instanceof ObservationValue) {
return (ObservationValue<?>) decodedObject;
} else if (decodedObject instanceof GmlMeasureType) {
GmlMeasureType measureType = (GmlMeasureType) decodedObject;
QuantityValue quantitiyValue = new QuantityValue(measureType.getValue(), measureType.getUnit());
return new SingleObservationValue<>(quantitiyValue);
} else if (decodedObject instanceof ReferenceType) {
if (omObservation.isSetType() && omObservation.getType().isSetHref() && omObservation.getType().getHref().equals(OmConstants.OBS_TYPE_REFERENCE_OBSERVATION)) {
return new SingleObservationValue<>(new ReferenceValue((ReferenceType) decodedObject));
}
return new SingleObservationValue<>(new CategoryValue(((ReferenceType) decodedObject).getHref()));
} else if (decodedObject instanceof Geometry) {
return new SingleObservationValue<>(new GeometryValue((Geometry) decodedObject));
} else if (decodedObject instanceof AbstractGeometry) {
SingleObservationValue<Geometry> result = new SingleObservationValue<>();
result.setValue(new GeometryValue(((AbstractGeometry) decodedObject).getGeometry()));
return result;
} else if (decodedObject instanceof SweDataArray) {
return new SingleObservationValue<>(new SweDataArrayValue((SweDataArray) decodedObject));
} else if (decodedObject instanceof SweDataRecord) {
return new SingleObservationValue<>(new ComplexValue((SweDataRecord) decodedObject));
}
throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested result type '{}' is not supported by this service!", decodedObject.getClass().getSimpleName());
}
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class FesDecoderv20 method parsePropertyIsBetweenFilter.
/**
* Parse XML propertyIsBetween element
*
* @param comparisonOpsType
* XML propertyIsBetween element
* @return SOS comparison filter
* @throws DecodingException
* If an error occurs of the filter is not supported
*/
private ComparisonFilter parsePropertyIsBetweenFilter(PropertyIsBetweenType comparisonOpsType) throws DecodingException {
ComparisonFilter comparisonFilter = new ComparisonFilter();
comparisonFilter.setOperator(ComparisonOperator.PropertyIsBetween);
try {
comparisonFilter.setValueReference(parseValueReference(comparisonOpsType.getExpression()));
} catch (XmlException xmle) {
throw valueReferenceParsingException(xmle);
}
if (comparisonOpsType.getLowerBoundary().getExpression() instanceof LiteralType) {
comparisonFilter.setValue(parseLiteralValue((LiteralType) comparisonOpsType.getLowerBoundary().getExpression()));
}
if (comparisonOpsType.getUpperBoundary().getExpression() instanceof LiteralType) {
comparisonFilter.setValueUpper(parseLiteralValue((LiteralType) comparisonOpsType.getUpperBoundary().getExpression()));
}
return comparisonFilter;
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class FesDecoderv20 method parseSpatialFilterType.
/**
* Parses the spatial filter of a request.
*
* @param xbSpatialOpsType
* XmlBean representing the feature of interest parameter of the
* request
* @return Returns SpatialFilter created from the passed foi request
* parameter
*
* @throws DecodingException
* * if creation of the SpatialFilter failed
*/
private SpatialFilter parseSpatialFilterType(SpatialOpsType xbSpatialOpsType) throws DecodingException {
SpatialFilter spatialFilter = new SpatialFilter();
try {
if (xbSpatialOpsType instanceof BBOXType) {
spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
BBOXType xbBBOX = (BBOXType) xbSpatialOpsType;
if (isValueReferenceExpression(xbBBOX.getExpression())) {
spatialFilter.setValueReference(parseValueReference(xbBBOX.getExpression()));
}
XmlCursor geometryCursor = xbSpatialOpsType.newCursor();
if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE_32)) {
Object sosGeometry = decodeXmlObject(Factory.parse(geometryCursor.getDomNode()));
if (sosGeometry instanceof Geometry) {
spatialFilter.setGeometry((Geometry) sosGeometry);
} else if (sosGeometry instanceof ReferencedEnvelope) {
spatialFilter.setGeometry((ReferencedEnvelope) sosGeometry);
} else {
throw new UnsupportedDecoderXmlInputException(this, xbSpatialOpsType);
}
} else {
throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter operand is not supported by this SOS!");
}
geometryCursor.dispose();
} else {
throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter is not supported by this SOS!");
}
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing spatial filter!", xmle);
}
return spatialFilter;
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class CapabilitiesTypeDecoder method parseOffering.
private SosObservationOffering parseOffering(AbstractContentsType.Offering offering) {
SosObservationOffering observationOffering = new SosObservationOffering();
if (offering.getDomNode().hasChildNodes()) {
final Node node = XmlHelper.getNodeFromNodeList(offering.getDomNode().getChildNodes());
try {
ObservationOfferingPropertyType offeringType = ObservationOfferingPropertyType.Factory.parse(node);
ObservationOfferingType obsOffPropType = offeringType.getObservationOffering();
observationOffering.setOffering(parseOffering(obsOffPropType));
observationOffering.setProcedures(parseProcedure(obsOffPropType));
observationOffering.setProcedureDescriptionFormat(parseProcedureDescriptionFormat(obsOffPropType));
observationOffering.setObservableProperties(parseObservableProperties(obsOffPropType));
observationOffering.setRelatedFeatures(parseRelatedFeatures(obsOffPropType));
observationOffering.setObservedArea(parseObservedArea(obsOffPropType));
observationOffering.setPhenomenonTime(parsePhenomenonTime(obsOffPropType));
observationOffering.setResultTime(parseResultTime(obsOffPropType));
observationOffering.setResponseFormats(parseResponseFormats(obsOffPropType));
observationOffering.setObservationTypes(parseObservationTypes(obsOffPropType));
observationOffering.setFeatureOfInterestTypes(parseFeatureOfInterestTypes(obsOffPropType));
observationOffering.setExtensions(parseOfferingExtension(obsOffPropType));
} catch (XmlException | DecodingException ex) {
LOGGER.error(ex.getLocalizedMessage(), ex);
}
}
return observationOffering;
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class OgcDecoderv100 method parseSpatialOperatorType.
private Object parseSpatialOperatorType(BinarySpatialOpType xbSpatialOpsType) throws DecodingException {
SpatialFilter spatialFilter = new SpatialFilter();
try {
if (xbSpatialOpsType instanceof BBOXTypeImpl) {
spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
BBOXTypeImpl xbBBOX = (BBOXTypeImpl) xbSpatialOpsType;
spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
XmlCursor geometryCursor = xbBBOX.newCursor();
if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE)) {
Object sosGeometry = decodeXmlElement(XmlObject.Factory.parse(geometryCursor.getDomNode()));
if (sosGeometry instanceof Geometry) {
spatialFilter.setGeometry((Geometry) sosGeometry);
}
} else {
throw unsupportedSpatialFilter();
}
geometryCursor.dispose();
} else {
throw unsupportedSpatialFilter();
}
} catch (XmlException xmle) {
throw errorParsingSpatialFilter(xmle);
}
return spatialFilter;
}
Aggregations