Merge branch 'development' of https://gitlab.lrz.de/lrr-tum/students/eragp-misim...
[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                 // TODO update standardSnippetIDMapping.json
26                 try (InputStream s = StandardHighLevelStateHandlerSnippetSuppliers.class.getResourceAsStream("./standardSnippetIDMapping.json"))
27                 {
28                         if (s == null)
29                                 throw new IOException("Resource not found");
30                         SnippetIDClassNames tmp = JsonHandler.readJson(s, SnippetIDClassNames.class);
31                         tmp.standardSubcomponentHandlerSuppliers.forEach(subcomponentHandlerSupplier::addStandardSnippetID);
32                         tmp.standardAtomicHandlerSuppliers.forEach(atomicHandlerSupplier::addStandardSnippetID);
33                 }
34                 catch (Exception e)
35                 {
36                         System.err.println("Failed to initialize standard snippet ID mapping: ");
37                         e.printStackTrace();
38                 }
39         }
40
41         private static class SnippetIDClassNames
42         {
43                 public Map<String, String> standardSubcomponentHandlerSuppliers;
44                 public Map<String, String> standardAtomicHandlerSuppliers;
45         }
46
47         private StandardHighLevelStateHandlerSnippetSuppliers()
48         {
49                 throw new UnsupportedOperationException();
50         }
51 }