<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<facts>
<fact id="ItemPrice" displayName="Item Price">
<defaultValue>0</defaultValue>
<script><![CDATA[
Double Value_Sales= 500;
Double Unit_Sales= 10;
Double res=Value_Sales/Unit_Sales;
return res;
]]></script>
</fact>
</facts>
Above is the sample groovy script written in xml file for finding item price.
Java code for processing Groovy:
List<Fact> factList = NREUtils.readXml("/SampleDictionary.xml") //cutome API
GroovyShell shell = new GroovyShell();
String scriptStr = factList.get(0).getScript();
Script groovyScript = shell.parse(scriptStr); // return "ItemPrice" script
Binding binding = new Binding();
groovyScript.setBinding(binding);
Object val = groovyScript.run(); // **Result will be 50**
I would like the corresponding Scala code for the same.