Merge branch 'better-json-fix' into json-fix-extended
authorChristian Femers <femers@in.tum.de>
Tue, 3 Sep 2019 05:47:55 +0000 (07:47 +0200)
committerChristian Femers <femers@in.tum.de>
Tue, 3 Sep 2019 05:47:55 +0000 (07:47 +0200)
net.mograsim.logic.model.am2900/META-INF/MANIFEST.MF
net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java
net.mograsim.machine/META-INF/MANIFEST.MF

index 6dfa183..e063ca6 100644 (file)
@@ -7,7 +7,6 @@ Export-Package: net.mograsim.logic.model.am2900,
  net.mograsim.logic.model.am2900.components,
  net.mograsim.logic.model.am2900.components.am2904,
  net.mograsim.logic.model.am2900.components.am2910,
- net.mograsim.logic.model.am2900.machine,
  net.mograsim.logic.model.examples
 Bundle-RequiredExecutionEnvironment: JavaSE-11
 Require-Bundle: net.mograsim.machine;bundle-version="0.1.0";visibility:=reexport,
index 05e4f2d..18d6640 100644 (file)
@@ -3,13 +3,10 @@ package net.mograsim.logic.model.serializing;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UncheckedIOException;
-import java.lang.reflect.InvocationTargetException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
-import java.util.function.Supplier;
-
 import com.google.gson.JsonElement;
 import com.google.gson.JsonNull;
 import com.google.gson.JsonObject;
@@ -27,6 +24,7 @@ public class IndirectGUIComponentCreator
 
        private static final Map<String, ComponentSupplier> componentSuppliers = new HashMap<>();
        private static final Map<String, ResourceLoader> resourceLoaders = new HashMap<>();
+       private static final Map<String, JsonObject> componentCache = new HashMap<>();
 
        static
        {
@@ -95,6 +93,8 @@ public class IndirectGUIComponentCreator
        {
                if (id != null)
                {
+                       if (componentCache.containsKey(id))
+                               return loadComponentFromJsonObject(model, id, name, componentCache.get(id));
                        String resolvedID = resolveID(id);
                        if (resolvedID != null)
                        {
@@ -135,7 +135,8 @@ public class IndirectGUIComponentCreator
                                                        JsonObject jsonContents = JsonHandler.readJson(loader.loadResource(resID), JsonObject.class);
                                                        return loadComponentFromJsonObject(model, id, name, jsonContents);
                                                }
-                                               loader.loadClass(resID);
+                                               if (!componentSuppliers.containsKey(resID))
+                                                       loader.loadClass(resID);
                                                ComponentSupplier componentSupplier = componentSuppliers.get(resID);
                                                if (componentSupplier != null)
                                                        return componentSupplier.create(model, params, name);
@@ -179,6 +180,7 @@ public class IndirectGUIComponentCreator
 
        private static SubmodelComponent loadComponentFromJsonObject(ViewModelModifiable model, String id, String name, JsonObject jsonContents)
        {
+               componentCache.putIfAbsent(id, jsonContents);
                SerializablePojo jsonContentsAsSerializablePojo = JsonHandler.parser.fromJson(jsonContents, SerializablePojo.class);
                if (jsonContentsAsSerializablePojo.version == null)
                        return LegacySubmodelComponentSerializer.deserialize(model,
index dfdcb05..8c6df1e 100644 (file)
@@ -6,9 +6,9 @@ Bundle-Version: 0.1.0.qualifier
 Bundle-Vendor: Mograsim Team
 Automatic-Module-Name: net.mograsim.machine
 Bundle-RequiredExecutionEnvironment: JavaSE-11
-Require-Bundle: net.mograsim.logic.core;bundle-version="0.1.0",
- net.mograsim.logic.model;bundle-version="0.1.0",
- net.mograsim.preferences
+Require-Bundle: net.mograsim.logic.core;bundle-version="0.1.0";visibility:=reexport,
+ net.mograsim.logic.model;bundle-version="0.1.0";visibility:=reexport,
+ net.mograsim.preferences;visibility:=reexport
 Export-Package: net.mograsim.machine,
  net.mograsim.machine.isa,
  net.mograsim.machine.isa.types,