use of org.phoenicis.scripts.wizard.UiSetupWizardImplementation in project POL-POM-5 by PlayOnLinux.
the class NashornEngineFactory method createEngine.
NashornEngine createEngine() {
final Set<List<String>> includedScripts = new HashSet<>();
final NashornEngine nashornEngine = new NashornEngine(new ScriptEngineManager().getEngineByName("nashorn"));
nashornEngine.eval(new InputStreamReader(getClass().getResourceAsStream("utils.js")), this::throwException);
nashornEngine.put("Bean", (Function<String, Object>) title -> applicationContext.getBean(title), this::throwException);
nashornEngine.put("SetupWizard", (Function<String, UiSetupWizardImplementation>) (name) -> {
final UiSetupWizardImplementation uiSetupWizardImplementation = uiSetupWizardFactory.create(name);
nashornEngine.addErrorHandler(e -> uiSetupWizardImplementation.close());
return uiSetupWizardImplementation;
}, this::throwException);
nashornEngine.put("EngineProgressUi", (Function<String, UiProgressWizardImplementation>) (name) -> {
final UiProgressWizardImplementation uiProgressWizardImplementation = uiProgressWizardFactory.create(name);
nashornEngine.addErrorHandler(e -> uiProgressWizardImplementation.close());
return uiProgressWizardImplementation;
}, this::throwException);
nashornEngine.put("include", (Consumer<ScriptObjectMirror>) args -> {
final String[] arguments = args.to(String[].class);
final String script = scriptFetcher.getScript(arguments);
if (script == null) {
throwException(new ScriptException(Arrays.asList(arguments).toString() + " is not found"));
}
if (includedScripts.add(Arrays.asList(arguments))) {
nashornEngine.eval("//# sourceURL=" + Arrays.asList(arguments).toString() + "\n" + script, this::throwException);
}
}, this::throwException);
return nashornEngine;
}
Aggregations