Make DataTree take EffectiveModelContext 15/84815/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Sep 2019 15:46:13 +0000 (17:46 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Sep 2019 15:55:01 +0000 (17:55 +0200)
This deprecates setSchemaContext() in favor of
setEffectiveModelContext(), so that users are encouraged to
migrate.

JIRA: MDSAL-435
Change-Id: If859130e204a058f89c2fee04d4be69969215399
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/DataTree.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTree.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/StructuralApplyModificationTest.java

index 9c9b26d5fb7d19a7f38cdc05b7bf96e24b1de919..378b980dd91b726bbfe353aea5e0fd557709a511 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema.tree;
 
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
@@ -19,9 +20,22 @@ public interface DataTree extends DataTreeTip, ReadOnlyDataTree {
      *
      * @param newSchemaContext new SchemaContext
      * @throws IllegalArgumentException if the new context is incompatible
+     * @throws NullPointerException if newSchemaContext is null
+     * @deprecated Prefer {@link #setEffectiveModelContext(EffectiveModelContext)}.
      */
+    @Deprecated
     void setSchemaContext(SchemaContext newSchemaContext);
 
+    /**
+     * Make the data tree use a new schema context. The context will be used
+     * only by subsequent operations.
+     *
+     * @param newModelContext new EffectiveModelContext
+     * @throws IllegalArgumentException if the new context is incompatible
+     * @throws NullPointerException if newModelContext is null
+     */
+    void setEffectiveModelContext(EffectiveModelContext newModelContext);
+
     /**
      * Commit a data tree candidate.
      *
index 1990b1590ea35fd6db614922a0450d4d86b8fd21..2baabdee0fce1f3b617a1d63b6b44c91877dccb7 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
@@ -48,7 +49,7 @@ final class InMemoryDataTree extends AbstractDataTreeTip implements DataTree {
     private volatile DataTreeState state;
 
     InMemoryDataTree(final TreeNode rootNode, final DataTreeConfiguration treeConfig,
-        final SchemaContext schemaContext) {
+            final SchemaContext schemaContext) {
         this.treeConfig = requireNonNull(treeConfig, "treeConfig");
         maskMandatory = true;
         state = DataTreeState.createInitial(rootNode);
@@ -80,12 +81,22 @@ final class InMemoryDataTree extends AbstractDataTreeTip implements DataTree {
         return SchemaAwareApplyOperation.from(rootSchemaNode, treeConfig);
     }
 
+    @Deprecated
+    @Override
+    public void setSchemaContext(final SchemaContext newSchemaContext) {
+        internalSetSchemaContext(newSchemaContext);
+    }
+
+    @Override
+    public void setEffectiveModelContext(final EffectiveModelContext newModelContext) {
+        internalSetSchemaContext(newModelContext);
+    }
+
     /*
      * This method is synchronized to guard against user attempting to install
      * multiple contexts. Otherwise it runs in a lock-free manner.
      */
-    @Override
-    public synchronized void setSchemaContext(final SchemaContext newSchemaContext) {
+    private synchronized void internalSetSchemaContext(final SchemaContext newSchemaContext) {
         requireNonNull(newSchemaContext);
 
         LOG.debug("Following schema contexts will be attempted {}", newSchemaContext);
index 4937c0398190b797ba5222960cfdbe4598d6878b..e08ff0ccd46f97e70b7d578f9b384150f872ecba 100644 (file)
@@ -32,7 +32,7 @@ public final class StructuralApplyModificationTest extends AbstractTestModelTest
     @Before
     public void setUp() {
         inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION);
-        inMemoryDataTree.setSchemaContext(SCHEMA_CONTEXT);
+        inMemoryDataTree.setEffectiveModelContext(SCHEMA_CONTEXT);
     }
 
     @Test