]> git.basschouten.com Git - openhab-addons.git/blob
e1316cf8d0c35b527f87bcab69bd585621ca9e88
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.avmfritz.internal.util;
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.avmfritz.internal.dto.DeviceListModel;
21 import org.openhab.binding.avmfritz.internal.dto.templates.TemplateListModel;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * Implementation for a static use of JAXBContext as singleton instance.
27  *
28  * @author Christoph Weitkamp - Initial contribution
29  */
30 @NonNullByDefault
31 public class JAXBUtils {
32
33     private static final Logger LOGGER = LoggerFactory.getLogger(JAXBUtils.class);
34
35     public static final @Nullable JAXBContext JAXBCONTEXT_DEVICES = initJAXBContextDevices();
36     public static final @Nullable JAXBContext JAXBCONTEXT_TEMPLATES = initJAXBContextTemplates();
37
38     private static @Nullable JAXBContext initJAXBContextDevices() {
39         try {
40             return JAXBContext.newInstance(DeviceListModel.class);
41         } catch (JAXBException e) {
42             LOGGER.error("Exception creating JAXBContext for devices: {}", e.getLocalizedMessage(), e);
43             return null;
44         }
45     }
46
47     private static @Nullable JAXBContext initJAXBContextTemplates() {
48         try {
49             return JAXBContext.newInstance(TemplateListModel.class);
50         } catch (JAXBException e) {
51             LOGGER.error("Exception creating JAXBContext for templates: {}", e.getLocalizedMessage(), e);
52             return null;
53         }
54     }
55 }