2 * Copyright (c) 2010-2023 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;
17 import javax.xml.stream.XMLInputFactory;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.avmfritz.internal.dto.DeviceListModel;
22 import org.openhab.binding.avmfritz.internal.dto.templates.TemplateListModel;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Implementation for a static use of JAXBContext as singleton instance.
29 * @author Christoph Weitkamp - Initial contribution
32 public class JAXBUtils {
34 private static final Logger LOGGER = LoggerFactory.getLogger(JAXBUtils.class);
36 public static final @Nullable JAXBContext JAXBCONTEXT_DEVICES = initJAXBContextDevices();
37 public static final @Nullable JAXBContext JAXBCONTEXT_TEMPLATES = initJAXBContextTemplates();
38 public static final XMLInputFactory XMLINPUTFACTORY = initXMLInputFactory();
40 private static @Nullable JAXBContext initJAXBContextDevices() {
42 return JAXBContext.newInstance(DeviceListModel.class);
43 } catch (JAXBException e) {
44 LOGGER.error("Exception creating JAXBContext for devices: {}", e.getLocalizedMessage(), e);
49 private static @Nullable JAXBContext initJAXBContextTemplates() {
51 return JAXBContext.newInstance(TemplateListModel.class);
52 } catch (JAXBException e) {
53 LOGGER.error("Exception creating JAXBContext for templates: {}", e.getLocalizedMessage(), e);
58 private static XMLInputFactory initXMLInputFactory() {
59 XMLInputFactory xif = XMLInputFactory.newInstance();
60 xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
61 xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);