2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
10 import static java.util.Objects.requireNonNull;
12 import java.util.Optional;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
14 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
20 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
22 class ListEntryModificationStrategy extends DataNodeContainerModificationStrategy<ListSchemaNode> {
23 private static final class EnforcingMandatory extends ListEntryModificationStrategy {
24 private final MandatoryLeafEnforcer enforcer;
26 EnforcingMandatory(final ListSchemaNode schemaNode, final DataTreeConfiguration treeConfig,
27 final MandatoryLeafEnforcer enforcer) {
28 super(schemaNode, treeConfig);
29 this.enforcer = requireNonNull(enforcer);
33 void additionalVerifyValueChildren(final NormalizedNode<?, ?> writtenValue) {
34 enforcer.enforceOnData(writtenValue);
38 protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
39 final Version version) {
40 final TreeNode ret = super.applyMerge(modification, currentMeta, version);
41 enforcer.enforceOnTreeNode(ret);
46 protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode<?, ?> newValue,
47 final Optional<TreeNode> currentMeta, final Version version) {
48 final TreeNode ret = super.applyWrite(modification, newValue, currentMeta, version);
49 enforcer.enforceOnTreeNode(ret);
54 protected TreeNode applyTouch(final ModifiedNode modification, final TreeNode currentMeta,
55 final Version version) {
56 final TreeNode ret = super.applyTouch(modification, currentMeta, version);
57 enforcer.enforceOnTreeNode(ret);
62 private static final NormalizedNodeContainerSupport<NodeIdentifierWithPredicates, MapEntryNode> SUPPORT =
63 new NormalizedNodeContainerSupport<>(MapEntryNode.class, ImmutableMapEntryNodeBuilder::create,
64 ImmutableMapEntryNodeBuilder::create);
66 ListEntryModificationStrategy(final ListSchemaNode schema, final DataTreeConfiguration treeConfig) {
67 super(SUPPORT, schema, treeConfig);
70 static ListEntryModificationStrategy of(final ListSchemaNode schema, final DataTreeConfiguration treeConfig) {
71 final Optional<MandatoryLeafEnforcer> enforcer = MandatoryLeafEnforcer.forContainer(schema, treeConfig);
72 return enforcer.isPresent() ? new EnforcingMandatory(schema, treeConfig, enforcer.get())
73 : new ListEntryModificationStrategy(schema, treeConfig);