Friends,
We are writing a framework for a validation...
We do have a config file like below...
<root>
<property name="Premium">
<xmlTag>//Message/Request/Product/Benefit/Premium/amount</xmlTag>
<valueType>float</valueType>
<validation condition=">" value="0">Premium Amount cannot be less than Zero.</validation>
</property>
I get the XML Value using XPath and convert it to float by <valueType>
element value...
No, I do have value="0"
also been converted to float.
Now, I do have to apply the condition which has been specified as condition=">"
.
I don't want to do this on IF ELSEIF....ELSE loop.
Is there any other way to convert "<" in to an operator <
or use compare operator on a String?
In this way, my code will be simple and useful for future more operators.
=============================================================================
Thanks all for the suggestions and answers...
I have decided to use the BeanShell's bsh.Interpreter. It does the work for me...
sample code for you all...
System.out.println(new bsh.Interpreter().eval("1 < 0"));
System.out.println(new bsh.Interpreter().eval("1 > 0"));
System.out.println(new bsh.Interpreter().eval("1 >= 0"));
System.out.println(new bsh.Interpreter().eval("0 >= 0"));
System.out.println(new bsh.Interpreter().eval("1 != 0"));
System.out.println(new bsh.Interpreter().eval("0 != 0"));
System.out.println(new bsh.Interpreter().eval("1 == 0"));
System.out.println(new bsh.Interpreter().eval("0 == 0"));
returned me true/false.
Thanks & Good luck...