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;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.roku.internal.dto.ActiveApp;
21 import org.openhab.binding.roku.internal.dto.Apps;
22 import org.openhab.binding.roku.internal.dto.DeviceInfo;
23 import org.openhab.binding.roku.internal.dto.Player;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Implementation for a static use of JAXBContext as singleton instance.
30 * @author Michael Lobstein - Initial contribution
33 public class JAXBUtils {
35 private static final Logger LOGGER = LoggerFactory.getLogger(JAXBUtils.class);
37 public static final @Nullable JAXBContext JAXBCONTEXT_ACTIVE_APP = initJAXBContextActiveApp();
38 public static final @Nullable JAXBContext JAXBCONTEXT_APPS = initJAXBContextApps();
39 public static final @Nullable JAXBContext JAXBCONTEXT_DEVICE_INFO = initJAXBContextDeviceInfo();
40 public static final @Nullable JAXBContext JAXBCONTEXT_PLAYER = initJAXBContextPlayer();
42 private static @Nullable JAXBContext initJAXBContextActiveApp() {
44 return JAXBContext.newInstance(ActiveApp.class);
45 } catch (JAXBException e) {
46 LOGGER.error("Exception creating JAXBContext for active app: {}", e.getLocalizedMessage(), e);
51 private static @Nullable JAXBContext initJAXBContextApps() {
53 return JAXBContext.newInstance(Apps.class);
54 } catch (JAXBException e) {
55 LOGGER.error("Exception creating JAXBContext for app list: {}", e.getLocalizedMessage(), e);
60 private static @Nullable JAXBContext initJAXBContextDeviceInfo() {
62 return JAXBContext.newInstance(DeviceInfo.class);
63 } catch (JAXBException e) {
64 LOGGER.error("Exception creating JAXBContext for device info: {}", e.getLocalizedMessage(), e);
69 private static @Nullable JAXBContext initJAXBContextPlayer() {
71 return JAXBContext.newInstance(Player.class);
72 } catch (JAXBException e) {
73 LOGGER.error("Exception creating JAXBContext for player info: {}", e.getLocalizedMessage(), e);