Search in sources :

Example 16 with ExpressionFactory

use of javax.el.ExpressionFactory in project tomcat70 by apache.

the class TestELParser method bug56185.

@Test
public void bug56185() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    TesterBeanC beanC = new TesterBeanC();
    ValueExpression var = factory.createValueExpression(beanC, TesterBeanC.class);
    context.getVariableMapper().setVariable("myBean", var);
    ValueExpression ve = factory.createValueExpression(context, "${(myBean.int1 > 1 and myBean.myBool) or " + "((myBean.myBool or myBean.myBool1) and myBean.int1 > 1)}", Boolean.class);
    Assert.assertEquals(Boolean.FALSE, ve.getValue(context));
    beanC.setInt1(2);
    beanC.setMyBool1(true);
    Assert.assertEquals(Boolean.TRUE, ve.getValue(context));
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 17 with ExpressionFactory

use of javax.el.ExpressionFactory in project tomcat70 by apache.

the class TestELParser method testJavaKeyWordIdentifier.

@Test
public void testJavaKeyWordIdentifier() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    TesterBeanA beanA = new TesterBeanA();
    beanA.setInt("five");
    ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("this", var);
    // Should fail
    Exception e = null;
    try {
        factory.createValueExpression(context, "${this}", String.class);
    } catch (ELException ele) {
        e = ele;
    }
    Assert.assertNotNull(e);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ELException(javax.el.ELException) ELException(javax.el.ELException) Test(org.junit.Test)

Example 18 with ExpressionFactory

use of javax.el.ExpressionFactory in project jersey by jersey.

the class LinkELContextTest method testEmbeddedExpression.

@Test
public void testEmbeddedExpression() {
    System.out.println("Embedded expression");
    ExpressionFactory factory = ExpressionFactory.newInstance();
    LinkELContext context = new LinkELContext(new EntityBean(), null);
    ValueExpression expr = factory.createValueExpression(context, "foo/${entity.id}/bar", String.class);
    Object value = expr.getValue(context);
    assertEquals("foo/" + ID + "/bar", value);
}
Also used : ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) Test(org.junit.Test)

Example 19 with ExpressionFactory

use of javax.el.ExpressionFactory in project jersey by jersey.

the class LinkELContextTest method testMultipleExpressions.

@Test
public void testMultipleExpressions() {
    System.out.println("Multiple expressions");
    ExpressionFactory factory = ExpressionFactory.newInstance();
    LinkELContext context = new LinkELContext(new EntityBean(), null);
    ValueExpression expr = factory.createValueExpression(context, "foo/${entity.id}/bar/${entity.name}", String.class);
    Object value = expr.getValue(context);
    assertEquals("foo/" + ID + "/bar/" + NAME, value);
}
Also used : ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) Test(org.junit.Test)

Example 20 with ExpressionFactory

use of javax.el.ExpressionFactory in project camel by apache.

the class JuelExpression method evaluate.

public <T> T evaluate(Exchange exchange, Class<T> tClass) {
    // Create (if needed) the ExpressionFactory first from the CamelContext using FactoryFinder
    ExpressionFactory factory = getExpressionFactory(exchange.getContext());
    ELContext context = populateContext(createContext(), exchange);
    ValueExpression valueExpression = factory.createValueExpression(context, expression, type);
    Object value = valueExpression.getValue(context);
    LOG.trace("Value returned {}", value);
    return exchange.getContext().getTypeConverter().convertTo(tClass, value);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression)

Aggregations

ExpressionFactory (javax.el.ExpressionFactory)39 ValueExpression (javax.el.ValueExpression)28 Test (org.junit.Test)24 ELContext (javax.el.ELContext)22 ELContextImpl (org.apache.jasper.el.ELContextImpl)15 ELException (javax.el.ELException)4 ValueReference (javax.el.ValueReference)3 IOException (java.io.IOException)2 StringTokenizer (java.util.StringTokenizer)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 FacesException (javax.faces.FacesException)2 FacesContext (javax.faces.context.FacesContext)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1 SimpleContext (de.odysseus.el.util.SimpleContext)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ELResolver (javax.el.ELResolver)1 ServletContextEvent (javax.servlet.ServletContextEvent)1