Use YANG-derived prefixes 30/108030/15
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Sep 2023 20:33:47 +0000 (22:33 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 29 Sep 2023 10:57:28 +0000 (12:57 +0200)
commit316df6dff3f5d3126840db3b732a0797fbd3d35a
tree900a34fe5938adc849afd901e16269c533fe29e0
parent99715f7b5483c08f7fe4ec9232281ea04a3941b2
Use YANG-derived prefixes

All XML examples starting from RFC6020 onwards use a module's prefix to
identify the module.

This is not something that is universally feasible to do, as the
document context may indicate a different namespace mapping, which may
be more efficient to use.

Such assignments may also conflict with already-assigned prefixes and
redefining XML namespaces increases cognitive load in analysis -- hence
we have to avoid that.

Also prefix assignments are not a global namespace, so we could easily
end up with ambigous mappings. This is unlikely, but it can easily
happen.

With an EffectiveModelContext we can perform analysis on what is valid
within that enclosed world and use that as a guide. When
NamespacePrefixes decides current RandomPrefix (which is not random at
all!) does not have a mapping, we can consult an analysis object to give
us guidance.

This patch renames RandomPrefix to 'NamespacePrefixes' and introduces
PreferredPrefixes, which can be computed from an EffectiveModelContext.

These two then act in unison to assign prefixes based on prefix
statements present in modules forming an EffectiveModelContext whenever
we need to do such a thing.

JIRA: YANGTOOLS-1544
Change-Id: Iafc5806f53d8927e46f059287e2ae3ed2c77ff26
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
16 files changed:
codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/IdentityrefXmlCodec.java
codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/InstanceIdentifierSerializer.java
codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/InstanceIdentifierXmlCodec.java
codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/NamespacePrefixes.java [moved from codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/RandomPrefix.java with 54% similarity]
codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/PreferredPrefixes.java [new file with mode: 0644]
codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/SchemaAwareXMLStreamNormalizedNodeStreamWriter.java
codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/SchemaAwareXMLStreamWriterUtils.java
codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/SchemalessXMLStreamNormalizedNodeStreamWriter.java
codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/StreamWriterFacade.java
codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XMLStreamNormalizedNodeStreamWriter.java
codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlCodecFactory.java
codec/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NamespacePrefixesTest.java [moved from codec/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/RandomPrefixTest.java with 66% similarity]
codec/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/PreferredPrefixesTest.java [new file with mode: 0644]
codec/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlStreamUtilsTest.java
codec/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YT1473Test.java
codec/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YT1543Test.java