Rework body formatting wiring
[netconf.git] / protocol / restconf-api / src / main / java / org / opendaylight / restconf / api / FormattableBody.java
index ae277a23efcea042eb88631516e94eee70d92fd9..870bcd2d28df8a9e3dbdedd95feb65c13d11092a 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.restconf.api;
 
-import static java.util.Objects.requireNonNull;
-
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import java.io.IOException;
@@ -17,46 +15,33 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.opendaylight.yangtools.concepts.Immutable;
 
 /**
- * A body which is capable of being formatted to an {@link OutputStream} in either JSON or XML format.
+ * A body which is capable of being formatted to an {@link OutputStream} in either JSON or XML format using particular
+ * {@link FormatParameters}.
  */
 @NonNullByDefault
 public abstract class FormattableBody implements Immutable {
-    private final FormatParameters format;
-
-    protected FormattableBody(final FormatParameters format) {
-        this.format = requireNonNull(format);
-    }
-
     /**
      * Write the content of this body as a JSON document.
      *
+     * @param format {@link FormatParameters}
      * @param out output stream
      * @throws IOException if an IO error occurs.
      */
-    public final void formatToJSON(final OutputStream out) throws IOException {
-        formatToJSON(requireNonNull(out), format);
-    }
-
-    protected abstract void formatToJSON(OutputStream out, FormatParameters format) throws IOException;
+    public abstract void formatToJSON(FormatParameters format, OutputStream out) throws IOException;
 
     /**
      * Write the content of this body as an XML document.
      *
+     * @param format {@link FormatParameters}
      * @param out output stream
      * @throws IOException if an IO error occurs.
      */
-    public final void formatToXML(final OutputStream out) throws IOException {
-        formatToXML(requireNonNull(out), format);
-    }
+    public abstract void formatToXML(FormatParameters format, OutputStream out) throws IOException;
 
-    protected abstract void formatToXML(OutputStream out, FormatParameters format) throws IOException;
+    protected abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
 
     @Override
     public final String toString() {
         return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
     }
-
-    protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
-        return helper.add("prettyPrint", format.prettyPrint().value());
-    }
 }