Remove SchemaNode#getPath from ControllerContext
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / restconf / impl / ControllerContext.java
index 313b71d70444be25deebc93db67394506c4eba85..4ce6f060f5673ffb994ca9d7fbb58818f7b45279 100644 (file)
@@ -533,9 +533,10 @@ public final class ControllerContext implements EffectiveModelContextListener, C
             return null;
         }
 
+        final EffectiveModelContext modelContext = mountPoint != null ? getModelContext(mountPoint) : globalSchema;
+
         if (strings.isEmpty()) {
-            return createContext(builder.build(), (DataSchemaNode) parentNode, mountPoint,
-                mountPoint != null ? getModelContext(mountPoint) : globalSchema);
+            return createContext(builder.build(), (DataSchemaNode) parentNode, mountPoint, modelContext);
         }
 
         final String head = strings.iterator().next();
@@ -633,8 +634,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C
                     rpc = getRpcDefinition(module, rpcName);
                 }
                 if (rpc != null) {
-                    return new InstanceIdentifierContext<>(builder.build(), rpc, mountPoint,
-                            mountPoint != null ? getModelContext(mountPoint) : globalSchema);
+                    return new InstanceIdentifierContext<>(builder.build(), rpc, mountPoint, modelContext);
                 }
             }
 
@@ -695,7 +695,12 @@ public final class ControllerContext implements EffectiveModelContextListener, C
                                 ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
                     }
 
-                    addKeyValue(keyValues, listNode.getDataChildByName(key), uriKeyValue, mountPoint);
+                    final SchemaInferenceStack stack = SchemaInferenceStack.of(modelContext);
+                    final YangInstanceIdentifier identifier = builder.build();
+                    identifier.getPathArguments().forEach(p -> stack.enterSchemaTree(p.getNodeType()));
+                    stack.enterSchemaTree(targetNode.getQName());
+                    stack.enterSchemaTree(key);
+                    addKeyValue(keyValues, listNode.getDataChildByName(key), uriKeyValue, mountPoint, stack);
                     index++;
                 }
             }
@@ -712,8 +717,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C
                     returnJustMountPoint);
         }
 
-        return createContext(builder.build(), targetNode, mountPoint,
-            mountPoint != null ? getModelContext(mountPoint) : globalSchema);
+        return createContext(builder.build(), targetNode, mountPoint, modelContext);
     }
 
     private static InstanceIdentifierContext<?> createContext(final YangInstanceIdentifier instance,
@@ -770,23 +774,21 @@ public final class ControllerContext implements EffectiveModelContextListener, C
     }
 
     private void addKeyValue(final HashMap<QName, Object> map, final DataSchemaNode node, final String uriValue,
-            final DOMMountPoint mountPoint) {
+            final DOMMountPoint mountPoint, final SchemaInferenceStack stack) {
         checkArgument(node instanceof LeafSchemaNode);
 
-        final EffectiveModelContext schemaContext = mountPoint == null ? globalSchema : getModelContext(mountPoint);
         final String urlDecoded = urlPathArgDecode(requireNonNull(uriValue));
         TypeDefinition<?> typedef = ((LeafSchemaNode) node).getType();
         final TypeDefinition<?> baseType = RestUtil.resolveBaseTypeFrom(typedef);
         if (baseType instanceof LeafrefTypeDefinition) {
-            typedef = SchemaInferenceStack.ofInstantiatedPath(schemaContext, node.getPath())
-                .resolveLeafref((LeafrefTypeDefinition) baseType);
+            typedef = stack.resolveLeafref((LeafrefTypeDefinition) baseType);
         }
         final IllegalArgumentCodec<Object, Object> codec = RestCodec.from(typedef, mountPoint, this);
         Object decoded = codec.deserialize(urlDecoded);
         String additionalInfo = "";
         if (decoded == null) {
             if (typedef instanceof IdentityrefTypeDefinition) {
-                decoded = toQName(schemaContext, urlDecoded);
+                decoded = toQName(stack.getEffectiveModelContext(), urlDecoded);
                 additionalInfo =
                         "For key which is of type identityref it should be in format module_name:identity_name.";
             }