Restructured serializing/deserializing
[Mograsim.git] / net.mograsim.logic.model / src / net / mograsim / logic / model / snippets / highlevelstatehandlers / standard / StandardHighLevelStateHandlerSnippetSuppliers.java
1 package net.mograsim.logic.model.snippets.highlevelstatehandlers.standard;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.Map;
6
7 import net.mograsim.logic.model.snippets.CodeSnippetSupplier;
8 import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.atomic.AtomicHighLevelStateHandler;
9 import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.subcomponent.SubcomponentHighLevelStateHandler;
10 import net.mograsim.logic.model.util.JsonHandler;
11
12 public class StandardHighLevelStateHandlerSnippetSuppliers
13 {
14         public static final CodeSnippetSupplier<HighLevelStateHandlerContext, AtomicHighLevelStateHandler> atomicHandlerSupplier;
15         public static final CodeSnippetSupplier<HighLevelStateHandlerContext, SubcomponentHighLevelStateHandler> subcomponentHandlerSupplier;
16
17         static
18         {
19                 atomicHandlerSupplier = new CodeSnippetSupplier<>(null);
20                 subcomponentHandlerSupplier = new CodeSnippetSupplier<>(null);
21         }
22
23         static
24         {
25                 try (InputStream s = StandardHighLevelStateHandlerSnippetSuppliers.class.getResourceAsStream("./standardSnippetIDMapping.json"))
26                 {
27                         if (s == null)
28                                 throw new IOException("Resource not found");
29                         SnippetIDClassNames tmp = JsonHandler.readJson(s, SnippetIDClassNames.class);
30                         tmp.standardSubcomponentHandlerSuppliers.forEach(subcomponentHandlerSupplier::addStandardSnippetID);
31                         tmp.standardAtomicHandlerSuppliers.forEach(atomicHandlerSupplier::addStandardSnippetID);
32                 }
33                 catch (Exception e)
34                 {
35                         System.err.println("Failed to initialize standard snippet ID mapping: ");
36                         e.printStackTrace();
37                 }
38         }
39
40         private static class SnippetIDClassNames
41         {
42                 public Map<String, String> standardSubcomponentHandlerSuppliers;
43                 public Map<String, String> standardAtomicHandlerSuppliers;
44         }
45
46         private StandardHighLevelStateHandlerSnippetSuppliers()
47         {
48                 throw new UnsupportedOperationException();
49         }
50 }