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 com.google.common.collect.ImmutableList;
11 import com.google.common.collect.ImmutableList.Builder;
12 import java.util.Collection;
13 import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
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 IllegalArgumentCodec<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).body();
31 final IllegalArgumentCodec<Object, Object> codec = getValueCodec();
32 final Builder<Object> builder = ImmutableList.builderWithExpectedSize(domValues.size());
33 for (final LeafSetEntryNode<Object> valueNode : domValues) {
34 builder.add(codec.deserialize(valueNode.body()));
36 return builder.build();