本文整理汇总了Java中org.mvel2.MVEL.eval方法的典型用法代码示例。如果您正苦于以下问题:Java MVEL.eval方法的具体用法?Java MVEL.eval怎么用?Java MVEL.eval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mvel2.MVEL
的用法示例。
在下文中一共展示了MVEL.eval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.mvel2.MVEL; //导入方法依赖的package包/类
public static void main(String[] args) {
Foo foo = new Foo();
foo.setName("test");
Map context = new HashMap();
String expression = "foo.name == 'test'";
VariableResolverFactory functionFactory = new MapVariableResolverFactory(context);
context.put("foo",foo);
Boolean result = (Boolean) MVEL.eval(expression,functionFactory);
System.out.println(result);
Serializable compileExpression = MVEL.compileExpression(expression);
result = (Boolean) MVEL.executeExpression(compileExpression, context, functionFactory);
System.out.print(result);
}
示例2: testMvel
import org.mvel2.MVEL; //导入方法依赖的package包/类
public static void testMvel(){
//Map<String, Object> params = new HashMap<String, Object>();
//params.put("x", 10);
//params.put("y", 20);
//Object result = MVEL.eval("x+y", params);
List<Integer> lst=new ArrayList<>();
for(int i=0;i<10*100*100;i++){
lst.add(i);
}
Map<String, Object> input = new HashMap<String, Object>();
input.put("AA",lst);
//Object result = MVEL.eval(" val v=0;for(x:lst) { v=v+x;} return v;", lst);
//Object result = MVEL.eval(" foreach (x : AA) { System.out.println(x+\"\");} return 0;", input);
Object result = MVEL.eval(" foreach (x : AA) { System.out.println(x+1000);} return 0;", input);
//打印到51,然后 Error: can't load this type of class file
log.e("AAAA:"+result);
}
示例3: testJIRA208
import org.mvel2.MVEL; //导入方法依赖的package包/类
public void testJIRA208() {
Map<String, Object> vars = new LinkedHashMap<String, Object>();
vars.put("bal", 999);
String[] testCases = {"bal - 80 - 90 - 30", "bal-80-90-30", "100 + 80 == 180", "100+80==180"};
// System.out.println("bal = " + vars.get("bal"));
Object val1, val2;
for (String expr : testCases) {
System.out.println("Evaluating '" + expr + "': ......");
val1 = MVEL.eval(expr, vars);
// System.out.println("'" + expr + " ' = " + ret.toString());
assertNotNull(val1);
Serializable compiled = MVEL.compileExpression(expr);
val2 = executeExpression(compiled, vars);
// System.out.println("'" + expr + " ' = " + ret.toString());
assertNotNull(val2);
assertEquals("expression did not evaluate correctly: " + expr, val1, val2);
}
}
示例4: testJIRA208b
import org.mvel2.MVEL; //导入方法依赖的package包/类
public void testJIRA208b() {
Map<String, Object> vars = new LinkedHashMap<String, Object>();
vars.put("bal", 999);
String[] testCases = {
// "bal + 80 - 80",
// "bal - 80 + 80", "bal * 80 / 80",
"bal / 80 * 80"
};
// System.out.println("bal = " + vars.get("bal"));
Object val1, val2;
for (String expr : testCases) {
System.out.println("Evaluating '" + expr + "': ......");
val1 = MVEL.eval(expr, vars);
// System.out.println("'" + expr + " ' = " + ret.toString());
assertNotNull(val1);
Serializable compiled = MVEL.compileExpression(expr);
val2 = executeExpression(compiled, vars);
// System.out.println("'" + expr + " ' = " + ret.toString());
assertNotNull(val2);
assertEquals("expression did not evaluate correctly: " + expr, val1, val2);
}
}
示例5: testJIRA210
import org.mvel2.MVEL; //导入方法依赖的package包/类
public void testJIRA210() {
Map<String, Object> vars = new LinkedHashMap<String, Object>();
vars.put("bal", new BigDecimal("999.99"));
String[] testCases = {"bal - 1 + \"abc\"",};
Object val1, val2;
for (String expr : testCases) {
System.out.println("Evaluating '" + expr + "': ......");
val1 = MVEL.eval(expr, vars);
// System.out.println("'" + expr + " ' = " + ret.toString());
assertNotNull(val1);
Serializable compiled = MVEL.compileExpression(expr);
val2 = executeExpression(compiled, vars);
// System.out.println("'" + expr + " ' = " + ret.toString());
assertNotNull(val2);
assertEquals("expression did not evaluate correctly: " + expr, val1, val2);
}
}
示例6: parseExpress
import org.mvel2.MVEL; //导入方法依赖的package包/类
/**
* 通过MVEL来解析表达式的值,如果出错不抛出异常.
* @param exp 待解析表达式
* @param paramObj 参数对象
* @return 返回解析后的值
*/
public static Object parseExpress(String exp, Object paramObj) {
try {
return MVEL.eval(exp, paramObj);
} catch (Exception e) {
log.error("解析表达式出错,表达式为:" + exp, e);
return null;
}
}
示例7: eval
import org.mvel2.MVEL; //导入方法依赖的package包/类
private static boolean eval(String text, CacheInvokeContext context, EL el) {
if (el == EL.MVEL) {
return (Boolean) MVEL.eval(text, context);
} else {
throw new CacheException("not support yet:" + el);
}
}
示例8: execute
import org.mvel2.MVEL; //导入方法依赖的package包/类
public Integer execute(String columnValue, Map<String, Object> extension) {
Map<String, Object> vrs = new HashMap<String, Object>();
//, Map<String, ElFunction<?,?>> functionMap
//vrs.putAll(functionMap);// 拓展函数
Map<String, Object> params = new HashMap<String, Object>();
params.put("value", columnValue);
vrs.put("$ROOT", params);
VariableResolverFactory vrfactory = new MapVariableResolverFactory(vrs);
return MVEL.eval(expression, params, vrfactory, Integer.class);
}
示例9: parseExpressWithException
import org.mvel2.MVEL; //导入方法依赖的package包/类
/**
* 通过MVEL来解析表达式的值,如果出错则抛出异常.
* @param exp 待解析表达式
* @param paramObj 参数对象
* @return 返回解析后的值
*/
public static Object parseExpressWithException(String exp, Object paramObj) {
Object obj;
try {
obj = MVEL.eval(exp, paramObj);
} catch (Exception e) {
throw new ParseExpressionException("解析Mvel表达式异常,解析出错的表达式为:" + exp, e);
}
return obj;
}
示例10: checkMvelExpression
import org.mvel2.MVEL; //导入方法依赖的package包/类
public static Object checkMvelExpression(String source){
if(source.startsWith(MVEL_PREFIX)){
String expression = source.substring(MVEL_PREFIX.length());
return MVEL.eval(expression);
} else {
return source;
}
}
示例11: getReducedValue
import org.mvel2.MVEL; //导入方法依赖的package包/类
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
try {
if (!((Boolean) MVEL.eval(this.name, ctx, factory))) {
throw new AssertionError("assertion failed in expression: " + new String(this.name));
}
else {
return true;
}
}
catch (ClassCastException e) {
throw new CompileException("assertion does not contain a boolean statement");
}
}
示例12: run
import org.mvel2.MVEL; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Object run(Map<String, Object> variables) {
if (variables == null) {
variables = new HashMap<String, Object>();
}
VariableResolverFactory factory = new MapVariableResolverFactory(variables, _propertyResolverFactory);
return isCompiled() ? MVEL.executeExpression(_compiled, factory) : MVEL.eval(_expression, factory);
}
示例13: getReducedValue
import org.mvel2.MVEL; //导入方法依赖的package包/类
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
Object o = MVEL.eval(name, ctx, factory);
if (o instanceof Integer) {
return ~((Integer) o);
}
else {
throw new CompileException("was expecting type: Integer; but found type: " + (o == null ? "null" : o.getClass().getName()));
}
}
示例14: testProtoWithOtherProtoRef
import org.mvel2.MVEL; //导入方法依赖的package包/类
public void testProtoWithOtherProtoRef() {
if (!run) return;
String ex = "proto Parent { Child child = new Child(); }; proto Child { Parent parent; }; " +
"Parent parent = new Parent(); if (parent.child.parent == null) { 'YEP' } else { 'NOPE' }";
Object o = MVEL.eval(ex, new HashMap<String, Object>());
assertEquals("YEP", o);
}
示例15: eval
import org.mvel2.MVEL; //导入方法依赖的package包/类
public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) {
String file = MVEL.eval(includeExpression, ctx, factory, String.class);
if (this.preExpression != null) {
MVEL.eval(preExpression, ctx, factory);
}
if (next != null) {
return next.eval(runtime, appender.append(String.valueOf(TemplateRuntime.eval(readInFile(file), ctx, factory))), ctx, factory);
}
else {
return appender.append(String.valueOf(MVEL.eval(readInFile(file), ctx, factory)));
}
}