use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class InspireXmlEncoder method encodeObject.
private XmlObject encodeObject(InspireObject objectToEncode, EncodingContext ctx) throws EncodingException {
try {
checkIfSupported(objectToEncode);
ByteArrayOutputStream out = new ByteArrayOutputStream();
EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
new InspireXmlStreamWriter(context, out, objectToEncode).write();
String s = out.toString("UTF8");
return XmlObject.Factory.parse(s);
} catch (XMLStreamException | DateTimeFormatException | XmlException | UnsupportedEncodingException ex) {
throw new EncodingException("Error encoding Inspire extended capabilities!", ex);
}
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class DeleteObservationEncoder method create.
@Override
protected XmlObject create(DeleteObservationResponse dor) throws EncodingException {
if (dor == null) {
throw new UnsupportedEncoderInputException(this, DeleteObservationResponse.class);
}
String observationId = dor.getObservationId();
DeleteObservationResponseDocument xbDeleteObsDoc = DeleteObservationResponseDocument.Factory.newInstance(getXmlOptions());
DeleteObservationResponseType xbDeleteObservationResponse = xbDeleteObsDoc.addNewDeleteObservationResponse();
xbDeleteObservationResponse.setDeletedObservation(observationId);
return xbDeleteObsDoc;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class SamplingEncoderv100 method createFeature.
private XmlObject createFeature(AbstractFeature absFeature) throws EncodingException {
if (absFeature instanceof AbstractSamplingFeature) {
AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGPOINT) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT) || sampFeat.getGeometry() instanceof Point) {
SamplingPointDocument xbSamplingPointDoc = SamplingPointDocument.Factory.newInstance(getXmlOptions());
SamplingPointType xbSamplingPoint = xbSamplingPointDoc.addNewSamplingPoint();
addValuesToFeature(xbSamplingPoint, sampFeat);
XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
xbSamplingPoint.addNewPosition().addNewPoint().set(xbGeomety);
sampFeat.wasEncoded();
return xbSamplingPointDoc;
} else if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGCURVE) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_CURVE) || sampFeat.getGeometry() instanceof LineString) {
SamplingCurveDocument xbSamplingCurveDoc = SamplingCurveDocument.Factory.newInstance(getXmlOptions());
SamplingCurveType xbSamplingCurve = xbSamplingCurveDoc.addNewSamplingCurve();
addValuesToFeature(xbSamplingCurve, sampFeat);
XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
xbSamplingCurve.addNewShape().addNewCurve().set(xbGeomety);
sampFeat.wasEncoded();
return xbSamplingCurveDoc;
} else if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGSURFACE) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_SURFACE) || sampFeat.getGeometry() instanceof Polygon) {
SamplingSurfaceDocument xbSamplingSurfaceDoc = SamplingSurfaceDocument.Factory.newInstance(getXmlOptions());
SamplingSurfaceType xbSamplingSurface = xbSamplingSurfaceDoc.addNewSamplingSurface();
addValuesToFeature(xbSamplingSurface, sampFeat);
XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
xbSamplingSurface.addNewShape().addNewSurface().set(xbGeomety);
sampFeat.wasEncoded();
return xbSamplingSurfaceDoc;
}
} else if (absFeature instanceof FeatureCollection) {
createFeatureCollection((FeatureCollection) absFeature);
}
throw new UnsupportedEncoderInputException(this, absFeature);
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class SamplingEncoderv100 method addValuesToFeature.
private void addValuesToFeature(SamplingFeatureType xbSamplingFeature, AbstractSamplingFeature sampFeat) throws EncodingException {
xbSamplingFeature.setId(sampFeat.getGmlId());
if (sampFeat.isSetIdentifier()) {
sampFeat.getIdentifierCodeWithAuthority().setCodeSpace("uniquID");
xbSamplingFeature.addNewName().set(encodeObjectToXml(GmlConstants.NS_GML, sampFeat.getIdentifierCodeWithAuthority()));
}
if (sampFeat.isSetName()) {
for (CodeType sosName : sampFeat.getName()) {
xbSamplingFeature.addNewName().set(encodeObjectToXml(GmlConstants.NS_GML, sosName));
}
}
// TODO: CHECK
if (sampFeat.getSampledFeatures() != null && !sampFeat.getSampledFeatures().isEmpty()) {
for (AbstractFeature sampledFeature : sampFeat.getSampledFeatures()) {
FeaturePropertyType sp = xbSamplingFeature.addNewSampledFeature();
sp.setHref(sampledFeature.getIdentifier());
if (sampFeat.isSetName() && sampFeat.getFirstName().isSetValue()) {
sp.setTitle(sampFeat.getFirstName().getValue());
}
// xbSamplingFeature.addNewSampledFeature().set(createFeature(sampledFeature));
}
} else {
xbSamplingFeature.addNewSampledFeature().setHref(GmlConstants.NIL_UNKNOWN);
}
// set metadataProperty
setMetaDataProperty(xbSamplingFeature, sampFeat);
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class SamplingEncoderv20 method addSampledFeatures.
protected void addSampledFeatures(SFSamplingFeatureType sfsft, AbstractSamplingFeature sampFeat) throws EncodingException {
if (sampFeat.isSetSampledFeatures()) {
for (AbstractFeature sampledFeature : sampFeat.getSampledFeatures()) {
XmlObject encodeObjectToXml = encodeObjectToXml(GmlConstants.NS_GML_32, sampledFeature, new EncodingContext().with(XmlBeansEncodingFlags.REFERENCED));
sfsft.addNewSampledFeature().set(encodeObjectToXml);
}
} else {
sfsft.addNewSampledFeature().setHref(OGCConstants.UNKNOWN);
}
}
Aggregations