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.yangtools.yang.data.util;
10 import java.util.ArrayList;
11 import java.util.Collection;
12 import java.util.List;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
17 import org.opendaylight.yangtools.yang.data.api.Node;
18 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
22 * @deprecated Use one of the {@link NormalizedNodeContainer} implementation packages.
25 public abstract class AbstractContainerNode extends AbstractNode<List<Node<?>>> implements CompositeNode {
28 public SimpleNode<?> getFirstSimpleByName(final QName leaf) {
29 List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
30 if (list.size() == 0) {
36 protected AbstractContainerNode(final QName name, final CompositeNode parent) {
40 public AbstractContainerNode(final QName name) {
45 public List<Node<?>> getChildren() {
50 public List<Node<?>> getValue() {
51 Map<QName, List<Node<?>>> map = getNodeMap();
53 throw new IllegalStateException("nodeMap should not be null");
55 List<Node<?>> ret = new ArrayList<Node<?>>();
56 Collection<List<Node<?>>> values = map.values();
57 for (List<Node<?>> list : values) {
63 protected abstract Map<QName, List<Node<?>>> getNodeMap();
66 public List<CompositeNode> getCompositesByName(final QName children) {
67 Map<QName, List<Node<?>>> map = getNodeMap();
69 throw new IllegalStateException("nodeMap should not be null");
71 List<Node<?>> toFilter = map.get(children);
72 List<CompositeNode> list = new ArrayList<CompositeNode>();
73 for (Node<?> node : toFilter) {
74 if (node instanceof CompositeNode) {
75 list.add((CompositeNode) node);
82 public List<SimpleNode<?>> getSimpleNodesByName(final QName children) {
83 Map<QName, List<Node<?>>> map = getNodeMap();
85 throw new IllegalStateException("nodeMap should not be null");
87 List<Node<?>> toFilter = map.get(children);
88 List<SimpleNode<?>> list = new ArrayList<SimpleNode<?>>();
90 for (Node<?> node : toFilter) {
91 if (node instanceof SimpleNode<?>) {
92 list.add((SimpleNode<?>) node);
99 public CompositeNode getFirstCompositeByName(final QName container) {
100 List<CompositeNode> list = getCompositesByName(container);
101 if (list.size() == 0) {
107 public SimpleNode<?> getFirstLeafByName(final QName leaf) {
108 List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
109 if (list.size() == 0) {
116 public List<CompositeNode> getCompositesByName(final String children) {
117 return getCompositesByName(localQName(children));
121 public List<SimpleNode<?>> getSimpleNodesByName(final String children) {
122 return getSimpleNodesByName(localQName(children));
125 private QName localQName(final String str) {
126 return QName.create(getNodeType(), str);