2 * Copyright (c) 2010-2021 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.roku.internal.communication;
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.roku.internal.dto.ActiveApp;
22 import org.openhab.binding.roku.internal.dto.Apps;
23 import org.openhab.binding.roku.internal.dto.DeviceInfo;
24 import org.openhab.binding.roku.internal.dto.Player;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Implementation for a static use of JAXBContext as singleton instance.
31 * @author Michael Lobstein - Initial contribution
34 public class JAXBUtils {
36 private static final Logger LOGGER = LoggerFactory.getLogger(JAXBUtils.class);
38 public static final @Nullable JAXBContext JAXBCONTEXT_ACTIVE_APP = initJAXBContextActiveApp();
39 public static final @Nullable JAXBContext JAXBCONTEXT_APPS = initJAXBContextApps();
40 public static final @Nullable JAXBContext JAXBCONTEXT_DEVICE_INFO = initJAXBContextDeviceInfo();
41 public static final @Nullable JAXBContext JAXBCONTEXT_PLAYER = initJAXBContextPlayer();
42 public static final XMLInputFactory XMLINPUTFACTORY = initXMLInputFactory();
44 private static @Nullable JAXBContext initJAXBContextActiveApp() {
46 return JAXBContext.newInstance(ActiveApp.class);
47 } catch (JAXBException e) {
48 LOGGER.error("Exception creating JAXBContext for active app: {}", e.getLocalizedMessage(), e);
53 private static @Nullable JAXBContext initJAXBContextApps() {
55 return JAXBContext.newInstance(Apps.class);
56 } catch (JAXBException e) {
57 LOGGER.error("Exception creating JAXBContext for app list: {}", e.getLocalizedMessage(), e);
62 private static @Nullable JAXBContext initJAXBContextDeviceInfo() {
64 return JAXBContext.newInstance(DeviceInfo.class);
65 } catch (JAXBException e) {
66 LOGGER.error("Exception creating JAXBContext for device info: {}", e.getLocalizedMessage(), e);
71 private static @Nullable JAXBContext initJAXBContextPlayer() {
73 return JAXBContext.newInstance(Player.class);
74 } catch (JAXBException e) {
75 LOGGER.error("Exception creating JAXBContext for player info: {}", e.getLocalizedMessage(), e);
80 private static XMLInputFactory initXMLInputFactory() {
81 XMLInputFactory xif = XMLInputFactory.newInstance();
82 xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
83 xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);