Search in sources :

Example 31 with EncodingContext

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

the class AbstractWmlEncoderv20 method createObservationProcess.

/**
 * Creates an WaterML 2.0 ObservationProcess XML object from SOS
 * ObservationProcess object
 *
 * @param procedure
 *            SOS ObservationProcess
 * @param context
 *            Additional values
 * @return WaterML 2.0 ObservationProcess XML object
 * @throws EncodingException
 *             If an error occurs
 */
protected ObservationProcessDocument createObservationProcess(ObservationProcess procedure, EncodingContext context) throws EncodingException {
    XmlObject encodedObject = null;
    try {
        if (procedure.isSetXml()) {
            encodedObject = XmlObject.Factory.parse(procedure.getXml());
            checkAndAddIdentifier(procedure, ((ObservationProcessDocument) encodedObject).getObservationProcess());
        } else {
            encodedObject = ObservationProcessDocument.Factory.newInstance();
            ObservationProcessType observationProcess = ((ObservationProcessDocument) encodedObject).addNewObservationProcess();
            if (context.has(XmlBeansEncodingFlags.GMLID)) {
                observationProcess.setId(PROCESS_ID_PREFIX + context.get(XmlBeansEncodingFlags.GMLID));
            } else {
                observationProcess.setId(PROCESS_ID_PREFIX + JavaHelper.generateID(procedure.toString()));
            }
            if (procedure.isSetIdentifier()) {
                observationProcess.addNewIdentifier().set(encodeGML(procedure.getIdentifierCodeWithAuthority()));
            }
            if (procedure.isSetName()) {
                for (final CodeType sosName : procedure.getName()) {
                    observationProcess.addNewName().set(encodeGML(sosName));
                }
            }
            addProcessType(observationProcess, procedure);
            addOriginatingProcess(observationProcess, procedure);
            addAggregatingDuration(observationProcess, procedure);
            addVerticalDatum(observationProcess, procedure);
            addComment(observationProcess, procedure);
            addProcessReference(observationProcess, procedure);
            addInput(observationProcess, procedure);
            addParameter(observationProcess, procedure);
        }
    } catch (final XmlException xmle) {
        throw new EncodingException(xmle);
    }
    try {
        LOGGER.debug("Encoded object {} is valid: {}", encodedObject.schemaType().toString(), XmlHelper.validateDocument(encodedObject));
    } catch (DecodingException e) {
        throw new EncodingException(e);
    }
    return (ObservationProcessDocument) encodedObject;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) ObservationProcessType(net.opengis.waterml.x20.ObservationProcessType) XmlException(org.apache.xmlbeans.XmlException) ObservationProcessDocument(net.opengis.waterml.x20.ObservationProcessDocument) CodeType(org.n52.shetland.ogc.gml.CodeType) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException)

Example 32 with EncodingContext

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

the class OwsEncoderv110 method encode.

@Override
public XmlObject encode(Object element, EncodingContext additionalValues) throws EncodingException {
    if (element instanceof OwsServiceIdentification) {
        return encodeServiceIdentification((OwsServiceIdentification) element);
    } else if (element instanceof OwsServiceProvider) {
        return encodeServiceProvider((OwsServiceProvider) element);
    } else if (element instanceof OwsOperationsMetadata) {
        return encodeOperationsMetadata((OwsOperationsMetadata) element);
    } else if (element instanceof OwsExceptionReport) {
        if (isEncodeExceptionsOnly(additionalValues) && !((OwsExceptionReport) element).getExceptions().isEmpty()) {
            return encodeOwsException(((OwsExceptionReport) element).getExceptions().get(0));
        }
        return encodeOwsExceptionReport((OwsExceptionReport) element);
    } else if (element instanceof OwsMetadata) {
        MetadataType metadataType = MetadataType.Factory.newInstance(getXmlOptions());
        encodeOwsMetadata((OwsMetadata) element, metadataType);
        return metadataType;
    } else if (element instanceof OwsDomain) {
        DomainType domainType = DomainType.Factory.newInstance(getXmlOptions());
        encodeOwsDomain((OwsDomain) element, domainType);
        return domainType;
    } else if (element instanceof OwsAcceptVersions) {
        return encodeAcceptVersions((OwsAcceptVersions) element);
    } else if (element instanceof OwsSections) {
        return encodeSections((OwsSections) element);
    }
    throw new UnsupportedEncoderInputException(this, element);
}
Also used : OwsDomain(org.n52.shetland.ogc.ows.OwsDomain) DomainType(net.opengis.ows.x11.DomainType) OwsOperationsMetadata(org.n52.shetland.ogc.ows.OwsOperationsMetadata) OwsMetadata(org.n52.shetland.ogc.ows.OwsMetadata) OwsSections(org.n52.shetland.ogc.ows.OwsSections) OwsServiceProvider(org.n52.shetland.ogc.ows.OwsServiceProvider) MetadataType(net.opengis.ows.x11.MetadataType) DomainMetadataType(net.opengis.ows.x11.DomainMetadataType) OwsServiceIdentification(org.n52.shetland.ogc.ows.OwsServiceIdentification) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) OwsAcceptVersions(org.n52.shetland.ogc.ows.OwsAcceptVersions) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 33 with EncodingContext

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

the class EnvironmentalMonitoringFaciltityPropertyTypeEncoder method encode.

@Override
public XmlObject encode(AbstractFeature abstractFeature, EncodingContext context) throws EncodingException {
    if (abstractFeature instanceof EnvironmentalMonitoringFacility) {
        EnvironmentalMonitoringFacilityPropertyType emfpt = EnvironmentalMonitoringFacilityPropertyType.Factory.newInstance();
        emfpt.setEnvironmentalMonitoringFacility(createEnvironmentalMonitoringFaciltityType((EnvironmentalMonitoringFacility) abstractFeature));
        return emfpt;
    }
    throw new UnsupportedEncoderInputException(this, abstractFeature);
}
Also used : EnvironmentalMonitoringFacility(org.n52.shetland.inspire.ef.EnvironmentalMonitoringFacility) EnvironmentalMonitoringFacilityPropertyType(eu.europa.ec.inspire.schemas.ef.x40.EnvironmentalMonitoringFacilityPropertyType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 34 with EncodingContext

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

the class AbstractOmV20XmlStreamWriter method writeFeatureOfIntererst.

/**
 * Write om:featureOfInterest encoded or as xlink:href to stream
 *
 * @throws XMLStreamException
 *             If an error occurs when writing to stream
 * @throws EncodingException
 *             If an error occurs when creating elements to be written
 */
protected void writeFeatureOfIntererst() throws XMLStreamException, EncodingException {
    Optional<String> namespace = getDefaultFeatureEncodingNamespace();
    AbstractFeature foi = getElement().getObservationConstellation().getFeatureOfInterest();
    if (namespace.isPresent()) {
        EncodingContext codingContext = EncodingContext.of(XmlEncoderFlags.ENCODE_NAMESPACE, namespace.get());
        Encoder<XmlObject, AbstractFeature> encoder = getEncoder(GmlConstants.NS_GML_32, foi);
        writeXmlObject(encoder.encode(foi, codingContext), OmConstants.QN_OM_20_FEATURE_OF_INTEREST);
    } else {
        empty(OmConstants.QN_OM_20_FEATURE_OF_INTEREST);
        addXlinkHrefAttr(foi.getIdentifier());
        if (foi.isSetName() && foi.getFirstName().isSetValue()) {
            addXlinkTitleAttr(foi.getFirstName().getValue());
        }
    }
}
Also used : EncodingContext(org.n52.svalbard.encode.EncodingContext) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject)

Example 35 with EncodingContext

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

the class Soap12XmlStreamWriter method writeBodyContent.

/**
 * Encode and write the {@link OwsServiceResponse} to stream
 *
 * @param bodyResponse The service internal response to encode and write
 *
 * @throws XMLStreamException If an error occurs when writing to {@link OutputStream}
 * @throws EncodingException  If an encoding error occurs
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void writeBodyContent(OwsServiceResponse bodyResponse) throws XMLStreamException, EncodingException {
    Encoder<Object, OwsServiceResponse> encoder = getEncoder(new OperationResponseEncoderKey(new OwsOperationKey(bodyResponse), MediaTypes.APPLICATION_XML));
    if (encoder instanceof StreamingEncoder<?, ?>) {
        EncodingContext ctx = getContext().with(XmlBeansEncodingFlags.DOCUMENT).without(XmlBeansEncodingFlags.PROPERTY_TYPE).without(XmlBeansEncodingFlags.TYPE).with(StreamingEncoderFlags.EMBEDDED, true);
        ((StreamingEncoder) encoder).encode(bodyResponse, getOutputStream(), ctx);
    } else {
        String soapBodyContent = ((XmlObject) encoder.encode(bodyResponse)).xmlText(getXmlOptions());
        rawText(stripXmlDeclaration(soapBodyContent));
    }
}
Also used : EncodingContext(org.n52.svalbard.encode.EncodingContext) OperationResponseEncoderKey(org.n52.svalbard.encode.OperationResponseEncoderKey) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) StreamingEncoder(org.n52.svalbard.encode.StreamingEncoder) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey)

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