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 com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableMap;
12 import com.google.common.collect.ImmutableMap.Builder;
14 import java.util.Map.Entry;
16 import org.opendaylight.yangtools.concepts.Immutable;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
20 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
23 final class CaseEnforcer implements Immutable {
24 private final Map<NodeIdentifier, DataSchemaNode> children;
25 private final MandatoryLeafEnforcer enforcer;
27 private CaseEnforcer(final Map<NodeIdentifier, DataSchemaNode> children, final MandatoryLeafEnforcer enforcer) {
28 this.children = Preconditions.checkNotNull(children);
29 this.enforcer = Preconditions.checkNotNull(enforcer);
32 static CaseEnforcer forTree(final ChoiceCaseNode schema, final TreeType type) {
33 final Builder<NodeIdentifier, DataSchemaNode> builder = ImmutableMap.builder();
34 if (SchemaAwareApplyOperation.belongsToTree(type, schema)) {
35 for (DataSchemaNode child : schema.getChildNodes()) {
36 if (SchemaAwareApplyOperation.belongsToTree(type, child)) {
37 builder.put(NodeIdentifier.create(child.getQName()), child);
42 final Map<NodeIdentifier, DataSchemaNode> children = builder.build();
43 return children.isEmpty() ? null : new CaseEnforcer(children, MandatoryLeafEnforcer.forContainer(schema, type));
46 Set<Entry<NodeIdentifier, DataSchemaNode>> getChildEntries() {
47 return children.entrySet();
50 Set<NodeIdentifier> getChildIdentifiers() {
51 return children.keySet();
54 void enforceOnTreeNode(final NormalizedNode<?, ?> normalizedNode) {
55 enforcer.enforceOnTreeNode(normalizedNode);