{
this.machineDefinition = am2900MachineDefinition;
viewModel = new ViewModelModifiable();
- IndirectGUIComponentCreator.createComponent(viewModel, "resloader:Am2900Loader:jsonres:components/GUIAm2900.json");
+ IndirectGUIComponentCreator.createComponent(viewModel,
+ "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/GUIAm2900.json");
LogicModelParameters params = new LogicModelParameters();
params.gateProcessTime = 50;
params.wireTravelTime = 10;
public static void createTestbench(ViewModelModifiable model)
{
Am2900Loader.setup();
- GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "resloader:Am2900Loader:jsonres:components/GUIAm2900.json");
+ GUIComponent comp = IndirectGUIComponentCreator.createComponent(model,
+ "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/GUIAm2900.json");
List<String> inputPinNames = new ArrayList<>();
List<String> outputPinNames = new ArrayList<>();
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException
{
- return Class.forName(name, true, getClassLoader());// TODO duplication
+ return ReflectionHelper.tryInvokeStaticInitializer(name, getClassLoader());
}
public abstract ClassLoader getClassLoader();
import net.mograsim.logic.model.model.ViewModelModifiable;
import net.mograsim.logic.model.model.components.GUIComponent;
import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
-import net.mograsim.logic.model.snippets.CodeSnippetSupplier;
import net.mograsim.logic.model.util.JsonHandler;
public class IndirectGUIComponentCreator
private static void tryLoadResourceLoader(String loaderClassName)
{
- CodeSnippetSupplier.tryInvokeStaticInitializer(loaderClassName, "Error loading resoruce loader %s: %s\n");
+ ReflectionHelper.tryInvokeStaticInitializer(loaderClassName, "Error loading resoruce loader %s: %s\n");
}
public static interface ComponentSupplier
--- /dev/null
+package net.mograsim.logic.model.serializing;
+
+public class ReflectionHelper
+{
+ private ReflectionHelper()
+ {
+ }
+
+ public static Class<?> tryInvokeStaticInitializer(String className, String errorMessageFormat)
+ {
+ return tryInvokeStaticInitializer(className, errorMessageFormat, ReflectionHelper.class.getClassLoader());
+ }
+
+ public static Class<?> tryInvokeStaticInitializer(String className, String errorMessageFormat, ClassLoader classLoader)
+ {
+ try
+ {
+ return tryInvokeStaticInitializer(className, classLoader);
+ }
+ catch (ClassNotFoundException e)
+ {
+ System.err.printf(errorMessageFormat, className, "ClassNotFoundException thrown: " + e.getMessage());
+ return null;
+ }
+ }
+
+ public static Class<?> tryInvokeStaticInitializer(String className) throws ClassNotFoundException
+ {
+ return tryInvokeStaticInitializer(className, ReflectionHelper.class.getClassLoader());
+ }
+
+ public static Class<?> tryInvokeStaticInitializer(String className, ClassLoader classLoader) throws ClassNotFoundException
+ {
+ return Class.forName(className, true, classLoader);
+ }
+}
\ No newline at end of file
import java.util.HashMap;
import java.util.Map;
+import net.mograsim.logic.model.serializing.ReflectionHelper;
+
public class CodeSnippetSupplier<C, S>
{
private final Map<String, String> standardSnippetIDClassNames = new HashMap<>();
private static void tryLoadSnippetClass(String snippetClassName)
{
- tryInvokeStaticInitializer(snippetClassName, "Error getting snippet class: %s: %s\n");
+ ReflectionHelper.tryInvokeStaticInitializer(snippetClassName, "Error getting snippet class: %s: %s\n");
}
-
- public static void tryInvokeStaticInitializer(String className, String errorMessageFormat)
- {
- try
- {
- Class.forName(className, true, CodeSnippetSupplier.class.getClassLoader());
- }
- catch (ClassNotFoundException e)
- {
- System.err.printf(errorMessageFormat, className, "ClassNotFoundException thrown: " + e.getMessage());
- }
- }
-
}
\ No newline at end of file