Search in sources :

Example 56 with ValueExpression

use of javax.el.ValueExpression in project jersey by jersey.

the class ELLinkBuilder method getParameterValues.

private static Map<String, Object> getParameterValues(List<String> parameterNames, InjectLinkDescriptor linkField, LinkELContext context, UriInfo uriInfo) {
    Map<String, Object> values = new HashMap<>();
    for (String name : parameterNames) {
        String elExpression = linkField.getBinding(name);
        if (elExpression == null) {
            String value = uriInfo.getPathParameters().getFirst(name);
            if (value == null) {
                value = uriInfo.getQueryParameters().getFirst(name);
            }
            if (value != null) {
                values.put(name, value);
                continue;
            }
            elExpression = "${" + ResponseContextResolver.INSTANCE_OBJECT + "." + name + "}";
        }
        ValueExpression expr = expressionFactory.createValueExpression(context, elExpression, String.class);
        Object value = expr.getValue(context);
        values.put(name, value != null ? value.toString() : null);
    }
    return values;
}
Also used : HashMap(java.util.HashMap) ValueExpression(javax.el.ValueExpression)

Example 57 with ValueExpression

use of javax.el.ValueExpression in project jersey by jersey.

the class LinkELContextTest method testEmbeddedExpression.

@Test
public void testEmbeddedExpression() {
    System.out.println("Embedded expression");
    ExpressionFactory factory = ExpressionFactory.newInstance();
    LinkELContext context = new LinkELContext(new EntityBean(), null);
    ValueExpression expr = factory.createValueExpression(context, "foo/${entity.id}/bar", String.class);
    Object value = expr.getValue(context);
    assertEquals("foo/" + ID + "/bar", value);
}
Also used : ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) Test(org.junit.Test)

Example 58 with ValueExpression

use of javax.el.ValueExpression in project jersey by jersey.

the class LinkELContextTest method testMultipleExpressions.

@Test
public void testMultipleExpressions() {
    System.out.println("Multiple expressions");
    ExpressionFactory factory = ExpressionFactory.newInstance();
    LinkELContext context = new LinkELContext(new EntityBean(), null);
    ValueExpression expr = factory.createValueExpression(context, "foo/${entity.id}/bar/${entity.name}", String.class);
    Object value = expr.getValue(context);
    assertEquals("foo/" + ID + "/bar/" + NAME, value);
}
Also used : ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) Test(org.junit.Test)

Example 59 with ValueExpression

use of javax.el.ValueExpression in project camel by apache.

the class JuelExpression method evaluate.

public <T> T evaluate(Exchange exchange, Class<T> tClass) {
    // Create (if needed) the ExpressionFactory first from the CamelContext using FactoryFinder
    ExpressionFactory factory = getExpressionFactory(exchange.getContext());
    ELContext context = populateContext(createContext(), exchange);
    ValueExpression valueExpression = factory.createValueExpression(context, expression, type);
    Object value = valueExpression.getValue(context);
    LOG.trace("Value returned {}", value);
    return exchange.getContext().getTypeConverter().convertTo(tClass, value);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression)

Aggregations

ValueExpression (javax.el.ValueExpression)59 Test (org.junit.Test)36 ExpressionFactory (javax.el.ExpressionFactory)33 ELContext (javax.el.ELContext)27 ELContextImpl (org.apache.jasper.el.ELContextImpl)17 VariableMapper (javax.el.VariableMapper)9 ELException (javax.el.ELException)7 ELProcessor (javax.el.ELProcessor)7 MethodExpression (javax.el.MethodExpression)7 PropertyNotFoundException (javax.el.PropertyNotFoundException)4 ValueReference (javax.el.ValueReference)4 SimpleContext (de.odysseus.el.util.SimpleContext)2 HashMap (java.util.HashMap)2 ELClass (javax.el.ELClass)2 FunctionMapper (javax.el.FunctionMapper)2 ELParseException (javax.servlet.jsp.el.ELParseException)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1