public static ExecutionEnvironment instance() { if (INSTANCES.size() == 1) { return THE_ONE == null ? THE_ONE = INSTANCES.values().iterator().next() : THE_ONE; } IModule mod = INSTANCES.size() > 0 ? TypeSystem.getCurrentModule() : null; if (mod != null) { ExecutionEnvironment execEnv = (ExecutionEnvironment) mod.getExecutionEnvironment(); if (execEnv == null) { throw new IllegalStateException( "Module, " + mod.getName() + ", has a null execution environment. This is bad."); } return execEnv; } if (INSTANCES.size() > 0) { // Return first non-default project // Yes, this is a guess, but we need to guess for the case where we're running tests // and loading classes in lots of threads where the current module is not pushed for (ExecutionEnvironment execEnv : INSTANCES.values()) { if (execEnv.getProject() != DEFAULT_PROJECT && !execEnv.getProject().isDisposed()) { return execEnv; } } } return instance(DEFAULT_PROJECT); }
void checkForDuplicates(String moduleName) { for (IModule m : getModules()) { if (m.getName().equals(moduleName)) { throw new RuntimeException("Module " + moduleName + " allready exists."); } } }
public IModule getModule(String strModuleName) { for (IModule m : _modules) { if (m.getName().equals(strModuleName)) { return m; } } if (isSingleModuleMode() && GLOBAL_MODULE_NAME.equals(strModuleName)) { return getGlobalModule(); } return null; }
public void addModule(IModule module) { checkForDuplicates(module.getName()); // noinspection unchecked _modules.add(module); module.update(); pushModule(module); try { ((Module) module).initializeTypeLoaders(); } finally { popModule(module); } }