Remove netconf from commons/opendaylight pom
[controller.git] / opendaylight / netconf / tools / netconf-cli / src / main / java / org / opendaylight / controller / netconf / cli / writer / impl / LeafSetNodeCliSerializer.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.netconf.cli.writer.impl;
9
10 import java.util.Collections;
11 import org.opendaylight.controller.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;
16
17 final class LeafSetNodeCliSerializer implements
18         FromNormalizedNodeSerializer<String, LeafSetNode<?>, LeafListSchemaNode> {
19     private final LeafSetEntryNodeCliSerializer leafSetEntryNodeSerializer;
20     private final OutFormatter out;
21
22     LeafSetNodeCliSerializer(final OutFormatter out, final LeafSetEntryNodeCliSerializer leafSetEntryNodeSerializer) {
23         this.out = out;
24         this.leafSetEntryNodeSerializer = leafSetEntryNodeSerializer;
25     }
26
27     @Override
28     public Iterable<String> serialize(final LeafListSchemaNode schema, final LeafSetNode<?> node) {
29         final StringBuilder output = new StringBuilder();
30         out.increaseIndent();
31         out.addStringWithIndent(output, node.getNodeType().getLocalName());
32         out.openComposite(output);
33         out.newLine(output);
34         for (final LeafSetEntryNode<?> leafEntryNode : node.getValue()) {
35             final Iterable<String> valueFromLeafSetEntry = leafSetEntryNodeSerializer.serialize(schema, leafEntryNode);
36             output.append(valueFromLeafSetEntry.iterator().next());
37             out.newLine(output);
38         }
39         out.closeCompositeWithIndent(output);
40         out.decreaseIndent();
41         return Collections.singletonList(output.toString());
42     }
43 }