Search in sources :

Example 41 with EncodingContext

use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.

the class GmlEncoderv321 method createVerticalCRS.

private XmlObject createVerticalCRS(VerticalCRS verticalCRS, EncodingContext ctx) throws EncodingException {
    VerticalCRSType vcrst = VerticalCRSType.Factory.newInstance();
    addAbstractCRSValues(vcrst, verticalCRS);
    // verticalCS
    Referenceable<VerticalCS> verticalCS = verticalCRS.getVerticalCS();
    VerticalCSPropertyType vcspt = vcrst.addNewVerticalCS();
    if (verticalCS.isReference()) {
        Reference reference = verticalCS.getReference();
        reference.getActuate().map(Actuate::toString).map(ActuateType.Enum::forString).ifPresent(vcspt::setActuate);
        reference.getArcrole().ifPresent(vcspt::setArcrole);
        reference.getHref().map(URI::toString).ifPresent(vcspt::setHref);
        reference.getRole().ifPresent(vcspt::setRole);
        reference.getShow().map(Show::toString).map(ShowType.Enum::forString).ifPresent(vcspt::setShow);
        reference.getTitle().ifPresent(vcspt::setTitle);
        reference.getType().map(Type::toString).map(TypeType.Enum::forString).ifPresent(vcspt::setType);
    } else {
        if (verticalCS.isInstance()) {
            Nillable<VerticalCS> nillable = verticalCS.getInstance();
            if (nillable.isPresent()) {
                XmlObject xml = createVerticalCS(nillable.get(), EncodingContext.empty());
                if (xml != null && xml instanceof VerticalCSType) {
                    vcspt.set((VerticalCSType) xml);
                } else {
                    vcspt.setNil();
                    vcspt.setNilReason(Nillable.missing().get());
                }
            } else {
                vcspt.setNil();
                if (nillable.hasReason()) {
                    vcspt.setNilReason(nillable.getNilReason().get());
                } else {
                    vcspt.setNilReason(Nillable.missing().get());
                }
            }
        }
    }
    // verticalDatum
    Referenceable<VerticalDatum> verticalDatum = verticalCRS.getVerticalDatum();
    VerticalDatumPropertyType vdpt = vcrst.addNewVerticalDatum();
    if (verticalDatum.isReference()) {
        Reference reference = verticalDatum.getReference();
        reference.getActuate().map(Actuate::toString).map(ActuateType.Enum::forString).ifPresent(vdpt::setActuate);
        reference.getArcrole().ifPresent(vdpt::setArcrole);
        reference.getHref().map(URI::toString).ifPresent(vdpt::setHref);
        reference.getRole().ifPresent(vdpt::setRole);
        reference.getShow().map(Show::toString).map(ShowType.Enum::forString).ifPresent(vdpt::setShow);
        reference.getTitle().ifPresent(vdpt::setTitle);
        reference.getType().map(Type::toString).map(TypeType.Enum::forString).ifPresent(vdpt::setType);
    } else {
        if (verticalDatum.isInstance()) {
            Nillable<VerticalDatum> nillable = verticalDatum.getInstance();
            if (nillable.isPresent()) {
                XmlObject xml = createVerticalDatum(nillable.get(), EncodingContext.empty());
                if (xml != null && xml instanceof VerticalDatumType) {
                    vdpt.setVerticalDatum((VerticalDatumType) xml);
                } else {
                    vdpt.setNil();
                    vdpt.setNilReason(Nillable.missing().get());
                }
            } else {
                vdpt.setNil();
                if (nillable.hasReason()) {
                    vdpt.setNilReason(nillable.getNilReason().get());
                } else {
                    vdpt.setNilReason(Nillable.missing().get());
                }
            }
        }
    }
    if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
        VerticalCRSPropertyType vcrspt = VerticalCRSPropertyType.Factory.newInstance();
        vcrspt.setVerticalCRS(vcrst);
        return vcrspt;
    }
    return vcrst;
}
Also used : ActuateType(org.w3.x1999.xlink.ActuateType) Reference(org.n52.shetland.w3c.xlink.Reference) VerticalDatumPropertyType(net.opengis.gml.x32.VerticalDatumPropertyType) VerticalCSPropertyType(net.opengis.gml.x32.VerticalCSPropertyType) VerticalCSType(net.opengis.gml.x32.VerticalCSType) VerticalDatum(org.n52.shetland.ogc.gml.VerticalDatum) Actuate(org.n52.shetland.w3c.xlink.Actuate) EnvelopeType(net.opengis.gml.x32.EnvelopeType) MultiPointType(net.opengis.gml.x32.MultiPointType) VerticalDatumPropertyType(net.opengis.gml.x32.VerticalDatumPropertyType) CodeType(net.opengis.gml.x32.CodeType) DirectPositionListType(net.opengis.gml.x32.DirectPositionListType) CoordinateSystemAxisPropertyType(net.opengis.gml.x32.CoordinateSystemAxisPropertyType) VerticalCSType(net.opengis.gml.x32.VerticalCSType) TimePeriodPropertyType(net.opengis.gml.x32.TimePeriodPropertyType) LineStringType(net.opengis.gml.x32.LineStringType) CoordinateSystemAxisType(net.opengis.gml.x32.CoordinateSystemAxisType) FeaturePropertyType(net.opengis.gml.x32.FeaturePropertyType) TimeInstantPropertyType(net.opengis.gml.x32.TimeInstantPropertyType) TimeIndeterminateValueType(net.opengis.gml.x32.TimeIndeterminateValueType) GeometryPropertyType(net.opengis.gml.x32.GeometryPropertyType) PolygonType(net.opengis.gml.x32.PolygonType) VerticalDatumType(net.opengis.gml.x32.VerticalDatumType) MultiCurveType(net.opengis.gml.x32.MultiCurveType) AggregationType(net.opengis.gml.x32.AggregationType) AbstractCRSType(net.opengis.gml.x32.AbstractCRSType) ShowType(org.w3.x1999.xlink.ShowType) AbstractRingPropertyType(net.opengis.gml.x32.AbstractRingPropertyType) LinearRingType(net.opengis.gml.x32.LinearRingType) EXExtentType(org.isotc211.x2005.gmd.EXExtentType) TimePeriodType(net.opengis.gml.x32.TimePeriodType) ReferenceType(net.opengis.gml.x32.ReferenceType) TimeInstantType(net.opengis.gml.x32.TimeInstantType) GenericMetaDataType(net.opengis.gml.x32.GenericMetaDataType) ActuateType(org.w3.x1999.xlink.ActuateType) TimePositionType(net.opengis.gml.x32.TimePositionType) VerticalCRSType(net.opengis.gml.x32.VerticalCRSType) CurvePropertyType(net.opengis.gml.x32.CurvePropertyType) DefinitionType(net.opengis.gml.x32.DefinitionType) AbstractCoordinateSystemType(net.opengis.gml.x32.AbstractCoordinateSystemType) AbstractDatumType(net.opengis.gml.x32.AbstractDatumType) AbstractRingType(net.opengis.gml.x32.AbstractRingType) MeasureType(net.opengis.gml.x32.MeasureType) VerticalCSPropertyType(net.opengis.gml.x32.VerticalCSPropertyType) CodeWithAuthorityType(net.opengis.gml.x32.CodeWithAuthorityType) TypeType(org.w3.x1999.xlink.TypeType) Type(org.n52.shetland.w3c.xlink.Type) AbstractGeometryType(net.opengis.gml.x32.AbstractGeometryType) DirectPositionType(net.opengis.gml.x32.DirectPositionType) FeatureCollectionType(net.opengis.gml.x32.FeatureCollectionType) PointType(net.opengis.gml.x32.PointType) VerticalCRSPropertyType(net.opengis.gml.x32.VerticalCRSPropertyType) VerticalCS(org.n52.shetland.ogc.gml.VerticalCS) VerticalDatumType(net.opengis.gml.x32.VerticalDatumType) VerticalCRSPropertyType(net.opengis.gml.x32.VerticalCRSPropertyType) Show(org.n52.shetland.w3c.xlink.Show) XmlObject(org.apache.xmlbeans.XmlObject) TypeType(org.w3.x1999.xlink.TypeType) VerticalCRSType(net.opengis.gml.x32.VerticalCRSType) ShowType(org.w3.x1999.xlink.ShowType)

Example 42 with EncodingContext

use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.

the class GmlEncoderv321 method addAbstractDatumValues.

private void addAbstractDatumValues(AbstractDatumType adt, AbstractDatum abstractDatum, EncodingContext ctx) throws EncodingException {
    addDefinitonValues(adt, abstractDatum);
    if (abstractDatum.hasAnchorDefinition()) {
        adt.setAnchorDefinition(createCodeType(abstractDatum.getAnchorDefinition()));
    }
    if (abstractDatum.hasDomainOfValidity()) {
        net.opengis.gml.x32.DomainOfValidityDocument.DomainOfValidity dov = adt.addNewDomainOfValidity();
        Referenceable<DomainOfValidity> domainOfValidity = abstractDatum.getDomainOfValidity();
        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 (abstractDatum.hasRealizationEpoch()) {
        adt.setRealizationEpoch(abstractDatum.getRealizationEpoch().toCalendar(Locale.ROOT));
    }
    abstractDatum.getScope().forEach(scope -> adt.addNewScope().setStringValue(scope));
}
Also used : ActuateType(org.w3.x1999.xlink.ActuateType) DomainOfValidity(org.n52.shetland.ogc.gml.DomainOfValidity) Reference(org.n52.shetland.w3c.xlink.Reference) Actuate(org.n52.shetland.w3c.xlink.Actuate) EnvelopeType(net.opengis.gml.x32.EnvelopeType) MultiPointType(net.opengis.gml.x32.MultiPointType) VerticalDatumPropertyType(net.opengis.gml.x32.VerticalDatumPropertyType) CodeType(net.opengis.gml.x32.CodeType) DirectPositionListType(net.opengis.gml.x32.DirectPositionListType) CoordinateSystemAxisPropertyType(net.opengis.gml.x32.CoordinateSystemAxisPropertyType) VerticalCSType(net.opengis.gml.x32.VerticalCSType) TimePeriodPropertyType(net.opengis.gml.x32.TimePeriodPropertyType) LineStringType(net.opengis.gml.x32.LineStringType) CoordinateSystemAxisType(net.opengis.gml.x32.CoordinateSystemAxisType) FeaturePropertyType(net.opengis.gml.x32.FeaturePropertyType) TimeInstantPropertyType(net.opengis.gml.x32.TimeInstantPropertyType) TimeIndeterminateValueType(net.opengis.gml.x32.TimeIndeterminateValueType) GeometryPropertyType(net.opengis.gml.x32.GeometryPropertyType) PolygonType(net.opengis.gml.x32.PolygonType) VerticalDatumType(net.opengis.gml.x32.VerticalDatumType) MultiCurveType(net.opengis.gml.x32.MultiCurveType) AggregationType(net.opengis.gml.x32.AggregationType) AbstractCRSType(net.opengis.gml.x32.AbstractCRSType) ShowType(org.w3.x1999.xlink.ShowType) AbstractRingPropertyType(net.opengis.gml.x32.AbstractRingPropertyType) LinearRingType(net.opengis.gml.x32.LinearRingType) EXExtentType(org.isotc211.x2005.gmd.EXExtentType) TimePeriodType(net.opengis.gml.x32.TimePeriodType) ReferenceType(net.opengis.gml.x32.ReferenceType) TimeInstantType(net.opengis.gml.x32.TimeInstantType) GenericMetaDataType(net.opengis.gml.x32.GenericMetaDataType) ActuateType(org.w3.x1999.xlink.ActuateType) TimePositionType(net.opengis.gml.x32.TimePositionType) VerticalCRSType(net.opengis.gml.x32.VerticalCRSType) CurvePropertyType(net.opengis.gml.x32.CurvePropertyType) DefinitionType(net.opengis.gml.x32.DefinitionType) AbstractCoordinateSystemType(net.opengis.gml.x32.AbstractCoordinateSystemType) AbstractDatumType(net.opengis.gml.x32.AbstractDatumType) AbstractRingType(net.opengis.gml.x32.AbstractRingType) MeasureType(net.opengis.gml.x32.MeasureType) VerticalCSPropertyType(net.opengis.gml.x32.VerticalCSPropertyType) CodeWithAuthorityType(net.opengis.gml.x32.CodeWithAuthorityType) TypeType(org.w3.x1999.xlink.TypeType) Type(org.n52.shetland.w3c.xlink.Type) AbstractGeometryType(net.opengis.gml.x32.AbstractGeometryType) DirectPositionType(net.opengis.gml.x32.DirectPositionType) FeatureCollectionType(net.opengis.gml.x32.FeatureCollectionType) PointType(net.opengis.gml.x32.PointType) VerticalCRSPropertyType(net.opengis.gml.x32.VerticalCRSPropertyType) Show(org.n52.shetland.w3c.xlink.Show) TypeType(org.w3.x1999.xlink.TypeType) ShowType(org.w3.x1999.xlink.ShowType)

Example 43 with EncodingContext

use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.

the class SweCommonEncoderv101 method createSimpleType.

private AbstractDataComponentType createSimpleType(SweAbstractSimpleType<?> sosSimpleType, EncodingContext additionalValues) throws EncodingException {
    AbstractDataComponentType abstractDataComponentType = null;
    if (sosSimpleType instanceof SweBoolean) {
        abstractDataComponentType = createBoolean((SweBoolean) sosSimpleType);
    } else if (sosSimpleType instanceof SweCategory) {
        abstractDataComponentType = createCategory((SweCategory) sosSimpleType);
    } else if (sosSimpleType instanceof SweCount) {
        abstractDataComponentType = createCount((SweCount) sosSimpleType);
    } else if (sosSimpleType instanceof SweCountRange) {
        abstractDataComponentType = createCountRange((SweCountRange) sosSimpleType);
    } else if (sosSimpleType instanceof SweObservableProperty) {
        abstractDataComponentType = createObservableProperty((SweObservableProperty) sosSimpleType);
    } else if (sosSimpleType instanceof SweQuantity) {
        abstractDataComponentType = createQuantity((SweQuantity) sosSimpleType);
    } else if (sosSimpleType instanceof SweQuantityRange) {
        abstractDataComponentType = createQuantityRange((SweQuantityRange) sosSimpleType);
    } else if (sosSimpleType instanceof SweText) {
        abstractDataComponentType = createText((SweText) sosSimpleType);
    } else if (sosSimpleType instanceof SweTimeRange) {
        abstractDataComponentType = createTimeRange((SweTimeRange) sosSimpleType);
    } else if (sosSimpleType instanceof SweTime) {
        abstractDataComponentType = createTime((SweTime) sosSimpleType);
    } else {
        throw new NotYetSupportedEncodingException(SweAbstractSimpleType.class.getSimpleName(), sosSimpleType);
    }
    addAbstractDataComponentValues(abstractDataComponentType, sosSimpleType);
    return abstractDataComponentType;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) AbstractDataComponentType(net.opengis.swe.x101.AbstractDataComponentType) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) SweCountRange(org.n52.shetland.ogc.swe.simpleType.SweCountRange) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SweObservableProperty(org.n52.shetland.ogc.swe.simpleType.SweObservableProperty)

Example 44 with EncodingContext

use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.

the class RelatedOfferingsEncoder method encode.

@Override
public XmlObject encode(RelatedOfferings objectToEncode, EncodingContext ctx) throws EncodingException {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
        new RelatedOfferingXmlStreamWriter(context, baos, objectToEncode).write();
        return XmlObject.Factory.parse(baos.toString("UTF8"));
    } catch (XMLStreamException | XmlException | UnsupportedEncodingException ex) {
        String message = String.format("Error encoding %s", objectToEncode.getClass().getSimpleName());
        throw new EncodingException(message, ex);
    }
}
Also used : RelatedOfferingXmlStreamWriter(org.n52.svalbard.write.RelatedOfferingXmlStreamWriter) XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 45 with EncodingContext

use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.

the class SensorMLEncoderv101 method encode.

@Override
public XmlObject encode(final Object response, final EncodingContext additionalValues) throws EncodingException {
    XmlObject encodedObject = null;
    if (response instanceof AbstractSensorML) {
        encodedObject = createSensorDescription((AbstractSensorML) response);
    // }
    // FIXME workaround? if of type UnknowProcedureType try to parse the
    // description string, UNIT is missing "NOT_DEFINED"?!
    // else if (response instanceof SosProcedureDescriptionUnknownType)
    // {
    // final String procDescXMLString = ((SosProcedureDescription)
    // response).getXml();
    // final AbstractSensorML sensorDesc = new AbstractSensorML();
    // sensorDesc.setXml(procDescXMLString);
    // encodedObject = createSensorDescriptionFromString(sensorDesc);
    } else {
        throw new UnsupportedEncoderInputException(this, response);
    }
    // check if all gml:id are unique
    XmlHelper.makeGmlIdsUnique(encodedObject.getDomNode());
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : AbstractSensorML(org.n52.shetland.ogc.sensorML.AbstractSensorML) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlObject(org.apache.xmlbeans.XmlObject) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Aggregations

EncodingException (org.n52.svalbard.encode.exception.EncodingException)26 XmlObject (org.apache.xmlbeans.XmlObject)24 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)15 XmlException (org.apache.xmlbeans.XmlException)9 XMLStreamException (javax.xml.stream.XMLStreamException)6 OmObservation (org.n52.shetland.ogc.om.OmObservation)6 Supplier (java.util.function.Supplier)5 Time (org.n52.shetland.ogc.gml.time.Time)5 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 AbstractCRSType (net.opengis.gml.x32.AbstractCRSType)4 CodeType (net.opengis.gml.x32.CodeType)4 FeaturePropertyType (net.opengis.gml.x32.FeaturePropertyType)4 DateTime (org.joda.time.DateTime)4 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)4 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 AbstractGeometryType (net.opengis.gml.x32.AbstractGeometryType)3 GeometryPropertyType (net.opengis.gml.x32.GeometryPropertyType)3