start(getDocumentName()); namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK); namespace(W3CConstants.NS_XSI_PREFIX, W3CConstants.NS_XSI); namespace(OmConstants.NS_OM_PREFIX, OmConstants.NS_OM_2); namespace(GmlConstants.NS_GML_PREFIX, GmlConstants.NS_GML_32); writeAddtitionalNamespaces(); String observationID = addGmlId(observation); checkAndWriteIdentifier(); checkAndWriteName(); checkAndWriteDescription(); if (observation.getObservationConstellation().isSetObservationType()) { writeObservationType(observation.getObservationConstellation().getObservationType()); writeMetaDataProperty(observation.getMetaDataProperty()); writePhenomenonTime(phenomenonTime); writeResultTime(); if (observation.isSetValidTime()) { writeValidTime(observation.getValidTime()); writeProcedure(); if (observation.isSetParameter()) { writeParameter(); writeObservableProperty(); writeFeatureOfIntererst(); writeResult(); end(getDocumentName());
/** * Write observation typ as om:type to stream * * @param observationType * Observation type to write * * @throws XMLStreamException * If an error occurs when writing to stream */ protected void writeObservationType(String observationType) throws XMLStreamException { empty(OmConstants.QN_OM_20_OBSERVATION_TYPE); addXlinkHrefAttr(observationType); }
/** * Write extension information * * @param map * Map with values * @param element * element name * @throws XMLStreamException * If an error occurs when writing to stream * @throws EncodingException * If an error occurs when creating elements to be written */ protected void writeMetadata(Map<String, NamedValue<?>> map, QName element) throws XMLStreamException, EncodingException { for (Entry<String, NamedValue<?>> entry : map.entrySet()) { Object o = getEncoder(OmConstants.NS_OM_2, entry.getValue()).encode(entry.getValue(), EncodingContext.of(XmlBeansEncodingFlags.DOCUMENT)); if (o != null && o instanceof XmlObject) { start(GetDataAvailabilityConstants.GDA_EXTENSION); attr("name", entry.getKey()); rawText(((XmlObject) o).xmlText(getXmlOptions())); end(GetDataAvailabilityConstants.GDA_EXTENSION); } } }
/** * Write description as gml:descritpion to stream * * @param description * Description to write * * @throws XMLStreamException * If an error occurs when writing to stream */ protected void writeDescription(String description) throws XMLStreamException { start(GmlConstants.QN_DESCRIPTION_32); chars(description); endInline(GmlConstants.QN_DESCRIPTION_32); }
OmObservation observation = getElement(); if (observation.getValue() instanceof AbstractObservationValue<?>) { ((AbstractObservationValue<?>) observation.getValue()).setValuesForResultEncoding(observation); XmlObject createResult = (XmlObject) getEncoder(getEncodeNamespace().orElse(OmConstants.NS_OM_2), observation.getValue()).encode(observation.getValue()); if (createResult != null) { if (createResult.xmlText().contains(XML_FRAGMENT)) { XmlObject set = OMObservationType.Factory.newInstance(getXmlOptions()).addNewResult().set(createResult); writeXmlObject(set, OmConstants.QN_OM_20_RESULT); } else { if (checkResult(createResult)) { QName name = createResult.schemaType().getName(); String prefix = name.getPrefix(); newCursor.dispose(); writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT); } else { start(OmConstants.QN_OM_20_RESULT); writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT); end(OmConstants.QN_OM_20_RESULT); empty(OmConstants.QN_OM_20_RESULT);
/** * 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()); } } }
/** * Write om:observedProperty to stream * * @throws XMLStreamException * If an error occurs when writing to stream */ protected void writeObservableProperty() throws XMLStreamException { empty(OmConstants.QN_OM_20_OBSERVED_PROPERTY); OmObservation observation = getElement(); addXlinkHrefAttr(observation.getObservationConstellation().getObservableProperty().getIdentifier()); if (observation.getObservationConstellation().getObservableProperty().isSetName() && observation.getObservationConstellation().getObservableProperty().getFirstName().isSetValue()) { addXlinkTitleAttr( observation.getObservationConstellation().getObservableProperty().getFirstName().getValue()); } }
/** * Write om:resultTime 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 writeResultTime() throws XMLStreamException, EncodingException { OmObservation observation = getElement(); TimeInstant resultTime = observation.getResultTime(); Time phenomenonTime = observation.getPhenomenonTime(); // get result time from SOS result time if (observation.getResultTime() != null) { if (resultTime.equals(phenomenonTime)) { empty(OmConstants.QN_OM_20_RESULT_TIME); addXlinkHrefAttr("#".concat(phenomenonTime.getGmlId())); } else { addResultTime(resultTime); } } else if (phenomenonTime instanceof TimeInstant) { // if result time is not set, get result time from phenomenon time empty(OmConstants.QN_OM_20_RESULT_TIME); addXlinkHrefAttr("#".concat(phenomenonTime.getGmlId())); } else if (phenomenonTime instanceof TimePeriod) { TimeInstant rsTime = new TimeInstant(((TimePeriod) observation.getPhenomenonTime()).getEnd()); addResultTime(rsTime); } }
@Override protected void checkAndWriteDescription() throws XMLStreamException { if (getElement().getObservationConstellation().isSetDescription()) { writeDescription(getElement().getObservationConstellation().getDescription()); } else { super.checkAndWriteDescription(); } }
@Override protected void checkAndWriteIdentifier() throws EncodingException, XMLStreamException { if (getElement().getObservationConstellation().isSetIdentifier()) { writeIdentifier(getElement().getObservationConstellation().getIdentifierCodeWithAuthority()); } else { super.checkAndWriteIdentifier(); } }
@Override protected void checkAndWriteName() throws EncodingException, XMLStreamException { if (getElement().getObservationConstellation().isSetName()) { for (CodeType name : getElement().getObservationConstellation().getName()) { writeName(name); } } else { super.checkAndWriteName(); } }
/** * Add gml:id to om:OM_Observation element * * @param observation * {@link OmObservation} with the GML id * * @return observation id * * @throws XMLStreamException * If an error occurs when writing to stream */ private String addGmlId(OmObservation observation) throws XMLStreamException { String observationID = JavaHelper.generateID(Double.toString(System.currentTimeMillis() * Math.random())); if (observation.isSetObservationID()) { observationID = observation.getObservationID(); } else { observation.setObservationID(observationID); } attr(GmlConstants.QN_ID_32, "o_" + observationID); return observationID; }
OmObservation observation = getElement(); if (observation.getValue() instanceof AbstractObservationValue<?>) { ((AbstractObservationValue<?>) observation.getValue()).setValuesForResultEncoding(observation); XmlObject createResult = (XmlObject) getEncoder(getEncodeNamespace().orElse(OmConstants.NS_OM_2), observation.getValue()).encode(observation.getValue()); if (createResult != null) { if (createResult.xmlText().contains(XML_FRAGMENT)) { XmlObject set = OMObservationType.Factory.newInstance(getXmlOptions()).addNewResult().set(createResult); writeXmlObject(set, OmConstants.QN_OM_20_RESULT); } else { if (checkResult(createResult)) { QName name = createResult.schemaType().getName(); String prefix = name.getPrefix(); newCursor.dispose(); writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT); } else { start(OmConstants.QN_OM_20_RESULT); writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT); end(OmConstants.QN_OM_20_RESULT); empty(OmConstants.QN_OM_20_RESULT);
/** * 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()); } } }
/** * Write om:observedProperty to stream * * @throws XMLStreamException * If an error occurs when writing to stream */ protected void writeObservableProperty() throws XMLStreamException { empty(OmConstants.QN_OM_20_OBSERVED_PROPERTY); OmObservation observation = getElement(); addXlinkHrefAttr(observation.getObservationConstellation().getObservableProperty().getIdentifier()); if (observation.getObservationConstellation().getObservableProperty().isSetName() && observation.getObservationConstellation().getObservableProperty().getFirstName().isSetValue()) { addXlinkTitleAttr( observation.getObservationConstellation().getObservableProperty().getFirstName().getValue()); } }
/** * Write om:resultTime 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 writeResultTime() throws XMLStreamException, EncodingException { OmObservation observation = getElement(); TimeInstant resultTime = observation.getResultTime(); Time phenomenonTime = observation.getPhenomenonTime(); // get result time from SOS result time if (observation.getResultTime() != null) { if (resultTime.equals(phenomenonTime)) { empty(OmConstants.QN_OM_20_RESULT_TIME); addXlinkHrefAttr("#".concat(phenomenonTime.getGmlId())); } else { addResultTime(resultTime); } } else if (phenomenonTime instanceof TimeInstant) { // if result time is not set, get result time from phenomenon time empty(OmConstants.QN_OM_20_RESULT_TIME); addXlinkHrefAttr("#".concat(phenomenonTime.getGmlId())); } else if (phenomenonTime instanceof TimePeriod) { TimeInstant rsTime = new TimeInstant(((TimePeriod) observation.getPhenomenonTime()).getEnd()); addResultTime(rsTime); } }
/** * Write description as gml:descritpion to stream * * @param description * Description to write * * @throws XMLStreamException * If an error occurs when writing to stream */ protected void writeDescription(String description) throws XMLStreamException { start(GmlConstants.QN_DESCRIPTION_32); chars(description); endInline(GmlConstants.QN_DESCRIPTION_32); }
@Override protected void checkAndWriteDescription() throws XMLStreamException { if (getElement().getObservationConstellation().isSetDescription()) { writeDescription(getElement().getObservationConstellation().getDescription()); } else { super.checkAndWriteDescription(); } }
@Override protected void checkAndWriteIdentifier() throws EncodingException, XMLStreamException { if (getElement().getObservationConstellation().isSetIdentifier()) { writeIdentifier(getElement().getObservationConstellation().getIdentifierCodeWithAuthority()); } else { super.checkAndWriteIdentifier(); } }
@Override protected void checkAndWriteName() throws EncodingException, XMLStreamException { if (getElement().getObservationConstellation().isSetName()) { for (CodeType name : getElement().getObservationConstellation().getName()) { writeName(name); } } else { super.checkAndWriteName(); } }