1 package org.opendaylight.controller.yang.model.util;
3 import java.util.ArrayList;
4 import java.util.Iterator;
8 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
9 import org.opendaylight.controller.yang.model.api.DataNodeContainer;
10 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
11 import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
12 import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
13 import org.opendaylight.controller.yang.model.api.ListSchemaNode;
15 public class DataNodeIterator implements Iterator<DataSchemaNode> {
17 private final DataNodeContainer container;
18 private final List<ListSchemaNode> allLists;
19 private final List<ContainerSchemaNode> allContainers;
20 private final List<LeafSchemaNode> allLeafs;
21 private final List<LeafListSchemaNode> allLeafLists;
22 private final List<DataSchemaNode> allChilds;
24 public DataNodeIterator(final DataNodeContainer container) {
25 if (container == null) {
26 throw new IllegalArgumentException("Data Node Container MUST be specified!");
29 this.allContainers = new ArrayList<ContainerSchemaNode>();
30 this.allLists = new ArrayList<ListSchemaNode>();
31 this.allLeafs = new ArrayList<LeafSchemaNode>();
32 this.allLeafLists = new ArrayList<LeafListSchemaNode>();
33 this.allChilds = new ArrayList<DataSchemaNode>();
35 this.container = container;
37 traverse(this.container);
40 public List<ContainerSchemaNode> allContainers() {
44 public List<ListSchemaNode> allLists() {
48 public List<LeafSchemaNode> allLeafs() {
52 public List<LeafListSchemaNode> allLeafLists() {
56 private void traverse(final DataNodeContainer dataNode) {
57 if (!containChildDataNodeContainer(dataNode)) {
61 final Set<DataSchemaNode> childs = dataNode.getChildNodes();
63 for (DataSchemaNode childNode : childs) {
64 allChilds.add(childNode);
65 if (childNode instanceof ContainerSchemaNode) {
66 final ContainerSchemaNode container = (ContainerSchemaNode) childNode;
67 allContainers.add(container);
69 } else if (childNode instanceof ListSchemaNode) {
70 final ListSchemaNode list = (ListSchemaNode) childNode;
73 } else if (childNode instanceof LeafSchemaNode) {
74 final LeafSchemaNode leaf = (LeafSchemaNode) childNode;
76 } else if (childNode instanceof LeafListSchemaNode) {
77 final LeafListSchemaNode leafList = (LeafListSchemaNode) childNode;
78 allLeafLists.add(leafList);
85 * Returns <code>true</code> if and only if the child node contain at least
86 * one child container schema node or child list schema node, otherwise will
87 * always returns <code>false</code>
90 * @return <code>true</code> if and only if the child node contain at least
91 * one child container schema node or child list schema node,
92 * otherwise will always returns <code>false</code>
94 private boolean containChildDataNodeContainer(
95 final DataNodeContainer container) {
96 if (container != null) {
97 final Set<DataSchemaNode> childs = container.getChildNodes();
98 if ((childs != null) && (childs.size() > 0)) {
99 for (final DataSchemaNode childNode : childs) {
100 if (childNode instanceof DataNodeContainer) {
110 public boolean hasNext() {
111 if (container.getChildNodes() != null) {
112 Set<DataSchemaNode> childs = container.getChildNodes();
114 if ((childs != null) && !childs.isEmpty()) {
115 return childs.iterator().hasNext();
122 public DataSchemaNode next() {
123 return allChilds.iterator().next();
127 public void remove() {
128 throw new UnsupportedOperationException();