org.bidib.wizard.common.script.DefaultScriptContext Maven / Gradle / Ivy
package org.bidib.wizard.common.script;
import java.util.HashMap;
import java.util.Map;
import org.bidib.wizard.api.context.ApplicationContext;
public class DefaultScriptContext implements ApplicationContext {
public static final String KEY_SELECTED_NODE = "selectedNode";
public static final String KEY_ANALOG_LABELS = "analogLabels";
public static final String KEY_BACKLIGHT_LABELS = "backlightLabels";
public static final String KEY_FEEDBACKPORT_LABELS = "feedbackPortLabels";
public static final String KEY_FEEDBACKPOSITION_LABELS = "feedbackPositionLabels";
public static final String KEY_INPUT_LABELS = "inputLabels";
public static final String KEY_LIGHT_LABELS = "lightLabels";
public static final String KEY_MOTOR_LABELS = "motorLabels";
public static final String KEY_SERVO_LABELS = "servoLabels";
public static final String KEY_SOUND_LABELS = "soundLabels";
public static final String KEY_SWITCH_LABELS = "switchLabels";
public static final String KEY_SWITCHPAIR_LABELS = "switchPairLabels";
public static final String KEY_PORT_LABELS = "portLabels";
public static final String KEY_NODE_LABELS = "nodeLabels";
public static final String KEY_MACRO_LABELS = "macroLabels";
public static final String KEY_FLAG_LABELS = "flagLabels";
public static final String KEY_ACCESSORY_LABELS = "accessoryLabels";
public static final String KEY_ASPECT_LABELS = "aspectLabels";
public static final String KEY_MAIN_MODEL = "mainModel";
public static final String KEY_SELECTED_MACRO = "selectedMacro";
public static final String KEY_SELECTED_ACCESSORY = "selectedAccessory";
public static final String KEY_SCRIPT_WARNINGS = "scriptWarnings";
public static final String KEY_LANG = "lang";
public static final String KEY_PARAMETERS = "parameters";
private final Map registry = new HashMap<>();
public DefaultScriptContext() {
}
@Override
public Object register(String key, Object content) {
synchronized (registry) {
return registry.put(key, content);
}
}
@Override
public Object unregister(String key) {
synchronized (registry) {
return registry.remove(key);
}
}
@Override
public Object get(String key) {
synchronized (registry) {
return registry.get(key);
}
}
@Override
public T get(String key, Class type) {
return get(type, get(key));
}
protected T get(Class type, Object body) {
// if same type
if (type.isInstance(body)) {
return type.cast(body);
}
return null;
}
}