]> git.basschouten.com Git - openhab-addons.git/blob
e572f8811ecc0a3ae53b15ead0462ebb816066c8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.mynice.internal.xml;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.mynice.internal.xml.dto.Authentication;
17 import org.openhab.binding.mynice.internal.xml.dto.Authentication.UserPerm;
18 import org.openhab.binding.mynice.internal.xml.dto.CommandType;
19 import org.openhab.binding.mynice.internal.xml.dto.Device;
20 import org.openhab.binding.mynice.internal.xml.dto.Device.DeviceType;
21 import org.openhab.binding.mynice.internal.xml.dto.Error;
22 import org.openhab.binding.mynice.internal.xml.dto.Event;
23 import org.openhab.binding.mynice.internal.xml.dto.Interface;
24 import org.openhab.binding.mynice.internal.xml.dto.Properties;
25 import org.openhab.binding.mynice.internal.xml.dto.Response;
26
27 import com.thoughtworks.xstream.XStream;
28 import com.thoughtworks.xstream.io.xml.StaxDriver;
29
30 /**
31  * The {@link MyNiceXStream} class is a utility class that wraps an XStream object and provide additional
32  * functionality specific to the MyNice binding. It automatically load the correct converter classes and
33  * processes the XStream annotations used by the object classes.
34  *
35  * @author GaĆ«l L'hopital - Initial contribution
36  */
37
38 @NonNullByDefault
39 public class MyNiceXStream extends XStream {
40     public static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
41
42     public MyNiceXStream() {
43         super(new StaxDriver());
44         allowTypesByWildcard(new String[] { Response.class.getPackageName() + ".**" });
45         setClassLoader(getClass().getClassLoader());
46         autodetectAnnotations(true);
47         ignoreUnknownElements();
48         alias("Response", Response.class);
49         alias("Event", Event.class);
50         alias("Authentication", Authentication.class);
51         alias("CommandType", CommandType.class);
52         alias("UserPerm", UserPerm.class);
53         alias("DeviceType", DeviceType.class);
54         alias("Error", Error.class);
55         alias("Interface", Interface.class);
56         alias("Device", Device.class);
57         alias("Properties", Properties.class);
58     }
59
60     public Event deserialize(String response) {
61         return (Event) fromXML(XML_HEADER + response);
62     }
63 }