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.mdsal.binding.yang.types;
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
13 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
16 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
18 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
21 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
22 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
24 final class TypedefResolver {
25 private TypedefResolver() {
29 static List<TypeDefinition<?>> getAllTypedefs(final Module module) {
30 final List<TypeDefinition<?>> ret = new ArrayList<>();
32 fillRecursively(ret, module);
34 for (NotificationDefinition notificationDefinition : module.getNotifications()) {
35 fillRecursively(ret, notificationDefinition);
38 for (RpcDefinition rpcDefinition : module.getRpcs()) {
39 ret.addAll(rpcDefinition.getTypeDefinitions());
40 fillRecursively(ret, rpcDefinition.getInput());
41 fillRecursively(ret, rpcDefinition.getOutput());
47 private static void fillRecursively(final List<TypeDefinition<?>> list, final DataNodeContainer container) {
48 for (DataSchemaNode childNode : container.getChildNodes()) {
49 if (!childNode.isAugmenting()) {
50 if (childNode instanceof ContainerSchemaNode) {
51 fillRecursively(list, (ContainerSchemaNode) childNode);
52 } else if (childNode instanceof ListSchemaNode) {
53 fillRecursively(list, (ListSchemaNode) childNode);
54 } else if (childNode instanceof ChoiceSchemaNode) {
55 for (CaseSchemaNode caseNode : ((ChoiceSchemaNode) childNode).getCases()) {
56 fillRecursively(list, caseNode);
62 list.addAll(container.getTypeDefinitions());
64 for (GroupingDefinition grouping : container.getGroupings()) {
65 fillRecursively(list, grouping);