]> git.basschouten.com Git - openhab-addons.git/blob
81426d7f397760a6af2a32b2a9dfea383d64db4e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.ihc.internal.ws.datatypes;
14
15 import java.io.IOException;
16
17 import javax.xml.xpath.XPathExpressionException;
18
19 import org.openhab.binding.ihc.internal.ws.exeptions.IhcExecption;
20
21 /**
22  * Class for WSControllerState complex type.
23  *
24  * @author Pauli Anttila - Initial contribution
25  */
26
27 public class WSControllerState {
28     private String state;
29
30     public WSControllerState() {
31     }
32
33     public WSControllerState(String state) {
34         this.state = state;
35     }
36
37     /**
38      * Gets the state value for this WSControllerState.
39      *
40      * @return state
41      */
42     public String getState() {
43         return state;
44     }
45
46     /**
47      * Sets the state value for this WSControllerState.
48      *
49      * @param state
50      */
51     public void setState(String state) {
52         this.state = state;
53     }
54
55     public WSControllerState parseXMLData(String data) throws IhcExecption {
56         try {
57             if (data.contains("getState1")) {
58                 state = XPathUtils.parseXMLValue(data, "/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:getState1/ns1:state");
59             } else if (data.contains("waitForControllerStateChange3")) {
60                 state = XPathUtils.parseXMLValue(data,
61                         "/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:waitForControllerStateChange3/ns1:state");
62             } else {
63                 throw new IhcExecption("Encoding error, unsupported data");
64             }
65             return this;
66         } catch (IOException | XPathExpressionException e) {
67             throw new IhcExecption("Error occured during XML data parsing", e);
68         }
69     }
70 }