Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / java / org / opendaylight / mwtn / devicemanager / impl / xml / XmlMapper.java
1 /*
2 * Copyright (c) 2016 Wipro Ltd. 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
9 package org.opendaylight.mwtn.devicemanager.impl.xml;
10
11 import java.io.StringWriter;
12
13 import javax.xml.bind.JAXBContext;
14 import javax.xml.bind.JAXBException;
15 import javax.xml.bind.Marshaller;
16
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class XmlMapper {
21     private static final Logger LOG = LoggerFactory.getLogger(XmlMapper.class);
22
23     public String getXmlString(MwtNotificationBase base) {
24         String xml;
25         JAXBContext jaxbContext;
26         try {
27             jaxbContext = JAXBContext.newInstance(AttributeValueChangedNotificationXml.class,
28                     ObjectCreationNotificationXml.class, ObjectDeletionNotificationXml.class,
29                     ProblemNotificationXml.class);
30             Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
31             jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
32
33             StringWriter stringWriter = new StringWriter();
34             jaxbMarshaller.marshal(base, stringWriter);
35             xml = stringWriter.toString();
36         } catch (JAXBException e) {
37             LOG.warn("Problem in marshalling xml file {}", e);
38             xml = null;
39         }
40         return xml;
41     }
42 }