use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class UpdateSensorRequestDecoder method parseProcedureDesciption.
private SosProcedureDescription<?> parseProcedureDesciption(String xml, String pdf) throws DecodingException {
try {
final XmlObject xb = XmlObject.Factory.parse(xml);
Decoder<?, XmlObject> decoder = getDecoder(new XmlNamespaceDecoderKey(pdf, xb.getClass()));
if (decoder == null) {
throw new DecodingException(JSONConstants.PROCEDURE_DESCRIPTION_FORMAT, "The requested %s is not supported!", JSONConstants.PROCEDURE_DESCRIPTION_FORMAT);
}
Object decode = decoder.decode(xb);
if (decode instanceof SosProcedureDescription<?>) {
return (SosProcedureDescription<?>) decode;
} else if (decode instanceof AbstractFeature) {
return new SosProcedureDescription<AbstractFeature>((AbstractFeature) decode);
} else {
throw new DecodingException("The decoded element {} is not of type {}!", decode.getClass().getName(), AbstractFeature.class.getName());
}
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing procedure description of InsertSensor request!", xmle);
}
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class SpecimenDecoderv20 method getSampledFeatures.
/**
* Parse {@link FeaturePropertyType} sampledFeature to
* {@link AbstractFeature} list.
*
* @param sampledFeature
* SampledFeature to parse
* @return List with the parsed sampledFeature
* @throws DecodingException
* If an error occurs
*/
private List<AbstractFeature> getSampledFeatures(final FeaturePropertyType sampledFeature) throws DecodingException {
final List<AbstractFeature> sampledFeatures = new ArrayList<AbstractFeature>(1);
if (sampledFeature != null && !sampledFeature.isNil()) {
// if xlink:href is set
if (sampledFeature.getHref() != null && !sampledFeature.getHref().isEmpty()) {
if (sampledFeature.getHref().startsWith("#")) {
sampledFeatures.add(new SamplingFeature(null, sampledFeature.getHref().replace("#", "")));
} else {
final AbstractSamplingFeature sampFeat = new SamplingFeature(new CodeWithAuthority(sampledFeature.getHref()));
if (sampledFeature.getTitle() != null && !sampledFeature.getTitle().isEmpty()) {
sampFeat.addName(new CodeType(sampledFeature.getTitle()));
}
sampledFeatures.add(sampFeat);
}
} else {
XmlObject abstractFeature = null;
if (sampledFeature.getAbstractFeature() != null) {
abstractFeature = sampledFeature.getAbstractFeature();
} else if (sampledFeature.getDomNode().hasChildNodes()) {
try {
abstractFeature = XmlObject.Factory.parse(XmlHelper.getNodeFromNodeList(sampledFeature.getDomNode().getChildNodes()));
} catch (final XmlException xmle) {
throw new DecodingException("Error while parsing feature request!", xmle);
}
}
if (abstractFeature != null) {
final Object decodedObject = decodeXmlObject(abstractFeature);
if (decodedObject instanceof AbstractFeature) {
sampledFeatures.add((AbstractFeature) decodedObject);
}
}
throw new DecodingException("The requested sampledFeature type is not supported by this service!");
}
}
return sampledFeatures;
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class SwesDecoderv20 method parseMetadata.
private SosInsertionMetadata parseMetadata(final Metadata[] metadataArray) throws DecodingException {
final SosInsertionMetadata sosMetadata = new SosInsertionMetadata();
try {
for (final Metadata metadata : metadataArray) {
SosInsertionMetadataType xbSosInsertionMetadata = null;
if (metadata.getInsertionMetadata() != null && metadata.getInsertionMetadata().schemaType() == SosInsertionMetadataType.type) {
xbSosInsertionMetadata = (SosInsertionMetadataType) metadata.getInsertionMetadata();
} else {
if (metadata.getDomNode().hasChildNodes()) {
final Node node = getNodeFromNodeList(metadata.getDomNode().getChildNodes());
final SosInsertionMetadataPropertyType xbMetadata = SosInsertionMetadataPropertyType.Factory.parse(node);
xbSosInsertionMetadata = xbMetadata.getSosInsertionMetadata();
}
}
if (xbSosInsertionMetadata != null) {
// featureOfInterest types
if (xbSosInsertionMetadata.getFeatureOfInterestTypeArray() != null) {
sosMetadata.setFeatureOfInterestTypes(Arrays.asList(xbSosInsertionMetadata.getFeatureOfInterestTypeArray()));
}
// observation types
if (xbSosInsertionMetadata.getObservationTypeArray() != null) {
sosMetadata.setObservationTypes(Arrays.asList(xbSosInsertionMetadata.getObservationTypeArray()));
}
}
}
} catch (final XmlException xmle) {
throw new DecodingException("An error occurred while parsing the metadata in the http post request", xmle);
}
return sosMetadata;
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class SamplingDecoderv20 method getSampledFeatures.
/**
* Parse {@link FeaturePropertyType} sampledFeature to
* {@link AbstractFeature} list.
*
* @param sampledFeature
* SampledFeature to parse
* @return List with the parsed sampledFeature
* @throws DecodingException
* If an error occurs
*/
private List<AbstractFeature> getSampledFeatures(final FeaturePropertyType sampledFeature) throws DecodingException {
final List<AbstractFeature> sampledFeatures = new ArrayList<>(1);
if (sampledFeature != null && !sampledFeature.isNil()) {
// if xlink:href is set
if (sampledFeature.getHref() != null && !sampledFeature.getHref().isEmpty()) {
if (sampledFeature.getHref().startsWith("#")) {
sampledFeatures.add(new SamplingFeature(null, sampledFeature.getHref().replace("#", "")));
} else {
final SamplingFeature sampFeat = new SamplingFeature(new CodeWithAuthority(sampledFeature.getHref()));
if (sampledFeature.getTitle() != null && !sampledFeature.getTitle().isEmpty()) {
sampFeat.addName(new CodeType(sampledFeature.getTitle()));
}
sampledFeatures.add(sampFeat);
}
} else {
XmlObject abstractFeature = null;
if (sampledFeature.getAbstractFeature() != null) {
abstractFeature = sampledFeature.getAbstractFeature();
} else if (sampledFeature.getDomNode().hasChildNodes()) {
try {
abstractFeature = XmlObject.Factory.parse(XmlHelper.getNodeFromNodeList(sampledFeature.getDomNode().getChildNodes()));
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing feature request!", xmle);
}
}
if (abstractFeature != null) {
final Object decodedObject = decodeXmlObject(abstractFeature);
if (decodedObject instanceof AbstractFeature) {
sampledFeatures.add((AbstractFeature) decodedObject);
}
}
throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested sampledFeature type is not supported by this service!");
}
}
return sampledFeatures;
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class AbstractWmlEncoderv20 method createMonitoringPoint.
/**
* Creates a WaterML 2.0 MonitoringPoint XML object from SOS feature object
*
* @param absFeature
* SOS feature
* @return WaterML 2.0 MonitoringPoint XML object
* @throws EncodingException
* If an error occurs
*/
protected XmlObject createMonitoringPoint(AbstractFeature absFeature) throws EncodingException {
if (absFeature instanceof AbstractSamplingFeature) {
AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
StringBuilder builder = new StringBuilder();
builder.append("mp_");
builder.append(JavaHelper.generateID(absFeature.getIdentifierCodeWithAuthority().getValue()));
absFeature.setGmlId(builder.toString());
MonitoringPointDocument monitoringPointDoc = MonitoringPointDocument.Factory.newInstance(getXmlOptions());
if (sampFeat.isSetXml()) {
try {
XmlObject feature = XmlObject.Factory.parse(sampFeat.getXml());
if (XmlHelper.getNamespace(feature).equals(WaterMLConstants.NS_WML_20)) {
if (feature instanceof MonitoringPointDocument) {
monitoringPointDoc = (MonitoringPointDocument) feature;
} else if (feature instanceof MonitoringPointType) {
monitoringPointDoc.setSFSpatialSamplingFeature((MonitoringPointType) feature);
}
XmlHelper.updateGmlIDs(monitoringPointDoc.getDomNode(), absFeature.getGmlId(), null);
return monitoringPointDoc;
}
} catch (XmlException xmle) {
throw new EncodingException("Error while encoding GetFeatureOfInterest response, invalid samplingFeature description!", xmle);
}
}
MonitoringPointType mpt = monitoringPointDoc.addNewMonitoringPoint();
// set gml:id
mpt.setId(absFeature.getGmlId());
if (sampFeat.isSetIdentifier()) {
XmlObject xmlObject = encodeGML(sampFeat.getIdentifierCodeWithAuthority());
if (xmlObject != null) {
mpt.addNewIdentifier().set(xmlObject);
}
}
if (sampFeat.isSetName()) {
for (CodeType sosName : sampFeat.getName()) {
mpt.addNewName().set(encodeGML(sosName));
}
}
if (sampFeat.isSetDescription()) {
if (!mpt.isSetDescription()) {
mpt.addNewDescription();
}
mpt.getDescription().setStringValue(sampFeat.getDescription());
}
// TODO: CHECK
if (sampFeat.getSampledFeatures() != null && !sampFeat.getSampledFeatures().isEmpty()) {
if (sampFeat.getSampledFeatures().size() == 1) {
XmlObject encodeObjectToXml = encodeObjectToXml(GmlConstants.NS_GML_32, sampFeat.getSampledFeatures().get(0));
mpt.addNewSampledFeature().set(encodeObjectToXml);
} else {
FeatureCollection featureCollection = new FeatureCollection();
featureCollection.setGmlId("sampledFeatures_" + absFeature.getGmlId());
for (AbstractFeature sampledFeature : sampFeat.getSampledFeatures()) {
featureCollection.addMember(sampledFeature);
}
XmlObject encodeObjectToXml = encodeGML(featureCollection);
mpt.addNewSampledFeature().set(encodeObjectToXml);
}
} else {
mpt.addNewSampledFeature().setHref(GmlConstants.NIL_UNKNOWN);
}
if (sampFeat.isSetParameter()) {
addParameter(mpt, sampFeat);
}
// set position
ShapeType xbShape = mpt.addNewShape();
Encoder<XmlObject, Geometry> encoder = getEncoder(getEncoderKey(GmlConstants.NS_GML_32, sampFeat.getGeometry()));
if (encoder != null) {
XmlObject xmlObject = encoder.encode(sampFeat.getGeometry(), new EncodingContext().with(XmlBeansEncodingFlags.GMLID, absFeature.getGmlId()));
xbShape.addNewAbstractGeometry().set(xmlObject);
XmlHelper.substituteElement(xbShape.getAbstractGeometry(), xmlObject);
} else {
throw new EncodingException("Error while encoding geometry for feature, needed encoder is missing!");
}
if (absFeature instanceof WmlMonitoringPoint) {
addMonitoringPointValues(mpt, (WmlMonitoringPoint) absFeature);
}
sampFeat.wasEncoded();
return monitoringPointDoc;
}
throw new UnsupportedEncoderInputException(this, absFeature);
}
Aggregations