Package org.apache.commons.jexl

Examples of org.apache.commons.jexl.JexlContext


        String exp = var.execute();

        try
        {
            Expression e = ExpressionFactory.createExpression(exp);
            JexlContext jc = JexlHelper.createContext();
            jc.getVars().put("ctx", sampler.getThreadContext()); //$NON-NLS-1$
            jc.getVars().put("vars", getVariables()); //$NON-NLS-1$
            jc.getVars().put("theadName", sampler.getThreadName()); //$NON-NLS-1$
            jc.getVars().put("sampler", sampler); //$NON-NLS-1$
            jc.getVars().put("sampleResult", result); //$NON-NLS-1$

            // Now evaluate the expression, getting the result
            Object o = e.evaluate(jc);
            if (o != null)
            {
View Full Code Here


            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);
        }
View Full Code Here

        JMeterVariables vars = jmctx.getVariables();

        try
        {
            Script script = ScriptFactory.createScript(exp);
            JexlContext jc = JexlHelper.createContext();
            @SuppressWarnings("unchecked")
            final Map<String, Object> jexlVars = jc.getVars();
            jexlVars.put("log", log); //$NON-NLS-1$
            jexlVars.put("ctx", jmctx); //$NON-NLS-1$
            jexlVars.put("vars", vars); //$NON-NLS-1$
            jexlVars.put("props", JMeterUtils.getJMeterProperties()); //$NON-NLS-1$
            // Previously mis-spelt as theadName
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();
        }
View Full Code Here

        return "${" + expression.getExpression() + "}";
    }

    public Object evaluate(JellyContext context) {
        try {
            JexlContext jexlContext = new JellyJexlContext( context );
            if (log.isDebugEnabled()) {
                log.debug("Evaluating EL: " + expression.getExpression());
            }
            Object value = expression.evaluate(jexlContext);
View Full Code Here

                                  Object returnValue,
                                  Throwable exceptionThrown) {
        StringBuilder retVal = new StringBuilder(text.length());

        //create a JexlContext to be used in all evaluations
        JexlContext jexlContext = new HashMapContext();
        for (int i = 0; i < args.length; i++) {
            jexlContext.getVars().put("$" + i, args[i]);
        }
        jexlContext.getVars().put("$this", annotatedObject);
        jexlContext.getVars().put("$return", returnValue);
        jexlContext.getVars().put("$exception", exceptionThrown);

        // look for {expression} in the passed in text
        int bracketIndex;
        int lastCloseBracketIndex = -1;
        while ((bracketIndex = text.indexOf('{', lastCloseBracketIndex + 1)) >= 0) {
View Full Code Here

        if (isLeafNode()) {
            return matchPattern(classMetaData, memberMetaData);
        }
        else {
            try {
                JexlContext jexlContext = JexlHelper.createContext();

                for (Iterator it = m_expressionRefs.entrySet().iterator(); it.hasNext();) {
                    Map.Entry entry = (Map.Entry)it.next();

                    String name = (String)entry.getKey();
                    Expression expression = (Expression)entry.getValue();

                    if (expression instanceof CflowExpression) {
                        jexlContext.getVars().put(name, Boolean.TRUE);
                        continue;
                    }

                    // try to find a match somewhere in the class hierarchy (interface or super class)
                    if (expression.match(classMetaData, memberMetaData)) {
                        jexlContext.getVars().put(name, Boolean.TRUE);
                    }
                    else {
                        jexlContext.getVars().put(name, Boolean.FALSE);
                    }
                }
                return evaluateExpression(jexlContext);
            }
            catch (Exception e) {
View Full Code Here

        if (isLeafNode() && this instanceof ThrowsExpression) {
            return ((ThrowsExpression)this).matchPattern(classMetaData, memberMetaData, exceptionType);
        }
        else {
            try {
                JexlContext jexlContext = JexlHelper.createContext();

                for (Iterator it = m_expressionRefs.entrySet().iterator(); it.hasNext();) {
                    Map.Entry entry = (Map.Entry)it.next();

                    String name = (String)entry.getKey();
                    Expression expression = (Expression)entry.getValue();

                    if (expression instanceof CflowExpression) {
                        jexlContext.getVars().put(name, Boolean.TRUE);
                        continue;
                    }

                    // try to find a match somewhere in the class hierarchy (interface or super class)
                    if (expression.match(classMetaData, memberMetaData, exceptionType)) {
                        jexlContext.getVars().put(name, Boolean.TRUE);
                    }
                    else {
                        jexlContext.getVars().put(name, Boolean.FALSE);
                    }
                }
                return evaluateExpression(jexlContext);
            }
            catch (Exception e) {
View Full Code Here

* @author <a href="mailto:jboner@codehaus.org">Jonas Bon�r</a>
*/
public class JexlTest extends TestCase {

    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);
    }
View Full Code Here

        Object actual = e.evaluate(jc);
        assertEquals(Boolean.FALSE, actual);
    }

    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);
    }
View Full Code Here

TOP

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

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.