Eliminate FormatParameters
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / api / DatabindFormattableBody.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech, s.r.o. 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.restconf.server.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.io.IOException;
13 import java.io.OutputStream;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.opendaylight.restconf.api.FormattableBody;
16 import org.opendaylight.restconf.api.query.PrettyPrintParam;
17
18 /**
19  * A {@link FormattableBody} which has an attached {@link DatabindContext}.
20  */
21 @NonNullByDefault
22 public abstract class DatabindFormattableBody extends FormattableBody {
23     private final DatabindContext databind;
24
25     protected DatabindFormattableBody(final DatabindContext databind) {
26         this.databind = requireNonNull(databind);
27     }
28
29     @Override
30     public final void formatToJSON(final PrettyPrintParam prettyPrint, final OutputStream out) throws IOException {
31         formatToJSON(databind, prettyPrint, out);
32     }
33
34     protected abstract void formatToJSON(DatabindContext databind, PrettyPrintParam prettyPrint, OutputStream out)
35         throws IOException;
36
37     @Override
38     public final void formatToXML(final PrettyPrintParam prettyPrint, final OutputStream out) throws IOException {
39         formatToXML(databind, prettyPrint, out);
40     }
41
42     protected abstract void formatToXML(DatabindContext databind, PrettyPrintParam prettyPrint, OutputStream out)
43         throws IOException;
44 }