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.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.openhab.binding.roku.internal.dto.TvChannel;
26 import org.openhab.binding.roku.internal.dto.TvChannels;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Implementation for a static use of JAXBContext as singleton instance.
33 * @author Michael Lobstein - Initial contribution
36 public class JAXBUtils {
38 private static final Logger LOGGER = LoggerFactory.getLogger(JAXBUtils.class);
40 public static final @Nullable JAXBContext JAXBCONTEXT_ACTIVE_APP = initJAXBContextActiveApp();
41 public static final @Nullable JAXBContext JAXBCONTEXT_APPS = initJAXBContextApps();
42 public static final @Nullable JAXBContext JAXBCONTEXT_DEVICE_INFO = initJAXBContextDeviceInfo();
43 public static final @Nullable JAXBContext JAXBCONTEXT_PLAYER = initJAXBContextPlayer();
44 public static final @Nullable JAXBContext JAXBCONTEXT_TVCHANNEL = initJAXBContextTvChannel();
45 public static final @Nullable JAXBContext JAXBCONTEXT_TVCHANNELS = initJAXBContextTvChannels();
46 public static final XMLInputFactory XMLINPUTFACTORY = initXMLInputFactory();
48 private static @Nullable JAXBContext initJAXBContextActiveApp() {
50 return JAXBContext.newInstance(ActiveApp.class);
51 } catch (JAXBException e) {
52 LOGGER.error("Exception creating JAXBContext for active app: {}", e.getLocalizedMessage(), e);
57 private static @Nullable JAXBContext initJAXBContextApps() {
59 return JAXBContext.newInstance(Apps.class);
60 } catch (JAXBException e) {
61 LOGGER.error("Exception creating JAXBContext for app list: {}", e.getLocalizedMessage(), e);
66 private static @Nullable JAXBContext initJAXBContextDeviceInfo() {
68 return JAXBContext.newInstance(DeviceInfo.class);
69 } catch (JAXBException e) {
70 LOGGER.error("Exception creating JAXBContext for device info: {}", e.getLocalizedMessage(), e);
75 private static @Nullable JAXBContext initJAXBContextPlayer() {
77 return JAXBContext.newInstance(Player.class);
78 } catch (JAXBException e) {
79 LOGGER.error("Exception creating JAXBContext for player info: {}", e.getLocalizedMessage(), e);
84 private static @Nullable JAXBContext initJAXBContextTvChannel() {
86 return JAXBContext.newInstance(TvChannel.class);
87 } catch (JAXBException e) {
88 LOGGER.error("Exception creating JAXBContext for TvChannel info: {}", e.getLocalizedMessage(), e);
93 private static @Nullable JAXBContext initJAXBContextTvChannels() {
95 return JAXBContext.newInstance(TvChannels.class);
96 } catch (JAXBException e) {
97 LOGGER.error("Exception creating JAXBContext for TvChannels info: {}", e.getLocalizedMessage(), e);
102 private static XMLInputFactory initXMLInputFactory() {
103 XMLInputFactory xif = XMLInputFactory.newInstance();
104 xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
105 xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);