source: default/v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src-gen/de/ugoe/cs/swe/bnftools/ui/internal/EbnfActivator.java

Last change on this file was 61, checked in by hkaulbersch, 10 years ago

initial commit

  • Property svn:mime-type set to text/plain
File size: 2.6 KB
Line 
1/*
2 * generated by Xtext
3 */
4package de.ugoe.cs.swe.bnftools.ui.internal;
5
6import java.util.Collections;
7import java.util.Map;
8
9import org.apache.log4j.Logger;
10import org.eclipse.ui.plugin.AbstractUIPlugin;
11import org.eclipse.xtext.ui.shared.SharedStateModule;
12import org.eclipse.xtext.util.Modules2;
13import org.osgi.framework.BundleContext;
14
15import com.google.common.collect.Maps;
16import com.google.inject.Guice;
17import com.google.inject.Injector;
18import com.google.inject.Module;
19
20/**
21 * This class was generated. Customizations should only happen in a newly
22 * introduced subclass.
23 */
24public class EbnfActivator extends AbstractUIPlugin {
25       
26        public static final String DE_UGOE_CS_SWE_BNFTOOLS_EBNF = "de.ugoe.cs.swe.bnftools.Ebnf";
27       
28        private static final Logger logger = Logger.getLogger(EbnfActivator.class);
29       
30        private static EbnfActivator INSTANCE;
31       
32        private Map<String, Injector> injectors = Collections.synchronizedMap(Maps.<String, Injector> newHashMapWithExpectedSize(1));
33       
34        @Override
35        public void start(BundleContext context) throws Exception {
36                super.start(context);
37                INSTANCE = this;
38        }
39       
40        @Override
41        public void stop(BundleContext context) throws Exception {
42                injectors.clear();
43                INSTANCE = null;
44                super.stop(context);
45        }
46       
47        public static EbnfActivator getInstance() {
48                return INSTANCE;
49        }
50       
51        public Injector getInjector(String language) {
52                synchronized (injectors) {
53                        Injector injector = injectors.get(language);
54                        if (injector == null) {
55                                injectors.put(language, injector = createInjector(language));
56                        }
57                        return injector;
58                }
59        }
60       
61        protected Injector createInjector(String language) {
62                try {
63                        Module runtimeModule = getRuntimeModule(language);
64                        Module sharedStateModule = getSharedStateModule();
65                        Module uiModule = getUiModule(language);
66                        Module mergedModule = Modules2.mixin(runtimeModule, sharedStateModule, uiModule);
67                        return Guice.createInjector(mergedModule);
68                } catch (Exception e) {
69                        logger.error("Failed to create injector for " + language);
70                        logger.error(e.getMessage(), e);
71                        throw new RuntimeException("Failed to create injector for " + language, e);
72                }
73        }
74
75        protected Module getRuntimeModule(String grammar) {
76                if (DE_UGOE_CS_SWE_BNFTOOLS_EBNF.equals(grammar)) {
77                        return new de.ugoe.cs.swe.bnftools.EbnfRuntimeModule();
78                }
79               
80                throw new IllegalArgumentException(grammar);
81        }
82       
83        protected Module getUiModule(String grammar) {
84                if (DE_UGOE_CS_SWE_BNFTOOLS_EBNF.equals(grammar)) {
85                        return new de.ugoe.cs.swe.bnftools.ui.EbnfUiModule(this);
86                }
87               
88                throw new IllegalArgumentException(grammar);
89        }
90       
91        protected Module getSharedStateModule() {
92                return new SharedStateModule();
93        }
94       
95}
Note: See TracBrowser for help on using the repository browser.