Java Code Examples for org.apache.xmlbeans.XmlObject#set()

The following examples show how to use org.apache.xmlbeans.XmlObject#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SweCommonEncoderv20.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
private DataRecordType.Field createField(SweField field)
        throws EncodingException {
    SweAbstractDataComponent element = field.getElement();
    DataRecordType.Field xmlField = DataRecordType.Field.Factory.newInstance(getXmlOptions());

    if (field.isSetName()) {
        xmlField.setName(NcName.makeValid(field.getName().getValue()));
    }

    if (element != null) {
        XmlObject encodeObjectToXml = createAbstractDataComponent(element, EncodingContext.empty());
        XmlObject substituteElement =
                XmlHelper.substituteElement(xmlField.addNewAbstractDataComponent(), encodeObjectToXml);
        substituteElement.set(encodeObjectToXml);
    }
    return xmlField;
}
 
Example 2
Source File: SensorMLEncoderv20.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
private void addDataComponentOrObservablePropertyType(DataComponentOrObservablePropertyType type, SmlIo sosSMLIO)
        throws EncodingException {
    if (sosSMLIO.isSetHref()) {
        type.setHref(sosSMLIO.getHref());
        if (sosSMLIO.isSetTitle()) {
            type.setTitle(sosSMLIO.getTitle());
        }
    } else if (sosSMLIO.getIoValue() instanceof SweObservableProperty) {
        addValueToObservableProperty(type.addNewObservableProperty(), sosSMLIO.getIoValue());
        // TODO } else if (sosSMLIO.getIoValue() instanceof
        // SmlDataInterface) {
    } else {
        final XmlObject encodeObjectToXml = encodeObjectToXmlSwe20(sosSMLIO.getIoValue());
        XmlObject substituteElement =
                XmlHelper.substituteElement(type.addNewAbstractDataComponent(), encodeObjectToXml);
        substituteElement.set(encodeObjectToXml);
    }
}
 
Example 3
Source File: SensorMLEncoderv101.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
private Capabilities createCapability(final SmlCapabilities capabilities) throws EncodingException {
    final Capabilities xbCapabilities = Capabilities.Factory.newInstance(getXmlOptions());
    if (capabilities.isSetName()) {
        xbCapabilities.setName(capabilities.getName());
    }
    if (capabilities.isSetAbstractDataRecord() && capabilities.getDataRecord().isSetFields()) {
        final XmlObject encodedDataRecord =
                encodeObjectToXml(SweConstants.NS_SWE_101, capabilities.getDataRecord());
        final XmlObject substituteElement =
                XmlHelper.substituteElement(xbCapabilities.addNewAbstractDataRecord(), encodedDataRecord);
        substituteElement.set(encodedDataRecord);
    } else if (capabilities.isSetHref()) {
        xbCapabilities.setHref(capabilities.getHref());
        if (capabilities.isSetTitle()) {
            xbCapabilities.setTitle(capabilities.getTitle());
        }
    }
    return xbCapabilities;
}
 
Example 4
Source File: SamplingEncoderv20.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
protected void setMetaDataProperty(SFSamplingFeatureType sfssft, AbstractSamplingFeature sampFeat)
        throws EncodingException {
    if (sampFeat.isSetMetaDataProperty()) {
        for (AbstractMetaData abstractMetaData : sampFeat.getMetaDataProperty()) {
            XmlObject encodeObject = encodeObjectToXml(GmlConstants.NS_GML_32, abstractMetaData);
            XmlObject substituteElement = XmlHelper
                    .substituteElement(sfssft.addNewMetaDataProperty().addNewAbstractMetaData(), encodeObject);
            substituteElement.set(encodeObject);
        }
    }
}
 
Example 5
Source File: DescribeSensorResponseEncoder.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Override
protected XmlObject create(DescribeSensorResponse response)
        throws EncodingException {
    DescribeSensorResponseDocument doc = DescribeSensorResponseDocument.Factory.newInstance(getXmlOptions());
    DescribeSensorResponseType dsr = doc.addNewDescribeSensorResponse();
    if (response.hasExtensions()) {
        createExtension(dsr, response.getExtensions());
    }
    dsr.setProcedureDescriptionFormat(response.getOutputFormat());
    for (SosProcedureDescription<?> sosProcedureDescription : response.getProcedureDescriptions()) {
        SensorDescriptionType sensorDescription = dsr.addNewDescription().addNewSensorDescription();
        sensorDescription.addNewData().set(getSensorDescription(response, sosProcedureDescription));
        if (sosProcedureDescription.isSetValidTime()) {
            XmlObject xoValidTime =
                    encodeObjectToXml(GmlConstants.NS_GML_32, sosProcedureDescription.getValidTime());
            XmlObject substitution = sensorDescription.addNewValidTime().addNewAbstractTimeGeometricPrimitive()
                    .substitute(GmlHelper.getGml321QnameForITime(sosProcedureDescription.getValidTime()),
                            xoValidTime.schemaType());
            substitution.set(xoValidTime);
        }
    }
    // in a single observation the gml:ids must be unique
    if (response.getProcedureDescriptions().size() > 1) {
        XmlHelper.makeGmlIdsUnique(doc.getDomNode());
    }
    return doc;
}
 
Example 6
Source File: GetCapabilitiesResponseEncoder.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
private void setExtensions(XmlObject xml, OwsCapabilitiesExtension extension) throws EncodingException {
    if (extension instanceof SosInsertionCapabilities) {
        xml.set(createInsertionCapabilities((SosInsertionCapabilities) extension));
    } else if (extension instanceof StringBasedExtension) {
        try {
            xml.set(XmlObject.Factory.parse(((StringBasedExtension) extension).getExtension()));
        } catch (XmlException ex) {
            throw errorEncodingSwesExtension(ex);
        }
    } else {
        throw new EncodingException("The extension element is not supported by this service!");
    }
}
 
Example 7
Source File: GetResultResponseEncoder.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Override
protected XmlObject create(GetResultResponse response) throws EncodingException {
    GetResultResponseDocument doc = GetResultResponseDocument.Factory.newInstance(getXmlOptions());
    GetResultResponseType gtr = doc.addNewGetResultResponse();
    if (response.hasExtensions()) {
        createExtension(gtr, response.getExtensions());
    }
    XmlObject resultValues = gtr.addNewResultValues();
    if (response.hasResultValues()) {
        XmlString xmlString = XmlString.Factory.newInstance();
        xmlString.setStringValue(response.getResultValues());
        resultValues.set(xmlString);
    }
    return doc;
}
 
Example 8
Source File: AbstractOmEncoderv20.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
private void setMetaDataProperty(OmObservation sosObservation, OMObservationType xbObservation)
        throws EncodingException {
    if (sosObservation.isSetMetaDataProperty()) {
        for (AbstractMetaData abstractMetaData : sosObservation.getMetaDataProperty()) {
            XmlObject encodeObject = encodeGML(abstractMetaData);
            XmlObject substituteElement = XmlHelper.substituteElement(
                    xbObservation.addNewMetaDataProperty().addNewAbstractMetaData(), encodeObject);
            substituteElement.set(encodeObject);
        }
    }
}
 
Example 9
Source File: OmEncoderv100.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
private void addResultTime(ObservationType xbObs, TimeInstant iTime)
        throws EncodingException {
    XmlObject xmlObject = encodeObjectToXml(GmlConstants.NS_GML, iTime);
    XmlObject substitution = xbObs.addNewResultTime().addNewTimeObject()
            .substitute(GmlHelper.getGml311QnameForITime(iTime), xmlObject.schemaType());
    substitution.set(xmlObject);
}
 
Example 10
Source File: OmEncoderv100.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
private void addSamplingTime(ObservationType xbObservation, Time iTime)
        throws EncodingException {
    XmlObject xmlObject = encodeObjectToXml(GmlConstants.NS_GML, iTime);
    XmlObject substitution = xbObservation.addNewSamplingTime().addNewTimeObject()
            .substitute(GmlHelper.getGml311QnameForITime(iTime), xmlObject.schemaType());
    substitution.set(xmlObject);
}
 
Example 11
Source File: OmEncoderv100.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
private void addMultiObservationValueToResult(XmlObject xbResult, OmObservation sosObservation)
        throws EncodingException {
    SweDataArray dataArray = sweHelper.createSosSweDataArray(sosObservation);
    xbResult.set(encodeObjectToXml(SweConstants.NS_SWE_101, dataArray,
            EncodingContext.of(XmlBeansEncodingFlags.FOR_OBSERVATION)));
}
 
Example 12
Source File: Iso19139GmdEncoder.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 13
Source File: OmEncoderv100.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
private void addSingleObservationToResult(XmlObject xbResult, OmObservation sosObservation)
        throws EncodingException {
    String observationType = sosObservation.getObservationConstellation().getObservationType();
    SingleObservationValue<?> observationValue = (SingleObservationValue<?>) sosObservation.getValue();
    if (observationValue.getValue() instanceof QuantityValue) {
        QuantityValue quantityValue = (QuantityValue) observationValue.getValue();
        xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, quantityValue));
    } else if (observationValue.getValue() instanceof CountValue) {
        CountValue countValue = (CountValue) observationValue.getValue();
        XmlInteger xbInteger = XmlInteger.Factory.newInstance(getXmlOptions());
        if (countValue.getValue() != null && countValue.getValue() != Integer.MIN_VALUE) {
            xbInteger.setBigIntegerValue(new BigInteger(countValue.getValue().toString()));
        } else {
            xbInteger.setNil();
        }
        xbResult.set(xbInteger);
    } else if (observationValue.getValue() instanceof TextValue) {
        TextValue textValue = (TextValue) observationValue.getValue();
        XmlString xbString = XmlString.Factory.newInstance(getXmlOptions());
        if (textValue.getValue() != null && !textValue.getValue().isEmpty()) {
            xbString.setStringValue(textValue.getValue());
        } else {
            xbString.setNil();
        }
        xbResult.set(xbString);
    } else if (observationValue.getValue() instanceof BooleanValue) {
        BooleanValue booleanValue = (BooleanValue) observationValue.getValue();
        XmlBoolean xbBoolean = XmlBoolean.Factory.newInstance(getXmlOptions());
        if (booleanValue.getValue() != null) {
            xbBoolean.setBooleanValue(booleanValue.getValue());
        } else {
            xbBoolean.setNil();
        }
        xbResult.set(xbBoolean);
    } else if (observationValue.getValue() instanceof CategoryValue) {
        CategoryValue categoryValue = (CategoryValue) observationValue.getValue();
        if (categoryValue.getValue() != null && !categoryValue.getValue().isEmpty()) {
            xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, categoryValue, EncodingContext.of(
                    XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
        } else {
            xbResult.setNil();
        }
    } else if (observationValue.getValue() instanceof GeometryValue) {
        GeometryValue geometryValue = (GeometryValue) observationValue.getValue();
        if (geometryValue.getValue() != null) {
            xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, geometryValue.getValue(), EncodingContext.of(
                    XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
        } else {
            xbResult.setNil();
        }
    } else if (OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION.equals(observationType)
            || OmConstants.RESULT_MODEL_OBSERVATION.getLocalPart().equals(observationType)) {
        SweDataArray dataArray = sweHelper.createSosSweDataArray(sosObservation);
        xbResult.set(encodeObjectToXml(SweConstants.NS_SWE_101, dataArray,
                EncodingContext.of(XmlBeansEncodingFlags.FOR_OBSERVATION)));
    }
}
 
Example 14
Source File: SpecimenEncoderv20.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
private void addSamplingTime(SFSpecimenType sfst, SfSpecimen specimen) throws EncodingException {
    XmlObject xmlObject = encodeGML32(specimen.getSamplingTime());
    XmlObject substitution = sfst.addNewSamplingTime().addNewAbstractTimeObject()
            .substitute(GmlHelper.getGml321QnameForITime(specimen.getSamplingTime()), xmlObject.schemaType());
    substitution.set(xmlObject);
}
 
Example 15
Source File: AbstractXmlEncoder.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
protected XmlObject substitute(XmlObject elementToSubstitute, XmlObject substitutionElement) {
    XmlObject substituteElement = XmlHelper.substituteElement(elementToSubstitute, substitutionElement);
    substituteElement.set(substitutionElement);
    return substituteElement;
}
 
Example 16
Source File: AbstractOmEncoderv20.java    From arctic-sea with Apache License 2.0 3 votes vote down vote up
/**
 * Method to add the result time to the XML observation object
 *
 * @param xbObs
 *            XML observation object
 * @param time
 *            SOS result time representation
 * @throws EncodingException
 *             If an error occurs.
 */
private void addResultTime(OMObservationType xbObs, TimeInstant time)
        throws EncodingException {
    XmlObject xmlObject = encodeGML(time);
    xbObs.addNewResultTime().addNewTimeInstant().set(xmlObject);
    XmlObject substitution = xbObs.getResultTime().getTimeInstant()
            .substitute(GmlHelper.getGml321QnameForITime(time), xmlObject.schemaType());
    substitution.set(xmlObject);
}
 
Example 17
Source File: AbstractOmEncoderv20.java    From arctic-sea with Apache License 2.0 3 votes vote down vote up
/**
 * Method to add the phenomenon time to the XML observation object
 *
 * @param timeObjectPropertyType
 *            XML time object from XML observation object
 * @param time
 *            SOS phenomenon time representation
 * @throws EncodingException
 *             If an error occurs
 */
private void addPhenomenonTime(TimeObjectPropertyType timeObjectPropertyType, Time time)
        throws EncodingException {
    XmlObject xmlObject = encodeGML(time);
    XmlObject substitution = timeObjectPropertyType.addNewAbstractTimeObject()
            .substitute(GmlHelper.getGml321QnameForITime(time), xmlObject.schemaType());
    substitution.set(xmlObject);
}