Search in sources :

Example 1 with EncodingContext

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

the class AbstractOmEncoderv20 method encode.

@Override
public void encode(Object objectToEncode, OutputStream outputStream, EncodingContext ctx) throws EncodingException {
    try {
        XmlOptions xmlOptions = getXmlOptions();
        if (ctx.has(StreamingEncoderFlags.EMBEDDED)) {
            xmlOptions.setSaveNoXmlDecl();
        }
        encode(objectToEncode, ctx.with(StreamingEncoderFlags.ENCODER, this)).save(outputStream, xmlOptions);
    } catch (IOException ioe) {
        throw new EncodingException("Error while writing element to stream!", ioe);
    } finally {
        if (ctx.has(StreamingEncoderFlags.EMBEDDED)) {
            getXmlOptions().remove(XmlOptions.SAVE_NO_XML_DECL);
        }
    }
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlOptions(org.apache.xmlbeans.XmlOptions) IOException(java.io.IOException)

Example 2 with EncodingContext

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

the class AbstractOmEncoderv20 method encode.

@Override
public XmlObject encode(Object element, EncodingContext additionalValues) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof OmObservation) {
        encodedObject = encodeOmObservation((OmObservation) element, additionalValues);
    } else if (element instanceof NamedValue) {
        NamedValueType nvt = createNamedValue((NamedValue<?>) element);
        if (additionalValues.has(XmlBeansEncodingFlags.DOCUMENT)) {
            NamedValueDocument nvd = NamedValueDocument.Factory.newInstance();
            nvd.setNamedValue(nvt);
            encodedObject = nvd;
        } else if (additionalValues.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            NamedValuePropertyType nvpt = NamedValuePropertyType.Factory.newInstance();
            nvpt.setNamedValue(nvt);
            encodedObject = nvpt;
        } else {
            encodedObject = nvt;
        }
    } else if (element instanceof AbstractFeature) {
        encodedObject = encodeFeatureOfInterest((AbstractFeature) element);
    } else if (element instanceof SosProcedureDescription) {
        encodedObject = encodeProcedureDescription((SosProcedureDescription<?>) element);
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    // XmlHelper.validateDocument(encodedObject));
    return encodedObject;
}
Also used : NamedValueDocument(net.opengis.om.x20.NamedValueDocument) NamedValueType(net.opengis.om.x20.NamedValueType) OmObservation(org.n52.shetland.ogc.om.OmObservation) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject) NamedValue(org.n52.shetland.ogc.om.NamedValue) NamedValuePropertyType(net.opengis.om.x20.NamedValuePropertyType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 3 with EncodingContext

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

the class Iso19139GmdEncoder method encodeEXExtent.

private XmlObject encodeEXExtent(EXExtent exExtent, EncodingContext context) throws EncodingException {
    EXExtentType exet = EXExtentType.Factory.newInstance();
    if (exExtent.hasDescription()) {
        exet.addNewDescription().setCharacterString(exExtent.getDescription());
    }
    if (exExtent.hasVerticalExtent()) {
        for (Referenceable<EXVerticalExtent> verticalExtent : exExtent.getExVerticalExtent()) {
            EXVerticalExtentPropertyType exvept = exet.addNewVerticalElement();
            if (verticalExtent.isReference()) {
                Reference reference = verticalExtent.getReference();
                reference.getActuate().map(Actuate::toString).map(ActuateType.Enum::forString).ifPresent(exvept::setActuate);
                reference.getArcrole().ifPresent(exvept::setArcrole);
                reference.getHref().map(URI::toString).ifPresent(exvept::setHref);
                reference.getRole().ifPresent(exvept::setRole);
                reference.getShow().map(Show::toString).map(ShowType.Enum::forString).ifPresent(exvept::setShow);
                reference.getTitle().ifPresent(exvept::setTitle);
                reference.getType().map(Type::toString).map(TypeType.Enum::forString).ifPresent(exvept::setType);
            } else {
                if (verticalExtent.isInstance()) {
                    Nillable<EXVerticalExtent> nillable = verticalExtent.getInstance();
                    if (nillable.isPresent()) {
                        XmlObject xml = encodeEXVerticalExtent(nillable.get(), EncodingContext.empty());
                        if (xml != null && xml instanceof EXVerticalExtentType) {
                            exvept.setEXVerticalExtent((EXVerticalExtentType) xml);
                        } else {
                            exvept.setNil();
                            exvept.setNilReason(Nillable.missing().get());
                        }
                    } else {
                        exvept.setNil();
                        if (nillable.hasReason()) {
                            exvept.setNilReason(nillable.getNilReason().get());
                        } else {
                            exvept.setNilReason(Nillable.missing().get());
                        }
                    }
                }
            }
        }
    }
    if (context.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
        EXExtentPropertyType exept = EXExtentPropertyType.Factory.newInstance(getXmlOptions());
        exept.setEXExtent(exet);
        return exept;
    } else if (context.has(XmlBeansEncodingFlags.DOCUMENT)) {
        EXExtentDocument exed = EXExtentDocument.Factory.newInstance(getXmlOptions());
        exed.setEXExtent(exet);
        return exed;
    }
    return exet;
}
Also used : ActuateType(org.w3.x1999.xlink.ActuateType) Reference(org.n52.shetland.w3c.xlink.Reference) EXExtentDocument(org.isotc211.x2005.gmd.EXExtentDocument) EXExtentType(org.isotc211.x2005.gmd.EXExtentType) EXVerticalExtentPropertyType(org.isotc211.x2005.gmd.EXVerticalExtentPropertyType) EXVerticalExtentType(org.isotc211.x2005.gmd.EXVerticalExtentType) Actuate(org.n52.shetland.w3c.xlink.Actuate) CIAddressType(org.isotc211.x2005.gmd.CIAddressType) CIContactPropertyType(org.isotc211.x2005.gmd.CIContactPropertyType) DQDomainConsistencyPropertyType(org.isotc211.x2005.gmd.DQDomainConsistencyPropertyType) CodeType(net.opengis.gml.x32.CodeType) MDMetadataPropertyType(org.isotc211.x2005.gmd.MDMetadataPropertyType) MDMetadataType(org.isotc211.x2005.gmd.MDMetadataType) LocalisedCharacterStringPropertyType(org.isotc211.x2005.gmd.LocalisedCharacterStringPropertyType) CharacterStringPropertyType(org.isotc211.x2005.gco.CharacterStringPropertyType) EXExtentPropertyType(org.isotc211.x2005.gmd.EXExtentPropertyType) CICitationType(org.isotc211.x2005.gmd.CICitationType) MDDataIdentificationType(org.isotc211.x2005.gmd.MDDataIdentificationType) DQDomainConsistencyType(org.isotc211.x2005.gmd.DQDomainConsistencyType) EXVerticalExtentType(org.isotc211.x2005.gmd.EXVerticalExtentType) GmdDateType(org.n52.shetland.iso.gmd.GmdDateType) CodeListValueType(org.isotc211.x2005.gco.CodeListValueType) AbstractCRSType(net.opengis.gml.x32.AbstractCRSType) DQResultPropertyType(org.isotc211.x2005.gmd.DQResultPropertyType) CIDateType(org.isotc211.x2005.gmd.CIDateType) CIContactType(org.isotc211.x2005.gmd.CIContactType) ShowType(org.w3.x1999.xlink.ShowType) MDIdentificationPropertyType(org.isotc211.x2005.gmd.MDIdentificationPropertyType) EXExtentType(org.isotc211.x2005.gmd.EXExtentType) CIOnlineResourcePropertyType(org.isotc211.x2005.gmd.CIOnlineResourcePropertyType) BaseUnitType(net.opengis.gml.x32.BaseUnitType) CITelephonePropertyType(org.isotc211.x2005.gmd.CITelephonePropertyType) ActuateType(org.w3.x1999.xlink.ActuateType) CIAddressPropertyType(org.isotc211.x2005.gmd.CIAddressPropertyType) UnitOfMeasurePropertyType(org.isotc211.x2005.gco.UnitOfMeasurePropertyType) EXVerticalExtentPropertyType(org.isotc211.x2005.gmd.EXVerticalExtentPropertyType) CIOnlineResourceType(org.isotc211.x2005.gmd.CIOnlineResourceType) DQQuantitativeResultType(org.isotc211.x2005.gmd.DQQuantitativeResultType) CIResponsiblePartyType(org.isotc211.x2005.gmd.CIResponsiblePartyType) SupportedType(org.n52.shetland.ogc.SupportedType) LocalisedCharacterStringType(org.isotc211.x2005.gmd.LocalisedCharacterStringType) CICitationPropertyType(org.isotc211.x2005.gmd.CICitationPropertyType) CITelephoneType(org.isotc211.x2005.gmd.CITelephoneType) DQConformanceResultType(org.isotc211.x2005.gmd.DQConformanceResultType) TypeType(org.w3.x1999.xlink.TypeType) Type(org.n52.shetland.w3c.xlink.Type) CIRoleCodePropertyType(org.isotc211.x2005.gmd.CIRoleCodePropertyType) MDDataIdentificationPropertyType(org.isotc211.x2005.gmd.MDDataIdentificationPropertyType) RealPropertyType(org.isotc211.x2005.gco.RealPropertyType) AbstractMDIdentificationType(org.isotc211.x2005.gmd.AbstractMDIdentificationType) PTFreeTextType(org.isotc211.x2005.gmd.PTFreeTextType) SCCRSPropertyType(org.isotc211.x2005.gsr.SCCRSPropertyType) CIResponsiblePartyPropertyType(org.isotc211.x2005.gmd.CIResponsiblePartyPropertyType) EXVerticalExtent(org.n52.shetland.iso.gmd.EXVerticalExtent) EXExtentPropertyType(org.isotc211.x2005.gmd.EXExtentPropertyType) Show(org.n52.shetland.w3c.xlink.Show) XmlObject(org.apache.xmlbeans.XmlObject) TypeType(org.w3.x1999.xlink.TypeType) ShowType(org.w3.x1999.xlink.ShowType)

Example 4 with EncodingContext

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

the class Iso19139GmdEncoder method encodeEXVerticalExtent.

private XmlObject encodeEXVerticalExtent(EXVerticalExtent exVerticalExtent, EncodingContext context) throws EncodingException {
    EXVerticalExtentType exvet = EXVerticalExtentType.Factory.newInstance();
    if (exVerticalExtent.isSetId()) {
        exvet.setId(exVerticalExtent.getId());
    }
    if (exVerticalExtent.isSetUuid()) {
        exvet.setUuid(exVerticalExtent.getUuid());
    }
    // min value
    Nillable<Double> minNillable = exVerticalExtent.getMinimumValue();
    RealPropertyType rptMinValue = exvet.addNewMinimumValue();
    if (minNillable.isPresent()) {
        rptMinValue.setReal(minNillable.get());
    } else {
        rptMinValue.setNil();
        if (minNillable.hasReason()) {
            rptMinValue.setNilReason(minNillable.getNilReason().get());
        } else {
            rptMinValue.setNilReason(Nillable.missing().get());
        }
    }
    // max value
    Nillable<Double> maxNillable = exVerticalExtent.getMaximumValue();
    RealPropertyType rptMinMaxValue = exvet.addNewMaximumValue();
    if (maxNillable.isPresent()) {
        rptMinMaxValue.setReal(maxNillable.get());
    } else {
        rptMinMaxValue.setNil();
        if (maxNillable.hasReason()) {
            rptMinMaxValue.setNilReason(maxNillable.getNilReason().get());
        } else {
            rptMinMaxValue.setNilReason(Nillable.missing().get());
        }
    }
    // verticalCRS
    SCCRSPropertyType sccrspt = exvet.addNewVerticalCRS();
    Referenceable<ScCRS> verticalCRS = exVerticalExtent.getVerticalCRS();
    if (verticalCRS.isReference()) {
        Reference reference = verticalCRS.getReference();
        reference.getActuate().map(Actuate::toString).map(ActuateType.Enum::forString).ifPresent(sccrspt::setActuate);
        reference.getArcrole().ifPresent(sccrspt::setArcrole);
        reference.getHref().map(URI::toString).ifPresent(sccrspt::setHref);
        reference.getRole().ifPresent(sccrspt::setRole);
        reference.getShow().map(Show::toString).map(ShowType.Enum::forString).ifPresent(sccrspt::setShow);
        reference.getTitle().ifPresent(sccrspt::setTitle);
        reference.getType().map(Type::toString).map(TypeType.Enum::forString).ifPresent(sccrspt::setType);
    } else {
        if (verticalCRS.isInstance()) {
            Nillable<ScCRS> nillable = verticalCRS.getInstance();
            if (nillable.isPresent()) {
                XmlObject xml = encodeObjectToXml(GmlConstants.NS_GML_32, nillable.get().getAbstractCrs());
                if (xml != null && xml instanceof AbstractCRSType) {
                    final XmlObject substituteElement = XmlHelper.substituteElement(sccrspt.addNewAbstractCRS(), xml);
                    substituteElement.set(xml);
                } else {
                    sccrspt.setNil();
                    sccrspt.setNilReason(Nillable.missing().get());
                }
            } else {
                sccrspt.setNil();
                if (nillable.hasReason()) {
                    sccrspt.setNilReason(nillable.getNilReason().get());
                } else {
                    sccrspt.setNilReason(Nillable.missing().get());
                }
            }
        }
    }
    if (context.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
        EXVerticalExtentPropertyType exvept = EXVerticalExtentPropertyType.Factory.newInstance(getXmlOptions());
        exvept.setEXVerticalExtent(exvet);
        return exvept;
    } else if (context.has(XmlBeansEncodingFlags.DOCUMENT)) {
        EXVerticalExtentDocument exved = EXVerticalExtentDocument.Factory.newInstance(getXmlOptions());
        exved.setEXVerticalExtent(exvet);
        return exved;
    }
    return exvet;
}
Also used : ActuateType(org.w3.x1999.xlink.ActuateType) Reference(org.n52.shetland.w3c.xlink.Reference) ScCRS(org.n52.shetland.iso.gmd.ScCRS) EXVerticalExtentPropertyType(org.isotc211.x2005.gmd.EXVerticalExtentPropertyType) EXVerticalExtentType(org.isotc211.x2005.gmd.EXVerticalExtentType) Actuate(org.n52.shetland.w3c.xlink.Actuate) CIAddressType(org.isotc211.x2005.gmd.CIAddressType) CIContactPropertyType(org.isotc211.x2005.gmd.CIContactPropertyType) DQDomainConsistencyPropertyType(org.isotc211.x2005.gmd.DQDomainConsistencyPropertyType) CodeType(net.opengis.gml.x32.CodeType) MDMetadataPropertyType(org.isotc211.x2005.gmd.MDMetadataPropertyType) MDMetadataType(org.isotc211.x2005.gmd.MDMetadataType) LocalisedCharacterStringPropertyType(org.isotc211.x2005.gmd.LocalisedCharacterStringPropertyType) CharacterStringPropertyType(org.isotc211.x2005.gco.CharacterStringPropertyType) EXExtentPropertyType(org.isotc211.x2005.gmd.EXExtentPropertyType) CICitationType(org.isotc211.x2005.gmd.CICitationType) MDDataIdentificationType(org.isotc211.x2005.gmd.MDDataIdentificationType) DQDomainConsistencyType(org.isotc211.x2005.gmd.DQDomainConsistencyType) EXVerticalExtentType(org.isotc211.x2005.gmd.EXVerticalExtentType) GmdDateType(org.n52.shetland.iso.gmd.GmdDateType) CodeListValueType(org.isotc211.x2005.gco.CodeListValueType) AbstractCRSType(net.opengis.gml.x32.AbstractCRSType) DQResultPropertyType(org.isotc211.x2005.gmd.DQResultPropertyType) CIDateType(org.isotc211.x2005.gmd.CIDateType) CIContactType(org.isotc211.x2005.gmd.CIContactType) ShowType(org.w3.x1999.xlink.ShowType) MDIdentificationPropertyType(org.isotc211.x2005.gmd.MDIdentificationPropertyType) EXExtentType(org.isotc211.x2005.gmd.EXExtentType) CIOnlineResourcePropertyType(org.isotc211.x2005.gmd.CIOnlineResourcePropertyType) BaseUnitType(net.opengis.gml.x32.BaseUnitType) CITelephonePropertyType(org.isotc211.x2005.gmd.CITelephonePropertyType) ActuateType(org.w3.x1999.xlink.ActuateType) CIAddressPropertyType(org.isotc211.x2005.gmd.CIAddressPropertyType) UnitOfMeasurePropertyType(org.isotc211.x2005.gco.UnitOfMeasurePropertyType) EXVerticalExtentPropertyType(org.isotc211.x2005.gmd.EXVerticalExtentPropertyType) CIOnlineResourceType(org.isotc211.x2005.gmd.CIOnlineResourceType) DQQuantitativeResultType(org.isotc211.x2005.gmd.DQQuantitativeResultType) CIResponsiblePartyType(org.isotc211.x2005.gmd.CIResponsiblePartyType) SupportedType(org.n52.shetland.ogc.SupportedType) LocalisedCharacterStringType(org.isotc211.x2005.gmd.LocalisedCharacterStringType) CICitationPropertyType(org.isotc211.x2005.gmd.CICitationPropertyType) CITelephoneType(org.isotc211.x2005.gmd.CITelephoneType) DQConformanceResultType(org.isotc211.x2005.gmd.DQConformanceResultType) TypeType(org.w3.x1999.xlink.TypeType) Type(org.n52.shetland.w3c.xlink.Type) CIRoleCodePropertyType(org.isotc211.x2005.gmd.CIRoleCodePropertyType) MDDataIdentificationPropertyType(org.isotc211.x2005.gmd.MDDataIdentificationPropertyType) RealPropertyType(org.isotc211.x2005.gco.RealPropertyType) AbstractMDIdentificationType(org.isotc211.x2005.gmd.AbstractMDIdentificationType) PTFreeTextType(org.isotc211.x2005.gmd.PTFreeTextType) SCCRSPropertyType(org.isotc211.x2005.gsr.SCCRSPropertyType) CIResponsiblePartyPropertyType(org.isotc211.x2005.gmd.CIResponsiblePartyPropertyType) RealPropertyType(org.isotc211.x2005.gco.RealPropertyType) SCCRSPropertyType(org.isotc211.x2005.gsr.SCCRSPropertyType) AbstractCRSType(net.opengis.gml.x32.AbstractCRSType) Show(org.n52.shetland.w3c.xlink.Show) XmlObject(org.apache.xmlbeans.XmlObject) EXVerticalExtentDocument(org.isotc211.x2005.gmd.EXVerticalExtentDocument) TypeType(org.w3.x1999.xlink.TypeType) ShowType(org.w3.x1999.xlink.ShowType)

Example 5 with EncodingContext

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

the class OmEncoderv100 method encode.

@Override
public XmlObject encode(Object element, EncodingContext additionalValues) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof OmObservation) {
        encodedObject = createObservation((OmObservation) element, additionalValues);
    } else if (element instanceof GetObservationResponse) {
        GetObservationResponse response = (GetObservationResponse) element;
        encodedObject = createObservationCollection(response.getObservationCollection(), response.getResultModel());
    } else if (element instanceof GetObservationByIdResponse) {
        GetObservationByIdResponse response = (GetObservationByIdResponse) element;
        encodedObject = createObservationCollection(response.getObservationCollection(), response.getResultModel());
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) GetObservationResponse(org.n52.shetland.ogc.sos.response.GetObservationResponse) XmlObject(org.apache.xmlbeans.XmlObject) GetObservationByIdResponse(org.n52.shetland.ogc.sos.response.GetObservationByIdResponse) 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