2 * Copyright (c) 2014 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.binding.data.codec.impl;
10 import com.google.common.collect.Iterables;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.yangtools.yang.binding.DataObject;
14 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
19 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
21 class ListNodeCodecContext extends DataObjectCodecContext<ListSchemaNode> {
22 protected ListNodeCodecContext(final DataContainerCodecPrototype<ListSchemaNode> prototype) {
27 protected Object dataFromNormalizedNode(final NormalizedNode<?, ?> node) {
28 if (node instanceof MapNode) {
29 return fromMap((MapNode) node);
30 } else if (node instanceof MapEntryNode) {
31 return fromMapEntry((MapEntryNode) node);
32 } else if (node instanceof UnkeyedListNode) {
33 return fromUnkeyedList((UnkeyedListNode) node);
34 } else if (node instanceof UnkeyedListEntryNode) {
35 return fromUnkeyedListEntry((UnkeyedListEntryNode) node);
37 throw new IllegalStateException("Unsupported data type " + node.getClass());
41 private List<DataObject> fromMap(final MapNode nodes) {
42 List<DataObject> ret = new ArrayList<>(Iterables.size(nodes.getValue()));
43 for(MapEntryNode node : nodes.getValue()) {
44 ret.add(fromMapEntry(node));
49 private DataObject fromMapEntry(final MapEntryNode node) {
50 return createBindingProxy(node);
53 private DataObject fromUnkeyedListEntry(final UnkeyedListEntryNode node) {
54 return createBindingProxy(node);
57 private List<DataObject> fromUnkeyedList(final UnkeyedListNode nodes) {
58 // FIXME: Could be this lazy transformed list?
59 List<DataObject> ret = new ArrayList<>(Iterables.size(nodes.getValue()));
60 for (UnkeyedListEntryNode node : nodes.getValue()) {
61 ret.add(fromUnkeyedListEntry(node));