Search in sources :

Example 6 with ELResolver

use of javax.el.ELResolver 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");
    }
}
Also used : TesterPageContext(javax.servlet.jsp.TesterPageContext) StandardELContext(javax.el.StandardELContext) ELContext(javax.el.ELContext) ELResolver(javax.el.ELResolver) StandardELContext(javax.el.StandardELContext) Test(org.junit.Test)

Example 7 with ELResolver

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

the class AstValue method setValue.

@Override
public void setValue(EvaluationContext ctx, Object value) throws ELException {
    Target t = getTarget(ctx);
    ctx.setPropertyResolved(false);
    ELResolver resolver = ctx.getELResolver();
    // coerce to the expected type
    Class<?> targetClass = resolver.getType(ctx, t.base, t.property);
    resolver.setValue(ctx, t.base, t.property, ELSupport.coerceToType(ctx, value, targetClass));
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get("error.resolver.unhandled", t.base, t.property));
    }
}
Also used : ELResolver(javax.el.ELResolver) PropertyNotFoundException(javax.el.PropertyNotFoundException)

Example 8 with ELResolver

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

the class AstValue method getTarget.

private final Target getTarget(EvaluationContext ctx) throws ELException {
    // evaluate expr-a to value-a
    Object base = this.children[0].getValue(ctx);
    // if our base is null (we know there are more properties to evaluate)
    if (base == null) {
        throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.base", this.children[0].getImage()));
    }
    // set up our start/end
    Object property = null;
    int propCount = this.jjtGetNumChildren();
    int i = 1;
    // Evaluate any properties or methods before our target
    ELResolver resolver = ctx.getELResolver();
    while (i < propCount) {
        if (i + 2 < propCount && this.children[i + 1] instanceof AstMethodParameters) {
            // Method call not at end of expression
            base = resolver.invoke(ctx, base, this.children[i].getValue(ctx), null, ((AstMethodParameters) this.children[i + 1]).getParameters(ctx));
            i += 2;
        } else if (i + 2 == propCount && this.children[i + 1] instanceof AstMethodParameters) {
            // Method call at end of expression
            ctx.setPropertyResolved(false);
            property = this.children[i].getValue(ctx);
            i += 2;
            if (property == null) {
                throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property));
            }
        } else if (i + 1 < propCount) {
            // Object with property not at end of expression
            property = this.children[i].getValue(ctx);
            ctx.setPropertyResolved(false);
            base = resolver.getValue(ctx, base, property);
            i++;
        } else {
            // Object with property at end of expression
            ctx.setPropertyResolved(false);
            property = this.children[i].getValue(ctx);
            i++;
            if (property == null) {
                throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property));
            }
        }
        if (base == null) {
            throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property));
        }
    }
    Target t = new Target();
    t.base = base;
    t.property = property;
    return t;
}
Also used : PropertyNotFoundException(javax.el.PropertyNotFoundException) ELResolver(javax.el.ELResolver)

Example 9 with ELResolver

use of javax.el.ELResolver in project tomee by apache.

the class OpenEJBLifecycle method initializeServletContext.

public static void initializeServletContext(final ServletContext servletContext, final WebBeansContext context) {
    if (context == null || !context.getBeanManagerImpl().isInUse()) {
        return;
    }
    final ELAdaptor elAdaptor = context.getService(ELAdaptor.class);
    final ELResolver resolver = elAdaptor.getOwbELResolver();
    //Application is configured as JSP
    if (context.getOpenWebBeansConfiguration().isJspApplication()) {
        logger.debug("Application is configured as JSP. Adding EL Resolver.");
        setJspELFactory(servletContext, resolver);
    }
    // Add BeanManager to the 'javax.enterprise.inject.spi.BeanManager' servlet context attribute
    servletContext.setAttribute(BeanManager.class.getName(), context.getBeanManagerImpl());
}
Also used : ELResolver(javax.el.ELResolver) BeanManager(javax.enterprise.inject.spi.BeanManager) ELAdaptor(org.apache.webbeans.spi.adaptor.ELAdaptor)

Aggregations

ELResolver (javax.el.ELResolver)9 CompositeELResolver (javax.el.CompositeELResolver)3 PropertyNotFoundException (javax.el.PropertyNotFoundException)3 ArrayELResolver (javax.el.ArrayELResolver)2 ListELResolver (javax.el.ListELResolver)2 MapELResolver (javax.el.MapELResolver)2 ResourceBundleELResolver (javax.el.ResourceBundleELResolver)2 ImplicitObjectELResolver (javax.servlet.jsp.el.ImplicitObjectELResolver)2 SimpleContext (de.odysseus.el.util.SimpleContext)1 PrivilegedAction (java.security.PrivilegedAction)1 ArrayList (java.util.ArrayList)1 BeanELResolver (javax.el.BeanELResolver)1 ELContext (javax.el.ELContext)1 ELContextEvent (javax.el.ELContextEvent)1 ELException (javax.el.ELException)1 LambdaExpression (javax.el.LambdaExpression)1 StandardELContext (javax.el.StandardELContext)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 TesterPageContext (javax.servlet.jsp.TesterPageContext)1 ScopedAttributeELResolver (javax.servlet.jsp.el.ScopedAttributeELResolver)1