All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.irit.smac.may.speadl.ui.internal.SpeADLActivator Maven / Gradle / Ivy

/*
 * generated by Xtext
 */
package fr.irit.smac.may.speadl.ui.internal;

import java.util.Collections;
import java.util.Map;

import org.apache.log4j.Logger;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.xtext.ui.shared.SharedStateModule;
import org.eclipse.xtext.util.Modules2;
import org.osgi.framework.BundleContext;

import com.google.common.collect.Maps;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;

/**
 * This class was generated. Customizations should only happen in a newly
 * introduced subclass. 
 */
public class SpeADLActivator extends AbstractUIPlugin {
	
	public static final String FR_IRIT_SMAC_MAY_SPEADL_SPEADL = "fr.irit.smac.may.speadl.SpeADL";
	
	private static final Logger logger = Logger.getLogger(SpeADLActivator.class);
	
	private static SpeADLActivator INSTANCE;
	
	private Map injectors = Collections.synchronizedMap(Maps. newHashMapWithExpectedSize(1));
	
	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
		INSTANCE = this;
	}
	
	@Override
	public void stop(BundleContext context) throws Exception {
		injectors.clear();
		INSTANCE = null;
		super.stop(context);
	}
	
	public static SpeADLActivator getInstance() {
		return INSTANCE;
	}
	
	public Injector getInjector(String language) {
		synchronized (injectors) {
			Injector injector = injectors.get(language);
			if (injector == null) {
				injectors.put(language, injector = createInjector(language));
			}
			return injector;
		}
	}
	
	protected Injector createInjector(String language) {
		try {
			Module runtimeModule = getRuntimeModule(language);
			Module sharedStateModule = getSharedStateModule();
			Module uiModule = getUiModule(language);
			Module mergedModule = Modules2.mixin(runtimeModule, sharedStateModule, uiModule);
			return Guice.createInjector(mergedModule);
		} catch (Exception e) {
			logger.error("Failed to create injector for " + language);
			logger.error(e.getMessage(), e);
			throw new RuntimeException("Failed to create injector for " + language, e);
		}
	}

	protected Module getRuntimeModule(String grammar) {
		if (FR_IRIT_SMAC_MAY_SPEADL_SPEADL.equals(grammar)) {
			return new fr.irit.smac.may.speadl.SpeADLRuntimeModule();
		}
		
		throw new IllegalArgumentException(grammar);
	}
	
	protected Module getUiModule(String grammar) {
		if (FR_IRIT_SMAC_MAY_SPEADL_SPEADL.equals(grammar)) {
			return new fr.irit.smac.may.speadl.ui.SpeADLUiModule(this);
		}
		
		throw new IllegalArgumentException(grammar);
	}
	
	protected Module getSharedStateModule() {
		return new SharedStateModule();
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy