In the above message mapping, we can see javac, jre, args,
java as tags. The javac contains the path of the compiler, javac.exe. The jre
contains the path of the java.exe. The args contains param as subelements,
which are the arguments to the java code. Finally, the java tag contains the
source code of the mapping program.
Java Functions
Below is the java function getParameter and Dyna_SAP_Compiler,
accepting the input.
getParameter()
The all the param tags are made into a single context by a
custom java function getParameter(), which gives the output as arguments
separated by a space.
Dyna_SAP_Compiler
Java Code: Dyna_SAP_Compiler
//write your code here
String output="";
InputStream in=null;
try {
String className = JavaCode.substring(JavaCode.indexOf("class") + 5, JavaCode.indexOf("{")).trim();
FileOutputStream f = new FileOutputStream(new File("c:
"+ className + ".java"));
f.write(JavaCode.getBytes());
f.close();
String javac=javac_exe" -classpath c:
. c:
" className + ".java -d c:
";
String java=jre_exe" -classpath c:
. " className" "arguments;
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(javac);
in = p.getInputStream();
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
String line="";
while ( (line = br.readLine()) != null){}
p.waitFor();
p = rt.exec(java);
in = p.getInputStream();
isr = new InputStreamReader(in);
br = new BufferedReader(isr);
output="";
line="";
while ( (line = br.readLine()) != null)
{
output=line"\n";
}
p.waitFor();
} catch (Exception e) {
output = e.getMessage();
}
return output.substring(689);
This shows the unbelievable flexibility of XI to have design time work (mapping)
at runtime (using Java code).
Note:
Using CDATA for java tag gave me some
error (unable to load map, but compiled successfully). Java code can be URL
encoded! After compiling, the result is always pre-occupied by 689 bytes (may
differ) and then comes the actual output result. The above program can be
modified in a way to stop repeated compilation if already compiled for
optimized results.