Merge changes I114cbac1,I45c2e7cd
[controller.git] / opendaylight / netconf / netconf-cli / src / main / java / org / opendaylight / controller / netconf / cli / writer / impl / AbstractWriter.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.WriteException;
14 import org.opendaylight.controller.netconf.cli.writer.Writer;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
17
18 public abstract class AbstractWriter<T extends DataSchemaNode> implements Writer<T> {
19
20     protected ConsoleIO console;
21
22     public AbstractWriter(final ConsoleIO console) {
23         this.console = console;
24     }
25
26     @Override
27     public void write(final T dataSchemaNode, final List<NormalizedNode<?, ?>> dataNodes) throws WriteException {
28         try {
29             writeInner(dataSchemaNode, dataNodes);
30         } catch (final IOException e) {
31             throw new WriteException("Unable to write data to output for " + dataSchemaNode.getQName(), e);
32         }
33     }
34
35     protected abstract void writeInner(final T dataSchemaNode, final List<NormalizedNode<?, ?>> dataNodes) throws IOException,
36             WriteException;
37 }