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.impl;
10 import java.util.ArrayList;
11 import java.util.List;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
16 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
17 import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
18 import org.opendaylight.yangtools.yang.data.api.Node;
19 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
22 * @author michal.rehak
25 public class CompositeNodeTOImpl extends AbstractNodeTO<List<Node<?>>> implements CompositeNode {
27 private Map<QName, List<Node<?>>> nodeMap;
32 * use null to create top composite node (without parent)
35 public CompositeNodeTOImpl(QName qname, CompositeNode parent, List<Node<?>> value) {
36 super(qname, parent, value);
38 nodeMap = NodeUtils.buildNodeMap(getValue());
46 * use null to create top composite node (without parent)
50 public CompositeNodeTOImpl(QName qname, CompositeNode parent, List<Node<?>> value, ModifyAction modifyAction) {
51 super(qname, parent, value, modifyAction);
58 protected Map<QName, List<Node<?>>> getNodeMap() {
63 public List<Node<?>> getChildren() {
68 public SimpleNode<?> getFirstSimpleByName(QName leafQName) {
69 List<SimpleNode<?>> list = getSimpleNodesByName(leafQName);
77 public List<CompositeNode> getCompositesByName(QName children) {
78 List<Node<?>> toFilter = getNodeMap().get(children);
79 List<CompositeNode> list = new ArrayList<CompositeNode>();
80 for (Node<?> node : toFilter) {
81 if (node instanceof CompositeNode) {
82 list.add((CompositeNode) node);
89 public List<SimpleNode<?>> getSimpleNodesByName(QName children) {
90 List<Node<?>> toFilter = getNodeMap().get(children);
91 List<SimpleNode<?>> list = new ArrayList<SimpleNode<?>>();
93 for (Node<?> node : toFilter) {
94 if (node instanceof SimpleNode<?>)
95 list.add((SimpleNode<?>) node);
101 public CompositeNode getFirstCompositeByName(QName container) {
102 List<CompositeNode> list = getCompositesByName(container);
103 if (list.isEmpty()) {
111 * @return TODO:: do we need this method?
113 public SimpleNode<?> getFirstLeafByName(QName leaf) {
114 List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
115 if (list.isEmpty()) {
122 public List<CompositeNode> getCompositesByName(String children) {
123 return getCompositesByName(new QName(getNodeType(), children));
127 public List<SimpleNode<?>> getSimpleNodesByName(String children) {
128 return getSimpleNodesByName(new QName(getNodeType(), children));
134 protected void init() {
135 if (getValue() != null) {
136 nodeMap = NodeUtils.buildNodeMap(getValue());
141 public MutableCompositeNode asMutable() {
142 throw new IllegalAccessError("cast to mutable is not supported - " + getClass().getSimpleName());
146 public String toString() {
147 return super.toString() + ", children.size = " + (getChildren() != null ? getChildren().size() : "n/a");