Search in sources :

Example 1 with CodingMode

use of org.opendaylight.netconf.shaded.exificient.core.CodingMode in project netconf by opendaylight.

the class EXIParameters method fromXmlElement.

public static EXIParameters fromXmlElement(final XmlElement root) throws UnsupportedOption {
    final CodingMode coding;
    final NodeList alignmentElements = root.getElementsByTagName(EXI_PARAMETER_ALIGNMENT);
    if (alignmentElements.getLength() > 0) {
        final Element alignmentElement = (Element) alignmentElements.item(0);
        final String alignmentTextContent = alignmentElement.getTextContent().trim();
        switch(alignmentTextContent) {
            case EXI_PARAMETER_BYTE_ALIGNED:
                coding = CodingMode.BYTE_PACKED;
                break;
            case EXI_PARAMETER_COMPRESSED:
                coding = CodingMode.COMPRESSION;
                break;
            case EXI_PARAMETER_PRE_COMPRESSION:
                coding = CodingMode.PRE_COMPRESSION;
                break;
            case EXI_PARAMETER_BIT_PACKED:
                coding = CodingMode.BIT_PACKED;
                break;
            default:
                LOG.warn("Unexpected value in alignmentTextContent: {} , using default value", alignmentTextContent);
                coding = CodingMode.BIT_PACKED;
                break;
        }
    } else {
        coding = CodingMode.BIT_PACKED;
    }
    final FidelityOptions fidelity = FidelityOptions.createDefault();
    final NodeList fidelityElements = root.getElementsByTagName(EXI_PARAMETER_FIDELITY);
    if (fidelityElements.getLength() > 0) {
        final Element fidelityElement = (Element) fidelityElements.item(0);
        fidelity.setFidelity(FidelityOptions.FEATURE_DTD, fidelityElement.getElementsByTagName(EXI_FIDELITY_DTD).getLength() > 0);
        fidelity.setFidelity(FidelityOptions.FEATURE_LEXICAL_VALUE, fidelityElement.getElementsByTagName(EXI_FIDELITY_LEXICAL_VALUES).getLength() > 0);
        fidelity.setFidelity(FidelityOptions.FEATURE_COMMENT, fidelityElement.getElementsByTagName(EXI_FIDELITY_COMMENTS).getLength() > 0);
        fidelity.setFidelity(FidelityOptions.FEATURE_PI, fidelityElement.getElementsByTagName(EXI_FIDELITY_PIS).getLength() > 0);
        fidelity.setFidelity(FidelityOptions.FEATURE_PREFIX, fidelityElement.getElementsByTagName(EXI_FIDELITY_PREFIXES).getLength() > 0);
    }
    final EXISchema schema;
    final NodeList schemaElements = root.getElementsByTagName(EXI_PARAMETER_SCHEMAS);
    if (schemaElements.getLength() > 0) {
        final Element schemaElement = (Element) schemaElements.item(0);
        final String schemaName = schemaElement.getTextContent().trim();
        schema = EXISchema.forOption(schemaName);
        checkArgument(schema != null, "Unsupported schema name %s", schemaName);
    } else {
        schema = EXISchema.NONE;
    }
    return new EXIParameters(coding, fidelity, schema);
}
Also used : CodingMode(org.opendaylight.netconf.shaded.exificient.core.CodingMode) NodeList(org.w3c.dom.NodeList) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Element(org.w3c.dom.Element) FidelityOptions(org.opendaylight.netconf.shaded.exificient.core.FidelityOptions)

Aggregations

XmlElement (org.opendaylight.netconf.api.xml.XmlElement)1 CodingMode (org.opendaylight.netconf.shaded.exificient.core.CodingMode)1 FidelityOptions (org.opendaylight.netconf.shaded.exificient.core.FidelityOptions)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1