2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.yangtools.yang.model.util;
\r
10 import java.util.ArrayList;
\r
11 import java.util.Iterator;
\r
12 import java.util.List;
\r
13 import java.util.Set;
\r
15 import org.opendaylight.yangtools.yang.model.api.*;
\r
17 public class DataNodeIterator implements Iterator<DataSchemaNode> {
\r
19 private final DataNodeContainer container;
\r
20 private final List<ListSchemaNode> allLists;
\r
21 private final List<ContainerSchemaNode> allContainers;
\r
22 private final List<ChoiceNode> allChoices;
\r
23 private final List<DataSchemaNode> allChilds;
\r
25 public DataNodeIterator(final DataNodeContainer container) {
\r
26 if (container == null) {
\r
27 throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!");
\r
30 this.allContainers = new ArrayList<>();
\r
31 this.allLists = new ArrayList<>();
\r
32 this.allChilds = new ArrayList<>();
\r
33 this.allChoices = new ArrayList<>();
\r
35 this.container = container;
\r
36 traverse(this.container);
\r
39 public List<ContainerSchemaNode> allContainers() {
\r
40 return allContainers;
\r
43 public List<ListSchemaNode> allLists() {
\r
47 public List<ChoiceNode> allChoices() {
\r
51 private void traverse(final DataNodeContainer dataNode) {
\r
52 if (dataNode == null) {
\r
56 final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();
\r
57 if (childNodes != null) {
\r
58 for (DataSchemaNode childNode : childNodes) {
\r
59 if (childNode.isAugmenting()) {
\r
62 allChilds.add(childNode);
\r
63 if (childNode instanceof ContainerSchemaNode) {
\r
64 final ContainerSchemaNode container = (ContainerSchemaNode) childNode;
\r
65 allContainers.add(container);
\r
66 traverse(container);
\r
67 } else if (childNode instanceof ListSchemaNode) {
\r
68 final ListSchemaNode list = (ListSchemaNode) childNode;
\r
71 } else if (childNode instanceof ChoiceNode) {
\r
72 final ChoiceNode choiceNode = (ChoiceNode) childNode;
\r
73 allChoices.add(choiceNode);
\r
74 final Set<ChoiceCaseNode> cases = choiceNode.getCases();
\r
75 if (cases != null) {
\r
76 for (final ChoiceCaseNode caseNode : cases) {
\r
84 if(dataNode instanceof Module) {
\r
85 traverseModule((Module)dataNode);
\r
88 final Set<GroupingDefinition> groupings = dataNode.getGroupings();
\r
89 if (groupings != null) {
\r
90 for (GroupingDefinition grouping : groupings) {
\r
97 private void traverseModule(Module module) {
\r
98 final Set<NotificationDefinition> notifications = module.getNotifications();
\r
99 for (NotificationDefinition notificationDefinition : notifications) {
\r
100 traverse(notificationDefinition);
\r
102 final Set<RpcDefinition> rpcs = module.getRpcs();
\r
103 for (RpcDefinition rpcDefinition : rpcs) {
\r
104 ContainerSchemaNode input = rpcDefinition.getInput();
\r
105 if(input != null) {
\r
108 ContainerSchemaNode output = rpcDefinition.getInput();
\r
109 if(input != null) {
\r
116 public boolean hasNext() {
\r
117 if (container.getChildNodes() != null) {
\r
118 final Set<DataSchemaNode> childNodes = container.getChildNodes();
\r
120 if ((childNodes != null) && !childNodes.isEmpty()) {
\r
121 return childNodes.iterator().hasNext();
\r
128 public DataSchemaNode next() {
\r
129 return allChilds.iterator().next();
\r
133 public void remove() {
\r
134 throw new UnsupportedOperationException();
\r