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
9 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
11 import com.google.common.base.Optional;
12 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
13 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
16 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 * Presence container modification strategy. In addition to {@link ContainerModificationStrategy} it also enforces
20 * presence of mandatory leaves.
22 final class PresenceContainerModificationStrategy extends ContainerModificationStrategy {
23 private final MandatoryLeafEnforcer enforcer;
25 PresenceContainerModificationStrategy(final ContainerSchemaNode schemaNode, final TreeType treeType) {
26 super(schemaNode, treeType);
27 enforcer = MandatoryLeafEnforcer.forContainer(schemaNode, treeType);
31 void verifyStructure(final NormalizedNode<?, ?> writtenValue, final boolean verifyChildren) {
32 if(verifyChildrenStructure() && verifyChildren) {
33 enforcer.enforceOnTreeNode(writtenValue);
35 super.verifyStructure(writtenValue, verifyChildren);
39 protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta, final Version version) {
40 final TreeNode ret = super.applyMerge(modification, currentMeta, version);
41 enforcer.enforceOnTreeNode(ret);
46 protected TreeNode applyWrite(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
47 final Version version) {
48 final TreeNode ret = super.applyWrite(modification, currentMeta, version);
49 enforcer.enforceOnTreeNode(ret);
54 protected TreeNode applyTouch(final ModifiedNode modification, final TreeNode currentMeta, final Version version) {
55 final TreeNode ret = super.applyTouch(modification, currentMeta, version);
56 enforcer.enforceOnTreeNode(ret);