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.mdsal.binding.dom.codec.impl;
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.opendaylight.yangtools.yang.binding.DataObject;
13 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
18 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
20 class ListNodeCodecContext<D extends DataObject> extends DataObjectCodecContext<D,ListSchemaNode> {
21 protected ListNodeCodecContext(final DataContainerCodecPrototype<ListSchemaNode> prototype) {
26 public D deserialize(final NormalizedNode<?, ?> node) {
27 if (node instanceof MapEntryNode) {
28 return fromMapEntry((MapEntryNode) node);
29 } else if (node instanceof UnkeyedListEntryNode) {
30 return fromUnkeyedListEntry((UnkeyedListEntryNode) node);
32 throw new IllegalStateException("Unsupported data type " + node.getClass());
37 protected Object deserializeObject(final NormalizedNode<?, ?> node) {
38 if (node instanceof MapNode) {
39 return fromMap((MapNode) node);
40 } else if (node instanceof MapEntryNode) {
41 return fromMapEntry((MapEntryNode) node);
42 } else if (node instanceof UnkeyedListNode) {
43 return fromUnkeyedList((UnkeyedListNode) node);
44 } else if (node instanceof UnkeyedListEntryNode) {
45 return fromUnkeyedListEntry((UnkeyedListEntryNode) node);
47 throw new IllegalStateException("Unsupported data type " + node.getClass());
51 private List<D> fromMap(final MapNode nodes) {
52 List<D> ret = new ArrayList<>(nodes.getValue().size());
53 for (MapEntryNode node : nodes.getValue()) {
54 ret.add(fromMapEntry(node));
59 private D fromMapEntry(final MapEntryNode node) {
60 return createBindingProxy(node);
63 private D fromUnkeyedListEntry(final UnkeyedListEntryNode node) {
64 return createBindingProxy(node);
67 private List<D> fromUnkeyedList(final UnkeyedListNode nodes) {
68 // FIXME: Could be this lazy transformed list?
69 List<D> ret = new ArrayList<>(nodes.getValue().size());
70 for (UnkeyedListEntryNode node : nodes.getValue()) {
71 ret.add(fromUnkeyedListEntry(node));