]> git.basschouten.com Git - openhab-addons.git/blob
1fee1bf347dbf4746d9bb32c957897774ee4dae5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.roku.internal.communication;
14
15 import javax.xml.bind.JAXBContext;
16 import javax.xml.bind.JAXBException;
17
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;
26
27 /**
28  * Implementation for a static use of JAXBContext as singleton instance.
29  *
30  * @author Michael Lobstein - Initial contribution
31  */
32 @NonNullByDefault
33 public class JAXBUtils {
34
35     private static final Logger LOGGER = LoggerFactory.getLogger(JAXBUtils.class);
36
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();
41
42     private static @Nullable JAXBContext initJAXBContextActiveApp() {
43         try {
44             return JAXBContext.newInstance(ActiveApp.class);
45         } catch (JAXBException e) {
46             LOGGER.error("Exception creating JAXBContext for active app: {}", e.getLocalizedMessage(), e);
47             return null;
48         }
49     }
50
51     private static @Nullable JAXBContext initJAXBContextApps() {
52         try {
53             return JAXBContext.newInstance(Apps.class);
54         } catch (JAXBException e) {
55             LOGGER.error("Exception creating JAXBContext for app list: {}", e.getLocalizedMessage(), e);
56             return null;
57         }
58     }
59
60     private static @Nullable JAXBContext initJAXBContextDeviceInfo() {
61         try {
62             return JAXBContext.newInstance(DeviceInfo.class);
63         } catch (JAXBException e) {
64             LOGGER.error("Exception creating JAXBContext for device info: {}", e.getLocalizedMessage(), e);
65             return null;
66         }
67     }
68
69     private static @Nullable JAXBContext initJAXBContextPlayer() {
70         try {
71             return JAXBContext.newInstance(Player.class);
72         } catch (JAXBException e) {
73             LOGGER.error("Exception creating JAXBContext for player info: {}", e.getLocalizedMessage(), e);
74             return null;
75         }
76     }
77 }