You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 4
Next »
Introduction
This article describes how a JAVA program can access arguments and set and return variables,
Implementation
Receiving variables
Variables are provided by the associated environment variable.
In the example the environment variable $VAR1 is send to stdout.
Returning Variables
Variables are returned as order return variables by writing name value pairs to a temporary file that is provided by the controller. There is one file for each order in each workflow. The name of the temporary file is stored in the environment variable $JS7_RETURN_VALUES. The variable is available with the next step in the workflow.
package js7;
import java.io.FileWriter;
import java.io.IOException;
public class SetAndGetVariables {
protected void setVar(String name, String value) throws IOException {
try {
String tmpFileName = System.getenv("JS7_RETURN_VALUES");
FileWriter fw = new FileWriter(tmpFileName, true);
fw.write(name + "=" + value);
fw.close();
} catch (IOException ioe) {
System.err.println("IOException: " + ioe.getMessage());
}
}
protected String getVar(String name){
return System.getenv(name);
}
public static void main(String[] args) throws IOException {
SetAndGetVariables setAndGetVariables = new SetAndGetVariables();
System.out.println("var1=" + setAndGetVariables.getVar("var1"));
setAndGetVariables.setVar("var1", "newValue");
}
}