Merge "BUG-1041 cli proposal #1"
[controller.git] / opendaylight / netconf / netconf-cli / src / main / java / org / opendaylight / controller / netconf / cli / writer / impl / LeafNodeCliSerializer.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 com.google.common.base.Preconditions;
11 import org.opendaylight.controller.netconf.cli.writer.OutFormatter;
12 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
13 import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.LeafNodeBaseSerializer;
14 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
15
16 final class LeafNodeCliSerializer extends LeafNodeBaseSerializer<String> {
17     private final OutFormatter out;
18
19     LeafNodeCliSerializer(final OutFormatter out) {
20         this.out = Preconditions.checkNotNull(out);
21     }
22
23     @Override
24     public String serializeLeaf(final LeafSchemaNode schema, final LeafNode<?> node) {
25         final StringBuilder output = new StringBuilder();
26         out.increaseIndent();
27         out.addStringWithIndent(output, node.getNodeType().getLocalName());
28         output.append(" ");
29         output.append(node.getValue());
30         out.decreaseIndent();
31         return output.toString();
32     }
33 }