Search in sources :

Example 1 with ValueReference

use of jakarta.el.ValueReference in project tomcat by apache.

the class TestValueExpressionImpl method testGetValueReference.

@Test
public void testGetValueReference() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class);
    context.getVariableMapper().setVariable("beanB", var);
    ValueExpression ve = factory.createValueExpression(context, "${beanB.name}", String.class);
    // First check the basics work
    String result = (String) ve.getValue(context);
    Assert.assertEquals("Tomcat", result);
    // Now check the value reference
    ValueReference vr = ve.getValueReference(context);
    Assert.assertNotNull(vr);
    Assert.assertEquals(beanB, vr.getBase());
    Assert.assertEquals("name", vr.getProperty());
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(jakarta.el.ValueReference) Test(org.junit.Test)

Example 2 with ValueReference

use of jakarta.el.ValueReference in project tomcat by apache.

the class TestValueExpressionImpl method testBug49345.

@Test
public void testBug49345() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    TesterBeanA beanA = new TesterBeanA();
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    beanA.setBean(beanB);
    ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);
    ValueExpression ve = factory.createValueExpression(context, "${beanA.bean.name}", String.class);
    // First check the basics work
    String result = (String) ve.getValue(context);
    Assert.assertEquals("Tomcat", result);
    // Now check the value reference
    ValueReference vr = ve.getValueReference(context);
    Assert.assertNotNull(vr);
    Assert.assertEquals(beanB, vr.getBase());
    Assert.assertEquals("name", vr.getProperty());
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(jakarta.el.ValueReference) Test(org.junit.Test)

Example 3 with ValueReference

use of jakarta.el.ValueReference in project tomcat by apache.

the class ValueExpressionImpl method getValueReference.

/**
 * @since EL 2.2
 */
@Override
public ValueReference getValueReference(ELContext context) {
    EvaluationContext ctx = new EvaluationContext(context, this.fnMapper, this.varMapper);
    context.notifyBeforeEvaluation(getExpressionString());
    ValueReference result = this.getNode().getValueReference(ctx);
    context.notifyAfterEvaluation(getExpressionString());
    return result;
}
Also used : EvaluationContext(org.apache.el.lang.EvaluationContext) ValueReference(jakarta.el.ValueReference)

Example 4 with ValueReference

use of jakarta.el.ValueReference in project tomcat by apache.

the class TestValueExpressionImpl method testGetValueReferenceVariable.

@Test
public void testGetValueReferenceVariable() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class);
    context.getVariableMapper().setVariable("beanB", var);
    ValueExpression var2 = factory.createValueExpression(context, "${beanB.name}", String.class);
    context.getVariableMapper().setVariable("foo", var2);
    ValueExpression ve = factory.createValueExpression(context, "${foo}", ValueExpression.class);
    // Now check the value reference
    ValueReference vr = ve.getValueReference(context);
    Assert.assertNotNull(vr);
    Assert.assertEquals(beanB, vr.getBase());
    Assert.assertEquals("name", vr.getProperty());
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(jakarta.el.ValueReference) Test(org.junit.Test)

Aggregations

ValueReference (jakarta.el.ValueReference)4 ELContext (jakarta.el.ELContext)3 ExpressionFactory (jakarta.el.ExpressionFactory)3 ValueExpression (jakarta.el.ValueExpression)3 ELContextImpl (org.apache.jasper.el.ELContextImpl)3 Test (org.junit.Test)3 EvaluationContext (org.apache.el.lang.EvaluationContext)1