Package org.apache.commons.jexl

Examples of org.apache.commons.jexl.Expression.evaluate()


    public void test_NEG2() throws Exception {
        JexlContext jc = JexlHelper.createContext();
        jc.getVars().put("A", Boolean.TRUE);
        Expression e = ExpressionFactory.createExpression("!(A)");
        Object actual = e.evaluate(jc);
        assertEquals(Boolean.FALSE, actual);
    }

    public void test_COMPLEX() throws Exception {
        JexlContext jc = JexlHelper.createContext();
View Full Code Here


        jc.getVars().put("A", Boolean.TRUE);
        jc.getVars().put("B", Boolean.FALSE);
        jc.getVars().put("C", Boolean.FALSE);

        Expression e = ExpressionFactory.createExpression("(A || B) && !C");
        Object actual = e.evaluate(jc);
        assertEquals(Boolean.TRUE, actual);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
View Full Code Here

            expr = ExpressionFactory.createExpression(builder.toString());
            cache.putIfAbsent(expression2, expr);
        }

        // 进行表达式求值
        return expr.evaluate(context);
    }

    @Override
    public Object getVar(String variant) {
        return mapVars.get(variant);
View Full Code Here

        if (sPropertyValue == null) {
            try {
                Expression expression = ExpressionFactory.createExpression(placeholder);
                JexlContext jexlContext = JexlHelper.createContext();
                jexlContext.setVars(props);
                sPropertyValue = expression.evaluate(jexlContext).toString();
            } catch (Throwable t) {
            }
        }
        return sPropertyValue;
    }
View Full Code Here

    private String parseSystemProperty(String placeholder) {
        try {
            Expression expression = ExpressionFactory.createExpression(placeholder);
            JexlContext jexlContext = JexlHelper.createContext();
            jexlContext.setVars(System.getProperties());
            return expression.evaluate(jexlContext).toString();
        } catch (Throwable t) {
            return null;
        }
    }
View Full Code Here

    private String parseEnvProperty(String placeholder) {
        try {
            Expression expression = ExpressionFactory.createExpression(placeholder);
            JexlContext jexlContext = JexlHelper.createContext();
            jexlContext.setVars(System.getenv());
            return expression.evaluate(jexlContext).toString();
        } catch (Throwable t) {
            return null;
        }
    }
}
View Full Code Here

    public void test_NEG1() throws Exception {
        JexlContext jc = JexlHelper.createContext();
        jc.getVars().put("A", Boolean.TRUE);
        Expression e = ExpressionFactory.createExpression("!A");
        Object actual = e.evaluate(jc);
        assertEquals(Boolean.FALSE, actual);
    }

    public void test_NEG2() throws Exception {
        JexlContext jc = JexlHelper.createContext();
View Full Code Here

    public void test_NEG2() throws Exception {
        JexlContext jc = JexlHelper.createContext();
        jc.getVars().put("A", Boolean.TRUE);
        Expression e = ExpressionFactory.createExpression("!(A)");
        Object actual = e.evaluate(jc);
        assertEquals(Boolean.FALSE, actual);
    }

    public void test_COMPLEX() throws Exception {
        JexlContext jc = JexlHelper.createContext();
View Full Code Here

        jc.getVars().put("A", Boolean.TRUE);
        jc.getVars().put("B", Boolean.FALSE);
        jc.getVars().put("C", Boolean.FALSE);

        Expression e = ExpressionFactory.createExpression("(A || B) && !C");
        Object actual = e.evaluate(jc);
        assertEquals(Boolean.TRUE, actual);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
View Full Code Here

        Expression expr = ExpressionFactory.createExpression(expression);

        JexlContext ctx = JexlHelper.createContext();
        ctx.setVars(vars);

        Object result = expr.evaluate(ctx);
        log.debug("Result: {}", result);

        return result;
    }   
}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.