diff --git a/rules/src/main/java/ch/maxant/rules/Engine.java b/rules/src/main/java/ch/maxant/rules/Engine.java index d7dd827..9fdc517 100644 --- a/rules/src/main/java/ch/maxant/rules/Engine.java +++ b/rules/src/main/java/ch/maxant/rules/Engine.java @@ -116,7 +116,8 @@ public class Engine { protected final boolean throwExceptionIfCompilationFails; protected final String inputName; - + protected final Map varBindings; + //reserved for subclasses and not used in this class - yuck, but hey. protected final String[] javascriptFilesToLoad; protected final Integer poolSize; @@ -140,6 +141,7 @@ public Engine(final Collection rules, String inputName, boolean throwExcep this(rules, inputName, throwExceptionIfCompilationFails, null, null, new HashMap()); } + /** * See {@link #Engine(Collection, String, boolean, Map)} */ @@ -165,13 +167,14 @@ public Engine(final Collection rules, String inputName, boolean throwExcep protected Engine(final Collection rules, String inputName, boolean throwExceptionIfCompilationFails, Integer poolSize, String[] javascriptFilesToLoad, Map statics) throws DuplicateNameException, CompileException, ParseException { this.inputName = inputName; + this.varBindings = varBindings; this.throwExceptionIfCompilationFails = throwExceptionIfCompilationFails; this.javascriptFilesToLoad = javascriptFilesToLoad; this.poolSize = poolSize; this.statics = statics; init(rules); } - + /** handles the initialisation */ protected void init(Collection rules) throws DuplicateNameException, CompileException, ParseException { log.info("\r\n\r\n*****Initialising rule engine...*****"); @@ -441,6 +444,7 @@ public List getMatchingRules(String nameSpacePattern, Input input) } Map vars = new HashMap(statics); // initialise with static stuff + vars.put(inputName, input); List matchingRules = new ArrayList(); @@ -485,4 +489,4 @@ private Rule getRule() { } - \ No newline at end of file + diff --git a/rules/src/main/java/ch/maxant/rules/JavascriptEngine.java b/rules/src/main/java/ch/maxant/rules/JavascriptEngine.java index a6b9cc8..a4cf30b 100644 --- a/rules/src/main/java/ch/maxant/rules/JavascriptEngine.java +++ b/rules/src/main/java/ch/maxant/rules/JavascriptEngine.java @@ -165,7 +165,7 @@ public JavascriptEngine(final Collection rules, String inputName, boolean } } } - + /** * Subclasses may override this. But the default will create a config which sets up the * pool using the size passed into the constructor, otherwise accessible as diff --git a/rules/src/test/java/ch/maxant/rules/blackbox/AbstractEngineTest.java b/rules/src/test/java/ch/maxant/rules/blackbox/AbstractEngineTest.java index de09a2e..c1b3a2e 100644 --- a/rules/src/test/java/ch/maxant/rules/blackbox/AbstractEngineTest.java +++ b/rules/src/test/java/ch/maxant/rules/blackbox/AbstractEngineTest.java @@ -48,6 +48,8 @@ public abstract class AbstractEngineTest { public abstract Engine getEngine(List rules, boolean throwExceptionIfCompilationFails) throws DuplicateNameException, CompileException, ParseException, ScriptException, IOException; + + public abstract Engine getEngine(List rules, String inputName, Map varBindings, boolean throwExceptionIfCompilationFails) throws DuplicateNameException, CompileException, ParseException, ScriptException, IOException; protected abstract boolean isJavascriptTest(); diff --git a/rules/src/test/java/ch/maxant/rules/blackbox/DefaultEngineTest.java b/rules/src/test/java/ch/maxant/rules/blackbox/DefaultEngineTest.java index ddeb6ac..db55d2c 100644 --- a/rules/src/test/java/ch/maxant/rules/blackbox/DefaultEngineTest.java +++ b/rules/src/test/java/ch/maxant/rules/blackbox/DefaultEngineTest.java @@ -39,6 +39,11 @@ public class DefaultEngineTest extends AbstractEngineTest { public Engine getEngine(List rules, boolean throwExceptionIfCompilationFails) throws DuplicateNameException, CompileException, ParseException { return new Engine(rules, throwExceptionIfCompilationFails); } + + @Override + public Engine getEngine(List rules, String inputName, Map varBindings, boolean throwExceptionIfCompilationFails) throws DuplicateNameException, CompileException, ParseException { + return new Engine(rules, inputName, varBindings, throwExceptionIfCompilationFails); + } @Override protected boolean isJavascriptTest() { diff --git a/rules/src/test/java/ch/maxant/rules/blackbox/JavascriptEngineTest.java b/rules/src/test/java/ch/maxant/rules/blackbox/JavascriptEngineTest.java index 22ea4d8..58c69a3 100644 --- a/rules/src/test/java/ch/maxant/rules/blackbox/JavascriptEngineTest.java +++ b/rules/src/test/java/ch/maxant/rules/blackbox/JavascriptEngineTest.java @@ -39,6 +39,12 @@ public Engine getEngine(List rules, boolean throwExceptionIfCompilationFai return new JavascriptEngine(rules, throwExceptionIfCompilationFails); } + @Override + public Engine getEngine(List rules, String inputName, Map varBindings, boolean throwExceptionIfCompilationFails) + throws DuplicateNameException, CompileException, ParseException, ScriptException, IOException { + return new JavascriptEngine(rules, inputName, varBindings, throwExceptionIfCompilationFails); + } + @Override protected boolean isJavascriptTest() { return true;