Wie, um eine Liste aller binding-Variablen mit der GroovyShell
Ich bin sehr neu in Groovy. Wie kann ich eine Liste aller Variablen, die ich übergeben, um die Bindung Konstruktor ?
Erwägung habe ich folgende :
@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;
}
Wie kann ich die Iteration über alle Variablen (über die hashMap) in groovy.Skript ?
Du musst angemeldet sein, um einen Kommentar abzugeben.
Script compiledScript
stellt das Skript, wenn man sich den Quellcode und du wirst sehen, dass es hat die Eigenschaft verbindlich und getter+setter und Bindung hat eine variable "Variablen". So gehen Sie :Für
Map<String, String>
...können Sie auch Eigenschaften wie diese :
gespeichert ist in die Bindung von Variablen.