Add SchemaInferenceStack.ofSchemaPath() 38/96438/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 7 Jun 2021 09:13:36 +0000 (11:13 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 7 Jun 2021 09:13:36 +0000 (11:13 +0200)
RESTCONF models are using groupings to communicate serialized data,
for which we need an alternative instantiation, which uses the legacy
SchemaPath interpretation.

Change-Id: I4dec567ade0705a9af7497d53689a286858c411e
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
data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeStreamWriterStack.java
model/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaInferenceStack.java

index 5a364ee6b8910f4ba356e4c8210671f96de881c0..eb7c77f67a6aa3f1e8f0f5ce2c6c7b32c693e4a6 100644 (file)
@@ -65,7 +65,7 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
         super(writer);
         this.schemaContext = requireNonNull(schemaContext);
 
-        final SchemaInferenceStack stack = SchemaInferenceStack.ofInstantiatedPath(schemaContext, path);
+        final SchemaInferenceStack stack = SchemaInferenceStack.ofSchemaPath(schemaContext, path);
         if (!stack.isEmpty()) {
             final EffectiveStatement<?, ?> current = stack.currentStatement();
             // FIXME: this should be one of NormalizedNodeContainer/NotificationDefinition/OperationDefinition
@@ -208,4 +208,4 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
             SchemaOrderedNormalizedNodeWriter.this.currentSchemaNode = previousSchemaNode;
         }
     }
-}
\ No newline at end of file
+}
index 89052d8f92b786a6c0c5a8eaa155b86495a46b95..6eb0e7750b0df3009a1bc869c8cb78d5327cf874 100644 (file)
@@ -148,7 +148,7 @@ public final class NormalizedNodeStreamWriterStack implements LeafrefResolver {
     @Deprecated
     public static @NonNull NormalizedNodeStreamWriterStack of(final EffectiveModelContext context,
             final SchemaPath path) {
-        return new NormalizedNodeStreamWriterStack(SchemaInferenceStack.ofInstantiatedPath(context, path));
+        return new NormalizedNodeStreamWriterStack(SchemaInferenceStack.ofSchemaPath(context, path));
     }
 
     /**
index 4a6c97a2113a23305be0c63bc617c1d68bd0bab1..91610e67880b98740ba212baeae3229fb408c143 100644 (file)
@@ -245,7 +245,7 @@ public final class SchemaInferenceStack implements Mutable, EffectiveModelContex
 
     /**
      * Create a new stack backed by an effective model, pointing to specified schema node identified by an absolute
-     * {@link SchemaPath} and its {@link SchemaPath#getPathFromRoot()}.
+     * {@link SchemaPath} and its {@link SchemaPath#getPathFromRoot()} interpreted as a schema node identifier.
      *
      * @param effectiveModel EffectiveModelContext to which this stack is attached
      * @return A new stack
@@ -262,6 +262,39 @@ public final class SchemaInferenceStack implements Mutable, EffectiveModelContex
         return ret;
     }
 
+    /**
+     * Create a new stack backed by an effective model, pointing to specified schema node identified by an absolute
+     * {@link SchemaPath} and its {@link SchemaPath#getPathFromRoot()}, interpreted as a series of steps along primarily
+     * schema tree, with grouping namespace being the alternative lookup.
+     *
+     * @param effectiveModel EffectiveModelContext to which this stack is attached
+     * @return A new stack
+     * @throws NullPointerException {@code effectiveModel} is null
+     * @throws IllegalArgumentException if {@code path} cannot be resolved in the effective model or if it is not an
+     *                                  absolute path.
+     */
+    @Deprecated
+    public static @NonNull SchemaInferenceStack ofSchemaPath(final EffectiveModelContext effectiveModel,
+            final SchemaPath path) {
+        checkArgument(path.isAbsolute(), "Cannot operate on relative path %s", path);
+        final SchemaInferenceStack ret = new SchemaInferenceStack(effectiveModel);
+
+        for (QName step : path.getPathFromRoot()) {
+            try {
+                ret.enterSchemaTree(step);
+            } catch (IllegalArgumentException schemaEx) {
+                try {
+                    ret.enterGrouping(step);
+                } catch (IllegalArgumentException ex) {
+                    ex.addSuppressed(schemaEx);
+                    throw ex;
+                }
+            }
+        }
+
+        return ret;
+    }
+
     @Override
     public EffectiveModelContext getEffectiveModelContext() {
         return effectiveModel;