A proposal for resolving the loading problem of json files
[Mograsim.git] / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / am2900 / Am2900Loader.java
1 package net.mograsim.logic.model.am2900;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.concurrent.atomic.AtomicBoolean;
6
7 import org.osgi.framework.BundleActivator;
8 import org.osgi.framework.BundleContext;
9
10 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
11 import net.mograsim.logic.model.serializing.ResourceLoader;
12
13 public class Am2900Loader implements BundleActivator
14 {
15         private static AtomicBoolean activated = new AtomicBoolean(false);
16
17         @Override
18         public void start(BundleContext context) throws Exception
19         {
20                 setup(); // TODO: useful?
21         }
22
23         @Override
24         public void stop(BundleContext context) throws Exception
25         {
26                 // nothing
27         }
28
29         public static void setup()
30         {
31                 if (activated.getAndSet(true))
32                         return;
33                 IndirectGUIComponentCreator.registerResourceLoader(new Am2900ResourceLoader(), "Am2900Loader");
34                 IndirectGUIComponentCreator.loadStandardComponentIDs(Am2900Loader.class.getResourceAsStream("standardComponentIDMapping.json"));
35                 System.out.println("SETUP DONE");
36         }
37
38         static
39         {
40                 setup();
41         }
42
43         /**
44          * @see ResourceLoader
45          */
46         public static ResourceLoader resourceLoader()
47         {
48                 return new Am2900ResourceLoader();
49         }
50
51         static class Am2900ResourceLoader implements ResourceLoader
52         {
53                 @Override
54                 public InputStream loadResource(String path) throws IOException
55                 {
56                         return Am2900ResourceLoader.class.getResourceAsStream(path);
57                 }
58         }
59 }