package de.hsadmin.cli;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class Scripting {

	public static void main(String[] args) {
		ScriptEngineManager engineManager = new ScriptEngineManager();
		ScriptEngine engine = engineManager.getEngineByName("js");
		try {
			engine.eval("if (typeof user === 'undefined') { user = { }; };");
			engine.eval("user['name'] = 'Klaus-Dieter';");
			engine.eval("if (typeof user === 'undefined') { user = { }; };");
			engine.eval("user['age'] = 44;");
			engine.eval("print(user.name + '\\n');");
			engine.eval("print(user.age + '\\n');");
			engine.eval("print(user + '\\n');");
		} catch (ScriptException e) {
			System.err.println(e.getMessage());
		}
	}
	
}
