2 * Copyright (c) 2015 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 java.util.Optional;
11 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
12 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
13 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
15 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
16 import org.opendaylight.yangtools.yang.model.api.ContainerLike;
19 * Structural containers are special in that they appear when implied by child nodes and disappear whenever they are
20 * empty. We could implement this as a subclass of {@link SchemaAwareApplyOperation}, but the automatic semantic
21 * is quite different from all the other strategies. We create a {@link ContainerModificationStrategy} to tap into that
22 * logic, but wrap it so we only call out into it. We do not use {@link PresenceContainerModificationStrategy} because
23 * it enforces presence of mandatory leaves, which is not something we want here, as structural containers are not
24 * root anchors for that validation.
26 final class StructuralContainerModificationStrategy extends ContainerModificationStrategy {
27 private final ContainerNode emptyNode;
29 StructuralContainerModificationStrategy(final ContainerLike schema, final DataTreeConfiguration treeConfig) {
30 super(schema, treeConfig);
31 this.emptyNode = ImmutableNodes.containerNode(schema.getQName());
35 Optional<? extends TreeNode> apply(final ModifiedNode modification, final Optional<? extends TreeNode> storeMeta,
36 final Version version) {
37 return AutomaticLifecycleMixin.apply(super::apply, this::applyWrite, emptyNode, modification, storeMeta,
42 TreeNode defaultTreeNode() {
43 return defaultTreeNode(emptyNode);