2 * Copyright (c) 2014 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.controller.netconf.cli.writer.impl;
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;
20 public class CompositeNodeWriter extends AbstractWriter<DataSchemaNode> {
22 private final OutFormatter outFormatter;
24 public CompositeNodeWriter(final ConsoleIO console, final OutFormatter outFormatter) {
26 this.outFormatter = outFormatter;
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);
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;
49 output.append(simpleNode.getValue());
50 outFormatter.newLine(output);
52 outFormatter.decreaseIndent();