From 05efa813196bd32c6c40c3b09d24690baf028164 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 24 May 2021 12:59:39 +0200 Subject: [PATCH] Restore special-case handling of NotificationDefinition We have historically had a weird special case for parsing notifications, where we would expect the stack to be initialized to point to the notification and then to enter it as an alternative to normal data tree. This functionality is used in NETCONF, restore it back in a slightly better format than before. Also drop a FIXME so we expose the functionality in a more structure way in the future. JIRA: YANGTOOLS-1288 Change-Id: I9237cf558525e4028626cfe7f67d76bbabebab4c Signed-off-by: Robert Varga --- .../util/NormalizedNodeStreamWriterStack.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeStreamWriterStack.java b/data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeStreamWriterStack.java index 19b4a5564b..89052d8f92 100644 --- a/data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeStreamWriterStack.java +++ b/data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeStreamWriterStack.java @@ -247,9 +247,19 @@ public final class NormalizedNodeStreamWriterStack implements LeafrefResolver { public SchemaNode startContainerNode(final NodeIdentifier name) { LOG.debug("Enter container {}", name); - final SchemaNode schema = enterDataTree(name); - checkArgument(schema instanceof ContainerLike || schema instanceof NotificationDefinition, - "Node %s is not a container nor a notification", schema); + + final SchemaNode schema; + if (schemaStack.isEmpty() && root instanceof NotificationDefinition) { + // Special case for stacks initialized at notification. We pretend the first container is contained within + // itself. + // FIXME: 8.0.0: factor this special case out to something more reasonable, like being initialized at the + // Notification's parent and knowing to enterSchemaTree() instead of enterDataTree(). + schema = (NotificationDefinition) root; + } else { + schema = enterDataTree(name); + checkArgument(schema instanceof ContainerLike, "Node %s is not a container", schema); + } + schemaStack.push(schema); return schema; } -- 2.36.6