aaa1ccc79ae81467c6e38bbf18e9f433db8b1c43
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / rest / impl / RestconfDelegatingNormalizedNodeWriter.java
1 /*
2  * Copyright (c) 2015 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.netconf.sal.rest.impl;
9
10 import java.io.IOException;
11 import org.opendaylight.netconf.sal.rest.api.RestconfNormalizedNodeWriter;
12 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
13 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
14 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
15
16 /**
17  * This class just delegates all of the functionality to Yangtools normalized node writer.
18  */
19 public final class RestconfDelegatingNormalizedNodeWriter implements RestconfNormalizedNodeWriter {
20     private final NormalizedNodeWriter delegNNWriter;
21
22     private RestconfDelegatingNormalizedNodeWriter(final NormalizedNodeStreamWriter streamWriter, final boolean
23             orderKeyLeaves) {
24         this.delegNNWriter = NormalizedNodeWriter.forStreamWriter(streamWriter, orderKeyLeaves);
25     }
26
27     public static RestconfDelegatingNormalizedNodeWriter forStreamWriter(final NormalizedNodeStreamWriter writer) {
28         return forStreamWriter(writer, true);
29     }
30
31     public static RestconfDelegatingNormalizedNodeWriter forStreamWriter(final NormalizedNodeStreamWriter writer,
32                                                                          final boolean orderKeyLeaves) {
33         return new RestconfDelegatingNormalizedNodeWriter(writer, orderKeyLeaves);
34     }
35
36     @Override
37     public RestconfDelegatingNormalizedNodeWriter write(final NormalizedNode node) throws IOException {
38         delegNNWriter.write(node);
39         return this;
40     }
41
42     @Override
43     public void flush() throws IOException {
44         delegNNWriter.flush();
45     }
46
47     @Override
48     public void close() throws IOException {
49         delegNNWriter.close();
50     }
51 }