i'm not sure if the thread's location is correct..
please move it if not appropriate.
I think it is possible to execute a string expression like the Webflow's <evaluate/> tag.
I have dynamic formula to execute. It changes frequently that's why I am planning to put it in xml as <property/> of a <bean/> tag...
then evaluate it, get the result and do other process..
here's image:
xml
javaCode:<bean id="computeService" class="abs.service.ComputeServiceImpl"> <property name="expression" value="1.0 / sqrt( sqrt( x1 ) )"/> </bean>
sample input/outputCode:public class ComputeServiceImpl implements ComputeService { private String expression; //getter setter here @Override public BigDecimal compute(BigDecimal x1) { // evaluateExpression(String) is sample only // the method will be able to evaluate the given expression BigDecimal result = evaluateExpression(expression, x1); // do other computations here return result; } private BigDecimal evaluateExpression(String expression, BigDecimal input) { BigDecimal result; // code here, it will update the result variable from the given expression return result; } }
Thanks in advance.Code:// the expression will be: // = 1.0 / Math.sqrt( Math.sqrt( x1.doubleValue() ) ) // = 0.562341325 BigDecimal result = computeService.compute(BigDecimal.TEN); System.out.println(result); >Prints 0.562341325



Reply With Quote