/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.sal.binding.yang.types; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; final class TypedefResolver { private TypedefResolver() { throw new UnsupportedOperationException(); } static List> getAllTypedefs(final Module module) { final List> ret = new ArrayList<>(); fillRecursively(ret, module); final Set notifications = module.getNotifications(); for (NotificationDefinition notificationDefinition : notifications) { fillRecursively(ret, notificationDefinition); } final Set rpcs = module.getRpcs(); for (RpcDefinition rpcDefinition : rpcs) { ret.addAll(rpcDefinition.getTypeDefinitions()); ContainerSchemaNode input = rpcDefinition.getInput(); if (input != null) { fillRecursively(ret, input); } ContainerSchemaNode output = rpcDefinition.getOutput(); if (output != null) { fillRecursively(ret, output); } } return ret; } private static void fillRecursively(final List> list, final DataNodeContainer container) { final Collection childNodes = container.getChildNodes(); if (childNodes != null) { for (DataSchemaNode childNode : childNodes) { if (!childNode.isAugmenting()) { if (childNode instanceof ContainerSchemaNode) { fillRecursively(list, (ContainerSchemaNode) childNode); } else if (childNode instanceof ListSchemaNode) { fillRecursively(list, (ListSchemaNode) childNode); } else if (childNode instanceof ChoiceSchemaNode) { final Set cases = ((ChoiceSchemaNode) childNode).getCases(); if (cases != null) { for (final ChoiceCaseNode caseNode : cases) { fillRecursively(list, caseNode); } } } } } } list.addAll(container.getTypeDefinitions()); final Set groupings = container.getGroupings(); if (groupings != null) { for (GroupingDefinition grouping : groupings) { fillRecursively(list, grouping); } } } }