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 if (childNode.isAugmenting()) {
67 allChilds.add(childNode);
68 if (childNode instanceof ContainerSchemaNode) {
69 final ContainerSchemaNode container = (ContainerSchemaNode) childNode;
70 allContainers.add(container);
72 } else if (childNode instanceof ListSchemaNode) {
73 final ListSchemaNode list = (ListSchemaNode) childNode;
76 } else if (childNode instanceof LeafSchemaNode) {
77 final LeafSchemaNode leaf = (LeafSchemaNode) childNode;
79 } else if (childNode instanceof LeafListSchemaNode) {
80 final LeafListSchemaNode leafList = (LeafListSchemaNode) childNode;
81 allLeafLists.add(leafList);
88 * Returns <code>true</code> if and only if the child node contain at least
89 * one child container schema node or child list schema node, otherwise will
90 * always returns <code>false</code>
93 * @return <code>true</code> if and only if the child node contain at least
94 * one child container schema node or child list schema node,
95 * otherwise will always returns <code>false</code>
97 private boolean containChildDataNodeContainer(
98 final DataNodeContainer container) {
99 if (container != null) {
100 final Set<DataSchemaNode> childs = container.getChildNodes();
101 if ((childs != null) && (childs.size() > 0)) {
102 for (final DataSchemaNode childNode : childs) {
103 if (childNode instanceof DataNodeContainer) {
113 public boolean hasNext() {
114 if (container.getChildNodes() != null) {
115 Set<DataSchemaNode> childs = container.getChildNodes();
117 if ((childs != null) && !childs.isEmpty()) {
118 return childs.iterator().hasNext();
125 public DataSchemaNode next() {
126 return allChilds.iterator().next();
130 public void remove() {
131 throw new UnsupportedOperationException();