use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class GmlEncoderv321 method createPosition.
private XmlObject createPosition(Geometry geom, EncodingContext ctx) throws EncodingException {
String foiId = ctx.<String>get(XmlBeansEncodingFlags.GMLID).orElse(null);
if (geom instanceof Point) {
PointType xbPoint = PointType.Factory.newInstance(getXmlOptions());
xbPoint.setId(getGmlID(geom, foiId));
createPointFromJtsGeometry((Point) geom, xbPoint);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
PointDocument xbPointDoc = PointDocument.Factory.newInstance(getXmlOptions());
xbPointDoc.setPoint(xbPoint);
return xbPointDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbPoint);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_POINT_32, PointType.type);
return geometryPropertyType;
}
return xbPoint;
} else if (geom instanceof LineString) {
LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
xbLineString.setId(getGmlID(geom, foiId));
createLineStringFromJtsGeometry((LineString) geom, xbLineString);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
LineStringDocument xbLineStringDoc = LineStringDocument.Factory.newInstance(getXmlOptions());
xbLineStringDoc.setLineString(xbLineString);
return xbLineStringDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbLineString);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_LINESTRING_32, LineStringType.type);
return geometryPropertyType;
}
return xbLineString;
} else if (geom instanceof MultiLineString) {
MultiCurveType xbMultiCurve = MultiCurveType.Factory.newInstance(getXmlOptions());
xbMultiCurve.setId(getGmlID(geom, foiId));
xbMultiCurve.setSrsName(getSrsName(geom));
for (int i = 0; i < geom.getNumGeometries(); ++i) {
Geometry lineString = geom.getGeometryN(i);
LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
xbLineString.setId(getGmlID(geom, foiId));
xbLineString.addNewPosList().setStringValue(JTSHelper.getCoordinatesString(lineString));
CurvePropertyType xbCurveMember = xbMultiCurve.addNewCurveMember();
xbCurveMember.addNewAbstractCurve().set(xbLineString);
XmlHelper.substituteElement(xbCurveMember.getAbstractCurve(), xbLineString);
}
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
MultiCurveDocument xbMultiCurveDoc = MultiCurveDocument.Factory.newInstance(getXmlOptions());
xbMultiCurveDoc.setMultiCurve(xbMultiCurve);
return xbMultiCurveDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType xbGeometryProperty = GeometryPropertyType.Factory.newInstance(getXmlOptions());
xbGeometryProperty.addNewAbstractGeometry().set(xbMultiCurve);
XmlHelper.substituteElement(xbGeometryProperty.getAbstractGeometry(), xbMultiCurve);
return xbGeometryProperty;
} else {
return xbMultiCurve;
}
} else if (geom instanceof Polygon) {
PolygonType xbPolygon = PolygonType.Factory.newInstance(getXmlOptions());
xbPolygon.setId(getGmlID(geom, foiId));
createPolygonFromJtsGeometry((Polygon) geom, xbPolygon);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
PolygonDocument xbPolygonDoc = PolygonDocument.Factory.newInstance(getXmlOptions());
xbPolygonDoc.setPolygon(xbPolygon);
return xbPolygonDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbPolygon);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_POLYGON_32, PolygonType.type);
return geometryPropertyType;
}
return xbPolygon;
} else if (geom instanceof MultiPoint) {
MultiPointType xbMultiPoint = MultiPointType.Factory.newInstance(getXmlOptions());
String id = getGmlID(geom, foiId);
xbMultiPoint.setId(id);
createMultiPointFromJtsGeometry((MultiPoint) geom, xbMultiPoint, id);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
MultiPointDocument xbMultiPointDoc = MultiPointDocument.Factory.newInstance(getXmlOptions());
xbMultiPointDoc.setMultiPoint(xbMultiPoint);
return xbMultiPointDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbMultiPoint);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_MULTI_POINT_32, PolygonType.type);
return geometryPropertyType;
}
return xbMultiPoint;
} else {
throw new UnsupportedEncoderInputException(this, geom);
}
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class GmlEncoderv321 method createGenericMetaData.
private XmlObject createGenericMetaData(GenericMetaData element, EncodingContext ctx) throws EncodingException {
GenericMetaDataDocument gmdd = GenericMetaDataDocument.Factory.newInstance(getXmlOptions());
GenericMetaDataType gmdt = gmdd.addNewGenericMetaData();
if (element.getContent() instanceof HasDefaultEncoding && ((HasDefaultEncoding<?>) element.getContent()).isSetDefaultElementEncoding()) {
// TODO check
gmdt.set(encodeObjectToXml(((HasDefaultEncoding<?>) element.getContent()).getDefaultElementEncoding(), element.getContent(), new EncodingContext().with(XmlBeansEncodingFlags.PROPERTY_TYPE, true)));
}
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
return gmdd;
}
return gmdt;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class GmlEncoderv321 method addAbstractCRSValues.
private void addAbstractCRSValues(AbstractCRSType acrst, AbstractCRS abstractCRS) throws EncodingException {
addDefinitonValues(acrst, abstractCRS);
if (abstractCRS.hasDomainOfValidity()) {
for (Referenceable<DomainOfValidity> domainOfValidity : abstractCRS.getDomainOfValidity()) {
net.opengis.gml.x32.DomainOfValidityDocument.DomainOfValidity dov = acrst.addNewDomainOfValidity();
if (domainOfValidity.isReference()) {
Reference reference = domainOfValidity.getReference();
reference.getActuate().map(Actuate::toString).map(ActuateType.Enum::forString).ifPresent(dov::setActuate);
reference.getArcrole().ifPresent(dov::setArcrole);
reference.getHref().map(URI::toString).ifPresent(dov::setHref);
reference.getRole().ifPresent(dov::setRole);
reference.getShow().map(Show::toString).map(ShowType.Enum::forString).ifPresent(dov::setShow);
reference.getTitle().ifPresent(dov::setTitle);
reference.getType().map(Type::toString).map(TypeType.Enum::forString).ifPresent(dov::setType);
} else {
if (domainOfValidity.isInstance()) {
Nillable<DomainOfValidity> nillable = domainOfValidity.getInstance();
if (nillable.isPresent()) {
net.opengis.gml.x32.DomainOfValidityDocument.DomainOfValidity xml = createDomainOfValidity(nillable.get(), EncodingContext.empty());
if (xml != null) {
dov.set(xml);
} else {
dov.setNil();
dov.setNilReason(Nillable.missing().get());
}
} else {
dov.setNil();
if (nillable.hasReason()) {
dov.setNilReason(nillable.getNilReason().get());
} else {
dov.setNilReason(Nillable.missing().get());
}
}
}
}
}
}
if (abstractCRS.hasScope()) {
abstractCRS.getScope().forEach(scope -> acrst.addNewScope().setStringValue(scope));
}
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class InsertFeatureOfInterestEncoder method create.
@Override
protected XmlObject create(InsertFeatureOfInterestResponse ifoir) throws EncodingException {
if (ifoir == null) {
throw new UnsupportedEncoderInputException(this, InsertFeatureOfInterestResponse.class);
}
InsertFeatureOfInterestResponseDocument ifoird = InsertFeatureOfInterestResponseDocument.Factory.newInstance(getXmlOptions());
ifoird.addNewInsertFeatureOfInterestResponse();
return ifoird;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class GetCapabilitiesResponseEncoder method create.
@Override
protected XmlObject create(GetCapabilitiesResponse response) throws EncodingException {
CapabilitiesDocument doc = CapabilitiesDocument.Factory.newInstance(getXmlOptions());
CapabilitiesType xbCaps = doc.addNewCapabilities();
if (response.isStatic()) {
String xml = response.getXmlString();
LOGGER.trace("Response is static. XML-String:\n{}\n", xml);
try {
doc.set(XmlObject.Factory.parse(xml));
return doc;
} catch (XmlException ex) {
throw new EncodingException("Error encoding static capabilities", ex);
}
}
// set version.
if (response.getCapabilities().getVersion() != null) {
xbCaps.setVersion(response.getCapabilities().getVersion());
} else {
xbCaps.setVersion(response.getVersion());
}
encodeServiceIdentification(response.getCapabilities(), xbCaps);
encodeServiceProvider(response.getCapabilities(), xbCaps);
encodeOperationsMetadata(response.getCapabilities(), xbCaps);
if (response.getCapabilities() instanceof SosCapabilities) {
SosCapabilities caps = (SosCapabilities) response.getCapabilities();
encodeFilterCapabilities(caps, xbCaps);
encodeContents(caps, xbCaps, response.getVersion());
encodeExtensions(caps, xbCaps);
}
return doc;
}
Aggregations