2 * Copyright (c) 2013 Cisco Systems, Inc. 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.netconf.test.tool.monitoring;
10 import javax.xml.bind.JAXBContext;
11 import javax.xml.bind.JAXBException;
12 import javax.xml.bind.Marshaller;
13 import javax.xml.transform.dom.DOMResult;
14 import org.w3c.dom.Document;
15 import org.w3c.dom.Element;
17 public class JaxBSerializer {
18 private static final JAXBContext JAXB_CONTEXT;
22 JAXB_CONTEXT = JAXBContext.newInstance(NetconfState.class);
23 } catch (final JAXBException e) {
24 throw new ExceptionInInitializerError(e);
28 public Element toXml(final NetconfState monitoringModel) {
31 final Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
33 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
35 res = new DOMResult();
36 marshaller.marshal(monitoringModel, res);
37 } catch (final JAXBException e) {
38 throw new RuntimeException("Unable to serialize netconf state " + monitoringModel, e);
40 return ((Document) res.getNode()).getDocumentElement();