2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.avmfritz.internal.util;
15 import javax.xml.bind.JAXBContext;
16 import javax.xml.bind.JAXBException;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.avmfritz.internal.dto.DeviceListModel;
21 import org.openhab.binding.avmfritz.internal.dto.templates.TemplateListModel;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Implementation for a static use of JAXBContext as singleton instance.
28 * @author Christoph Weitkamp - Initial contribution
31 public class JAXBUtils {
33 private static final Logger LOGGER = LoggerFactory.getLogger(JAXBUtils.class);
35 public static final @Nullable JAXBContext JAXBCONTEXT_DEVICES = initJAXBContextDevices();
36 public static final @Nullable JAXBContext JAXBCONTEXT_TEMPLATES = initJAXBContextTemplates();
38 private static @Nullable JAXBContext initJAXBContextDevices() {
40 return JAXBContext.newInstance(DeviceListModel.class);
41 } catch (JAXBException e) {
42 LOGGER.error("Exception creating JAXBContext for devices: {}", e.getLocalizedMessage(), e);
47 private static @Nullable JAXBContext initJAXBContextTemplates() {
49 return JAXBContext.newInstance(TemplateListModel.class);
50 } catch (JAXBException e) {
51 LOGGER.error("Exception creating JAXBContext for templates: {}", e.getLocalizedMessage(), e);