Package org.apache.commons.jexl

Examples of org.apache.commons.jexl.JexlContext


    public void testParse2()
        throws Exception
    {
        Parser parser = new Parser(new StringReader(";"));

        JexlContext jc = JexlHelper.createContext();

        SimpleNode sn = parser.parse(new StringReader("foo = \"bar\";"));
        sn.interpret(jc);
        sn = parser.parse(new StringReader("foo = 'bar';"));
        sn.interpret(jc);
View Full Code Here


     */
    public static void main(String[] args) throws Exception {
        /*
         *  First make a jexlContext and put stuff in it
         */
        JexlContext jc = JexlHelper.createContext();

        List l = new ArrayList();
        l.add("Hello from location 0");
        l.add(new Integer(2));
        jc.getVars().put("array", l);

        Expression e = ExpressionFactory.createExpression("array[1]");
        Object o = e.evaluate(jc);
        System.out.println("Object @ location 1 = " + o);

View Full Code Here

     */
    public static void main(String[] args) throws Exception {
        /*
         *  First make a jexlContext and put stuff in it
         */
        JexlContext jc = JexlHelper.createContext();

        jc.getVars().put("foo", new Foo());
        jc.getVars().put("number", new Integer(10));

        /*
         *  access a method w/o args
         */
        Expression e = ExpressionFactory.createExpression("foo.getFoo()");
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

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

        return result;
View Full Code Here

  public void testJEXL() throws Exception {

    Integer a = Integer.valueOf (5);
    Integer b = Integer.valueOf (8);
    JexlContext jc = JexlHelper.createContext();
    jc.getVars().put("a", a);
    jc.getVars().put("b", b);
    try {
      Expression e = ExpressionFactory.createExpression("a+b");
      Object o = e.evaluate(jc);
      assertEquals(o, Long.valueOf(13));
      System.out.println("JEXL library test ok");
View Full Code Here

 
  public void testJEXLSpeed() throws Exception {
    try {
      int basetimes = 100000;

      JexlContext jc = JexlHelper.createContext();
      jc.getVars().put("__udf__concat", FunctionRegistry.getUDFClass("concat").newInstance());
     
      measureSpeed("1 + 2",
          basetimes * 100,
          ExpressionFactory.createExpression("1 + 2"),
          jc,
View Full Code Here

    @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();
        }
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

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.