Friends,
We are writing a framework for checking ...
We have a configuration file as shown 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 using the value of the <valueType>
element ...
No, I have value="0"
, also converted to float.
Now I need to apply the condition that was specified as condition=">"
.
I do not want to do this on IF ELSEIF .... ELSE.
Is there any other way to convert "<" to a <
operator, or use the comparison operator on a String?
Thus, my code will be simple and useful for future operators.
==================================================== =============================
Thanks to everyone for the suggestions and answers ...
I decided to use BeanShell bsh.Interpreter. It does the job for me ...
sample code for all of you ...
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.
Thank you and good luck...