Bump upstreams to SNAPSHOTs
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / jersey / providers / patch / JsonPatchBodyReader.java
index c742886aef61c3ea60f78b723881f11dac26808a..c2886b4de7a9d28cd870c5b2a6c150affa372f00 100644 (file)
@@ -53,6 +53,7 @@ import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -229,17 +230,18 @@ public class JsonPatchBodyReader extends AbstractPatchBodyReader {
                     final String target = in.nextString();
                     if (target.equals("/")) {
                         edit.setTarget(path.getInstanceIdentifier());
-                        edit.setTargetSchemaNode(path.getSchemaContext());
+                        edit.setTargetSchemaNode(SchemaInferenceStack.of(path.getSchemaContext()).toInference());
                     } else {
                         edit.setTarget(ParserIdentifier.parserPatchTarget(path, target));
 
-                        final EffectiveStatement<?, ?> parentStmt = SchemaInferenceStack.ofInstantiatedPath(
-                            path.getSchemaContext(),
-                            schemaTree.findChild(edit.getTarget()).orElseThrow().getDataSchemaNode()
-                                .getPath().getParent())
-                            .currentStatement();
+                        final var stack = schemaTree.enterPath(edit.getTarget()).orElseThrow().stack();
+                        if (!stack.isEmpty()) {
+                            stack.exit();
+                        }
+
+                        final EffectiveStatement<?, ?> parentStmt = stack.currentStatement();
                         verify(parentStmt instanceof SchemaNode, "Unexpected parent %s", parentStmt);
-                        edit.setTargetSchemaNode((SchemaNode) parentStmt);
+                        edit.setTargetSchemaNode(stack.toInference());
                     }
 
                     break;
@@ -369,12 +371,11 @@ public class JsonPatchBodyReader extends AbstractPatchBodyReader {
      * @return NormalizedNode representing data
      */
     private static NormalizedNode readEditData(final @NonNull JsonReader in,
-             final @NonNull SchemaNode targetSchemaNode, final @NonNull InstanceIdentifierContext path) {
+             final @NonNull Inference targetSchemaNode, final @NonNull InstanceIdentifierContext path) {
         final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
         final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
         JsonParserStream.create(writer, JSONCodecFactorySupplier.RFC7951.getShared(path.getSchemaContext()),
-            SchemaInferenceStack.ofInstantiatedPath(path.getSchemaContext(), targetSchemaNode.getPath()).toInference())
-            .parse(in);
+            targetSchemaNode).parse(in);
 
         return resultHolder.getResult();
     }
@@ -423,7 +424,7 @@ public class JsonPatchBodyReader extends AbstractPatchBodyReader {
         private String id;
         private PatchEditOperation operation;
         private YangInstanceIdentifier target;
-        private SchemaNode targetSchemaNode;
+        private Inference targetSchemaNode;
         private NormalizedNode data;
 
         String getId() {
@@ -450,11 +451,11 @@ public class JsonPatchBodyReader extends AbstractPatchBodyReader {
             this.target = requireNonNull(target);
         }
 
-        SchemaNode getTargetSchemaNode() {
+        Inference getTargetSchemaNode() {
             return targetSchemaNode;
         }
 
-        void setTargetSchemaNode(final SchemaNode targetSchemaNode) {
+        void setTargetSchemaNode(final Inference targetSchemaNode) {
             this.targetSchemaNode = requireNonNull(targetSchemaNode);
         }