org.bidib.wizard.common.context.DefaultApplicationContext Maven / Gradle / Ivy
package org.bidib.wizard.common.context;
import java.util.LinkedHashMap;
import java.util.Map;
import org.bidib.wizard.api.context.ApplicationContext;
import org.springframework.stereotype.Component;
@Component
public class DefaultApplicationContext implements ApplicationContext {
private final Map registry = new LinkedHashMap<>();
public static final String KEY_FEEDBACK_POSITION_CONTROLLER = "feedbackPositionController";
public static final String KEY_MAIN_NODELIST_ACTION_LISTENER = "mainNodeListActionListener";
public static final String KEY_STEPCONTROL_CONTROLLER = "stepControlController";
public static final String KEY_CVDEFINITIONPANEL_CONTROLLER = "cvDefinitionPanelController";
public static final String KEY_MAIN_FRAME = "mainFrame";
public static final String KEY_NODE_TREE = "nodeTree";
public static final String KEY_CV_CONSOLE_MODEL = "cvConsoleModel";
public static final String KEY_DEBUG_CONSOLE_MODEL = "debugConsoleModel";
public static final String KEY_DEBUG_CONSOLE_CONTROLLER = "debugConsoleController";
public static final String KEY_MAIN_CONTROLLER = "mainController";
public static final String KEY_MACROLIST_CONTROLLER = "macroListController";
// public static final String KEY_LOCO_TABLE_CONTROLLER = "locoTableController";
public static final String KEY_DESKTOP = "desktop";
public static final String KEY_TOPTOOLBARPANEL = "topToolBarPanel";
public static final String KEY_SPRINGCONTEXT = "SpringContext";
public static final String KEY_VLC_DETECTED = "vlcDetected";
// public static final String KEY_DIALOGREGISTRY = "dialogRegistry";
private static ApplicationContext INSTANCE;
public static synchronized ApplicationContext getInstance() {
if (INSTANCE == null) {
INSTANCE = new DefaultApplicationContext();
}
return INSTANCE;
}
@Override
public Object register(String key, Object content) {
return registry.put(key, content);
}
@Override
public Object unregister(String key) {
return registry.remove(key);
}
@Override
public Object get(String key) {
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;
}
}