List of usage examples for org.apache.commons.jexl3 JxltEngine createExpression
public Expression createExpression(String expression)
From source file:datainstiller.data.DataAliasesConverter.java
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { DataAliases aliases = new DataAliases(); String nodeName;/*from ww w . j a v a 2 s . c om*/ String value; Object objValue = null; JxltEngine jxlt = new JexlBuilder().strict(true).silent(false).create().createJxltEngine(); while (reader.hasMoreChildren()) { reader.moveDown(); nodeName = reader.getNodeName(); value = reader.getValue(); if (value.matches("\\$\\[.+]")) { Pattern pattern = Pattern.compile("\\$\\[(.+)\\(\\s*'\\s*(.*)\\s*'\\s*,\\s*'\\s*(.*)\\s*'\\s*\\)"); Matcher matcher = pattern.matcher(value); if (matcher.find() != true) { throw new PatternUnmarshalException(value + " - invalid data generation expression!"); } GeneratorInterface genType = new DataGenerator().getGenerator(matcher.group(1).trim()); String init = matcher.group(2); String val = matcher.group(3); value = genType.generate(init, val); } else { JxltEngine.Expression expr = jxlt.createExpression(value); try { objValue = expr.evaluate(jexlContext); value = objValue.toString(); } catch (Exception e) { e.printStackTrace(); } } aliases.put(nodeName, value); if (objValue != null) { jexlContext.set(nodeName, objValue); } else { jexlContext.set(nodeName, value); } objValue = null; reader.moveUp(); } return aliases; }