Add AbstractSchemaExportBodyWriter and specialize it for YIN/YANG.
Also eliminate jersey.provides.schema package, as it does not really
make sense.
JIRA: NETCONF-773
Change-Id: Ia099e927da10f451cd843ba947a79312dd35af19
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.NormalizedNodeJsonBodyWriter;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.NormalizedNodeXmlBodyWriter;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyReader;
+import org.opendaylight.restconf.nb.rfc8040.jersey.providers.YangSchemaExportBodyWriter;
+import org.opendaylight.restconf.nb.rfc8040.jersey.providers.YinSchemaExportBodyWriter;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors.RestconfDocumentedExceptionMapper;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.JsonToPatchBodyReader;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.PatchJsonBodyWriter;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.PatchXmlBodyWriter;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.XmlToPatchBodyReader;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYangBodyWriter;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYinBodyWriter;
/**
* Abstract Restconf Application.
public final Set<Class<?>> getClasses() {
return Set.of(
NormalizedNodeJsonBodyWriter.class, NormalizedNodeXmlBodyWriter.class,
- SchemaExportContentYinBodyWriter.class, SchemaExportContentYangBodyWriter.class,
+ YinSchemaExportBodyWriter.class, YangSchemaExportBodyWriter.class,
PatchJsonBodyWriter.class, PatchXmlBodyWriter.class);
}
--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.nb.rfc8040.jersey.providers;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.MessageBodyWriter;
+import org.opendaylight.restconf.common.schema.SchemaExportContext;
+
+abstract class AbstractSchemaExportBodyWriter implements MessageBodyWriter<SchemaExportContext> {
+ @Override
+ public final boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type.equals(SchemaExportContext.class);
+ }
+}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema;
+package org.opendaylight.restconf.nb.rfc8040.jersey.providers;
import java.io.IOException;
import java.io.OutputStream;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import org.opendaylight.restconf.common.schema.SchemaExportContext;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
@Provider
-@Produces({ YangConstants.RFC6020_YANG_MEDIA_TYPE })
-public class SchemaExportContentYangBodyWriter implements MessageBodyWriter<SchemaExportContext> {
-
- @Override
- public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
- final MediaType mediaType) {
- return type.equals(SchemaExportContext.class);
- }
-
+@Produces(YangConstants.RFC6020_YANG_MEDIA_TYPE)
+public class YangSchemaExportBodyWriter extends AbstractSchemaExportBodyWriter {
@Override
public void writeTo(final SchemaExportContext context, final Class<?> type, final Type genericType,
final Annotation[] annotations, final MediaType mediaType,
- final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException,
- WebApplicationException {
+ final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException {
final RevisionSourceIdentifier sourceId = RevisionSourceIdentifier.create(context.getModule().getName(),
context.getModule().getQNameModule().getRevision());
final YangTextSchemaSource yangTextSchemaSource;
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema;
+package org.opendaylight.restconf.nb.rfc8040.jersey.providers;
+import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import javax.xml.stream.XMLStreamException;
import org.opendaylight.restconf.common.schema.SchemaExportContext;
import org.opendaylight.yangtools.yang.model.export.YinExportUtils;
@Provider
-@Produces({ YangConstants.RFC6020_YIN_MEDIA_TYPE })
-public class SchemaExportContentYinBodyWriter implements MessageBodyWriter<SchemaExportContext> {
-
- @Override
- public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
- final MediaType mediaType) {
- return type.equals(SchemaExportContext.class);
- }
-
+@Produces(YangConstants.RFC6020_YIN_MEDIA_TYPE)
+public class YinSchemaExportBodyWriter extends AbstractSchemaExportBodyWriter {
@Override
public void writeTo(final SchemaExportContext context, final Class<?> type, final Type genericType,
final Annotation[] annotations, final MediaType mediaType,
- final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws
- WebApplicationException {
+ final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException {
try {
- YinExportUtils.writeModuleAsYinText(context.getModule(), entityStream);
+ YinExportUtils.writeModuleAsYinText(context.getModule().asEffectiveStatement(), entityStream);
} catch (final XMLStreamException e) {
- throw new IllegalStateException(e);
+ throw new IOException("Failed to export module", e);
}
}
}