2 * Copyright (c) 2013 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.transform.base.parser;
10 import com.google.common.collect.Sets;
11 import java.util.LinkedHashMap;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
17 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
18 import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
20 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
21 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
22 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
23 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
27 * Abstract(base) parser for ChoiceNodes, parses elements of type E.
29 * @param <E> type of elements to be parsed
31 public abstract class ChoiceNodeBaseParser<E> extends BaseDispatcherParser<E, ChoiceNode, ChoiceSchemaNode> {
34 protected final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ChoiceNode> getBuilder(
35 final ChoiceSchemaNode schema) {
36 return Builders.choiceBuilder(schema);
40 protected final Set<DataSchemaNode> getRealSchemasForAugment(final ChoiceSchemaNode schema, final AugmentationSchema augmentSchema) {
41 Set<DataSchemaNode> fromAllCases = Sets.newHashSet();
43 fromAllCases.addAll(SchemaUtils.getRealSchemasForAugment(schema, augmentSchema));
45 for (ChoiceCaseNode choiceCaseNode : schema.getCases()) {
46 fromAllCases.addAll(SchemaUtils.getRealSchemasForAugment((AugmentationTarget) choiceCaseNode, augmentSchema));
53 protected final DataSchemaNode getSchemaForChild(final ChoiceSchemaNode schema,
54 final QName childQName) {
55 return SchemaUtils.findSchemaForChild(schema, childQName);
59 protected final Map<QName, ChoiceSchemaNode> mapChildElementsFromChoices(final ChoiceSchemaNode schema) {
60 Map<QName, ChoiceSchemaNode> mappedChoices = new LinkedHashMap<>();
62 for (ChoiceCaseNode choiceCaseNode : schema.getCases()) {
63 mappedChoices.putAll(SchemaUtils.mapChildElementsFromChoices(choiceCaseNode));
70 protected final Map<QName, AugmentationSchema> mapChildElementsFromAugments(final ChoiceSchemaNode schema) {
71 Map<QName, AugmentationSchema> mappedAugments = new LinkedHashMap<>();
73 for (ChoiceCaseNode choiceCaseNode : schema.getCases()) {
74 mappedAugments.putAll(SchemaUtils.mapChildElementsFromAugments(choiceCaseNode));
76 return mappedAugments;