Package org.apache.commons.jexl

Examples of org.apache.commons.jexl.Expression


    {
      try
      {
        CallflowNotification notif = (CallflowNotification) notification;
        JexlContext jc = JexlHelper.createContext();
        Expression msgExpression = null;
        msgExpression = ExpressionFactory.createExpression("log." + _filter);

        jc.getVars().put("log", notif.getMessageInfo());
        jc.getVars().put("message", notif.getMessageInfo().getMessage());

        return ((Boolean) msgExpression.evaluate(jc));
      }
      catch (Exception e)
      {
        Log.ignore(e);
      }
View Full Code Here


      return null;
   
    synchronized (this)
    {
      JexlContext jc = JexlHelper.createContext();
      Expression msgExpression = null;
      if (msgFilter != null && !msgFilter.trim().equals(""))
      {
        Log.debug("Get messages with filter: " + msgFilter);
        msgExpression = ExpressionFactory.createExpression("log." + msgFilter);
      }
   
      List<MessageInfo> result = new ArrayList<MessageInfo>();
      ListIterator<MessageInfo> it = iterate(false);
     
      int i = 0;
      while (it.hasPrevious() && i < maxMessages)
      {
        MessageInfo info = it.previous();
        jc.getVars().put("log", info);
        jc.getVars().put("message", info.getMessage());
     
        if (msgExpression == null || ((Boolean) msgExpression.evaluate(jc)).booleanValue())
        {
          result.add(0, info);
          i++;
        }
      }
View Full Code Here

      return null;
   
    synchronized (this)
    {
      JexlContext jc = JexlHelper.createContext();
      Expression msgExpression = null;
      if (msgFilter != null && !msgFilter.trim().equals(""))
      {
        Log.debug("Get messages with filter: " + msgFilter);
        msgExpression = ExpressionFactory.createExpression("log." + msgFilter);
      }
   
      List<MessageInfo> result = new ArrayList<MessageInfo>();
      ListIterator<MessageInfo> it = iterate(false);
     
      int i = 0;
      while (it.hasPrevious() && i < maxMessages)
      {
        MessageInfo info = it.previous();
        jc.getVars().put("log", info);
        jc.getVars().put("message", info.getMessage());
     
        if (msgExpression == null || ((Boolean) msgExpression.evaluate(jc)).booleanValue())
        {
          result.add(0, info);
          i++;
        }
      }
View Full Code Here

        ReflectionUtils.doWithMethods(obj.getClass(), new ReflectionUtils.MethodCallback() {
            @SuppressWarnings("unchecked")
            public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
                if (method.getAnnotation(Callback.class) != null) {
                    try {
                        Expression e = ExpressionFactory.createExpression(
                                method.getAnnotation(Callback.class).condition());
                        JexlContext jc = JexlHelper.createContext();
                        jc.getVars().put("this", obj);
                        Object r = e.evaluate(jc);
                        if (!(r instanceof Boolean)) {
                            throw new RuntimeException("Expression did not returned a boolean value but: " + r);
                        }
                        Boolean oldVal = req.getCallbacks().get(method);
                        Boolean newVal = (Boolean) r;
View Full Code Here

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

        log.debug("Evaluating expression: {}", expression);
       
        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

    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

            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

        if (vars == null) {
            return null;
        }
       
        Expression e = ExpressionFactory.createExpression(expression);

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

        return e.evaluate(jc);
    }
View Full Code Here

    @SuppressWarnings(value = "unchecked")
    public Object eval(String expression, Map<String, Object> contextData) {
        Object result = null;
        try {
            // Create expression
            Expression exp = ExpressionFactory.createExpression(expression);

            // Create a context and add data
            JexlContext jc = JexlHelper.createContext();
            if (null != contextData && contextData.size() > 0) {
                for (Map.Entry<String, Object> entry : contextData.entrySet()) {
                    jc.getVars().put(entry.getKey(), entry.getValue());
                }
            }

            // Now evaluate the expression, getting the result
            result = exp.evaluate(jc);
        } catch (Exception ex) {
        }
        return result;
    }
View Full Code Here

        JMeterContext jmctx = JMeterContextService.getContext();
        JMeterVariables vars = jmctx.getVariables();

        try
        {
            Expression e = ExpressionFactory.createExpression(exp);
            JexlContext jc = JexlHelper.createContext();
            final Map jexlVars = jc.getVars();
            jexlVars.put("ctx", jmctx); //$NON-NLS-1$               
            jexlVars.put("vars", vars); //$NON-NLS-1$
            jexlVars.put("props", JMeterUtils.getJMeterProperties()); //$NON-NLS-1$
            jexlVars.put("theadName", Thread.currentThread().getName()); //$NON-NLS-1$
            jexlVars.put("sampler", currentSampler); //$NON-NLS-1$ (may be null)
            jexlVars.put("sampleResult", previousResult); //$NON-NLS-1$ (may be null)

            // Now evaluate the expression, getting the result
            Object o = e.evaluate(jc);
            if (o != null)
            {
                str = o.toString();
            }
            if (vars != null && varName.length() > 0) {// vars will be null on TestPlan
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.