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,
}
}
- 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,
* 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;
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;
* 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,
}
}
+ /**
+ * 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);
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);
}
}
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;
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;
* </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.
*
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,
} 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);
}
+++ /dev/null
-/*
- * 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);
- }
-}