/**
* Evaluates the compiled script of a entry.
* @param entry The configuration entry to evaluate
* @param scopeValues All known values for script scope
* @return The computed value
* @throws ScriptException
*/
private Object evaluateScript(Entry<String, Map<String, Object>> entry, Map<String, Object> scopeValues) throws ScriptException {
Object value = null;
// executes compiled script
if(entry.getValue().containsKey("cscript")) {
CompiledScript cscript = (CompiledScript) entry.getValue().get("cscript");
// Add global variables thisValue and keyName to JavaScript context
Bindings bindings = cscript.getEngine().createBindings();
bindings.putAll(scopeValues);
value = cscript.eval(bindings);
}
// try to convert the returned value to BigDecimal
value = ObjectUtils.defaultIfNull(
NumberUtils.toBigDecimal(value), value);
// round to two digits, maybe not optimal for any result
if(value instanceof BigDecimal) {
((BigDecimal)value).setScale(2, BigDecimal.ROUND_HALF_UP);
}
return value;
}
EBusTelegramParser.java 文件源码
java
阅读 20
收藏 0
点赞 0
评论 0
项目:openhab-hdl
作者:
评论列表
文章目录