JAXBContext can be freely reused, so cache it, as it has significant
footprint in testing tool.
Change-Id: If2f53b9dfd4a1d30390580fd800aa2f5eb4e2b72
Signed-off-by: Robert Varga <rovarga@cisco.com>
import org.w3c.dom.Element;
public class JaxBSerializer {
+ private static final JAXBContext JAXB_CONTEXT;
+
+ static {
+ try {
+ JAXB_CONTEXT = JAXBContext.newInstance(NetconfState.class);
+ } catch (JAXBException e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
public Element toXml(final NetconfState monitoringModel) {
final DOMResult res;
try {
- final JAXBContext jaxbContext = JAXBContext.newInstance(NetconfState.class);
- final Marshaller marshaller = jaxbContext.createMarshaller();
+ final Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);