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.schema.ChoiceNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
19 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
20 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
23 final class ChoiceModificationStrategy extends AbstractNodeContainerModificationStrategy {
24 private final Map<YangInstanceIdentifier.PathArgument, ModificationApplyOperation> childNodes;
26 ChoiceModificationStrategy(final ChoiceSchemaNode schemaNode) {
27 super(ChoiceNode.class);
28 ImmutableMap.Builder<YangInstanceIdentifier.PathArgument, ModificationApplyOperation> child = ImmutableMap.builder();
30 for (ChoiceCaseNode caze : schemaNode.getCases()) {
31 for (DataSchemaNode cazeChild : caze.getChildNodes()) {
32 SchemaAwareApplyOperation childNode = SchemaAwareApplyOperation.from(cazeChild);
33 child.put(new YangInstanceIdentifier.NodeIdentifier(cazeChild.getQName()), childNode);
36 childNodes = child.build();
40 public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument child) {
41 return Optional.fromNullable(childNodes.get(child));
45 @SuppressWarnings("rawtypes")
46 protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
47 checkArgument(original instanceof ChoiceNode);
48 return ImmutableChoiceNodeBuilder.create((ChoiceNode) original);