Java Code Examples for javax.el.ValueExpression

The following are top voted examples for showing how to use javax.el.ValueExpression. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: tomcat7   File: TestELParser.java   View source code 7 votes vote down vote up
@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);
    assertEquals(Boolean.FALSE, ve.getValue(context));
    beanC.setInt1(2);
    beanC.setMyBool1(true);
    assertEquals(Boolean.TRUE, ve.getValue(context));
}
 
Example 2
Project: myfaces-trinidad   File: ValueBindingValueExpression.java   View source code 6 votes vote down vote up
/**
 * Given a ValueBinding <code>binding</code>, return a ValueExpression.
 * The returned ValueExpression will implement StateHolder and Serializable interfaces if
 * <code>ve</code> implements these interfaces.
 * @param binding  The ValueBinding
 * @return a ValueExpression equivalent to the ValueBinding
 */
public static ValueExpression getValueExpression(ValueBinding binding)
{
  // if we previously wrapped a ValueExpression, unwrap it and return it, otherwise create the
  // correct subclass of ValueBindingValueExpression
  if (binding instanceof ValueExpressionValueBinding)
    return ((ValueExpressionValueBinding)binding).getValueExpression();
  else if (binding instanceof StateHolder)
  {
    if (binding instanceof Serializable)
      return new SerializableStateHolderValueBindingValueExpression(binding);
    else
      return new StateHolderValueBindingValueExpression(binding);      
  }
  else if (binding instanceof Serializable)
  {
    return new SerializableValueBindingValueExpression(binding);
  }
  else
  {
    return new ValueBindingValueExpression(binding);      
  }
}
 
Example 3
Project: apache-tomcat-7.0.73-with-comment   File: ExpressionEvaluatorImpl.java   View source code 6 votes vote down vote up
@Override
public Expression parseExpression(String expression,
        @SuppressWarnings("rawtypes") // API does not use generics
        Class expectedType,
        FunctionMapper fMapper) throws ELException {
    try {
        ELContextImpl ctx =
            new ELContextImpl(ELContextImpl.getDefaultResolver());
        if (fMapper != null) {
            ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
        }
        ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
        return new ExpressionImpl(ve);
    } catch (javax.el.ELException e) {
        throw new ELParseException(e.getMessage());
    }
}
 
Example 4
Project: tomcat7   File: AstIdentifier.java   View source code 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getType(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Class<?> result = ctx.getELResolver().getType(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example 5
Project: myfaces-trinidad   File: PropertyArrayMap.java   View source code 6 votes vote down vote up
@Override
public Object put(
  PropertyKey key,
  Object      value)
{
  Object retValue = super.put(key, value);
  if (_createDeltas())
  {
    if (key.getMutable().isAtLeastSometimesMutable() || !_equals(value, retValue))
      _deltas.put(key, value);
  }
  else if (key.getMutable().isAtLeastSometimesMutable() && !(value instanceof ValueExpression))
  {
    _getMutableTracker(true).addProperty(key);
  }

  if (key.isPartialStateHolder())
  {
    _getPartialStateHolderTracker(true).addProperty(key);
  }

  return retValue;
}
 
Example 6
Project: tomcat7   File: AstIdentifier.java   View source code 6 votes vote down vote up
@Override
public boolean isReadOnly(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.isReadOnly(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    boolean result = ctx.getELResolver().isReadOnly(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example 7
Project: lazycat   File: AstIdentifier.java   View source code 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 8
Project: myfaces-trinidad   File: PropertyHashMap.java   View source code 6 votes vote down vote up
@Override
public Object put(
  PropertyKey key,
  Object      value)
{
  Object retValue = super.put(key, value);
  if (_createDeltas())
  {
    
    if ( key.getMutable().isAtLeastSometimesMutable() || !_equals(value, retValue))
      _deltas.put(key, value);
  }
  else if (key.getMutable().isAtLeastSometimesMutable() && !(value instanceof ValueExpression))
  {
    _getMutableTracker(true).addProperty(key);
  }
  
  if (key.isPartialStateHolder())
  {
    _getPartialStateHolderTracker(true).addProperty(key);
  }

  return retValue;
}
 
Example 9
Project: apache-tomcat-7.0.73-with-comment   File: TestValueExpressionImpl.java   View source code 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 10
Project: lazycat   File: ExpressionEvaluatorImpl.java   View source code 6 votes vote down vote up
@Override
public Expression parseExpression(String expression, @SuppressWarnings("rawtypes") // API
																					// does
																					// not
																					// use
																					// generics
Class expectedType, FunctionMapper fMapper) throws ELException {
	try {
		ELContextImpl ctx = new ELContextImpl(ELContextImpl.getDefaultResolver());
		if (fMapper != null) {
			ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
		}
		ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
		return new ExpressionImpl(ve);
	} catch (javax.el.ELException e) {
		throw new ELParseException(e.getMessage());
	}
}
 
Example 11
Project: tomcat7   File: ExpressionEvaluatorImpl.java   View source code 6 votes vote down vote up
@Override
public Expression parseExpression(String expression,
        @SuppressWarnings("rawtypes") // API does not use generics
        Class expectedType,
        FunctionMapper fMapper) throws ELException {
    try {
        ELContextImpl ctx =
            new ELContextImpl(ELContextImpl.getDefaultResolver());
        if (fMapper != null) {
            ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
        }
        ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
        return new ExpressionImpl(ve);
    } catch (javax.el.ELException e) {
        throw new ELParseException(e.getMessage());
    }
}
 
Example 12
Project: tomcat7   File: TestELParser.java   View source code 6 votes vote down vote up
@Test
public void testJavaKeyWordSuffix() {
    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("beanA", var);

    // Should fail
    Exception e = null;
    try {
        factory.createValueExpression(context, "${beanA.int}",
                String.class);
    } catch (ELException ele) {
        e = ele;
    }
    assertNotNull(e);
}
 
Example 13
Project: myfaces-trinidad   File: UIXComponentBase.java   View source code 6 votes vote down vote up
@Override
public void setValueExpression(String name,
                               ValueExpression expression)
{
  if (name == null)
    throw new NullPointerException();

  if ((expression != null) && expression.isLiteralText())
  {
    ELContext context =
        FacesContext.getCurrentInstance().getELContext();
    getAttributes().put(name, expression.getValue(context));
  }
  else
  {
    PropertyKey key = getPropertyKey(name);
    getFacesBean().setValueExpression(key, expression);
  }
}
 
Example 14
Project: tomcat7   File: TestELParser.java   View source code 6 votes vote down vote up
private void doTestBug56179(int parenthesesCount, String innerExpr) {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    ValueExpression var =
        factory.createValueExpression(Boolean.TRUE, Boolean.class);
    context.getVariableMapper().setVariable("test", var);

    StringBuilder expr = new StringBuilder();
    expr.append("${");
    for (int i = 0; i < parenthesesCount; i++) {
        expr.append("(");
    }
    expr.append(innerExpr);
    for (int i = 0; i < parenthesesCount; i++) {
        expr.append(")");
    }
    expr.append("}");
    ValueExpression ve = factory.createValueExpression(
            context, expr.toString(), String.class);

    String result = (String) ve.getValue(context);
    assertEquals("true", result);
}
 
Example 15
Project: tomcat7   File: TestELParser.java   View source code 6 votes vote down vote up
private void testExpression(String expression, String expected) {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    ValueExpression ve = factory.createValueExpression(
            context, expression, String.class);

    String result = (String) ve.getValue(context);
    assertEquals(expected, result);
}
 
Example 16
Project: tomcat7   File: TestMethodExpressionImpl.java   View source code 6 votes vote down vote up
@Test
public void testIsParametersProvided() {
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    ValueExpression var =
        factory.createValueExpression(beanB, TesterBeanB.class);
    context.getVariableMapper().setVariable("beanB", var);

    MethodExpression me1 = factory.createMethodExpression(
            context, "${beanB.getName}", String.class, new Class<?>[] {});
    MethodExpression me2 = factory.createMethodExpression(
            context, "${beanB.sayHello('JUnit')}", String.class,
            new Class<?>[] { String.class });

    assertFalse(me1.isParmetersProvided());
    assertTrue(me2.isParmetersProvided());
}
 
Example 17
Project: lazycat   File: AstIdentifier.java   View source code 6 votes vote down vote up
@Override
public boolean isReadOnly(EvaluationContext ctx) throws ELException {
	VariableMapper varMapper = ctx.getVariableMapper();
	if (varMapper != null) {
		ValueExpression expr = varMapper.resolveVariable(this.image);
		if (expr != null) {
			return expr.isReadOnly(ctx.getELContext());
		}
	}
	ctx.setPropertyResolved(false);
	boolean result = ctx.getELResolver().isReadOnly(ctx, null, this.image);
	if (!ctx.isPropertyResolved()) {
		throw new PropertyNotFoundException(MessageFactory.get("error.resolver.unhandled.null", this.image));
	}
	return result;
}
 
Example 18
Project: myfaces-trinidad   File: UIXComponentELTag.java   View source code 6 votes vote down vote up
/**
 * Set a property of type java.util.Set&lt;java.lang.String>.  If the value
 * is an EL expression, it will be stored as a ValueExpression.
 * Otherwise, it will parsed as a whitespace-separated series
 * of strings.
 * Null values are ignored.
 */
protected void setStringSetProperty(
  FacesBean       bean,
  PropertyKey     key,
  ValueExpression expression)
{
  if (expression == null)
    return;

  if (expression.isLiteralText())
  {
    bean.setProperty(key, TagUtils.parseNameTokensAsSet(
      expression.getValue(FacesContext.getCurrentInstance().getELContext())));
  }
  else
  {
    bean.setValueExpression(key, expression);
  }
}
 
Example 19
Project: apache-tomcat-7.0.73-with-comment   File: TestELParser.java   View source code 6 votes vote down vote up
private void doTestBug56179(int parenthesesCount, String innerExpr) {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    ValueExpression var =
        factory.createValueExpression(Boolean.TRUE, Boolean.class);
    context.getVariableMapper().setVariable("test", var);

    StringBuilder expr = new StringBuilder();
    expr.append("${");
    for (int i = 0; i < parenthesesCount; i++) {
        expr.append("(");
    }
    expr.append(innerExpr);
    for (int i = 0; i < parenthesesCount; i++) {
        expr.append(")");
    }
    expr.append("}");
    ValueExpression ve = factory.createValueExpression(
            context, expr.toString(), String.class);

    String result = (String) ve.getValue(context);
    assertEquals("true", result);
}
 
Example 20
Project: tomcat7   File: TestValueExpressionImpl.java   View source code 6 votes vote down vote up
@Test
public void testBug50105() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterEnum testEnum = TesterEnum.APPLE;

    ValueExpression var =
        factory.createValueExpression(testEnum, TesterEnum.class);
    context.getVariableMapper().setVariable("testEnum", var);

    // When coercing an Enum to a String, name() should always be used.
    ValueExpression ve1 = factory.createValueExpression(
            context, "${testEnum}", String.class);
    String result1 = (String) ve1.getValue(context);
    assertEquals("APPLE", result1);

    ValueExpression ve2 = factory.createValueExpression(
            context, "foo${testEnum}bar", String.class);
    String result2 = (String) ve2.getValue(context);
    assertEquals("fooAPPLEbar", result2);
}
 
Example 21
Project: myfaces-trinidad   File: FacesBeanImpl.java   View source code 6 votes vote down vote up
final public void setValueExpression(PropertyKey key,
                                     ValueExpression expression)
{
  _checkNotListKey(key);

  if (!key.getSupportsBinding())
  {
    throw new IllegalArgumentException(_LOG.getMessage(
      "CANNOT_FIND_PROPERTY", key.getName()));
  }

  if (expression == null)
  {
    PropertyMap map = _getExpressionsMap(false);
    if (map != null)
      map.remove(key);
  }
  else
  {
    _getExpressionsMap(true).put(key, expression);
  }

}
 
Example 22
Project: tomcat7   File: TestValueExpressionImpl.java   View source code 6 votes vote down vote up
/**
 * Test using list directly as variable.
 */
@Test
public void testBug51544Direct() throws Exception {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    List<?> list = Collections.emptyList();

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

    ValueExpression ve = factory.createValueExpression(
            context, "${list.size()}", Integer.class);

    Integer result = (Integer) ve.getValue(context);
    assertEquals(Integer.valueOf(0), result);
}
 
Example 23
Project: apache-tomcat-7.0.73-with-comment   File: AstIdentifier.java   View source code 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 24
Project: myfaces-trinidad   File: ReturnActionListenerTag.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void apply(FaceletContext faceletContext,
        UIComponent parent) throws IOException, FacesException, FaceletException, ELException
{
  if(ComponentHandler.isNew(parent))
  {
    ActionSource actionSource = (ActionSource)parent;
    ReturnActionListener listener = new ReturnActionListener();
    if (_value != null)
    {
      ValueExpression valueExp = _value.getValueExpression(faceletContext, Object.class);
      listener.setValueExpression(ReturnActionListener.VALUE_KEY,valueExp);
    }

    actionSource.addActionListener(listener);
  }
}
 
Example 25
Project: myfaces-trinidad   File: LabeledFacesMessage.java   View source code 6 votes vote down vote up
/**
 * Gets a string representation of the label.  If the label
 * is a ValueBinding, the expression is evaluated and the string
 * value returned.
 */
public String getLabelAsString(FacesContext context)
{
  Object label = getLabel();

  if (label instanceof ValueExpression)
  {
    label = ((ValueExpression) label).getValue(context.getELContext());          
  }
  else if (label instanceof ValueBinding)
  {
    label = ((ValueBinding) label).getValue(context);
  }

  if (label == null)
    return null;

  return label.toString();
}
 
Example 26
Project: apache-tomcat-7.0.73-with-comment   File: TestValueExpressionImpl.java   View source code 6 votes vote down vote up
/**
 * Test returning an empty list as a bean property.
 */
@Test
public void testBug51544Bean() throws Exception {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterBeanA beanA = new TesterBeanA();
    beanA.setValList(Collections.emptyList());

    ValueExpression var =
        factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);

    ValueExpression ve = factory.createValueExpression(
            context, "${beanA.valList.size()}", Integer.class);

    Integer result = (Integer) ve.getValue(context);
    assertEquals(Integer.valueOf(0), result);
}
 
Example 27
Project: myfaces-trinidad   File: ValueExpressionValueBinding.java   View source code 6 votes vote down vote up
/**
 * Given a ValueExpression <code>ve</code>, return a ValueBinding.
 * The returned ValueBinding will implement StateHolder and Serializable interfaces if
 * <code>ve</code> implements these interfaces.
 * @param ve  The ValueExpression
 * @return a ValueBinding equivalent to the ValueExpression
 */
public static ValueBinding getValueBinding(ValueExpression ve)
{
  // if we previously wrapped a ValueBinding, unwrap it and return it, otherwise create the
  // correct subclass of ValueBinding
  if (ve instanceof ValueBindingValueExpression)
    return ((ValueBindingValueExpression)ve).getValueBinding();
  else if (ve instanceof StateHolder)
  {
    if (ve instanceof Serializable)
      return new SerializableStateHolderValueExpressionValueBinding(ve);
    else
      return new StateHolderValueExpressionValueBinding(ve);      
  }
  else if (ve instanceof Serializable)
  {
    return new SerializableValueExpressionValueBinding(ve);
  }
  else
  {
    return new ValueExpressionValueBinding(ve);      
  }    
}
 
Example 28
Project: apache-tomcat-7.0.73-with-comment   File: TestValueExpressionImpl.java   View source code 6 votes vote down vote up
/**
 * Test using list directly as variable.
 */
@Test
public void testBug51544Direct() throws Exception {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    List<?> list = Collections.emptyList();

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

    ValueExpression ve = factory.createValueExpression(
            context, "${list.size()}", Integer.class);

    Integer result = (Integer) ve.getValue(context);
    assertEquals(Integer.valueOf(0), result);
}
 
Example 29
Project: lazycat   File: AstIdentifier.java   View source code 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx) throws ELException {
	VariableMapper varMapper = ctx.getVariableMapper();
	if (varMapper != null) {
		ValueExpression expr = varMapper.resolveVariable(this.image);
		if (expr != null) {
			return expr.getType(ctx.getELContext());
		}
	}
	ctx.setPropertyResolved(false);
	Class<?> result = ctx.getELResolver().getType(ctx, null, this.image);
	if (!ctx.isPropertyResolved()) {
		throw new PropertyNotFoundException(MessageFactory.get("error.resolver.unhandled.null", this.image));
	}
	return result;
}
 
Example 30
Project: myfaces-trinidad   File: HtmlResponseWriter.java   View source code 6 votes vote down vote up
private String _processPassThroughAttributes(String name, UIComponent component) {
  if (component == null) {
    return name;
  }
  _passThroughAttributes = component.getPassThroughAttributes(false);
  if (_passThroughAttributes != null)
  {
    Object value = _passThroughAttributes.get(Renderer.PASSTHROUGH_RENDERER_LOCALNAME_KEY);
    if (value instanceof ValueExpression)
    {
      value = ((ValueExpression)value).getValue(FacesContext.getCurrentInstance().getELContext());
    }
    if (value != null)
    {
      String elementName = value.toString();
      if (!name.equals(elementName)) {
        name = elementName;
      }
    }
  }
  return name;
}
 
Example 31
Project: myfaces-trinidad   File: UIXComponentELTag.java   View source code 5 votes vote down vote up
@Override
public void setBinding(ValueExpression valueExpression)
  throws JspException
{
  this._binding = valueExpression;
  super.setBinding(valueExpression);
}
 
Example 32
Project: myfaces-trinidad   File: MessageFactory.java   View source code 5 votes vote down vote up
private static void _assertIsValidCustomMessageType(Object customMessagePattern)
{
  if (!(customMessagePattern instanceof ValueExpression  ||
       customMessagePattern instanceof String))
       throw new IllegalArgumentException(_LOG.getMessage(
         "CUSTOM_MESSAGE_SHOULD_BE_VALUEBINDING_OR_STRING_TYPE"));
}
 
Example 33
Project: apache-tomcat-7.0.73-with-comment   File: ExpressionFactoryImpl.java   View source code 5 votes vote down vote up
@Override
public ValueExpression createValueExpression(Object instance,
        Class<?> expectedType) {
    if (expectedType == null) {
        throw new NullPointerException(MessageFactory
                .get("error.value.expectedType"));
    }
    return new ValueExpressionLiteral(instance, expectedType);
}
 
Example 34
Project: myfaces-trinidad   File: PreferencesProxy.java   View source code 5 votes vote down vote up
public Object getProxy()
{
  FacesContext context = FacesContext.getCurrentInstance();
  String viewId = _getViewId(context);

  if (viewId != null)
  {
    // Certain views have their own preferences
    // storage.  Figure out which preferences
    // we are proxying.
    String preferencesExpression = null;
    
    if (viewId.indexOf("/email/") >= 0)
      preferencesExpression = "#{email.preferences}";
    else if (viewId.indexOf("SkinDemo") >= 0)
      preferencesExpression = "#{sessionScope}";
    else if (viewId.indexOf("accessibilityProfileDemo") >= 0)
      preferencesExpression = "#{accProfileDemo}";

    if (preferencesExpression != null)
    {
      ValueExpression ve =
        context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), preferencesExpression, Object.class);
      return ve.getValue(context.getELContext());
    }
  }
  
  return Collections.EMPTY_MAP;
}
 
Example 35
Project: tomcat7   File: ELContextImpl.java   View source code 5 votes vote down vote up
@Override
public ValueExpression resolveVariable(String variable) {
    if (vars == null) {
        return null;
    }
    return vars.get(variable);
}
 
Example 36
Project: tomcat7   File: ELContextImpl.java   View source code 5 votes vote down vote up
@Override
public ValueExpression setVariable(String variable,
        ValueExpression expression) {
    if (vars == null)
        vars = new HashMap<String, ValueExpression>();
    return vars.put(variable, expression);
}
 
Example 37
Project: tomcat7   File: TestMethodExpressionImpl.java   View source code 5 votes vote down vote up
@Test
public void testInvokeWithSuper() {
    MethodExpression me = factory.createMethodExpression(context,
            "${beanA.setBean(beanBB)}", null ,
            new Class<?>[] { TesterBeanB.class });
    me.invoke(context, null);
    ValueExpression ve = factory.createValueExpression(context,
            "${beanA.bean.name}", String.class);
    Object r = ve.getValue(context);
    assertEquals("BB", r);
}
 
Example 38
Project: tomcat7   File: TestMethodExpressionImpl.java   View source code 5 votes vote down vote up
@Test
public void testBug49655() throws Exception {
    // This is the call the failed
    MethodExpression me = factory.createMethodExpression(context,
            "#{beanA.setName('New value')}", null, null);
    // The rest is to check it worked correctly
    me.invoke(context, null);
    ValueExpression ve = factory.createValueExpression(context,
            "#{beanA.name}", java.lang.String.class);
    assertEquals("New value", ve.getValue(context));
}
 
Example 39
Project: lams   File: AstIdentifier.java   View source code 5 votes vote down vote up
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);
}
 
Example 40
Project: apache-tomcat-7.0.73-with-comment   File: TestValueExpressionImpl.java   View source code 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());
}