SmachDSLActivator.java
Go to the documentation of this file.
00001 /*
00002  * generated by Xtext
00003  */
00004 package org.best.of.robotics.ui.internal;
00005 
00006 import java.util.Collections;
00007 import java.util.Map;
00008 
00009 import org.apache.log4j.Logger;
00010 import org.eclipse.ui.plugin.AbstractUIPlugin;
00011 import org.eclipse.xtext.ui.shared.SharedStateModule;
00012 import org.eclipse.xtext.util.Modules2;
00013 import org.osgi.framework.BundleContext;
00014 
00015 import com.google.common.collect.Maps;
00016 import com.google.inject.Guice;
00017 import com.google.inject.Injector;
00018 import com.google.inject.Module;
00019 
00024 public class SmachDSLActivator extends AbstractUIPlugin {
00025         
00026         public static final String ORG_BEST_OF_ROBOTICS_SMACHDSL = "org.best.of.robotics.SmachDSL";
00027         
00028         private static final Logger logger = Logger.getLogger(SmachDSLActivator.class);
00029         
00030         private static SmachDSLActivator INSTANCE;
00031         
00032         private Map<String, Injector> injectors = Collections.synchronizedMap(Maps.<String, Injector> newHashMapWithExpectedSize(1));
00033         
00034         @Override
00035         public void start(BundleContext context) throws Exception {
00036                 super.start(context);
00037                 INSTANCE = this;
00038         }
00039         
00040         @Override
00041         public void stop(BundleContext context) throws Exception {
00042                 injectors.clear();
00043                 INSTANCE = null;
00044                 super.stop(context);
00045         }
00046         
00047         public static SmachDSLActivator getInstance() {
00048                 return INSTANCE;
00049         }
00050         
00051         public Injector getInjector(String language) {
00052                 synchronized (injectors) {
00053                         Injector injector = injectors.get(language);
00054                         if (injector == null) {
00055                                 injectors.put(language, injector = createInjector(language));
00056                         }
00057                         return injector;
00058                 }
00059         }
00060         
00061         protected Injector createInjector(String language) {
00062                 try {
00063                         Module runtimeModule = getRuntimeModule(language);
00064                         Module sharedStateModule = getSharedStateModule();
00065                         Module uiModule = getUiModule(language);
00066                         Module mergedModule = Modules2.mixin(runtimeModule, sharedStateModule, uiModule);
00067                         return Guice.createInjector(mergedModule);
00068                 } catch (Exception e) {
00069                         logger.error("Failed to create injector for " + language);
00070                         logger.error(e.getMessage(), e);
00071                         throw new RuntimeException("Failed to create injector for " + language, e);
00072                 }
00073         }
00074 
00075         protected Module getRuntimeModule(String grammar) {
00076                 if (ORG_BEST_OF_ROBOTICS_SMACHDSL.equals(grammar)) {
00077                         return new org.best.of.robotics.SmachDSLRuntimeModule();
00078                 }
00079                 
00080                 throw new IllegalArgumentException(grammar);
00081         }
00082         
00083         protected Module getUiModule(String grammar) {
00084                 if (ORG_BEST_OF_ROBOTICS_SMACHDSL.equals(grammar)) {
00085                         return new org.best.of.robotics.ui.SmachDSLUiModule(this);
00086                 }
00087                 
00088                 throw new IllegalArgumentException(grammar);
00089         }
00090         
00091         protected Module getSharedStateModule() {
00092                 return new SharedStateModule();
00093         }
00094         
00095 }


bride_plugin_source
Author(s): Alexander Bubeck
autogenerated on Sun Oct 5 2014 22:38:34