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


Java MVEL.compileExpression方法代码示例

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


在下文中一共展示了MVEL.compileExpression方法的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: 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

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

示例4: 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:takbani,项目名称:blcdemo,代码行数:29,代码来源:ConsolidateFulfillmentFeesActivity.java

示例5: start

import org.mvel2.MVEL; //导入方法依赖的package包/类
public void start() {
    //Create two of the same expressions
    final String expression = "firstname";
    final String expression2 = "lastname";

    //Create a bean to run expressions against
    final Bean bean = new Bean();

    //Use reflection mode
    OptimizerFactory.setDefaultOptimizer(OptimizerFactory.SAFE_REFLECTIVE);

    //Compile the expressions
    Serializable mvelExp1 = MVEL.compileExpression(expression);
    Serializable mvelExp2 = MVEL.compileExpression(expression2);

    //run the threads
    runThreads(bean, mvelExp1, mvelExp2);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:19,代码来源:MVELThreadTest.java

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

示例7: testJIRA164

import org.mvel2.MVEL; //导入方法依赖的package包/类
public void testJIRA164() {
    Serializable s = MVEL.compileExpression("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 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));

    s = MVEL.compileExpression("1 / (var1 + var1) * var1", ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));

}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:ArithmeticTests.java

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

示例9: testJIRA164c

import org.mvel2.MVEL; //导入方法依赖的package包/类
public void testJIRA164c() {
    Serializable s = MVEL.compileExpression("1 + 1 / (var1 + var1 + 2 + 3) * 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 / (var1 + var1 + 2 + 3) * var1), MVEL.executeExpression(s, vars));

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

示例10: testMVEL226

import org.mvel2.MVEL; //导入方法依赖的package包/类
public void testMVEL226() {

        A226 a = new A226();
        Map m = Collections.singletonMap("a", a);
        Map<String, Object> nestMap = Collections.<String, Object>singletonMap("foo", "bar");
        String ex = "a.?map['foo']";
        Serializable s;

        assertNull(MVEL.getProperty(ex, m));

        OptimizerFactory.setDefaultOptimizer("ASM");
        s = MVEL.compileExpression(ex);
        assertNull(MVEL.executeExpression(s, m));
        a.map = nestMap;
        assertEquals("bar", MVEL.executeExpression(s, m));
        a.map = null;

        OptimizerFactory.setDefaultOptimizer(OptimizerFactory.DYNAMIC);

        s = MVEL.compileExpression(ex);
        assertNull(MVEL.executeExpression(s, m));
        a.map = nestMap;
        assertEquals("bar", MVEL.executeExpression(s, m));
    }
 
开发者ID:codehaus,项目名称:mvel,代码行数:25,代码来源:PropertyAccessTests.java

示例11: cache

import org.mvel2.MVEL; //导入方法依赖的package包/类
@Override
   protected Serializable cache() {
try {
    value = MVEL.compileExpression(content, context);
} catch (Exception e) {
    String message = MessageFormatter
	    .arrayFormat("无法将Id为[{}]的字符串[{}]转换为[{}]对象", new Object[] { id, content, clz}).getMessage();
    log.error(message, e);
    throw new IllegalArgumentException(message);
}
return value;
   }
 
开发者ID:ilivoo,项目名称:game,代码行数:13,代码来源:Formula.java

示例12: cache

import org.mvel2.MVEL; //导入方法依赖的package包/类
@Override
protected Serializable cache() {
	try {
		value = MVEL.compileExpression(content, context);
	} catch (Exception e) {
		String message = MessageFormatter
				.arrayFormat("无法将Id为[{}]的字符串[{}]转换为[{}]对象", new Object[] { id, content, clz }).getMessage();
		log.error(message, e);
		throw new IllegalArgumentException(message);
	}
	return value;
}
 
开发者ID:ilivoo,项目名称:game,代码行数:13,代码来源:Formula.java

示例13: cache

import org.mvel2.MVEL; //导入方法依赖的package包/类
protected static Serializable cache(String content) {
	Serializable value = null;
	try {
		value = MVEL.compileExpression(content, context);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return value;
}
 
开发者ID:ilivoo,项目名称:game,代码行数:10,代码来源:Start.java

示例14: translate

import org.mvel2.MVEL; //导入方法依赖的package包/类
private List<Object> translate(String text, TemplateRenderer.OutputContext ctx) {
    if (text == null) return null;
    List<Object> list = new ArrayList<Object>();
    int lastend = 0;
    while (true) {
        int[] se = indexOfExp(text, lastend);
        if (se == null) {
            break;
        }
        if (se[0] > lastend) {
            list.add(text.substring(lastend, se[0]));
        }
        lastend = se[1];

        TemplateRenderer.Var var = new TemplateRenderer.Var();
        var.ctx = ctx;
        var.raw = text.charAt(se[0]) == '#';
        var.exp = MVEL.compileExpression(text.substring(se[0] + 2, se[1] - 1));
        if (ctx == TemplateRenderer.OutputContext.Javascript && se[0] > 0 && se[1] < text.length()) {
            if ((text.charAt(se[0] - 1) == '"' || text.charAt(se[0] - 1) == '\'') || (text.charAt(se[1]) == '"' || text.charAt(se[1]) == '\'')) {
                var.ctx = TemplateRenderer.OutputContext.JavascriptString;
            }
        }
        list.add(var);
    }
    if (lastend < text.length()) {
        list.add(text.substring(lastend));
    }
    return list;
}
 
开发者ID:kobe2000,项目名称:webwheel,代码行数:31,代码来源:RendererFactory.java

示例15: CompiledIncludeNode

import org.mvel2.MVEL; //导入方法依赖的package包/类
public CompiledIncludeNode(int begin, String name, char[] template, int start, int end) {
    this.begin = begin;
    this.name = name;
    this.contents = subset(template, this.cStart = start, (this.end = this.cEnd = end) - start - 1);

    int mark;
    cIncludeExpression = MVEL.compileExpression(this.includeExpression = subset(contents, 0, mark = captureToEOS(contents, 0)));
    if (mark != contents.length)
        cPreExpression = MVEL.compileExpression(this.preExpression = subset(contents, ++mark, contents.length - mark));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:11,代码来源:CompiledIncludeNode.java


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