Added activator to scan for machines, everything works now.
[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();
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"); // TODO: Debug
36         }
37
38         /**
39          * @see ResourceLoader
40          */
41         public static ResourceLoader resourceLoader()
42         {
43                 return new Am2900ResourceLoader();
44         }
45
46         static class Am2900ResourceLoader implements ResourceLoader
47         {
48                 @Override
49                 public InputStream loadResource(String path) throws IOException
50                 {
51                         return Am2900ResourceLoader.class.getResourceAsStream(path);
52                 }
53
54                 @Override
55                 public Class<?> loadClass(String name) throws ClassNotFoundException
56                 {
57                         return Class.forName(name, true, Am2900ResourceLoader.class.getClassLoader());
58                 }
59         }
60 }