X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fserializing%2FIndirectGUIComponentCreator.java;h=2b747b2aba5b0557a96889299470f42665ae2d79;hb=4c9a2240352c246c76a056687a2d68208137b667;hp=884e3ba8725352d9b6a1dec570869a19faa6f4b8;hpb=1e23dc8fad83d496ed7c4fd3a681574366cd8d17;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java index 884e3ba8..2b747b2a 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java @@ -6,7 +6,6 @@ import java.io.UncheckedIOException; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.Set; import com.google.gson.JsonElement; import com.google.gson.JsonNull; @@ -19,7 +18,7 @@ import net.mograsim.logic.model.util.JsonHandler; public class IndirectGUIComponentCreator { private static final Map standardComponentIDs = new HashMap<>(); - private static final Set standardComponentIDSetUnmodifiable = Collections.unmodifiableSet(standardComponentIDs.keySet()); + private static final Map standardComponentIDsUnmodifiable = Collections.unmodifiableMap(standardComponentIDs); private static final Map componentSuppliers = new HashMap<>(); @@ -56,9 +55,9 @@ public class IndirectGUIComponentCreator standardComponentIDs.put(standardComponentID, associatedComponentID); } - public static Set getStandardComponentIDs() + public static Map getStandardComponentIDs() { - return standardComponentIDSetUnmodifiable; + return standardComponentIDsUnmodifiable; } public static void setComponentSupplier(String className, ComponentSupplier componentSupplier) @@ -85,11 +84,7 @@ public class IndirectGUIComponentCreator { if (id != null) { - String resolvedID; - if (id.startsWith("class:") || id.startsWith("file:")) - resolvedID = id; - else - resolvedID = standardComponentIDs.get(id); + String resolvedID = resolveID(id); if (resolvedID != null) { if (resolvedID.startsWith("class:")) @@ -99,6 +94,7 @@ public class IndirectGUIComponentCreator ComponentSupplier componentSupplier = componentSuppliers.get(className); if (componentSupplier != null) return componentSupplier.create(model, params, name); + throw new IllegalArgumentException("Component supplier not found for ID " + id + " (resolved: " + resolvedID + ")"); } else // we know id has to start with "file:" here // because standardComponentIDs only contains strings starting with "class:" or "file:" @@ -117,6 +113,13 @@ public class IndirectGUIComponentCreator throw new RuntimeException("Could not get component supplier for ID " + id); } + public static String resolveID(String id) + { + if (id.startsWith("class:") || id.startsWith("file:")) + return id; + return standardComponentIDs.get(id); + } + private static void tryLoadComponentClass(String componentClassName) { CodeSnippetSupplier.tryInvokeStaticInitializer(componentClassName, "Error loading component class %s: %s\n");