Reduce exception guard
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / jersey / providers / YinSchemaExportBodyWriter.java
1 /*
2  * Copyright (c) 2014 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.restconf.nb.rfc8040.jersey.providers;
9
10 import java.io.IOException;
11 import java.io.OutputStream;
12 import java.lang.annotation.Annotation;
13 import java.lang.reflect.Type;
14 import javax.ws.rs.Produces;
15 import javax.ws.rs.core.MediaType;
16 import javax.ws.rs.core.MultivaluedMap;
17 import javax.ws.rs.ext.Provider;
18 import javax.xml.stream.XMLStreamException;
19 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.SchemaExportContext;
20 import org.opendaylight.yangtools.yang.common.YangConstants;
21 import org.opendaylight.yangtools.yang.model.export.YinExportUtils;
22
23 @Provider
24 @Produces(YangConstants.RFC6020_YIN_MEDIA_TYPE)
25 public class YinSchemaExportBodyWriter extends AbstractSchemaExportBodyWriter {
26     @Override
27     public void writeTo(final SchemaExportContext context, final Class<?> type, final Type genericType,
28             final Annotation[] annotations, final MediaType mediaType,
29             final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException {
30         try {
31             YinExportUtils.writeModuleAsYinText(context.getModule().asEffectiveStatement(), entityStream);
32         } catch (final XMLStreamException e) {
33             throw new IOException("Failed to export module", e);
34         }
35     }
36 }