Package org.apache.commons.jexl2

Examples of org.apache.commons.jexl2.MethodTest$VarArgs


    public String evaluate(final String expression, final JexlContext jexlContext) {
        String result = "";

        if (StringUtils.isNotBlank(expression) && jexlContext != null) {
            try {
                Expression jexlExpression = jexlEngine.createExpression(expression);
                Object evaluated = jexlExpression.evaluate(jexlContext);
                if (evaluated != null) {
                    result = evaluated.toString();
                }
            } catch (JexlException e) {
                LOG.error("Invalid jexl expression: " + expression, e);
View Full Code Here


     */
    @Override
    public FeatureState process(final ContextManager contextManager)
    {
        final JexlEngine jexlEngine = new JexlEngine();
        Expression jexlExpression;
        if (expression != null) {
            jexlExpression = jexlEngine.createExpression(expression);
        } else {
            jexlExpression = getOldExpression(jexlEngine);
        }
       
        final Map<String, Object> contextMap = contextManager.getContext(context);
        final JexlContext jexlContext = new MapContext(contextMap);

        return Boolean.TRUE.equals(jexlExpression.evaluate(jexlContext)) ? FeatureState.ENABLED : FeatureState.DISABLED;
    }
View Full Code Here

     * @param expected is the expected value of the expression
     * @throws Exception if the expression could not be evaluationed or an assertion
     * fails
     */
    public void assertExpression(String expression, Object expected) throws Exception {
        Expression exp = engine.createExpression(expression);
        Object value = exp.evaluate(context);

        assertEquals("expression: " + expression, expected, value);
    }
View Full Code Here

    public void failExpression(String expression, String matchException) throws Exception {
        boolean[] flags = { engine.isLenient(), engine.isSilent() };
        try {
            engine.setLenient(false);
            engine.setSilent(false);
            Expression exp = engine.createExpression(expression);
            exp.evaluate(context);
            fail("expression: " + expression);
        } catch(JexlException xjexl) {
            if (matchException != null && !xjexl.getMessage().matches(matchException)) {
                fail("expression: " + expression + ", expected: " + matchException + ", got " + xjexl.getMessage());
            }
View Full Code Here

   
    /**
     * {@inheritDoc }
     */
    public Object evaluate(Object context, String expression) {
        Expression jexlExpression = engine.createExpression(expression);
        JexlContext jexlContext = new ObjectContext(engine, context);
       
        return jexlExpression.evaluate(jexlContext);
    }
View Full Code Here

    public Map<String, Object> getVariables() {
        return variables;
    }

    protected Expression createExpression(final String expression) throws Exception {
        Expression expr = engine.createExpression(expression);
        return expr;
    }
View Full Code Here

        if (expression == null) {
            throw new IllegalArgumentException("expression");
        }

        log.trace("Evaluating expression: {}", expression);
        Expression expr = createExpression(expression);
        Object obj = expr.evaluate(context);
        log.trace("Result: {}", obj);

        return obj;
    }
View Full Code Here

    private Object doEvaluate(final String expression) throws Exception {
        assert expression != null;

        log.debug("Evaluating expression: {}", expression);
       
        Expression expr = engine.createExpression(expression);

        JexlContext ctx = new MapContext(vars);

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

        return result;
    }   
View Full Code Here

    public static String evaluate(final String expression, final JexlContext jexlContext) {
        String result = StringUtils.EMPTY;

        if (StringUtils.isNotBlank(expression) && jexlContext != null) {
            try {
                Expression jexlExpression = getEngine().createExpression(expression);
                Object evaluated = jexlExpression.evaluate(jexlContext);
                if (evaluated != null) {
                    result = evaluated.toString();
                }
            } catch (JexlException e) {
                LOG.error("Invalid jexl expression: " + expression, e);
View Full Code Here

        return result;
    }

    public JexlContext addFieldsToContext(final Object attributable, final JexlContext jexlContext) {
        JexlContext context = jexlContext == null
                ? new MapContext()
                : jexlContext;

        final Field[] fields = attributable.getClass().getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            try {
                Field field = fields[i];
                field.setAccessible(true);
                final String fieldName = field.getName();
                if ((!field.isSynthetic()) && (!fieldName.startsWith("pc"))
                        && (!ArrayUtils.contains(IGNORE_FIELDS, fieldName))
                        && (!Iterable.class.isAssignableFrom(field.getType()))
                        && (!field.getType().isArray())) {

                    final Object fieldValue = field.get(attributable);

                    context.set(fieldName, fieldValue == null
                            ? ""
                            : (field.getType().equals(Date.class)
                            ? DataFormat.format((Date) fieldValue, false)
                            : fieldValue));
View Full Code Here

TOP

Related Classes of org.apache.commons.jexl2.MethodTest$VarArgs

Copyright © 2018 www.massapicom. 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.