com.github.outerman.be.util.JexlUtil Maven / Gradle / Ivy
package com.github.outerman.be.util;
import java.io.StringReader;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.jexl3.JexlBuilder;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
import org.apache.commons.jexl3.JexlException;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.MapContext;
import org.apache.commons.jexl3.internal.Debugger;
import org.apache.commons.jexl3.parser.ASTIdentifier;
import org.apache.commons.jexl3.parser.ASTJexlScript;
import org.apache.commons.jexl3.parser.JexlNode;
import org.apache.commons.jexl3.parser.Parser;
import com.github.outerman.be.contant.BusinessEngineException;
/**
* Java Expression Language Util
* @author gaoxue
*/
public final class JexlUtil {
private static JexlEngine jexl = new JexlBuilder().create();
private static JexlExpression createExpression(String expression) throws BusinessEngineException {
try {
JexlExpression jexlExpression = jexl.createExpression(expression);
return jexlExpression;
} catch (JexlException ex) {
throw new BusinessEngineException("", ex.getMessage(), null, ex);
}
}
private static JexlContext getContext(T data) {
JexlContext context = new MapContext();
BeanMap map = new org.apache.commons.beanutils.BeanMap(data);
for (Entry