2 * Copyright (c) 2016 Wipro Ltd. 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
 
   9 package org.opendaylight.mwtn.devicemanager.impl.xml;
 
  11 import java.io.StringWriter;
 
  13 import javax.xml.bind.JAXBContext;
 
  14 import javax.xml.bind.JAXBException;
 
  15 import javax.xml.bind.Marshaller;
 
  17 import org.slf4j.Logger;
 
  18 import org.slf4j.LoggerFactory;
 
  20 public class XmlMapper {
 
  21     private static final Logger LOG = LoggerFactory.getLogger(XmlMapper.class);
 
  23     public String getXmlString(MwtNotificationBase base) {
 
  25         JAXBContext jaxbContext;
 
  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);
 
  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);