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

The following examples show how to use javax.el.ValueExpression#setValue() . 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 void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            expr.setValue(ctx.getELContext(), value);
            return;
        }
    }
    ctx.setPropertyResolved(false);
    ctx.getELResolver().setValue(ctx, null, this.image, value);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
}
 
Example 2
Source File: TestValueExpressionImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testBug51177ObjectMap() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);

    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);

    Map<Object,Object> map = new HashMap<>();
    map.put("key1", o1);
    map.put("key2", o2);

    ValueExpression var =
        factory.createValueExpression(map, Map.class);
    context.getVariableMapper().setVariable("map", var);

    ValueExpression ve1 = factory.createValueExpression(
            context, "${map.key1}", Object.class);
    ve1.setValue(context, o2);
    Assert.assertEquals(o2, ve1.getValue(context));

    ValueExpression ve2 = factory.createValueExpression(
            context, "${map.key2}", Object.class);
    ve2.setValue(context, o1);
    Assert.assertEquals(o1, ve2.getValue(context));
}
 
Example 3
Source File: TestValueExpressionImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testBug51177ObjectList() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);

    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);

    List<Object> list = new ArrayList<>();
    list.add(0, o1);
    list.add(1, o2);

    ValueExpression var =
        factory.createValueExpression(list, List.class);
    context.getVariableMapper().setVariable("list", var);

    ValueExpression ve1 = factory.createValueExpression(
            context, "${list[0]}", Object.class);
    ve1.setValue(context, o2);
    Assert.assertEquals(o2, ve1.getValue(context));

    ValueExpression ve2 = factory.createValueExpression(
            context, "${list[1]}", Object.class);
    ve2.setValue(context, o1);
    Assert.assertEquals(o1, ve2.getValue(context));
}
 
Example 4
Source File: TestValueExpressionImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testBug56522SetNullValue() {
    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 set the value to null
    ve.setValue(context, null);

    Assert.assertEquals("", beanB.getName());
}
 
Example 5
Source File: AstIdentifier.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            expr.setValue(ctx.getELContext(), value);
            return;
        }
    }
    ctx.setPropertyResolved(false);
    ctx.getELResolver().setValue(ctx, null, this.image, value);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
}
 
Example 6
Source File: TestValueExpressionImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug51177ObjectMap() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);

    Map<Object,Object> map = new HashMap<Object,Object>();
    map.put("key1", o1);
    map.put("key2", o2);

    ValueExpression var =
        factory.createValueExpression(map, Map.class);
    context.getVariableMapper().setVariable("map", var);

    ValueExpression ve1 = factory.createValueExpression(
            context, "${map.key1}", Object.class);
    ve1.setValue(context, o2);
    assertEquals(o2, ve1.getValue(context));

    ValueExpression ve2 = factory.createValueExpression(
            context, "${map.key2}", Object.class);
    ve2.setValue(context, o1);
    assertEquals(o1, ve2.getValue(context));
}
 
Example 7
Source File: TestValueExpressionImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug51177ObjectList() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);

    List<Object> list = new ArrayList<Object>();
    list.add(0, o1);
    list.add(1, o2);

    ValueExpression var =
        factory.createValueExpression(list, List.class);
    context.getVariableMapper().setVariable("list", var);

    ValueExpression ve1 = factory.createValueExpression(
            context, "${list[0]}", Object.class);
    ve1.setValue(context, o2);
    assertEquals(o2, ve1.getValue(context));

    ValueExpression ve2 = factory.createValueExpression(
            context, "${list[1]}", Object.class);
    ve2.setValue(context, o1);
    assertEquals(o1, ve2.getValue(context));
}
 
Example 8
Source File: AstIdentifier.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            expr.setValue(ctx.getELContext(), value);
            return;
        }
    }
    ctx.setPropertyResolved(false);
    ctx.getELResolver().setValue(ctx, null, this.image, value);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
}
 
Example 9
Source File: TestValueExpressionImpl.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug51177ObjectMap() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);

    Map<Object,Object> map = new HashMap<Object,Object>();
    map.put("key1", o1);
    map.put("key2", o2);

    ValueExpression var =
        factory.createValueExpression(map, Map.class);
    context.getVariableMapper().setVariable("map", var);

    ValueExpression ve1 = factory.createValueExpression(
            context, "${map.key1}", Object.class);
    ve1.setValue(context, o2);
    assertEquals(o2, ve1.getValue(context));

    ValueExpression ve2 = factory.createValueExpression(
            context, "${map.key2}", Object.class);
    ve2.setValue(context, o1);
    assertEquals(o1, ve2.getValue(context));
}
 
Example 10
Source File: TestValueExpressionImpl.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug51177ObjectList() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);

    List<Object> list = new ArrayList<Object>();
    list.add(0, o1);
    list.add(1, o2);

    ValueExpression var =
        factory.createValueExpression(list, List.class);
    context.getVariableMapper().setVariable("list", var);

    ValueExpression ve1 = factory.createValueExpression(
            context, "${list[0]}", Object.class);
    ve1.setValue(context, o2);
    assertEquals(o2, ve1.getValue(context));

    ValueExpression ve2 = factory.createValueExpression(
            context, "${list[1]}", Object.class);
    ve2.setValue(context, o1);
    assertEquals(o1, ve2.getValue(context));
}
 
Example 11
Source File: UelUtil.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/** Evaluates a Unified Expression Language expression and sets the resulting object
 * to the specified value.
 * @param context Evaluation context (variables)
 * @param expression UEL expression
 * @param expectedType The expected object Class to set
 */
public static void setValue(Map<String, Object> context, String expression, Class<?> expectedType, Object value) {
    if (Debug.verboseOn()) {
        Debug.logVerbose("UelUtil.setValue invoked, expression = " + expression + ", value = " + value, module);
    }
    ELContext elContext = new BasicContext(context);
    ValueExpression ve = exprFactory.createValueExpression(elContext, expression, expectedType);
    ve.setValue(elContext, value);
}
 
Example 12
Source File: UelUtil.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/** Evaluates a Unified Expression Language expression and sets the resulting object
 * to null.
 * @param context Evaluation context (variables)
 * @param expression UEL expression
 */
public static void removeValue(Map<String, Object> context, String expression) {
    if (Debug.verboseOn()) {
        Debug.logVerbose("UelUtil.removeValue invoked, expression = " + expression , module);
    }
    ELContext elContext = new BasicContext(context);
    ValueExpression ve = exprFactory.createValueExpression(elContext, expression, Object.class);
    ve.setValue(elContext, null);
}