BUG 8566 Introduce a fallback for ChoiceSchemaNode lookup 06/58106/2
authorTomas Cere <tcere@cisco.com>
Wed, 31 May 2017 11:28:17 +0000 (13:28 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 2 Jun 2017 19:23:20 +0000 (19:23 +0000)
With the way parsing callbacks are handled between netconf and yangtools
theres no hook for case nodes, which we are missing in the path when doing
SchemaNode lookup. This introduces a callback that checks Choice children
for a possible match once the normal lookup fails.

Change-Id: Ieefc6771ec3c6892e00103cbab77f6340f197d62
Signed-off-by: Tomas Cere <tcere@cisco.com>
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java

index f56d69565f7288dccc13f0c42b7a154664f4ef7e..21d2d28113fcb2ef6d68c402a97a8f6a5fb800d0 100644 (file)
@@ -22,6 +22,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
@@ -395,9 +396,21 @@ public final class SchemaContextUtil {
 
         if (foundNode == null && parent instanceof ChoiceSchemaNode) {
             foundNode = ((ChoiceSchemaNode) parent).getCaseNodeByName(current);
+
             if (foundNode != null && nextPath.iterator().hasNext()) {
                 foundNode = findNodeIn(foundNode, nextPath);
             }
+
+            if (foundNode == null) {
+                // fallback that tries to map into one of the child cases
+                for (final ChoiceCaseNode caseNode : ((ChoiceSchemaNode) parent).getCases()) {
+                    final DataSchemaNode maybeChild = caseNode.getDataChildByName(current);
+                    if (maybeChild != null) {
+                        foundNode = findNodeIn(maybeChild, nextPath);
+                        break;
+                    }
+                }
+            }
         }
 
         if (foundNode == null) {