Package org.apache.commons.jexl

Examples of org.apache.commons.jexl.Expression


    @SuppressWarnings("unchecked")
    public String resolve(String expression, ObjectModel objectModel) {
        Object result = null;
        try {
            Expression e = ExpressionFactory.createExpression(expression);
            JexlContext jc = JexlHelper.createContext();
            jc.getVars().putAll(objectModel.getParameters());

            result = e.evaluate(jc);
        } catch (Exception e1) {
            e1.printStackTrace();
        }

        return result != null ? result.toString() : "";
View Full Code Here


        if (debug) {
            log.debug("Evaluating expression: " + expression);
        }

        Expression expr = ExpressionFactory.createExpression(expression);

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

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

        return result;
View Full Code Here

    private FlatResolver resolver = new FlatResolver(true);

    protected Expression createExpression(final String expression) throws Exception {
        // assert expression != null;

        Expression expr = ExpressionFactory.createExpression(expression);
        expr.addPreResolver(resolver);

        return expr;
    }
View Full Code Here

        boolean trace = log.isTraceEnabled();
        if (trace) {
            log.trace("Evaluating expression: " + expression);
        }

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

        return obj;
View Full Code Here

        if (debug) {
            log.debug("Evaluating expression: " + expression);
        }

        Expression expr = ExpressionFactory.createExpression(expression);

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

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

        return result;
View Full Code Here

    @SuppressWarnings("unchecked")
    public String resolve(String expression, ObjectModel objectModel) {
        Object o = null;
        try {
            Expression e = ExpressionFactory.createExpression(expression);
            JexlContext jc = JexlHelper.createContext();
            jc.getVars().putAll(objectModel.getParameters());

            o = e.evaluate(jc);
        } catch (Exception e1) {
            e1.printStackTrace();
        }

        return o != null ? o.toString() : "";
View Full Code Here

     * @param expressionText The JEXL expression text
     * @return A compiled JEXL expression representing the expression text
     * @throws Exception Thrown if there was an error compiling the expression text
     */
    protected Expression getJexlExpression(String expressionText) throws Exception {
        Expression retVal = jexlExpressionCache.get(expressionText);
        if (retVal == null) {
            //Don't need synchronization here - if we end up calling createExpression in 2 separate threads, that's fine
            jexlExpressionCache.put(expressionText, retVal = ExpressionFactory.createExpression(expressionText));
        }
        return retVal;
View Full Code Here

          generatedObject);
        jexlContext.getVars().put(ARGUMENT_VALUE,
          finalPropertyValue);
        String expressionString = propertyName.replace(
          ARGUMENT_TOKEN, ARGUMENT_VALUE);
        Expression expression = ExpressionFactory
          .createExpression("generatedObject."
            + expressionString);
        expression.evaluate(jexlContext);
    } else {
        // TODO Throw an Exception here since not including the
        // ARGUMENT_TOKEN in the expression is a violation of the
        // updated specification.
        log.warn("Using legacy property setting method.");
View Full Code Here

                    .keySet().iterator();
            while (it.hasNext()) {
                String variableName = it.next();
                String valueExpression = csvMappingDefinition
                        .getExtendedContext().get(variableName);
                Expression preProcessing = ExpressionFactory
                        .createExpression(valueExpression);
                preProcessing.addPreResolver(new PoundDefineJexlResolver());
                jexlContext.getVars().put(variableName,
                        preProcessing.evaluate(jexlContext));
            }
        }

        for (int i = 0; i < lastCsvIndex; i++) {
            if (fieldMappingList.get(currentFieldMappingIndex).getColumnIndex() != i) {
                csvFieldList.add("");
            } else {
                String expressionString = fieldMappingList.get(
                        currentFieldMappingIndex).getObjectToCsvExpression();
                Expression expression = ExpressionFactory
                        .createExpression(expressionString);
                csvFieldList.add(fieldMappingList.get(currentFieldMappingIndex)
                        .getCsvFieldValueFromObject(
                                expression.evaluate(jexlContext)));
                currentFieldMappingIndex++;

                if (currentFieldMappingIndex < fieldMappingList.size()) {
                    while (fieldMappingList.get(currentFieldMappingIndex)
                            .getColumnIndex() == i) {
View Full Code Here

                        return e.getValue(jxpathContext);
                    } finally {
                        jxpathContext.setLenient(oldLenient);
                    }
                } else if (compiled instanceof Expression) {
                    Expression e = (Expression)compiled;
                    return e.evaluate(jexlContext);
                }
                return compiled;
            } catch (InvocationTargetException e) {
                Throwable t = e.getTargetException();
                if (t instanceof Exception) {
                    throw (Exception)t;
                }
                throw (Error)t;
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.jexl.Expression

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.