use of jakarta.el.MethodExpression in project tomcat by apache.
the class AstIdentifier method getMethodExpression.
private final MethodExpression getMethodExpression(EvaluationContext ctx) throws ELException {
Object obj = null;
// case A: ValueExpression exists, getValue which must
// be a MethodExpression
VariableMapper varMapper = ctx.getVariableMapper();
ValueExpression ve = null;
if (varMapper != null) {
ve = varMapper.resolveVariable(this.image);
if (ve != null) {
obj = ve.getValue(ctx);
}
}
// a MethodExpression to be able to invoke
if (ve == null) {
ctx.setPropertyResolved(false);
obj = ctx.getELResolver().getValue(ctx, null, this.image);
}
// finally provide helpful hints
if (obj instanceof MethodExpression) {
return (MethodExpression) obj;
} else if (obj == null) {
throw new MethodNotFoundException(MessageFactory.get("error.identifier.noMethod", this.image));
} else {
throw new ELException(MessageFactory.get("error.identifier.notMethodExpression", this.image, obj.getClass().getName()));
}
}
use of jakarta.el.MethodExpression in project tomcat by apache.
the class TestMethodExpressionImpl method testBug53792d.
@Test
public void testBug53792d() {
MethodExpression me = factory.createMethodExpression(context, "#{beanB.sayHello().length()}", null, new Class<?>[] {});
Integer result = (Integer) me.invoke(context, new Object[] { "foo" });
Assert.assertEquals(beanB.sayHello().length(), result.intValue());
}
use of jakarta.el.MethodExpression in project tomcat by apache.
the class TestMethodExpressionImpl method testBug60844.
@Test(expected = IllegalArgumentException.class)
public void testBug60844() {
MethodExpression me2 = factory.createMethodExpression(context, "${beanC.sayHello}", null, new Class[] { TesterBeanA.class, TesterBeanB.class });
me2.invoke(context, new Object[] { new Object() });
}
use of jakarta.el.MethodExpression in project tomcat by apache.
the class TestMethodExpressionImpl method testBug57855b.
@Test(expected = IllegalArgumentException.class)
public void testBug57855b() {
MethodExpression me = factory.createMethodExpression(context, "${beanAA.echo2}", null, new Class[] { String.class });
me.invoke(context, null);
}
use of jakarta.el.MethodExpression in project tomcat by apache.
the class TestMethodExpressionImpl method testInvoke.
@Test
public void testInvoke() {
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 });
MethodExpression me3 = factory.createMethodExpression(context, "${beanB.sayHello}", String.class, new Class<?>[] { String.class });
Assert.assertEquals("B", me1.invoke(context, null));
Assert.assertEquals("Hello JUnit from B", me2.invoke(context, null));
Assert.assertEquals("Hello JUnit from B", me2.invoke(context, new Object[] { "JUnit2" }));
Assert.assertEquals("Hello JUnit2 from B", me3.invoke(context, new Object[] { "JUnit2" }));
Assert.assertEquals("Hello JUnit from B", me2.invoke(context, new Object[] { null }));
Assert.assertEquals("Hello from B", me3.invoke(context, new Object[] { null }));
}
Aggregations