문제

I'm very new to Groovy. How can I list all variables I passed to Binding constructor ?

Considering I have following :

@Test
public void test() {

    List<String> outputNames = Arrays.asList("returnValue", "ce");

    String script = getScript();
    Script compiledScript = compileScript(script);
    CustomError ce = new CustomError("shit", Arrays.asList(new Long(1)));

    Map<String, Object> inputObjects = new HashMap<String, Object>();
    inputObjects.put("input", "Hovada");
    inputObjects.put("error", ce);

    Binding binding = new Binding(inputObjects);
    compiledScript.setBinding(binding);
    compiledScript.run();

    for (String outputName : outputNames) {
        System.out.format("outputName : %s  =  %s", outputName, binding.getVariable(outputName));
    }
}

private Script compileScript(String script) {
    GroovyShell groovyShell = new GroovyShell();
    Script compiledScript = groovyShell.parse(script);
    return compiledScript;
}

How can I iterate over all the variables (over the hashMap) in groovy.script ?

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top