Calculate replicated log data size on recovery
[controller.git] / opendaylight / netconf / netconf-cli / src / main / java / org / opendaylight / controller / netconf / cli / writer / impl / CompositeNodeWriter.java
1 /*
2  * Copyright (c) 2014 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.io.IOException;
11 import java.util.List;
12 import org.opendaylight.controller.netconf.cli.io.ConsoleIO;
13 import org.opendaylight.controller.netconf.cli.writer.OutFormatter;
14 import org.opendaylight.controller.netconf.cli.writer.WriteException;
15 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
16 import org.opendaylight.yangtools.yang.data.api.Node;
17 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
19
20 public class CompositeNodeWriter extends AbstractWriter<DataSchemaNode> {
21
22     private final OutFormatter outFormatter;
23
24     public CompositeNodeWriter(final ConsoleIO console, final OutFormatter outFormatter) {
25         super(console);
26         this.outFormatter = outFormatter;
27     }
28
29     @Override
30     protected void writeInner(final DataSchemaNode dataSchemaNode, final List<Node<?>> dataNodes) throws IOException, WriteException {
31         final StringBuilder output = new StringBuilder();
32         writeNode(dataNodes, output);
33         console.writeLn(output);
34     }
35
36     private void writeNode(final List<Node<?>> dataNodes, final StringBuilder output) throws IOException, WriteException {
37         for (final Node<?> dataNode : dataNodes) {
38             outFormatter.increaseIndent();
39             outFormatter.addStringWithIndent(output, dataNode.getNodeType().getLocalName());
40             if (dataNode instanceof CompositeNode) {
41                 outFormatter.openComposite(output);
42                 outFormatter.newLine(output);
43                 writeNode(((CompositeNode) dataNode).getValue(), output);
44                 outFormatter.closeCompositeWithIndent(output);
45                 outFormatter.newLine(output);
46             } else if (dataNode instanceof SimpleNode<?>) {
47                 final SimpleNode<?> simpleNode = (SimpleNode<?>) dataNode;
48                 output.append(" ");
49                 output.append(simpleNode.getValue());
50                 outFormatter.newLine(output);
51             }
52             outFormatter.decreaseIndent();
53         }
54     }
55 }