2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.yang.data.util;
10 import java.util.ArrayList;
11 import java.util.Collection;
12 import java.util.List;
15 import org.opendaylight.controller.yang.common.QName;
16 import org.opendaylight.controller.yang.data.api.CompositeNode;
17 import org.opendaylight.controller.yang.data.api.Node;
18 import org.opendaylight.controller.yang.data.api.SimpleNode;
20 public abstract class AbstractContainerNode extends AbstractNode<List<Node<?>>>
21 implements CompositeNode {
23 public SimpleNode<?> getFirstSimpleByName(QName leaf) {
24 List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
30 protected AbstractContainerNode(QName name, CompositeNode parent) {
34 public AbstractContainerNode(QName name) {
38 public List<Node<?>> getChildren() {
42 public List<Node<?>> getValue() {
43 Map<QName, List<Node<?>>> map = getNodeMap();
45 throw new IllegalStateException("nodeMap should not be null");
46 List<Node<?>> ret = new ArrayList<Node<?>>();
47 Collection<List<Node<?>>> values = map.values();
48 for (List<Node<?>> list : values) {
54 protected abstract Map<QName, List<Node<?>>> getNodeMap();
56 public List<CompositeNode> getCompositesByName(QName children) {
57 Map<QName, List<Node<?>>> map = getNodeMap();
59 throw new IllegalStateException("nodeMap should not be null");
60 List<Node<?>> toFilter = map.get(children);
61 List<CompositeNode> list = new ArrayList<CompositeNode>();
62 for (Node<?> node : toFilter) {
63 if (node instanceof CompositeNode)
64 list.add((CompositeNode) node);
69 public List<SimpleNode<?>> getSimpleNodesByName(QName children) {
70 Map<QName, List<Node<?>>> map = getNodeMap();
72 throw new IllegalStateException("nodeMap should not be null");
73 List<Node<?>> toFilter = map.get(children);
74 List<SimpleNode<?>> list = new ArrayList<SimpleNode<?>>();
76 for (Node<?> node : toFilter) {
77 if (node instanceof SimpleNode<?>)
78 list.add((SimpleNode<?>) node);
83 public CompositeNode getFirstCompositeByName(QName container) {
84 List<CompositeNode> list = getCompositesByName(container);
90 public SimpleNode<?> getFirstLeafByName(QName leaf) {
91 List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
97 public List<CompositeNode> getCompositesByName(String children) {
98 return getCompositesByName(localQName(children));
101 public List<SimpleNode<?>> getSimpleNodesByName(String children) {
102 return getSimpleNodesByName(localQName(children));
105 private QName localQName(String str) {
106 return new QName(getNodeType(), str);