IndirectModelComponentCreator no longer caches jsonfile: components
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 11 Apr 2020 12:15:58 +0000 (14:15 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 11 Apr 2020 12:15:58 +0000 (14:15 +0200)
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectModelComponentCreator.java

index 926e48b..13205b2 100644 (file)
@@ -95,7 +95,7 @@ public class IndirectModelComponentCreator
                if (id == null)
                        throw new NullPointerException("Component ID is null");
                if (componentCache.containsKey(id))
-                       return loadComponentFromJsonObject(model, id, name, componentCache.get(id));
+                       return loadComponentFromJsonObject(model, id, name, componentCache.get(id), false);
                String resolvedID = resolveID(id);
                if (resolvedID == null)
                        throw new IllegalArgumentException("Unknown standard ID or illegal resolved ID: " + id);
@@ -113,7 +113,7 @@ public class IndirectModelComponentCreator
                        {
                                throw new UncheckedIOException("Error loading JSON file", e);
                        }
-                       return loadComponentFromJsonObject(model, id, name, jsonContents);
+                       return loadComponentFromJsonObject(model, id, name, jsonContents, false);
                }
                ResourceLoader loader;
                String resTypeID;
@@ -149,7 +149,7 @@ public class IndirectModelComponentCreator
                        {
                                throw new UncheckedIOException("Error loading JSON resource", e);
                        }
-                       return loadComponentFromJsonObject(model, id, name, jsonContents);
+                       return loadComponentFromJsonObject(model, id, name, jsonContents, true);
                } else if (resTypeID.equals("class"))
                {
                        ComponentSupplier componentSupplier = componentSuppliers.get(resID);
@@ -184,9 +184,10 @@ public class IndirectModelComponentCreator
        }
 
        private static SubmodelComponent loadComponentFromJsonObject(LogicModelModifiable model, String id, String name,
-                       SubmodelComponentParams jsonContents)
+                       SubmodelComponentParams jsonContents, boolean cache)
        {
-               componentCache.putIfAbsent(id, jsonContents);
+               if (cache)
+                       componentCache.putIfAbsent(id, jsonContents);
                return SubmodelComponentSerializer.deserialize(model, jsonContents, name, id, null);
        }