Java Code Examples for javax.el.ValueExpression#getValueReference()

The following examples show how to use javax.el.ValueExpression#getValueReference() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AstIdentifier.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public ValueReference getValueReference(EvaluationContext ctx) {
    VariableMapper varMapper = ctx.getVariableMapper();

    if (varMapper == null) {
        return null;
    }

    ValueExpression expr = varMapper.resolveVariable(this.image);

    if (expr == null) {
        return null;
    }

    return expr.getValueReference(ctx);
}
 
Example 2
Source File: TestValueExpressionImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@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());
}
 
Example 3
Source File: AstIdentifier.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public ValueReference getValueReference(EvaluationContext ctx) {
    VariableMapper varMapper = ctx.getVariableMapper();

    if (varMapper == null) {
        return null;
    }

    ValueExpression expr = varMapper.resolveVariable(this.image);

    if (expr == null) {
        return null;
    }

    return expr.getValueReference(ctx);
}
 
Example 4
Source File: TestValueExpressionImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetValueReference() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    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());
}
 
Example 5
Source File: AstIdentifier.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public ValueReference getValueReference(EvaluationContext ctx) {
    VariableMapper varMapper = ctx.getVariableMapper();

    if (varMapper == null) {
        return null;
    }

    ValueExpression expr = varMapper.resolveVariable(this.image);

    if (expr == null) {
        return null;
    }

    return expr.getValueReference(ctx);
}
 
Example 6
Source File: TestValueExpressionImpl.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetValueReference() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    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());
}
 
Example 7
Source File: TestValueExpressionImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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());
}
 
Example 8
Source File: TestValueExpressionImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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());
}
 
Example 9
Source File: TestValueExpressionImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetValueReferenceVariable() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    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());
}
 
Example 10
Source File: TestValueExpressionImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testBug49345() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    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());
}
 
Example 11
Source File: TestValueExpressionImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetValueReferenceVariable() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    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());
}
 
Example 12
Source File: TestValueExpressionImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testBug49345() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    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());
}
 
Example 13
Source File: ELTools.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
/**
 * Which annotations are given to an object described by an EL expression?
 *
 * @param p_expression
 *            EL expression of the JSF bean attribute
 * @return null if there are no annotations, or if they cannot be accessed
 */
public static Annotation[] readAnnotations(ValueExpression p_expression, UIComponent p_component) {
	FacesContext context = FacesContext.getCurrentInstance();
	ELContext elContext = context.getELContext();
	try {
		ValueReference valueReference = p_expression.getValueReference(elContext);
		Object base;
		if (null == valueReference) {
			base = evaluteBaseForMojarra(elContext, p_expression);
		} else {
			base = valueReference.getBase();
		}
		if (null == base) {
			return null;
		}
		Field declaredField = getField(base, p_expression.getExpressionString());
		if (null != declaredField) {
			return declaredField.getAnnotations();
		}
		Method getter = getGetter(base, p_expression.getExpressionString());
		if (null != getter) {
			return getter.getAnnotations();
		}
	} catch (PropertyNotFoundException ex) {
		// this happens if a bean is null. That's a legal state, so suffice it to return no annotation.
	}
	return null;
}