Java Code Examples for groovy.lang.GroovyShell#setVariable()

The following examples show how to use groovy.lang.GroovyShell#setVariable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroovyScriptEngine.java    From jeewx with Apache License 2.0 5 votes vote down vote up
private void setParameters(GroovyShell shell, Map<String, Object> vars) {
	if (vars == null)
		return;
	Set<?> set = vars.entrySet();
	for (Iterator<?> it = set.iterator(); it.hasNext();) {
		@SuppressWarnings("rawtypes")
		Map.Entry entry = (Map.Entry) it.next();
		shell.setVariable((String) entry.getKey(), entry.getValue());
	}
}
 
Example 2
Source File: GroovyEngine.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the engine.
 */
public void initialize(BSFManager mgr, String lang, Vector declaredBeans) throws BSFException {
    super.initialize(mgr, lang, declaredBeans);

    // create a shell
    shell = new GroovyShell(mgr.getClassLoader());

    // register the mgr with object name "bsf"
    shell.setVariable("bsf", new BSFFunctions(mgr, this));

    int size = declaredBeans.size();
    for (int i = 0; i < size; i++) {
        declareBean((BSFDeclaredBean) declaredBeans.elementAt(i));
    }
}
 
Example 3
Source File: GroovySandbox.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
private void setBindingsOnShell(GroovyShell shell) {
	for (String name : bindings.keySet()) {
		shell.setVariable(name, bindings.get(name));
	}
}