Needed to add special class loading, too
authorChristian Femers <femers@in.tum.de>
Tue, 3 Sep 2019 04:51:28 +0000 (06:51 +0200)
committerChristian Femers <femers@in.tum.de>
Tue, 3 Sep 2019 04:51:28 +0000 (06:51 +0200)
net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java
net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/ResourceLoader.java

index f346d02..05e4f2d 100644 (file)
@@ -130,8 +130,16 @@ public class IndirectGUIComponentCreator
                                                {
                                                        loader = Objects.requireNonNull(resourceLoaders.get(parts[1]));
                                                }
-                                               JsonObject jsonContents = JsonHandler.readJson(loader.loadResource(resID), JsonObject.class);
-                                               return loadComponentFromJsonObject(model, id, name, jsonContents);
+                                               if (resID.endsWith(".json"))
+                                               {
+                                                       JsonObject jsonContents = JsonHandler.readJson(loader.loadResource(resID), JsonObject.class);
+                                                       return loadComponentFromJsonObject(model, id, name, jsonContents);
+                                               }
+                                               loader.loadClass(resID);
+                                               ComponentSupplier componentSupplier = componentSuppliers.get(resID);
+                                               if (componentSupplier != null)
+                                                       return componentSupplier.create(model, params, name);
+                                               throw new IllegalArgumentException("Component supplier not found for ID " + id + " (class cannot initialize?)");
                                        }
                                        catch (IOException e)
                                        {
@@ -139,7 +147,7 @@ public class IndirectGUIComponentCreator
                                        }
                                        catch (ClassCastException | ReflectiveOperationException e)
                                        {
-                                               throw new IllegalArgumentException("invaild resource loader specified:" + parts[1], e);
+                                               throw new IllegalArgumentException("class not found / invaild resource loader specified:" + parts[1], e);
                                        }
                                } else if (resolvedID.startsWith("file:"))
                                {
index 83dd745..1052d5f 100644 (file)
@@ -20,4 +20,6 @@ import net.mograsim.logic.model.model.components.GUIComponent;
 public interface ResourceLoader
 {
        InputStream loadResource(String path) throws IOException;
+
+       Class<?> loadClass(String name) throws ClassNotFoundException;
 }