001package com.example.contrived;
002
003/* (c) 2016 randomnoun. All Rights Reserved. This work is licensed under a
004 * BSD Simplified License. ( http://www.randomnoun.com/bsd-simplified.html ) 
005 */
006
007import java.io.File;
008import java.io.FileNotFoundException;
009import java.util.Scanner;
010
011import javax.script.Bindings;
012import javax.script.ScriptEngine;
013import javax.script.ScriptEngineManager;
014import javax.script.ScriptException;
015
016/** Simple jessop example  
017 * 
018 * @author knoxg
019 */
020public class JessopExample {
021
022        public void main(String args[]) throws FileNotFoundException, ScriptException {
023                String filename = args[1];
024                Scanner scanner = new Scanner(new File(filename));
025                String input = scanner.useDelimiter("\\Z").next();
026                scanner.close();
027                ScriptEngine engine = new ScriptEngineManager().getEngineByName("jessop");
028                if (engine==null) { throw new IllegalStateException("Missing engine 'jessop'"); }
029                // maybe put a function in here, to be called by the script
030                // or a compound object
031                Bindings b = engine.createBindings();
032                b.put("name", "Count von Count"); // I have been told it is actually "Count von Count"
033                b.put("maxCount", 4);
034                engine.eval(input);
035        }
036}