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.GroupingDefinition;
12 import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
13 import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
14 import org.opendaylight.controller.yang.model.api.ListSchemaNode;
16 public class DataNodeIterator implements Iterator<DataSchemaNode> {
18 private final DataNodeContainer container;
19 private List<ListSchemaNode> allLists;
20 private List<ContainerSchemaNode> allContainers;
21 private List<LeafSchemaNode> allLeafs;
22 private List<LeafListSchemaNode> allLeafLists;
23 private List<DataSchemaNode> allChilds;
25 public DataNodeIterator(final DataNodeContainer container) {
26 if (container == null) {
27 throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!");
31 this.container = container;
32 traverse(this.container);
36 this.allContainers = new ArrayList<ContainerSchemaNode>();
37 this.allLists = new ArrayList<ListSchemaNode>();
38 this.allLeafs = new ArrayList<LeafSchemaNode>();
39 this.allLeafLists = new ArrayList<LeafListSchemaNode>();
40 this.allChilds = new ArrayList<DataSchemaNode>();
43 public List<ContainerSchemaNode> allContainers() {
47 public List<ListSchemaNode> allLists() {
51 public List<LeafSchemaNode> allLeafs() {
55 public List<LeafListSchemaNode> allLeafLists() {
59 private void traverse(final DataNodeContainer dataNode) {
60 if (dataNode == null) {
64 final Set<DataSchemaNode> childs = dataNode.getChildNodes();
66 for (DataSchemaNode childNode : childs) {
67 if (childNode.isAugmenting()) {
70 allChilds.add(childNode);
71 if (childNode instanceof ContainerSchemaNode) {
72 final ContainerSchemaNode container = (ContainerSchemaNode) childNode;
73 allContainers.add(container);
75 } else if (childNode instanceof ListSchemaNode) {
76 final ListSchemaNode list = (ListSchemaNode) childNode;
79 } else if (childNode instanceof LeafSchemaNode) {
80 final LeafSchemaNode leaf = (LeafSchemaNode) childNode;
82 } else if (childNode instanceof LeafListSchemaNode) {
83 final LeafListSchemaNode leafList = (LeafListSchemaNode) childNode;
84 allLeafLists.add(leafList);
89 final Set<GroupingDefinition> groupings = dataNode.getGroupings();
90 if(groupings != null) {
91 for(GroupingDefinition grouping : groupings) {
98 public boolean hasNext() {
99 if (container.getChildNodes() != null) {
100 Set<DataSchemaNode> childs = container.getChildNodes();
102 if ((childs != null) && !childs.isEmpty()) {
103 return childs.iterator().hasNext();
110 public DataSchemaNode next() {
111 return allChilds.iterator().next();
115 public void remove() {
116 throw new UnsupportedOperationException();