PageRenderTime 133ms CodeModel.GetById 20ms RepoModel.GetById 8ms app.codeStats 0ms

/plugins/grooveclipse/org.grooveclipse.ecore.refdsl.ui/src-gen/org/grooveclipse/ecore/ui/internal/RefDslActivator.java

http://grooveclipse.googlecode.com/
Java | 95 lines | 67 code | 21 blank | 7 comment | 2 complexity | 99a5010c5d29c1010b4a94007408b23f MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * generated by Xtext
  3. */
  4. package org.grooveclipse.ecore.ui.internal;
  5. import static com.google.inject.util.Modules.override;
  6. import static com.google.inject.Guice.createInjector;
  7. import org.apache.log4j.Logger;
  8. import org.eclipse.ui.plugin.AbstractUIPlugin;
  9. import org.osgi.framework.BundleContext;
  10. import com.google.inject.Injector;
  11. import com.google.inject.Module;
  12. import com.google.common.cache.Cache;
  13. import com.google.common.cache.CacheBuilder;
  14. import com.google.common.cache.CacheLoader;
  15. import java.util.concurrent.ExecutionException;
  16. import org.eclipse.xtext.ui.shared.SharedStateModule;
  17. /**
  18. * This class was generated. Customizations should only happen in a newly
  19. * introduced subclass.
  20. */
  21. public class RefDslActivator extends AbstractUIPlugin {
  22. private static final Logger logger = Logger.getLogger(RefDslActivator.class);
  23. private Cache<String, Injector> injectors = CacheBuilder.newBuilder().build(new CacheLoader<String, Injector>() {
  24. @Override
  25. public Injector load(String language) throws Exception {
  26. Module runtimeModule = getRuntimeModule(language);
  27. Module sharedStateModule = getSharedStateModule();
  28. Module uiModule = getUiModule(language);
  29. Module mergedModule = override(override(runtimeModule).with(sharedStateModule)).with(uiModule);
  30. return createInjector(mergedModule);
  31. }
  32. });
  33. private static RefDslActivator INSTANCE;
  34. public static final String ORG_GROOVECLIPSE_ECORE_REFDSL = "org.grooveclipse.ecore.RefDsl";
  35. public Injector getInjector(String languageName) {
  36. try {
  37. return injectors.get(languageName);
  38. } catch(ExecutionException e) {
  39. logger.error("Failed to create injector for " + languageName);
  40. logger.error(e.getMessage(), e);
  41. throw new RuntimeException("Failed to create injector for " + languageName, e);
  42. }
  43. }
  44. @Override
  45. public void start(BundleContext context) throws Exception {
  46. super.start(context);
  47. INSTANCE = this;
  48. }
  49. @Override
  50. public void stop(BundleContext context) throws Exception {
  51. injectors.invalidateAll();
  52. injectors.cleanUp();
  53. INSTANCE = null;
  54. super.stop(context);
  55. }
  56. public static RefDslActivator getInstance() {
  57. return INSTANCE;
  58. }
  59. protected Module getRuntimeModule(String grammar) {
  60. if (ORG_GROOVECLIPSE_ECORE_REFDSL.equals(grammar)) {
  61. return new org.grooveclipse.ecore.RefDslRuntimeModule();
  62. }
  63. throw new IllegalArgumentException(grammar);
  64. }
  65. protected Module getUiModule(String grammar) {
  66. if (ORG_GROOVECLIPSE_ECORE_REFDSL.equals(grammar)) {
  67. return new org.grooveclipse.ecore.ui.RefDslUiModule(this);
  68. }
  69. throw new IllegalArgumentException(grammar);
  70. }
  71. protected Module getSharedStateModule() {
  72. return new SharedStateModule();
  73. }
  74. }