2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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.restconf.nb.rfc8040.jersey.providers;
10 import static java.util.Objects.requireNonNull;
12 import java.io.IOException;
13 import java.io.OutputStream;
14 import java.lang.annotation.Annotation;
15 import java.lang.reflect.Type;
16 import javax.ws.rs.core.MediaType;
17 import javax.ws.rs.core.MultivaluedMap;
18 import javax.ws.rs.ext.MessageBodyWriter;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.opendaylight.restconf.api.query.PrettyPrintParam;
21 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
22 import org.opendaylight.restconf.nb.rfc8040.legacy.WriterParameters;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
26 abstract class AbstractNormalizedNodeBodyWriter implements MessageBodyWriter<NormalizedNodePayload> {
28 public final boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
29 final MediaType mediaType) {
30 return type.equals(NormalizedNodePayload.class);
34 public final void writeTo(final NormalizedNodePayload context, final Class<?> type, final Type genericType,
35 final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders,
36 final OutputStream entityStream) throws IOException {
37 writeData(context.inference().toSchemaInferenceStack(), context.data(), context.writerParameters(),
38 context.prettyPrint(), requireNonNull(entityStream));
42 abstract void writeData(SchemaInferenceStack stack, NormalizedNode data, WriterParameters writerParameters,
43 PrettyPrintParam prettyPrint, OutputStream out) throws IOException;