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


Java ParserContext.addImport方法代码示例

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


在下文中一共展示了ParserContext.addImport方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldApplyFeeToFulfillmentGroup

import org.mvel2.ParserContext; //导入方法依赖的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

示例2: testQualifiedForLoop

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testQualifiedForLoop() {
    ParserContext pCtx = new ParserContext();
    pCtx.setStrongTyping(true);
    pCtx.addImport(Foo.class);
    pCtx.addInput("l", ArrayList.class, new Class[] { Foo.class });

    List l = new ArrayList();
    l.add(new Foo());
    l.add(new Foo());
    l.add(new Foo());

    Map vars = new HashMap();
    vars.put("l", l);

    Serializable s = MVEL.compileExpression("String s = ''; for (Foo f : l) { s += f.name }; s", pCtx);

    String r  = (String) MVEL.executeExpression(s, vars);

    assertEquals("dogdogdog", r);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:21,代码来源:ControlFlowTests.java

示例3: testBreakpoints3

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testBreakpoints3() {
    String expr = "System.out.println( \"a1\" );\n" +
            "System.out.println( \"a2\" );\n" +
            "System.out.println( \"a3\" );\n" +
            "System.out.println( \"a4\" );\n";

    ExpressionCompiler compiler = new ExpressionCompiler(expr);

    ParserContext context = new ParserContext();
    context.addImport("System", System.class);
    context.setStrictTypeEnforcement(true);
    context.setDebugSymbols(true);
    context.setSourceFile("mysource");

    String s = org.mvel2.debug.DebugTools.decompile(compiler.compile(context));

    System.out.println("output: " + s);

    int fromIndex = 0;
    int count = 0;
    while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
        count++;
    }
    assertEquals(4, count);

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

示例4: testDebugSymbolsSingleStatement

import org.mvel2.ParserContext; //导入方法依赖的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

示例5: executeExpression

import org.mvel2.ParserContext; //导入方法依赖的package包/类
/**
 * Private method used by couldOfferApplyToOrder to execute the MVEL expression in the
 * appliesToOrderRules to determine if this offer can be applied.
 *
 * @param expression
 * @param vars
 * @return a Boolean object containing the result of executing the MVEL expression
 */
public Boolean executeExpression(String expression, Map<String, Object> vars) {
    try {
        Serializable exp;
        synchronized (EXPRESSION_CACHE) {
            exp = (Serializable) EXPRESSION_CACHE.get(expression);
            if (exp == null) {
                ParserContext context = new ParserContext();
                context.addImport("OfferType", OfferType.class);
                context.addImport("FulfillmentType", FulfillmentType.class);
                context.addImport("MVEL", MVEL.class);
                context.addImport("MvelHelper", MvelHelper.class);
                //            StringBuffer completeExpression = new StringBuffer(functions.toString());
                //            completeExpression.append(" ").append(expression);
                exp = MVEL.compileExpression(expression, context);

                EXPRESSION_CACHE.put(expression, exp);
            }
        }

        Object test = MVEL.executeExpression(exp, vars);
        
        return (Boolean) test;
    } catch (Exception e) {
        //Unable to execute the MVEL expression for some reason
        //Return false, but notify about the bad expression through logs
        LOG.warn("Unable to parse and/or execute an mvel expression. Reporting to the logs and returning false " +
                "for the match expression:" + expression, e);
        return false;
    }

}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:40,代码来源:AbstractBaseProcessor.java

示例6: testBreakpointsAcrossWith

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testBreakpointsAcrossWith() {
    String line1 = "System.out.println( \"a1\" );\n";
    String line2 = "c = new Cheese();\n";
    String line3 = "with ( c ) { type = 'cheddar',\n" +
            "             price = 10 };\n";
    String line4 = "System.out.println( \"a1\" );\n";
    String expr = line1 + line2 + line3 + line4;

    System.out.println(expr);

    ExpressionCompiler compiler = new ExpressionCompiler(expr);

    ParserContext context = new ParserContext();
    context.addImport("System", System.class);
    context.addImport("Cheese", Cheese.class);
    context.setStrictTypeEnforcement(true);
    context.setDebugSymbols(true);
    context.setSourceFile("mysource");

    String s = org.mvel2.debug.DebugTools.decompile(compiler.compile(context));

    System.out.println("output: " + s);

    int fromIndex = 0;
    int count = 0;
    while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
        count++;
    }
    assertEquals(5, count);

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

示例7: evaluateRule

import org.mvel2.ParserContext; //导入方法依赖的package包/类
/**
 * Evaluates the passed in rule given the passed in parameters.   
 * 
 * @param rule
 * @param ruleParameters
 * @return
 */
public static boolean evaluateRule(String rule, Map<String, Object> ruleParameters, Map expressionCache) {
    // Null or empty is a match
    if (rule == null || "".equals(rule)) {
        return true;
    } else {
        // MVEL expression compiling can be expensive so let's cache the expression
        Serializable exp = (Serializable) expressionCache.get(rule);
        if (exp == null) {
            synchronized (expressionCache) {
                ParserContext context = new ParserContext();
                context.addImport("MVEL", MVEL.class);
                context.addImport("MvelHelper", MvelHelper.class);
                exp = MVEL.compileExpression(rule, context);
                expressionCache.put(rule, exp);

            }
        }

        Map<String, Object> mvelParameters = new HashMap<String, Object>();

        if (ruleParameters != null) {
            for (String parameter : ruleParameters.keySet()) {
                mvelParameters.put(parameter, ruleParameters.get(parameter));
            }
        }

        try {
            Object test = MVEL.executeExpression(exp, mvelParameters);
            if (test == null) {
                // This can occur if there is no actual rule
                return true;
            }
            return (Boolean) test;
        } catch (Exception e) {
            //Unable to execute the MVEL expression for some reason
            //Return false, but notify about the bad expression through logs
            if (!TEST_MODE) {
                LOG.info("Unable to parse and/or execute the mvel expression (" + rule + "). Reporting to the logs and returning false for the match expression", e);
            }
            return false;
        }
    }
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:51,代码来源:MvelHelper.java

示例8: testInlineWith4

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testInlineWith4() {
    OptimizerFactory.setDefaultOptimizer("ASM");
    ExpressionCompiler expr = new ExpressionCompiler("new Foo().{ name = 'bar' }");
    ParserContext pCtx = new ParserContext();
    pCtx.addImport(Foo.class);

    CompiledExpression c = expr.compile(pCtx);

    Foo f = (Foo) executeExpression(c);

    assertEquals("bar", f.getName());

    f = (Foo) executeExpression(c);

    assertEquals("bar", f.getName());
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:WithTests.java

示例9: evaluateRule

import org.mvel2.ParserContext; //导入方法依赖的package包/类
/**
 * Evaluates the passed in rule given the passed in parameters.   
 * 
 * @param rule
 * @param ruleParameters
 * @return
 */
public static boolean evaluateRule(String rule, Map<String, Object> ruleParameters,
        Map<String, Serializable> expressionCache) {
    // Null or empty is a match
    if (rule == null || "".equals(rule)) {
        return true;
    } else {
        // MVEL expression compiling can be expensive so let's cache the expression
        Serializable exp = (Serializable) expressionCache.get(rule);
        if (exp == null) {
            ParserContext context = new ParserContext();
            context.addImport("MVEL", MVEL.class);
            context.addImport("MvelHelper", MvelHelper.class);
            exp = MVEL.compileExpression(rule, context);
            expressionCache.put(rule, exp);
        }

        Map<String, Object> mvelParameters = new HashMap<String, Object>();

        if (ruleParameters != null) {
            for (String parameter : ruleParameters.keySet()) {
                mvelParameters.put(parameter, ruleParameters.get(parameter));
            }
        }

        try {
            Object test = MVEL.executeExpression(exp, mvelParameters);
            if (test == null) {
                // This can occur if there is no actual rule
                return true;
            }
            return (Boolean) test;
        } catch (Exception e) {
            //Unable to execute the MVEL expression for some reason
            //Return false, but notify about the bad expression through logs
            if (!TEST_MODE) {
                LOG.info("Unable to parse and/or execute the mvel expression (" + rule + "). Reporting to the logs and returning false for the match expression", e);
            }
            return false;
        }
    }
}
 
开发者ID:takbani,项目名称:blcdemo,代码行数:49,代码来源:MvelHelper.java


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