DELL
2024-01-10 554f43497fca806ef44491c7833e1b7ad7c7b285
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * Copyright 2011-17 Fraunhofer ISE, energy & meteo Systems GmbH and other contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package org.openmuc.openiec61850.clientgui;
 
import java.io.IOException;
 
import javax.swing.tree.DefaultMutableTreeNode;
 
import org.openmuc.openiec61850.BasicDataAttribute;
import org.openmuc.openiec61850.BdaBoolean;
import org.openmuc.openiec61850.BdaCheck;
import org.openmuc.openiec61850.BdaDoubleBitPos;
import org.openmuc.openiec61850.BdaEntryTime;
import org.openmuc.openiec61850.BdaFloat32;
import org.openmuc.openiec61850.BdaFloat64;
import org.openmuc.openiec61850.BdaInt16;
import org.openmuc.openiec61850.BdaInt16U;
import org.openmuc.openiec61850.BdaInt32;
import org.openmuc.openiec61850.BdaInt32U;
import org.openmuc.openiec61850.BdaInt64;
import org.openmuc.openiec61850.BdaInt8;
import org.openmuc.openiec61850.BdaInt8U;
import org.openmuc.openiec61850.BdaOctetString;
import org.openmuc.openiec61850.BdaOptFlds;
import org.openmuc.openiec61850.BdaQuality;
import org.openmuc.openiec61850.BdaReasonForInclusion;
import org.openmuc.openiec61850.BdaTapCommand;
import org.openmuc.openiec61850.BdaTimestamp;
import org.openmuc.openiec61850.BdaTriggerConditions;
import org.openmuc.openiec61850.BdaUnicodeString;
import org.openmuc.openiec61850.BdaVisibleString;
import org.openmuc.openiec61850.ClientAssociation;
import org.openmuc.openiec61850.Fc;
import org.openmuc.openiec61850.FcModelNode;
import org.openmuc.openiec61850.ModelNode;
import org.openmuc.openiec61850.ServiceError;
import org.openmuc.openiec61850.clientgui.databind.BooleanDataBind;
import org.openmuc.openiec61850.clientgui.databind.CheckDataBind;
import org.openmuc.openiec61850.clientgui.databind.DoubleBitPosDataBind;
import org.openmuc.openiec61850.clientgui.databind.EntryTimeDataBind;
import org.openmuc.openiec61850.clientgui.databind.Float32DataBind;
import org.openmuc.openiec61850.clientgui.databind.Float64DataBind;
import org.openmuc.openiec61850.clientgui.databind.Int16DataBind;
import org.openmuc.openiec61850.clientgui.databind.Int16UDataBind;
import org.openmuc.openiec61850.clientgui.databind.Int32DataBind;
import org.openmuc.openiec61850.clientgui.databind.Int32UDataBind;
import org.openmuc.openiec61850.clientgui.databind.Int64DataBind;
import org.openmuc.openiec61850.clientgui.databind.Int8DataBind;
import org.openmuc.openiec61850.clientgui.databind.Int8UDataBind;
import org.openmuc.openiec61850.clientgui.databind.OctetStringDataBind;
import org.openmuc.openiec61850.clientgui.databind.OptfldsDataBind;
import org.openmuc.openiec61850.clientgui.databind.QualityDataBind;
import org.openmuc.openiec61850.clientgui.databind.ReasonForInclusionDataBind;
import org.openmuc.openiec61850.clientgui.databind.TapCommandDataBind;
import org.openmuc.openiec61850.clientgui.databind.TimeStampDataBind;
import org.openmuc.openiec61850.clientgui.databind.TriggerConditionDataBind;
import org.openmuc.openiec61850.clientgui.databind.UnicodeStringDataBind;
import org.openmuc.openiec61850.clientgui.databind.VisibleStringDataBind;
 
public class DataObjectTreeNode extends DefaultMutableTreeNode implements DataTreeNode {
 
    private static final long serialVersionUID = -3596243932937737877L;
 
    private final ModelNode node;
    private final BasicDataBind<?> data;
 
    public DataObjectTreeNode(String name, ModelNode node) {
        super(name);
        this.node = node;
        if (node != null && node.getChildren() == null) {
            // for (ModelNode child : node.getChildren()) {
            // if (child instanceof BasicDataAttribute) {
            // data.add(createDataBind((BasicDataAttribute) child));
            // }
            // }
            data = createDataBind((BasicDataAttribute) node);
        }
        else {
            data = null;
        }
    }
 
    public ModelNode getNode() {
        return node;
    }
 
    /*
     * (non-Javadoc)
     * 
     * @see org.openmuc.openiec61850.clientgui.DataTreeNode#getData()
     */
    @Override
    public BasicDataBind<?> getData() {
        return data;
    }
 
    /*
     * (non-Javadoc)
     * 
     * @see org.openmuc.openiec61850.clientgui.DataTreeNode#reset()
     */
    @Override
    public void reset(ClientAssociation association) throws ServiceError, IOException {
        if (association != null) {
            association.getDataValues((FcModelNode) node);
        }
        if (data != null) {
            data.reset();
        }
        else {
            for (int i = 0; i < getChildCount(); i++) {
                if (getChildAt(i) instanceof DataObjectTreeNode) {
                    DataTreeNode child = (DataTreeNode) getChildAt(i);
                    child.reset(null);
                }
            }
        }
    }
 
    /*
     * (non-Javadoc)
     * 
     * @see org.openmuc.openiec61850.clientgui.DataTreeNode#writeValues()
     */
    @Override
    public void writeValues(ClientAssociation association) throws ServiceError, IOException {
        if (data != null) {
            data.write();
        }
        else {
            for (int i = 0; i < getChildCount(); i++) {
                if (getChildAt(i) instanceof DataObjectTreeNode) {
                    DataTreeNode child = (DataTreeNode) getChildAt(i);
                    child.writeValues(null);
                }
            }
        }
        if (association != null) {
            //System.out.println("------writeValues----:" + node.toString());
            //System.out.println("------getName----:" + node.getChild("f"));
            association.setDataValues((FcModelNode) node);
        }
    }
 
    @Override
    public boolean writable() {
        if (node instanceof FcModelNode) {
            FcModelNode modelNode = (FcModelNode) node;
            Fc constraint = modelNode.getFc();
            return constraint != Fc.ST && constraint != Fc.MX;
        }
        return false;
    }
 
    @Override
    public boolean readable() {
        return node instanceof FcModelNode;
    }
 
    private static BasicDataBind<?> createDataBind(BasicDataAttribute bda) {
        switch (bda.getBasicType()) {
        case BOOLEAN:
            return new BooleanDataBind((BdaBoolean) bda);
        case ENTRY_TIME:
            return new EntryTimeDataBind((BdaEntryTime) bda);
        case FLOAT32:
            return new Float32DataBind((BdaFloat32) bda);
        case FLOAT64:
            return new Float64DataBind((BdaFloat64) bda);
        case INT16:
            return new Int16DataBind((BdaInt16) bda);
        case INT16U:
            return new Int16UDataBind((BdaInt16U) bda);
        case INT32:
            return new Int32DataBind((BdaInt32) bda);
        case INT32U:
            return new Int32UDataBind((BdaInt32U) bda);
        case INT64:
            return new Int64DataBind((BdaInt64) bda);
        case INT8:
            return new Int8DataBind((BdaInt8) bda);
        case INT8U:
            return new Int8UDataBind((BdaInt8U) bda);
        case OCTET_STRING:
            return new OctetStringDataBind((BdaOctetString) bda);
        case TIMESTAMP:
            return new TimeStampDataBind((BdaTimestamp) bda);
        case UNICODE_STRING:
            return new UnicodeStringDataBind((BdaUnicodeString) bda);
        case VISIBLE_STRING:
            return new VisibleStringDataBind((BdaVisibleString) bda);
        case CHECK:
            return new CheckDataBind((BdaCheck) bda);
        case DOUBLE_BIT_POS:
            return new DoubleBitPosDataBind((BdaDoubleBitPos) bda);
        case OPTFLDS:
            return new OptfldsDataBind((BdaOptFlds) bda);
        case QUALITY:
            return new QualityDataBind((BdaQuality) bda);
        case REASON_FOR_INCLUSION:
            return new ReasonForInclusionDataBind((BdaReasonForInclusion) bda);
        case TAP_COMMAND:
            return new TapCommandDataBind((BdaTapCommand) bda);
        case TRIGGER_CONDITIONS:
            return new TriggerConditionDataBind((BdaTriggerConditions) bda);
        default:
            throw new IllegalArgumentException("BasicType " + bda.getBasicType() + " unknown");
        }
    }
}