-
Notifications
You must be signed in to change notification settings - Fork 327
/
DefaultMaleDigitalBooleanActionSocket.java
196 lines (154 loc) · 5.57 KB
/
DefaultMaleDigitalBooleanActionSocket.java
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
package jmri.jmrit.logixng.implementation;
import java.util.*;
import javax.annotation.Nonnull;
import jmri.*;
import jmri.jmrit.logixng.*;
/**
* Every DigitalBooleanActionBean has an DefaultMaleDigitalBooleanActionSocket as its parent.
*
* @author Daniel Bergqvist Copyright 2018
*/
public class DefaultMaleDigitalBooleanActionSocket
extends AbstractMaleSocket implements MaleDigitalBooleanActionSocket {
// private final DigitalBooleanActionBean ((DigitalBooleanActionBean)getObject());
private DebugConfig _debugConfig = null;
private boolean _enabled = true;
public DefaultMaleDigitalBooleanActionSocket(@Nonnull BaseManager<? extends NamedBean> manager, @Nonnull DigitalBooleanActionBean action) {
super(manager, action);
}
/** {@inheritDoc} */
@Override
public void execute(boolean hasChangedToTrue, boolean hasChangedToFalse) throws JmriException {
if (! _enabled) {
return;
}
if ((_debugConfig != null)
&& ((DigitalBooleanActionDebugConfig)_debugConfig)._dontExecute) {
return;
}
ConditionalNG conditionalNG = getConditionalNG();
int currentStackPos = conditionalNG.getStack().getCount();
try {
conditionalNG.getSymbolTable().createSymbols(_localVariables);
((DigitalBooleanActionBean)getObject()).execute(hasChangedToTrue, hasChangedToFalse);
} catch (JmriException e) {
if (e.getErrors() != null) {
handleError(this, Bundle.getMessage("ExceptionExecuteMulti"), e.getErrors(), e, log);
} else {
handleError(this, Bundle.getMessage("ExceptionExecuteBooleanAction", e.getLocalizedMessage()), e, log);
}
} catch (RuntimeException e) {
handleError(this, Bundle.getMessage("ExceptionExecuteBooleanAction", e.getLocalizedMessage()), e, log);
}
conditionalNG.getStack().setCount(currentStackPos);
conditionalNG.getSymbolTable().removeSymbols(_localVariables);
}
@Override
public String getDisplayName() {
return ((DigitalBooleanActionBean)getObject()).getDisplayName();
}
@Override
public void disposeMe() {
((DigitalBooleanActionBean)getObject()).dispose();
}
/**
* Register listeners if this object needs that.
*/
@Override
public void registerListenersForThisClass() {
((DigitalBooleanActionBean)getObject()).registerListeners();
}
/**
* Register listeners if this object needs that.
*/
@Override
public void unregisterListenersForThisClass() {
((DigitalBooleanActionBean)getObject()).unregisterListeners();
}
@Override
public void setState(int s) throws JmriException {
((DigitalBooleanActionBean)getObject()).setState(s);
}
@Override
public int getState() {
return ((DigitalBooleanActionBean)getObject()).getState();
}
@Override
public String describeState(int state) {
return ((DigitalBooleanActionBean)getObject()).describeState(state);
}
@Override
public String getComment() {
return ((DigitalBooleanActionBean)getObject()).getComment();
}
@Override
public void setComment(String comment) {
((DigitalBooleanActionBean)getObject()).setComment(comment);
}
@Override
public void setProperty(String key, Object value) {
((DigitalBooleanActionBean)getObject()).setProperty(key, value);
}
@Override
public Object getProperty(String key) {
return ((DigitalBooleanActionBean)getObject()).getProperty(key);
}
@Override
public void removeProperty(String key) {
((DigitalBooleanActionBean)getObject()).removeProperty(key);
}
@Override
public Set<String> getPropertyKeys() {
return ((DigitalBooleanActionBean)getObject()).getPropertyKeys();
}
@Override
public String getBeanType() {
return ((DigitalBooleanActionBean)getObject()).getBeanType();
}
@Override
public int compareSystemNameSuffix(String suffix1, String suffix2, NamedBean n2) {
return ((DigitalBooleanActionBean)getObject()).compareSystemNameSuffix(suffix1, suffix2, n2);
}
/** {@inheritDoc} */
@Override
public void setDebugConfig(DebugConfig config) {
_debugConfig = config;
}
/** {@inheritDoc} */
@Override
public DebugConfig getDebugConfig() {
return _debugConfig;
}
/** {@inheritDoc} */
@Override
public DebugConfig createDebugConfig() {
return new DigitalBooleanActionDebugConfig();
}
/** {@inheritDoc} */
@Override
public void setEnabled(boolean enable) {
_enabled = enable;
if (isActive()) {
registerListeners();
} else {
unregisterListeners();
}
}
/** {@inheritDoc} */
@Override
public void setEnabledFlag(boolean enable) {
_enabled = enable;
}
/** {@inheritDoc} */
@Override
public boolean isEnabled() {
return _enabled;
}
public static class DigitalBooleanActionDebugConfig implements MaleSocket.DebugConfig {
// If true, the socket is not executing the action.
// It's useful if you want to test the LogixNG without affecting the
// layout (turnouts, sensors, and so on).
public boolean _dontExecute = false;
}
private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DefaultMaleDigitalBooleanActionSocket.class);
}