Search in sources :

Example 1 with ValueReference

use of javax.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);
    assertEquals("Tomcat", result);
    // Now check the value reference
    ValueReference vr = ve.getValueReference(context);
    assertNotNull(vr);
    assertEquals(beanB, vr.getBase());
    assertEquals("name", vr.getProperty());
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(javax.el.ValueReference) Test(org.junit.Test)

Example 2 with ValueReference

use of javax.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);
    assertEquals("Tomcat", result);
    // Now check the value reference
    ValueReference vr = ve.getValueReference(context);
    assertNotNull(vr);
    assertEquals(beanB, vr.getBase());
    assertEquals("name", vr.getProperty());
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(javax.el.ValueReference) Test(org.junit.Test)

Example 3 with ValueReference

use of javax.el.ValueReference in project oxCore by GluuFederation.

the class ValueExpressionAnalyzer method getValueReference.

public ValueReference getValueReference(ELContext elContext) {
    InterceptingResolver resolver = new InterceptingResolver(elContext.getELResolver());
    try {
        expression.setValue(decorateELContext(elContext, resolver), null);
    } catch (ELException ele) {
        return null;
    }
    ValueReference reference = resolver.getValueReference();
    if (reference != null) {
        Object base = reference.getBase();
        if (base instanceof CompositeComponentExpressionHolder) {
            ValueExpression ve = ((CompositeComponentExpressionHolder) base).getExpression((String) reference.getProperty());
            if (ve != null) {
                this.expression = ve;
                reference = getValueReference(elContext);
            }
        }
    }
    return reference;
}
Also used : CompositeComponentExpressionHolder(javax.faces.el.CompositeComponentExpressionHolder) ValueExpression(javax.el.ValueExpression) ELException(javax.el.ELException) ValueReference(javax.el.ValueReference)

Example 4 with ValueReference

use of javax.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);
    assertNotNull(vr);
    assertEquals(beanB, vr.getBase());
    assertEquals("name", vr.getProperty());
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(javax.el.ValueReference) Test(org.junit.Test)

Example 5 with ValueReference

use of javax.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(javax.el.ValueReference)

Aggregations

ValueReference (javax.el.ValueReference)5 ValueExpression (javax.el.ValueExpression)4 ELContext (javax.el.ELContext)3 ExpressionFactory (javax.el.ExpressionFactory)3 ELContextImpl (org.apache.jasper.el.ELContextImpl)3 Test (org.junit.Test)3 ELException (javax.el.ELException)1 CompositeComponentExpressionHolder (javax.faces.el.CompositeComponentExpressionHolder)1 EvaluationContext (org.apache.el.lang.EvaluationContext)1