From e49bb8ff62881d402d23aba150e5aa03409f760f Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Thu, 22 Mar 2018 15:54:06 +0100 Subject: [PATCH] Updated RulesManager --- .classpath | 2 +- .../org/warp/picalculator/math/rules/Rule.java | 4 +++- .../picalculator/math/rules/RulesManager.java | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.classpath b/.classpath index f048d21f..6c802bcb 100644 --- a/.classpath +++ b/.classpath @@ -6,7 +6,7 @@ - + diff --git a/src/main/java/org/warp/picalculator/math/rules/Rule.java b/src/main/java/org/warp/picalculator/math/rules/Rule.java index 821bd3b3..82c8a1db 100644 --- a/src/main/java/org/warp/picalculator/math/rules/Rule.java +++ b/src/main/java/org/warp/picalculator/math/rules/Rule.java @@ -1,5 +1,7 @@ package org.warp.picalculator.math.rules; +import java.io.Serializable; + import org.warp.picalculator.math.Function; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -10,7 +12,7 @@ import jdk.nashorn.internal.objects.annotations.SpecializedFunction; * @author Andrea Cavalli * */ -public interface Rule { +public interface Rule extends Serializable { /** * Get rule name * @return diff --git a/src/main/java/org/warp/picalculator/math/rules/RulesManager.java b/src/main/java/org/warp/picalculator/math/rules/RulesManager.java index 1395e0c8..d30ac325 100644 --- a/src/main/java/org/warp/picalculator/math/rules/RulesManager.java +++ b/src/main/java/org/warp/picalculator/math/rules/RulesManager.java @@ -109,21 +109,21 @@ public class RulesManager { } } if (!loadedFromCache) { - Rule r; + Rule r = null; try { r = compileJavaRule(scriptFile); RulesManager.addRule(r); + + Path p = Paths.get(compiledFile.replace("/", "_")).toAbsolutePath(); + System.out.println(p); + p.toFile().createNewFile(); + OutputStream fout = Files.newOutputStream(p, StandardOpenOption.CREATE); + ObjectOutputStream oos = new ObjectOutputStream(fout); + oos.writeObject(r); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } - - Path p = Paths.get(compiledFile.replace("/", "_")).toAbsolutePath(); - System.out.println(p); - p.toFile().createNewFile(); - OutputStream fout = Files.newOutputStream(p, StandardOpenOption.CREATE); - ObjectOutputStream oos = new ObjectOutputStream(fout); - oos.writeObject(script); } }