当前位置: 首页>>代码示例>>Java>>正文


Java GroovyShell.setVariable方法代码示例

本文整理汇总了Java中groovy.lang.GroovyShell.setVariable方法的典型用法代码示例。如果您正苦于以下问题:Java GroovyShell.setVariable方法的具体用法?Java GroovyShell.setVariable怎么用?Java GroovyShell.setVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在groovy.lang.GroovyShell的用法示例。


在下文中一共展示了GroovyShell.setVariable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: instantiateScriplet

import groovy.lang.GroovyShell; //导入方法依赖的package包/类
private Object instantiateScriplet(String scripletFilename)
		throws Exception {
	String[] tokens = SorcerUtil.tokenize(scripletFilename, "|");
	Object bean = null;
	Object configurator = null;
	GroovyShell shell = new GroovyShell();
	bean = shell.evaluate(new File(tokens[0]));
	for (int i = 1; i < tokens.length; i++) {
		configurator = shell.evaluate(new File(tokens[i]));
		if ((configurator instanceof Configurator)
				&& (bean instanceof Configurable)) {
			shell.setVariable("configurable", bean);
			bean = ((Configurator) configurator).configure();
		}
	}
	initBean(bean);
	return bean;
}
 
开发者ID:mwsobol,项目名称:SORCER,代码行数:19,代码来源:ProviderDelegate.java

示例2: runGroovyScript

import groovy.lang.GroovyShell; //导入方法依赖的package包/类
private void runGroovyScript() {

        SwingWorker worker = new SwingWorker<String, String>() {
            PrintStream oout = System.out;
            PrintStream oerr = System.err;

            @Override
            protected String doInBackground() throws Exception {
                //JTextAreaWriter writer = new JTextAreaWriter(jTextArea_Output);
                JTextAreaPrintStream printStream = new JTextAreaPrintStream(System.out, jTextArea_Output);
                jTextArea_Output.setText("");

                // Create an instance of the PythonInterpreter                                
                //String[] roots = new String[]{"./src"};
                //GroovyScriptEngine gse = new GroovyScriptEngine(roots);   
                GroovyShell shell = new GroovyShell();
                System.setOut(printStream);
                System.setErr(printStream);
                shell.setVariable("miapp", _parent);

                TextEditorPane textArea = getActiveTextArea();
                String code = textArea.getText();
                try {
                    Script script = shell.parse(code);
                    script.run();
                } catch (Exception e) {
                }

                return "";
            }

            @Override
            protected void done() {
                System.setOut(oout);
                System.setErr(oerr);
            }
        };
        worker.execute();
    }
 
开发者ID:meteoinfo,项目名称:MeteoInfoMap,代码行数:40,代码来源:FrmTextEditor.java

示例3: initialize

import groovy.lang.GroovyShell; //导入方法依赖的package包/类
/**
 * 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));
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:GroovyEngine.java

示例4: testGroovy

import groovy.lang.GroovyShell; //导入方法依赖的package包/类
@org.junit.Test
public void testGroovy() throws Exception {
  GroovyShell shell = new GroovyShell();
  shell.setVariable("done", (Runnable) () -> {
    testComplete();
  });
  shell.evaluate(LangTest.class.getResource("/plain/timer.groovy").toURI());
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-unit,代码行数:10,代码来源:LangTest.java

示例5: doWork

import groovy.lang.GroovyShell; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
	String script = getParameterAsString(PARAMETER_SCRIPT);
	if (getParameterAsBoolean(PARAMETER_STANDARD_IMPORTS)) {
		StringBuffer imports = new StringBuffer();
		imports.append("import com.rapidminer.example.*;\n");
		imports.append("import com.rapidminer.example.set.*;\n");
		imports.append("import com.rapidminer.example.table.*;\n");
		imports.append("import com.rapidminer.operator.*;\n");
		imports.append("import com.rapidminer.tools.Tools;\n");
		imports.append("import java.util.*;\n");

		script = imports.toString() + script;
	}

	Object result;
	try {
		GroovyShell shell = new GroovyShell(Plugin.getMajorClassLoader());
		// GroovyShell shell = new GroovyShell(ScriptingOperator.class.getClassLoader());
		List<IOObject> input = inExtender.getData(IOObject.class, false);
		shell.setVariable("input", input);
		shell.setVariable("operator", this);

		Script parsedScript = shell.parse(script);
		result = parsedScript.run();
	} catch (Throwable e) {
		throw new UserError(this, e, 945, "Groovy", e);
	}
	if (result instanceof Object[]) {
		outExtender.deliver(Arrays.asList((IOObject[]) result));
	} else if (result instanceof List) {
		List<IOObject> results = new LinkedList<IOObject>();
		for (Object single : (List) result) {
			if (single instanceof IOObject) {
				results.add((IOObject) single);
			} else {
				getLogger().warning("Unknown result type: " + single);
			}
		}
		outExtender.deliver(results);
	} else {
		if (result != null) {
			if (result instanceof IOObject) {
				outExtender.deliver(Collections.singletonList((IOObject) result));
				;
			} else {
				getLogger().warning("Unknown result: " + result.getClass() + ": " + result);
			}
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:52,代码来源:ScriptingOperator.java

示例6: evaluate

import groovy.lang.GroovyShell; //导入方法依赖的package包/类
@Override public Object evaluate(Object data) {
    GroovyShell groovy = new GroovyShell();
    groovy.setVariable("data", data);
    return groovy.evaluate(expression);
}
 
开发者ID:cescoffier,项目名称:fluid,代码行数:6,代码来源:GroovyDataExpression.java

示例7: main

import groovy.lang.GroovyShell; //导入方法依赖的package包/类
public static void main(String[] args) {
    if (args.length <= 0) {
        System.out.println("Usage: home [configuaration] [localcopy]");
        return;
    }

    String home = args[0];

    Properties p = new Properties();
    System.setProperty("openejb.home", home);
    p.put(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.LocalInitialContextFactory");
    p.put("openejb.loader", "embed");
    p.put("openejb.home", home);

    if (args.length > 1) {
        String conf = args[1];
        System.setProperty("openejb.configuration", conf);
        p.put("openejb.configuration", conf);
    }
    if (args.length > 2) {
        String copy = args[2];
        System.setProperty("openejb.localcopy", copy);
        p.put("openejb.localcopy", copy);
    }
    try {
        InitialContext ctx = new InitialContext(p);

        GroovyShell shell = new GroovyShell();
        shell.setVariable("context", ctx);
        //shell.evaluate("src/test/groovy/j2ee/CreateData.groovy");

        //shell.evaluate("src/main/groovy/ui/Console.groovy");
        GroovyObject console = (GroovyObject) InvokerHelper.invokeConstructorOf("groovy.ui.Console", null);
        console.setProperty("shell", shell);
        console.invokeMethod("run", null);
        /*
        */
    }
    catch (Exception e) {
        System.out.println("Caught: " + e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:43,代码来源:J2eeConsole.java

示例8: doWork

import groovy.lang.GroovyShell; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {		
	String script = getParameterAsString(PARAMETER_SCRIPT);
	if (getParameterAsBoolean(PARAMETER_STANDARD_IMPORTS)) {
		StringBuffer imports = new StringBuffer();
		imports.append("import com.rapidminer.example.*;\n");
		imports.append("import com.rapidminer.example.set.*;\n");
		imports.append("import com.rapidminer.example.table.*;\n");
		imports.append("import com.rapidminer.operator.*;\n");
		imports.append("import com.rapidminer.tools.Tools;\n");
		imports.append("import java.util.*;\n");

		script = imports.toString() + script;
	}

	Object result;
	try {	
		GroovyShell shell = new GroovyShell(Plugin.getMajorClassLoader());
		//GroovyShell shell = new GroovyShell(ScriptingOperator.class.getClassLoader());
		List<IOObject> input = inExtender.getData(IOObject.class, false);		
		shell.setVariable("input", input);
		shell.setVariable("operator", this);

		Script parsedScript = shell.parse(script);
		result = parsedScript.run();
	} catch (Throwable e) {
		throw new UserError(this, e, 945, "Groovy", e);
	}
	if (result instanceof Object[]) {
		outExtender.deliver(Arrays.asList((IOObject[])result));
	} else if (result instanceof List) {
		List<IOObject> results = new LinkedList<IOObject>();
		for (Object single : (List)result) {
			if (single instanceof IOObject) {
				results.add((IOObject)single);
			} else {
				getLogger().warning("Unknown result type: "+single);
			}
		}
		outExtender.deliver(results);			
	} else {
		if (result != null) {
			if (result instanceof IOObject) {
				outExtender.deliver(Collections.singletonList((IOObject)result));;
			} else {
				getLogger().warning("Unknown result: "+result.getClass()+": "+result);
			}
		}			
	}		
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:51,代码来源:ScriptingOperator.java


注:本文中的groovy.lang.GroovyShell.setVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。