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


Java MVEL类代码示例

本文整理汇总了Java中org.mvel2.MVEL的典型用法代码示例。如果您正苦于以下问题:Java MVEL类的具体用法?Java MVEL怎么用?Java MVEL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MVEL类属于org.mvel2包,在下文中一共展示了MVEL类的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: runMvel

import org.mvel2.MVEL; //导入依赖的package包/类
public static void runMvel(int xmax, int ymax, int zmax) {
    Map context = new HashMap();
    String expression = "x + y*2 - z";
    Serializable compileExpression = MVEL.compileExpression(expression);
    Integer result = 0;
    Date start = new Date();
    for (int xval = 0; xval < xmax; xval++) {
        for (int yval = 0; yval < ymax; yval++) {
            for (int zval = 0; zval <= zmax; zval++) {
                context.put("x", xval);
                context.put("y", yval);
                context.put("z", zval);
                VariableResolverFactory functionFactory = new MapVariableResolverFactory(context);
                Integer cal = (Integer) MVEL.executeExpression(compileExpression, context, functionFactory);
                result += cal;
            }
        }
    }
    Date end = new Date();
    System.out.println("MVEL:time is : " + (end.getTime() - start.getTime()) + ",result is " + result);

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

示例3: executeExpression

import org.mvel2.MVEL; //导入依赖的package包/类
/**
 * Helpful method for processing a boolean MVEL expression and associated arguments.
 *
 * Caches the expression in an LRUCache.
 * @param expression
 * @param vars
 * @return the result of the expression
 */
protected Boolean executeExpression(String expression, Map<String, Object> vars) {
    Serializable exp = (Serializable) expressionCache.get(expression);
    vars.put("MVEL", MVEL.class);

    if (exp == null) {
        try {
            exp = MVEL.compileExpression(expression, getParserContext());
        } catch (CompileException ce) {
            LOG.warn("Compile exception processing phrase: " + expression,ce);
            return Boolean.FALSE;
        }
        expressionCache.put(expression, exp);
    }

    try {
        return (Boolean) MVEL.executeExpression(exp, vars);
    } catch (Exception e) {
        LOG.error(e);
    }

    return false;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:31,代码来源:AbstractRuleProcessor.java

示例4: 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

示例5: parseEL

import org.mvel2.MVEL; //导入依赖的package包/类
public static Object[] parseEL(String script) {
    if (script == null || script.trim().equals("")) {
        return null;
    }
    Object[] rt = new Object[2];
    Matcher matcher = pattern.matcher(script);
    if (!matcher.matches()) {
        return null;
    }
    String s = matcher.group(1);
    if ("spel".equals(s)) {
        rt[0] = EL.SPRING_EL;
    } else if ("mvel".equals(s)) {
        rt[0] = EL.MVEL;
    } else if ("buildin".equals(s)) {
        rt[0] = EL.BUILD_IN;
    } else {
        throw new CacheConfigException("Can't parse \"" + script + "\"");
    }
    rt[1] = matcher.group(2);
    return rt;
}
 
开发者ID:alibaba,项目名称:jetcache,代码行数:23,代码来源:ExpressionUtil.java

示例6: write

import org.mvel2.MVEL; //导入依赖的package包/类
private void write(Writer writer, Object ctx, Map<String, Object> vars, List<Object> content) throws IOException {
    for (Object obj : content) {
        if (obj instanceof Var) {
            write(writer, (Var) obj, ctx, vars);
        } else if (obj instanceof Attr) {
            Attr attr = (Attr) obj;
            Object exp = attr.var.exp;
            Object v = MVEL.executeExpression(exp, ctx, vars);
            if (v != null && !v.equals(Boolean.FALSE)) {
                writer.write(' ');
                writer.write(attr.name);
                writer.write("=\"");
                if (!v.equals(Boolean.TRUE)) {
                    write(writer, attr.var, ctx, vars);
                }
                writer.write("\"");
            }
        } else if (obj instanceof Block) {
            Block block = (Block) obj;
            write(writer, ctx, vars, block.vars, block.content);
        } else {
            writer.write(obj.toString());
        }
    }
}
 
开发者ID:kobe2000,项目名称:webwheel,代码行数:26,代码来源:TemplateRenderer.java

示例7: shouldApplyFeeToFulfillmentGroup

import org.mvel2.MVEL; //导入依赖的package包/类
/**
 * If the SkuFee expression is null or empty, this method will always return true
 * 
 * @param fee
 * @param fulfillmentGroup
 * @return
 */
protected boolean shouldApplyFeeToFulfillmentGroup(SkuFee fee, FulfillmentGroup fulfillmentGroup) {
    boolean appliesToFulfillmentGroup = true;
    String feeExpression = fee.getExpression();
    
    if (!StringUtils.isEmpty(feeExpression)) {
        Serializable exp = (Serializable) EXPRESSION_CACHE.get(feeExpression);
        if (exp == null) {
            ParserContext mvelContext = new ParserContext();
            mvelContext.addImport("MVEL", MVEL.class);
            mvelContext.addImport("MvelHelper", MvelHelper.class);
            exp = MVEL.compileExpression(feeExpression, mvelContext);
        
            EXPRESSION_CACHE.put(feeExpression, exp);
        }
        HashMap<String, Object> vars = new HashMap<String, Object>();
        vars.put("fulfillmentGroup", fulfillmentGroup);
        return (Boolean)MVEL.executeExpression(feeExpression, vars);
    }
    
    return appliesToFulfillmentGroup;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:29,代码来源:ConsolidateFulfillmentFeesActivity.java

示例8: testListPropertyHandler4

import org.mvel2.MVEL; //导入依赖的package包/类
public void testListPropertyHandler4() {
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;

    OptimizerFactory.setDefaultOptimizer("ASM");

    final String[] res = new String[1];

    GlobalListenerFactory.registerGetListener(new Listener() {
        public void onEvent(Object context, String contextName, VariableResolverFactory variableFactory, Object value) {
            System.out.println("Listener Fired:" + contextName);
            res[0] = contextName;
        }
    });

    Serializable s = MVEL.compileSetExpression("list[0]");

    Base b;
    MVEL.executeSetExpression(s, new Base(), "hey you");
    res[0] = null;

    MVEL.executeSetExpression(s, b = new Base(), "hey you");

    assertEquals("set", b.list.get(0));
    assertEquals("list", res[0]);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:26,代码来源:PropertyHandlerTests.java

示例9: testDebugSymbolsSingleStatement

import org.mvel2.MVEL; //导入依赖的package包/类
public void testDebugSymbolsSingleStatement() {
    String ex = "System.out.println( Cheese.STILTON );";
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addImport( Cheese.class );
    try {
        ExpressionCompiler compiler = new ExpressionCompiler(ex);
        CompiledExpression expr = compiler.compile(ctx);

        // executing the following line with a MVEL.executeExpression() works fine
        // but executeDebugger() fails
        MVEL.executeDebugger( expr, null, (VariableResolverFactory)null );
    }
    catch (Throwable e) {
        e.printStackTrace();
        fail("Should not raise exception: " + e.getMessage());
    }
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:19,代码来源:DebuggerTests.java

示例10: testSetListListener

import org.mvel2.MVEL; //导入依赖的package包/类
public void testSetListListener() {
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;

    class MyListener implements Listener {
        public int counter;

        public void onEvent(Object context, String contextName,
                            VariableResolverFactory variableFactory, Object value) {
            counter++;
        }
    }

    class MyBean {
        private List someList;

        public List getSomeList() {
            return someList;
        }
    }

    MyListener listener = new MyListener();
    GlobalListenerFactory.registerGetListener(listener);
    MVEL.getProperty("someList", new MyBean());
    MVEL.getProperty("someList", new MyBean());
    assertEquals(2, listener.counter);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:27,代码来源:PropertyHandlerTests.java

示例11: testJIRA164d

import org.mvel2.MVEL; //导入依赖的package包/类
public void testJIRA164d() {
    Serializable s = MVEL.compileExpression("1 + 1 + 1 / (var1 + var1) * var1",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 1d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((1 + 1 + 1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));

    s = MVEL.compileExpression("1 + 1 + 1 / (var1 + var1) * var1",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((1 + 1 + 1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:ArithmeticTests.java

示例12: testProtoWithFunction2

import org.mvel2.MVEL; //导入依赖的package包/类
public void testProtoWithFunction2() {
    if (!run) return;

    String ex = "proto Adder {" +
                    "int count = 0;" +
                    "def accumulate() {" +
                    "if (count < 10) {" +
                    "System.out.println('counting:' + count);" +
                    "count++;" +
                    "accumulate();" +
                    "}" +
                    "}" +
                    "};" +
                    "adder = new Adder();" +
                    "adder.accumulate();" +
                    "adder.count;";

    Object o = MVEL.eval(ex, new HashMap<String, Object>());
    assertEquals(10, o);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:21,代码来源:ProtoTests.java

示例13: 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

示例14: eval

import org.mvel2.MVEL; //导入依赖的package包/类
public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) {
        if (preExpression != null) {
            MVEL.executeExpression(cPreExpression, ctx, factory);
        }


        if (next != null) {
            String namedTemplate = MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class);
            CompiledTemplate ct = runtime.getNamedTemplateRegistry().getNamedTemplate(namedTemplate);

            if (ct == null)
                throw new TemplateError("named template does not exist: " + namedTemplate);

            return next.eval(runtime, appender.append(String.valueOf(TemplateRuntime.execute(ct, ctx, factory, runtime.getNamedTemplateRegistry()))), ctx, factory);

//            return next.eval(runtime,
//                    appender.append(String.valueOf(TemplateRuntime.execute(runtime.getNamedTemplateRegistry().getNamedTemplate(MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class)), ctx, factory))), ctx, factory);
        } else {
            return appender.append(String.valueOf(TemplateRuntime.execute(runtime.getNamedTemplateRegistry().getNamedTemplate(MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class)), ctx, factory, runtime.getNamedTemplateRegistry())));
        }
    }
 
开发者ID:codehaus,项目名称:mvel,代码行数:22,代码来源:CompiledNamedIncludeNode.java

示例15: testJIRA164f

import org.mvel2.MVEL; //导入依赖的package包/类
public void testJIRA164f() {
    Serializable s = MVEL.compileExpression("10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 1d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((float) (10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14),
            ((Double) MVEL.executeExpression(s, vars)).floatValue());

    s = MVEL.compileExpression("10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((float) (10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14),
            ((Double) MVEL.executeExpression(s, vars)).floatValue());
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:19,代码来源:ArithmeticTests.java


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