blob: 98be90ad5a030bcb8a6b78ed25edac22dbcbd0c4 [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf), Loetz GmbH&Co.KG (Heidelberg)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Florian Pirchner - Initial implementation
*
* generated by Xtext 2.11.0
*/
package org.eclipse.osbp.dsl.entity.xtext.ui.internal;
import com.google.common.collect.Maps;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import java.util.Collections;
import java.util.Map;
import org.apache.log4j.Logger;
import org.eclipse.osbp.dsl.entity.xtext.EntityGrammarRuntimeModule;
import org.eclipse.osbp.dsl.entity.xtext.ui.EntityGrammarUiModule;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.xtext.ui.shared.SharedStateModule;
import org.eclipse.xtext.util.Modules2;
import org.osgi.framework.BundleContext;
/**
* This class was generated. Customizations should only happen in a newly
* introduced subclass.
*/
public class XtextActivator extends AbstractUIPlugin {
public static final String ORG_ECLIPSE_OSBP_DSL_ENTITY_XTEXT_ENTITYGRAMMAR = "org.eclipse.osbp.dsl.entity.xtext.EntityGrammar";
private static final Logger logger = Logger.getLogger(XtextActivator.class);
private static XtextActivator INSTANCE;
private Map<String, Injector> injectors = Collections.synchronizedMap(Maps.<String, Injector> 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 XtextActivator 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 (ORG_ECLIPSE_OSBP_DSL_ENTITY_XTEXT_ENTITYGRAMMAR.equals(grammar)) {
return new EntityGrammarRuntimeModule();
}
throw new IllegalArgumentException(grammar);
}
protected Module getUiModule(String grammar) {
if (ORG_ECLIPSE_OSBP_DSL_ENTITY_XTEXT_ENTITYGRAMMAR.equals(grammar)) {
return new EntityGrammarUiModule(this);
}
throw new IllegalArgumentException(grammar);
}
protected Module getSharedStateModule() {
return new SharedStateModule();
}
}