当前位置: 首页>>代码示例>>Java>>正文


Java MVEL.eval方法代码示例

本文整理汇总了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);

}
 
开发者ID:brucefengnju,项目名称:eldemo,代码行数:17,代码来源:RunMvel.java

示例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);
}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:19,代码来源:TestBeanUtils.java

示例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);
    }
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:22,代码来源:ArithmeticTests.java

示例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);
    }
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:26,代码来源:ArithmeticTests.java

示例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);
    }
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:21,代码来源:ArithmeticTests.java

示例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;
    }
}
 
开发者ID:blinkfox,项目名称:zealot,代码行数:15,代码来源:ParseHelper.java

示例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);
    }
}
 
开发者ID:alibaba,项目名称:jetcache,代码行数:8,代码来源:ExpressionUtil.java

示例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);
}
 
开发者ID:tongbanjie,项目名称:baymax,代码行数:11,代码来源:ELFunction.java

示例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;
}
 
开发者ID:blinkfox,项目名称:zealot,代码行数:16,代码来源:ParseHelper.java

示例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;
    }
}
 
开发者ID:igor-suhorukov,项目名称:aspectj-scripting,代码行数:9,代码来源:Utils.java

示例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");
    }
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:14,代码来源:AssertNode.java

示例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);
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:12,代码来源:MVELExpression.java

示例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()));
    }
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:10,代码来源:Invert.java

示例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);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:10,代码来源:ProtoTests.java

示例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)));
    }
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:15,代码来源:IncludeNode.java


注:本文中的org.mvel2.MVEL.eval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。