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 com.google.common.base.Preconditions.checkArgument;
11 import com.google.common.base.Optional;
12 import com.google.common.collect.ImmutableMap;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
20 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
21 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
22 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
25 final class ChoiceModificationStrategy extends AbstractNodeContainerModificationStrategy {
26 private final Map<YangInstanceIdentifier.PathArgument, ModificationApplyOperation> childNodes;
28 ChoiceModificationStrategy(final ChoiceSchemaNode schemaNode, final TreeType treeType) {
29 super(ChoiceNode.class, treeType);
30 final ImmutableMap.Builder<YangInstanceIdentifier.PathArgument, ModificationApplyOperation> child = ImmutableMap.builder();
32 for (final ChoiceCaseNode caze : schemaNode.getCases()) {
33 if (SchemaAwareApplyOperation.belongsToTree(treeType,caze)) {
34 for (final DataSchemaNode cazeChild : caze.getChildNodes()) {
35 if (SchemaAwareApplyOperation.belongsToTree(treeType,cazeChild)) {
36 final ModificationApplyOperation childNode = SchemaAwareApplyOperation.from(cazeChild, treeType);
37 child.put(NodeIdentifier.create(cazeChild.getQName()), childNode);
42 childNodes = child.build();
46 public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument child) {
47 return Optional.fromNullable(childNodes.get(child));
51 @SuppressWarnings("rawtypes")
52 protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
53 checkArgument(original instanceof ChoiceNode);
54 return ImmutableChoiceNodeBuilder.create((ChoiceNode) original);