Search in sources :

Example 26 with ValueExpression

use of jakarta.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(jakarta.el.PropertyNotFoundException) VariableMapper(jakarta.el.VariableMapper) ValueExpression(jakarta.el.ValueExpression)

Example 27 with ValueExpression

use of jakarta.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(jakarta.el.PropertyNotFoundException) VariableMapper(jakarta.el.VariableMapper) ValueExpression(jakarta.el.ValueExpression)

Example 28 with ValueExpression

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

the class AstIdentifier method getValueReference.

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

Example 29 with ValueExpression

use of jakarta.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(jakarta.el.ELClass) PropertyNotFoundException(jakarta.el.PropertyNotFoundException) VariableMapper(jakarta.el.VariableMapper) ValueExpression(jakarta.el.ValueExpression) ELException(jakarta.el.ELException)

Example 30 with ValueExpression

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

the class TestMethodExpressionImpl method testInvokeWithSuper.

@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);
    Assert.assertEquals("BB", r);
}
Also used : ValueExpression(jakarta.el.ValueExpression) MethodExpression(jakarta.el.MethodExpression) Test(org.junit.Test)

Aggregations

ValueExpression (jakarta.el.ValueExpression)42 Test (org.junit.Test)28 ELContext (jakarta.el.ELContext)24 ExpressionFactory (jakarta.el.ExpressionFactory)24 ELContextImpl (org.apache.jasper.el.ELContextImpl)17 VariableMapper (jakarta.el.VariableMapper)8 ELProcessor (jakarta.el.ELProcessor)7 MethodExpression (jakarta.el.MethodExpression)7 ELException (jakarta.el.ELException)6 PropertyNotFoundException (jakarta.el.PropertyNotFoundException)4 ValueReference (jakarta.el.ValueReference)3 ELClass (jakarta.el.ELClass)2 ELManager (jakarta.el.ELManager)1 FunctionMapper (jakarta.el.FunctionMapper)1 LambdaExpression (jakarta.el.LambdaExpression)1 MethodNotFoundException (jakarta.el.MethodNotFoundException)1 TesterELContext (jakarta.el.TesterELContext)1 ELParseException (jakarta.servlet.jsp.el.ELParseException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1