Restore special-case handling of NotificationDefinition 34/96334/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 24 May 2021 10:59:39 +0000 (12:59 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 24 May 2021 11:02:04 +0000 (13:02 +0200)
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 <robert.varga@pantheon.tech>
data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeStreamWriterStack.java

index 19b4a5564b25c6600abfc490a779b8d7ccca813b..89052d8f92b786a6c0c5a8eaa155b86495a46b95 100644 (file)
@@ -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;
     }