Package de.odysseus.el.util

Examples of de.odysseus.el.util.SimpleContext$Functions


*/
public class JuelTest extends TestCase {

    public void testJuel() throws Exception {
        ExpressionFactory factory = ExpressionFactory.newInstance();
        ELContext context  = new SimpleContext();
        ValueExpression valueExpression = factory.createValueExpression(context, "${123 * 2}", Object.class);
        Object value = valueExpression.getValue(context);

        System.out.println("Found: " + value + " for expression: " + valueExpression);
    }
View Full Code Here


        return context;
    }

    protected void setVariable(ELContext context, String name, Object value, Class<?> type) {
        ValueExpression valueExpression = getExpressionFactory().createValueExpression(value, type);
        SimpleContext simpleContext = (SimpleContext) context;
        simpleContext.setVariable(name, valueExpression);
    }
View Full Code Here

    /**
     * Factory method to create the EL context
     */
    protected ELContext createContext() {
        return new SimpleContext();
    }
View Full Code Here

        properties.setProperty("javax.el.methodInvocations", "true");
    }

    protected void setVariable(ELContext context, String name, Object value, Class<?> type) {
        ValueExpression valueExpression = getExpressionFactory().createValueExpression(value, type);
        SimpleContext simpleContext = (SimpleContext) context;
        simpleContext.setVariable(name, valueExpression);
    }
View Full Code Here

                add(new MapELResolver(false));
                add(new ResourceBundleELResolver());
                add(new BeanAndMethodELResolver());
            }
        };
        return new SimpleContext(resolver);
    }
View Full Code Here

*/
public class JuelTest extends TestCase {

    public void testJuel() throws Exception {
        ExpressionFactory factory = new ExpressionFactoryImpl();
        ELContext context  = new SimpleContext();
        ValueExpression valueExpression = factory.createValueExpression(context, "${123 * 2}", Object.class);
        Object value = valueExpression.getValue(context);

        assertEquals("Result is a Long object", 246L, value);
    }
View Full Code Here

*/
public class JuelTest extends TestCase {

    public void testJuel() throws Exception {
        ExpressionFactory factory = ExpressionFactory.newInstance();
        ELContext context  = new SimpleContext();
        ValueExpression valueExpression = factory.createValueExpression(context, "${123 * 2}", Object.class);
        Object value = valueExpression.getValue(context);

        System.out.println("Found: " + value + " for expression: " + valueExpression);
    }
View Full Code Here

  SimpleContext context;
  TreeStore store = new TreeStore(new Builder(), null);
 
  @Override
  protected void setUp() throws Exception {
    context = new SimpleContext(new SimpleResolver(new BeanELResolver()));
    context.getELResolver().setValue(context, null, "base", this);
  }
View Full Code Here

    }
    NodePrinter.dump(out, tree.getRoot());
    if (!tree.getFunctionNodes().iterator().hasNext() && !tree.getIdentifierNodes().iterator().hasNext()) {
      out.print(">> ");
      try {
        out.println(tree.getRoot().getValue(null, new SimpleContext(), null));
      } catch (ELException e) {
        out.println(e.getMessage());
      }
    }
    out.flush();
View Full Code Here

*/
public class Calculator {
  public static void main(String[] args) throws NoSuchMethodException, IOException {
    ExpressionFactory factory = new ExpressionFactoryImpl();

    SimpleContext context = new SimpleContext();

    // variables e, pi
    context.setVariable("e", factory.createValueExpression(Math.E, double.class));
    context.setVariable("pi", factory.createValueExpression(Math.PI, double.class));
   
    // functions sin, cos, tan, exp, log, abs, sqrt, min, max, pow
    context.setFunction("", "sin", Math.class.getMethod("sin", double.class));
    context.setFunction("", "cos", Math.class.getMethod("cos", double.class));
    context.setFunction("", "tan", Math.class.getMethod("tan", double.class));
    context.setFunction("", "exp", Math.class.getMethod("exp", double.class));
    context.setFunction("", "log", Math.class.getMethod("log", double.class));
    context.setFunction("", "abs", Math.class.getMethod("abs", double.class));
    context.setFunction("", "sqrt", Math.class.getMethod("sqrt", double.class));
    context.setFunction("", "min", Math.class.getMethod("min", double.class, double.class));
    context.setFunction("", "max", Math.class.getMethod("max", double.class, double.class));
    context.setFunction("", "pow", Math.class.getMethod("pow", double.class, double.class));

    // print out the rules of the game...
    System.out.println("> Enter one expression per line (without \"${\" and \"}\"). An expressions matching");
    System.out.println("> \"m[0-9]*\" saves the previous evaluation result to \"memory\". Other expressions");
    System.out.println("> are simply evaluated. Functions are sin, cos, tan, exp, log, abs, sqrt, min,");
View Full Code Here

TOP

Related Classes of de.odysseus.el.util.SimpleContext$Functions

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.