2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.Collection;
12 import java.util.List;
13 import org.opendaylight.yangtools.concepts.Codec;
14 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
19 final class LeafSetNodeCodecContext extends ValueNodeCodecContext.WithCodec {
20 LeafSetNodeCodecContext(final LeafListSchemaNode schema, final Codec<Object, Object> codec,
21 final String getterName) {
22 // FIXME: add support for defaults
23 super(schema, codec, getterName, null);
27 protected Object deserializeObject(final NormalizedNode<?, ?> normalizedNode) {
28 if (normalizedNode instanceof LeafSetNode<?>) {
29 @SuppressWarnings("unchecked")
30 final Collection<LeafSetEntryNode<Object>> domValues = ((LeafSetNode<Object>) normalizedNode).getValue();
31 final List<Object> result = new ArrayList<>(domValues.size());
32 for (final LeafSetEntryNode<Object> valueNode : domValues) {
33 result.add(getValueCodec().deserialize(valueNode.getValue()));