use of org.apache.commons.jexl2.JexlEngine in project newts by OpenNMS.
the class ResultDescriptor method expression.
public ResultDescriptor expression(String label, String expression) {
final JexlEngine je = new JexlEngine();
final Expression expr = je.createExpression(expression);
final String[] labels = getLabels().toArray(new String[0]);
CalculationFunction evaluate = new CalculationFunction() {
private static final long serialVersionUID = -3328049421398096252L;
@Override
public double apply(double... ds) {
JexlContext jc = new MapContext();
for (int i = 0; i < labels.length; i++) {
jc.set(labels[i], ds[i]);
}
return ((Number) expr.evaluate(jc)).doubleValue();
}
};
return calculate(label, evaluate, labels);
}
use of org.apache.commons.jexl2.JexlEngine in project dbeaver by serge-rider.
the class AbstractDescriptor method parseExpression.
public static Expression parseExpression(String exprString) throws DBException {
synchronized (AbstractDescriptor.class) {
if (jexlEngine == null) {
jexlEngine = new JexlEngine(null, null, null, null);
jexlEngine.setCache(100);
}
}
try {
return jexlEngine.createExpression(exprString);
} catch (JexlException e) {
throw new DBException("Bad expression", e);
}
}
use of org.apache.commons.jexl2.JexlEngine in project opennms by OpenNMS.
the class ExpressionConfigWrapper method evaluate.
@Override
public double evaluate(Map<String, Double> values) throws ThresholdExpressionException {
// Add all of the variable values to the script context
Map<String, Object> context = new HashMap<String, Object>();
context.putAll(values);
// To workaround NMS-5019
context.put("datasources", new HashMap<String, Double>(values));
context.put("math", new MathBinding());
double result = Double.NaN;
try {
// Fetch an instance of the JEXL script engine to evaluate the script expression
Object resultObject = new JexlEngine().createExpression(m_expression.getExpression()).evaluate(new MapContext(context));
result = Double.parseDouble(resultObject.toString());
} catch (Throwable e) {
throw new ThresholdExpressionException("Error while evaluating expression " + m_expression.getExpression() + ": " + e.getMessage(), e);
}
return result;
}
use of org.apache.commons.jexl2.JexlEngine in project opennms by OpenNMS.
the class JasperReportService method evaluateToString.
public static String evaluateToString(JasperReport report, JRExpression expression) {
Objects.requireNonNull(report);
Objects.requireNonNull(expression);
SubreportExpressionVisitor visitor = new SubreportExpressionVisitor(report);
String string = visitor.visit(expression);
if (string != null) {
JexlEngine engine = new JexlEngine();
return (String) engine.createExpression(string).evaluate(new MapContext());
}
return null;
}
use of org.apache.commons.jexl2.JexlEngine in project jmeter by apache.
the class Jexl3Function method threadFinished.
@Override
public void threadFinished() {
JexlEngine engine = threadLocalJexl.get();
if (engine != null) {
engine.clearCache();
threadLocalJexl.remove();
}
}
Aggregations