Search in sources :

Example 51 with ValueExpression

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

the class AstIdentifier method setValue.

@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));
    }
}
Also used : PropertyNotFoundException(javax.el.PropertyNotFoundException) VariableMapper(javax.el.VariableMapper) ValueExpression(javax.el.ValueExpression)

Example 52 with ValueExpression

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

the class AstIdentifier method getType.

@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;
}
Also used : PropertyNotFoundException(javax.el.PropertyNotFoundException) VariableMapper(javax.el.VariableMapper) ValueExpression(javax.el.ValueExpression)

Example 53 with ValueExpression

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

the class AstIdentifier method getValue.

@Override
public Object getValue(EvaluationContext ctx) throws ELException {
    // Lambda parameters
    if (ctx.isLambdaArgument(this.image)) {
        return ctx.getLambdaArgument(this.image);
    }
    // Variable mapper
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getValue(ctx.getELContext());
        }
    }
    // EL Resolvers
    ctx.setPropertyResolved(false);
    Object result;
    /* Putting the Boolean into the ELContext is part of a performance
         * optimisation for ScopedAttributeELResolver. When looking up "foo",
         * the resolver can't differentiate between ${ foo } and ${ foo.bar }.
         * This is important because the expensive class lookup only needs to
         * be performed in the later case. This flag tells the resolver if the
         * lookup can be skipped.
         */
    if (parent instanceof AstValue) {
        ctx.putContext(this.getClass(), Boolean.FALSE);
    } else {
        ctx.putContext(this.getClass(), Boolean.TRUE);
    }
    try {
        result = ctx.getELResolver().getValue(ctx, null, this.image);
    } finally {
        // Always reset the flag to false so the optimisation is not applied
        // inappropriately
        ctx.putContext(this.getClass(), Boolean.FALSE);
    }
    if (ctx.isPropertyResolved()) {
        return result;
    }
    // Import
    result = ctx.getImportHandler().resolveClass(this.image);
    if (result != null) {
        return new ELClass((Class<?>) result);
    }
    result = ctx.getImportHandler().resolveStatic(this.image);
    if (result != null) {
        try {
            return ((Class<?>) result).getField(this.image).get(null);
        } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
            throw new ELException(e);
        }
    }
    throw new PropertyNotFoundException(MessageFactory.get("error.resolver.unhandled.null", this.image));
}
Also used : ELClass(javax.el.ELClass) PropertyNotFoundException(javax.el.PropertyNotFoundException) VariableMapper(javax.el.VariableMapper) ValueExpression(javax.el.ValueExpression) ELException(javax.el.ELException)

Example 54 with ValueExpression

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

the class ELLinkBuilder method buildURI.

/**
     * TODO javadoc.
     */
static URI buildURI(InjectLinkDescriptor link, Object entity, Object resource, Object instance, UriInfo uriInfo, ResourceMappingContext rmc) {
    String template = link.getLinkTemplate(rmc);
    // first process any embedded EL expressions
    LinkELContext context = new LinkELContext(entity, resource, instance);
    ValueExpression expr = expressionFactory.createValueExpression(context, template, String.class);
    template = expr.getValue(context).toString();
    // now process any embedded URI template parameters
    UriBuilder ub = applyLinkStyle(template, link.getLinkStyle(), uriInfo);
    UriTemplateParser parser = new UriTemplateParser(template);
    List<String> parameterNames = parser.getNames();
    Map<String, Object> valueMap = getParameterValues(parameterNames, link, context, uriInfo);
    return ub.buildFromMap(valueMap);
}
Also used : ValueExpression(javax.el.ValueExpression) UriBuilder(javax.ws.rs.core.UriBuilder) UriTemplateParser(org.glassfish.jersey.uri.internal.UriTemplateParser)

Example 55 with ValueExpression

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

the class ELLinkBuilder method evaluateCondition.

/**
     * TODO javadoc.
     */
static boolean evaluateCondition(String condition, Object entity, Object resource, Object instance) {
    if (condition == null || condition.isEmpty()) {
        return true;
    }
    LinkELContext context = new LinkELContext(entity, resource, instance);
    ValueExpression expr = expressionFactory.createValueExpression(context, condition, boolean.class);
    Object result = expr.getValue(context).toString();
    return "true".equals(result);
}
Also used : 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