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 java.util.Collections;
11 import org.opendaylight.netconf.cli.writer.OutFormatter;
12 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
13 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
14 import org.opendaylight.yangtools.yang.data.impl.schema.transform.FromNormalizedNodeSerializer;
15 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
17 final class LeafSetNodeCliSerializer implements
18 FromNormalizedNodeSerializer<String, LeafSetNode<?>, LeafListSchemaNode> {
19 private final LeafSetEntryNodeCliSerializer leafSetEntryNodeSerializer;
20 private final OutFormatter out;
22 LeafSetNodeCliSerializer(final OutFormatter out, final LeafSetEntryNodeCliSerializer leafSetEntryNodeSerializer) {
24 this.leafSetEntryNodeSerializer = leafSetEntryNodeSerializer;
28 public Iterable<String> serialize(final LeafListSchemaNode schema, final LeafSetNode<?> node) {
29 final StringBuilder output = new StringBuilder();
31 out.addStringWithIndent(output, node.getNodeType().getLocalName());
32 out.openComposite(output);
34 for (final LeafSetEntryNode<?> leafEntryNode : node.getValue()) {
35 final Iterable<String> valueFromLeafSetEntry = leafSetEntryNodeSerializer.serialize(schema, leafEntryNode);
36 output.append(valueFromLeafSetEntry.iterator().next());
39 out.closeCompositeWithIndent(output);
41 return Collections.singletonList(output.toString());