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;
}
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);
}
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);
}
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());
}
}
}
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));
}
}
Aggregations