use of javax.el.ELContext in project tomcat by apache.
the class PageContextImpl method proprietaryEvaluate.
/**
* Proprietary method to evaluate EL expressions. XXX - This method should
* go away once the EL interpreter moves out of JSTL and into its own
* project. For now, this is necessary because the standard machinery is too
* slow.
*
* @param expression
* The expression to be evaluated
* @param expectedType
* The expected resulting type
* @param pageContext
* The page context
* @param functionMap
* Maps prefix and name to Method
* @return The result of the evaluation
* @throws ELException If an error occurs during the evaluation
*/
public static Object proprietaryEvaluate(final String expression, final Class<?> expectedType, final PageContext pageContext, final ProtectedFunctionMapper functionMap) throws ELException {
final ExpressionFactory exprFactory = jspf.getJspApplicationContext(pageContext.getServletContext()).getExpressionFactory();
ELContext ctx = pageContext.getELContext();
ELContextImpl ctxImpl;
if (ctx instanceof ELContextWrapper) {
ctxImpl = (ELContextImpl) ((ELContextWrapper) ctx).getWrappedELContext();
} else {
ctxImpl = (ELContextImpl) ctx;
}
ctxImpl.setFunctionMapper(functionMap);
ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
return ve.getValue(ctx);
}
use of javax.el.ELContext in project tomcat by apache.
the class TestScopedAttributeELResolverPerformance method testGetValuePerformance.
/*
* With the caching of NotFound responses this test takes ~20ms. Without the
* caching it takes ~6s.
*/
@Test
public void testGetValuePerformance() throws Exception {
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
context.putContext(JspContext.class, new TesterPageContext());
ELResolver resolver = new ScopedAttributeELResolver();
for (int i = 0; i < 100000; i++) {
resolver.getValue(context, null, "unknown");
}
}
use of javax.el.ELContext 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);
}
Aggregations