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.netconf.cli.writer.impl;
10 import com.google.common.base.Preconditions;
11 import java.util.Collections;
12 import org.opendaylight.netconf.cli.writer.OutFormatter;
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.impl.schema.transform.FromNormalizedNodeSerializer;
16 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
18 final class MapNodeCliSerializer implements FromNormalizedNodeSerializer<String, MapNode, ListSchemaNode> {
20 private final FromNormalizedNodeSerializer<String, MapEntryNode, ListSchemaNode> mapEntrySerializer;
21 private final OutFormatter out;
23 MapNodeCliSerializer(final OutFormatter out, final MapEntryNodeCliSerializer mapEntrySerializer) {
24 this.out = Preconditions.checkNotNull(out);
25 this.mapEntrySerializer = mapEntrySerializer;
29 public Iterable<String> serialize(final ListSchemaNode schema, final MapNode node) {
30 final StringBuilder output = new StringBuilder();
33 out.addStringWithIndent(output, node.getNodeType().getLocalName());
35 out.openComposite(output);
38 for (final MapEntryNode mapEntryNode : node.getValue()) {
39 final Iterable<String> valueFromLeafSetEntry = mapEntrySerializer.serialize(schema, mapEntryNode);
40 output.append(valueFromLeafSetEntry.iterator().next());
43 out.closeCompositeWithIndent(output);
46 return Collections.singletonList(output.toString());