Add SchemaNodeIdentifier-based constructor 31/99131/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 22 Dec 2021 07:25:29 +0000 (08:25 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 22 Dec 2021 07:32:06 +0000 (08:32 +0100)
We are deprecating SchemaPath, provide a proper constructor allowing
downstreams to use it instead of the SchemaPath-driven one.

Change-Id: If06f415d4e6dcd9b18875f78b463f47a62b00a75
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaOrderedNormalizedNodeWriter.java

index eb7c77f67a6aa3f1e8f0f5ce2c6c7b32c693e4a6..78640d7b5001a053e682e72021fce67e02cef89a 100644 (file)
@@ -28,7 +28,9 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaTreeInference;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
 
 /**
@@ -50,22 +52,14 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
     public SchemaOrderedNormalizedNodeWriter(final NormalizedNodeStreamWriter writer,
             final EffectiveModelContext schemaContext) {
         super(writer);
-        this.root = this.schemaContext = requireNonNull(schemaContext);
+        root = this.schemaContext = requireNonNull(schemaContext);
     }
 
-    /**
-     * Create a new writer backed by a {@link NormalizedNodeStreamWriter}.
-     *
-     * @param writer Back-end writer
-     * @param schemaContext Associated {@link EffectiveModelContext}
-     * @param path root path
-     */
-    public SchemaOrderedNormalizedNodeWriter(final NormalizedNodeStreamWriter writer,
-            final EffectiveModelContext schemaContext, final SchemaPath path) {
+    private SchemaOrderedNormalizedNodeWriter(final NormalizedNodeStreamWriter writer,
+            final SchemaInferenceStack stack) {
         super(writer);
-        this.schemaContext = requireNonNull(schemaContext);
+        schemaContext = stack.getEffectiveModelContext();
 
-        final SchemaInferenceStack stack = SchemaInferenceStack.ofSchemaPath(schemaContext, path);
         if (!stack.isEmpty()) {
             final EffectiveStatement<?, ?> current = stack.currentStatement();
             // FIXME: this should be one of NormalizedNodeContainer/NotificationDefinition/OperationDefinition
@@ -76,6 +70,43 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
         }
     }
 
+    /**
+     * Create a new writer backed by a {@link NormalizedNodeStreamWriter}.
+     *
+     * @param writer Back-end writer
+     * @param schemaContext Associated {@link EffectiveModelContext}
+     * @param path root path
+     */
+    public SchemaOrderedNormalizedNodeWriter(final NormalizedNodeStreamWriter writer,
+            final EffectiveModelContext schemaContext, final Absolute path) {
+        this(writer, SchemaInferenceStack.of(schemaContext, path));
+    }
+
+    /**
+     * Create a new writer backed by a {@link NormalizedNodeStreamWriter}.
+     *
+     * @param writer Back-end writer
+     * @param rootInference A SchemaTreeInference pointing to the root element
+     */
+    public SchemaOrderedNormalizedNodeWriter(final NormalizedNodeStreamWriter writer,
+            final SchemaTreeInference rootInference) {
+        this(writer, SchemaInferenceStack.ofInference(rootInference));
+    }
+
+    /**
+     * Create a new writer backed by a {@link NormalizedNodeStreamWriter}.
+     *
+     * @param writer Back-end writer
+     * @param schemaContext Associated {@link EffectiveModelContext}
+     * @param path root path
+     * @deprecated Use either one of the alternative constructors instead.
+     */
+    @Deprecated(since = "7.0.11")
+    public SchemaOrderedNormalizedNodeWriter(final NormalizedNodeStreamWriter writer,
+            final EffectiveModelContext schemaContext, final SchemaPath path) {
+        this(writer, SchemaInferenceStack.ofSchemaPath(schemaContext, path));
+    }
+
     @Override
     public SchemaOrderedNormalizedNodeWriter write(final NormalizedNode node) throws IOException {
         if (schemaContext.equals(root)) {
@@ -196,8 +227,8 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
          * Sets current schema node new value and store old value for later restore.
          */
         SchemaNodeSetter(final SchemaNode schemaNode) {
-            previousSchemaNode = SchemaOrderedNormalizedNodeWriter.this.currentSchemaNode;
-            SchemaOrderedNormalizedNodeWriter.this.currentSchemaNode = schemaNode;
+            previousSchemaNode = currentSchemaNode;
+            currentSchemaNode = schemaNode;
         }
 
         /**
@@ -205,7 +236,7 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
          */
         @Override
         public void close() {
-            SchemaOrderedNormalizedNodeWriter.this.currentSchemaNode = previousSchemaNode;
+            currentSchemaNode = previousSchemaNode;
         }
     }
 }