Seal ModificationApplyOperation 78/107678/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 3 Sep 2023 19:17:45 +0000 (21:17 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 4 Sep 2023 08:38:33 +0000 (10:38 +0200)
We have a carefully-structured class hierarchy here. Make sure the JVM
understands it when performing partial loading.

Change-Id: Ie4b50be7127c7b103a84212d4674f017b1a9e5bc
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/AbstractNodeContainerModificationStrategy.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/AbstractValidation.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/ContainerModificationStrategy.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/DataNodeContainerModificationStrategy.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/MapEntryModificationStrategy.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/ModificationApplyOperation.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/SchemaAwareApplyOperation.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/StructuralContainerModificationStrategy.java [deleted file]

index 24743f88f6fa3fd01a11235344e563a91cabc648..5a43bfdd28e996eaf24ffd8ce8626b24c0fcb9f5 100644 (file)
@@ -34,9 +34,11 @@ import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
 import org.opendaylight.yangtools.yang.data.tree.impl.node.Version;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 
-abstract class AbstractNodeContainerModificationStrategy<T extends DataSchemaNode>
+abstract sealed class AbstractNodeContainerModificationStrategy<T extends DataSchemaNode>
         extends SchemaAwareApplyOperation<T> {
-    abstract static class Invisible<T extends DataSchemaNode> extends AbstractNodeContainerModificationStrategy<T> {
+    abstract static sealed class Invisible<T extends DataSchemaNode>
+            extends AbstractNodeContainerModificationStrategy<T>
+            permits LeafSetModificationStrategy, MapModificationStrategy {
         private final @NonNull SchemaAwareApplyOperation<T> entryStrategy;
 
         Invisible(final NormalizedNodeContainerSupport<?, ?> support, final DataTreeConfiguration treeConfig,
@@ -60,7 +62,8 @@ abstract class AbstractNodeContainerModificationStrategy<T extends DataSchemaNod
         }
     }
 
-    abstract static class Visible<T extends DataSchemaNode> extends AbstractNodeContainerModificationStrategy<T> {
+    abstract static sealed class Visible<T extends DataSchemaNode> extends AbstractNodeContainerModificationStrategy<T>
+            permits ChoiceModificationStrategy, DataNodeContainerModificationStrategy {
         private final @NonNull T schema;
 
         Visible(final NormalizedNodeContainerSupport<?, ?> support, final DataTreeConfiguration treeConfig,
index de2488fb78bc510a4abfa8c83f1f4639f517a987..1055cbc09aa837a211269fec3d7a9dc293453ca0 100644 (file)
@@ -25,7 +25,8 @@ import org.slf4j.LoggerFactory;
  * A forwarding {@link ModificationApplyOperation}. Useful for strategies which do not deal with data layout, but rather
  * perform additional validation.
  */
-abstract class AbstractValidation extends ModificationApplyOperation {
+abstract sealed class AbstractValidation extends ModificationApplyOperation
+        permits MinMaxElementsValidation, UniqueValidation {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractValidation.class);
 
     private final @NonNull ModificationApplyOperation delegate;
index 1e5574bddf281ec52866e0e9df37683abbcd6144..906b9eed5b148464a73cf23a3813e9ea1db36f7c 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
@@ -26,8 +27,8 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
  * with mandatory nodes, as it needs to tap into {@link SchemaAwareApplyOperation}'s operations, or subclassed
  * for the purposes of {@link StructuralContainerModificationStrategy}'s automatic lifecycle.
  */
-class ContainerModificationStrategy extends DataNodeContainerModificationStrategy<ContainerLike> {
-    private static final class EnforcingMandatory extends ContainerModificationStrategy {
+sealed class ContainerModificationStrategy extends DataNodeContainerModificationStrategy<ContainerLike> {
+    static final class EnforcingMandatory extends ContainerModificationStrategy {
         private final MandatoryLeafEnforcer enforcer;
 
         EnforcingMandatory(final ContainerSchemaNode schemaNode, final DataTreeConfiguration treeConfig,
@@ -66,6 +67,35 @@ class ContainerModificationStrategy extends DataNodeContainerModificationStrateg
         }
     }
 
+    /**
+     * Structural containers are special in that they appear when implied by child nodes and disappear whenever they are
+     * empty. We could implement this as a subclass of {@link SchemaAwareApplyOperation}, but the automatic semantic
+     * is quite different from all the other strategies. We create a {@link ContainerModificationStrategy} to tap into
+     * that logic, but wrap it so we only call out into it. We do not use {@link PresenceContainerModificationStrategy}
+     * because it enforces presence of mandatory leaves, which is not something we want here, as structural containers
+     * are not root anchors for that validation.
+     */
+    static final class Structural extends ContainerModificationStrategy {
+        private final ContainerNode emptyNode;
+
+        Structural(final ContainerLike schema, final DataTreeConfiguration treeConfig) {
+            super(schema, treeConfig);
+            emptyNode = ImmutableNodes.containerNode(schema.getQName());
+        }
+
+        @Override
+        Optional<? extends TreeNode> apply(final ModifiedNode modification,
+                final Optional<? extends TreeNode> storeMeta, final Version version) {
+            return AutomaticLifecycleMixin.apply(super::apply, this::applyWrite, emptyNode, modification, storeMeta,
+                version);
+        }
+
+        @Override
+        TreeNode defaultTreeNode() {
+            return defaultTreeNode(emptyNode);
+        }
+    }
+
     private static final NormalizedNodeContainerSupport<NodeIdentifier, ContainerNode> SUPPORT =
             new NormalizedNodeContainerSupport<>(ContainerNode.class, ImmutableContainerNodeBuilder::create,
                     ImmutableContainerNodeBuilder::create);
@@ -74,13 +104,12 @@ class ContainerModificationStrategy extends DataNodeContainerModificationStrateg
         super(SUPPORT, schemaNode, treeConfig);
     }
 
-    static ModificationApplyOperation of(final ContainerSchemaNode schema, final DataTreeConfiguration treeConfig) {
+    static ContainerModificationStrategy of(final ContainerSchemaNode schema, final DataTreeConfiguration treeConfig) {
         if (schema.isPresenceContainer()) {
             final var enforcer = MandatoryLeafEnforcer.forContainer(schema, treeConfig);
             return enforcer != null ? new EnforcingMandatory(schema, treeConfig, enforcer)
                 : new ContainerModificationStrategy(schema, treeConfig);
         }
-
-        return new StructuralContainerModificationStrategy(schema, treeConfig);
+        return new Structural(schema, treeConfig);
     }
 }
index ae29c3e83508829fba320a954f73350b609532cf..8aa7321ed0c15a51a3825a294f15e1bfe0569eb3 100644 (file)
@@ -23,12 +23,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Base strategy for applying changes to a ContainerNode, irrespective of its
- * actual type.
+ * Base strategy for applying changes to a ContainerNode, irrespective of its actual type.
  *
  * @param <T> Type of the container node
  */
-class DataNodeContainerModificationStrategy<T extends DataSchemaNode & DataNodeContainer> extends Visible<T> {
+sealed class DataNodeContainerModificationStrategy<T extends DataSchemaNode & DataNodeContainer> extends Visible<T>
+        permits ContainerModificationStrategy, MapEntryModificationStrategy {
     private static final Logger LOG = LoggerFactory.getLogger(DataNodeContainerModificationStrategy.class);
     private static final VarHandle CHILDREN;
 
index 2015259c041e5ccd34edf42ac62b9e1ba8b3a8fb..0a35aeec9151fb3825edbd8fa03dfbb6be62c5e4 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
 import org.opendaylight.yangtools.yang.data.tree.impl.node.Version;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 
-class MapEntryModificationStrategy extends DataNodeContainerModificationStrategy<ListSchemaNode> {
+sealed class MapEntryModificationStrategy extends DataNodeContainerModificationStrategy<ListSchemaNode> {
     private static final class EnforcingMandatory extends MapEntryModificationStrategy {
         private final MandatoryLeafEnforcer enforcer;
 
index 32f990cb10404adeae1d8ae3bbda239e2527be28..1688d66f78893f1da50ca3da2b8a7bbeafe61fc4 100644 (file)
@@ -42,7 +42,8 @@ import org.opendaylight.yangtools.yang.data.tree.impl.node.Version;
  *   </li>
  * </ul>
  */
-abstract class ModificationApplyOperation implements StoreTreeNode<ModificationApplyOperation> {
+abstract sealed class ModificationApplyOperation implements StoreTreeNode<ModificationApplyOperation>
+        permits AbstractValidation, SchemaAwareApplyOperation {
     /**
      * Implementation of this operation must be stateless and must not change state of this object.
      *
index 8be123f28c0cbb33ff8664b8d07e2acd1cd4f371..9f97c637b7dd14546b062c0e5693f1b31d5b4db7 100644 (file)
@@ -38,7 +38,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-abstract class SchemaAwareApplyOperation<T extends DataSchemaNode> extends ModificationApplyOperation {
+abstract sealed class SchemaAwareApplyOperation<T extends DataSchemaNode> extends ModificationApplyOperation
+        permits AbstractNodeContainerModificationStrategy, ListModificationStrategy, ValueNodeModificationStrategy {
     private static final Logger LOG = LoggerFactory.getLogger(SchemaAwareApplyOperation.class);
 
     static ModificationApplyOperation from(final DataSchemaNode schemaNode,
@@ -61,7 +62,7 @@ abstract class SchemaAwareApplyOperation<T extends DataSchemaNode> extends Modif
         } else if (schemaNode instanceof AnyxmlSchemaNode anyxml) {
             return new ValueNodeModificationStrategy<>(AnyxmlNode.class, anyxml);
         } else if (schemaNode instanceof SchemaContext context) {
-            return new StructuralContainerModificationStrategy(context, treeConfig);
+            return new ContainerModificationStrategy.Structural(context, treeConfig);
         } else {
             throw new IllegalStateException("Unsupported schema " + schemaNode);
         }
diff --git a/data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/StructuralContainerModificationStrategy.java b/data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/StructuralContainerModificationStrategy.java
deleted file mode 100644 (file)
index 01c4570..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.tree.impl;
-
-import java.util.Optional;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
-import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
-import org.opendaylight.yangtools.yang.data.tree.impl.node.Version;
-import org.opendaylight.yangtools.yang.model.api.ContainerLike;
-
-/**
- * Structural containers are special in that they appear when implied by child nodes and disappear whenever they are
- * empty. We could implement this as a subclass of {@link SchemaAwareApplyOperation}, but the automatic semantic
- * is quite different from all the other strategies. We create a {@link ContainerModificationStrategy} to tap into that
- * logic, but wrap it so we only call out into it. We do not use {@link PresenceContainerModificationStrategy} because
- * it enforces presence of mandatory leaves, which is not something we want here, as structural containers are not
- * root anchors for that validation.
- */
-final class StructuralContainerModificationStrategy extends ContainerModificationStrategy {
-    private final ContainerNode emptyNode;
-
-    StructuralContainerModificationStrategy(final ContainerLike schema, final DataTreeConfiguration treeConfig) {
-        super(schema, treeConfig);
-        this.emptyNode = ImmutableNodes.containerNode(schema.getQName());
-    }
-
-    @Override
-    Optional<? extends TreeNode> apply(final ModifiedNode modification, final Optional<? extends TreeNode> storeMeta,
-            final Version version) {
-        return AutomaticLifecycleMixin.apply(super::apply, this::applyWrite, emptyNode, modification, storeMeta,
-            version);
-    }
-
-    @Override
-    TreeNode defaultTreeNode() {
-        return defaultTreeNode(emptyNode);
-    }
-}