Search in sources :

Example 6 with VariableMapper

use of javax.el.VariableMapper in project tomcat70 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("Identity '" + this.image + "' was null and was unable to invoke");
    } else {
        throw new ELException("Identity '" + this.image + "' does not reference a MethodExpression instance, returned type: " + obj.getClass().getName());
    }
}
Also used : VariableMapper(javax.el.VariableMapper) ValueExpression(javax.el.ValueExpression) ELException(javax.el.ELException) MethodExpression(javax.el.MethodExpression) MethodNotFoundException(javax.el.MethodNotFoundException)

Example 7 with VariableMapper

use of javax.el.VariableMapper in project tomcat70 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 8 with VariableMapper

use of javax.el.VariableMapper in project Activiti by Activiti.

the class JuelScriptEngine method createElContext.

private ELContext createElContext(final ScriptContext scriptCtx) {
    // Check if the ELContext is already stored on the ScriptContext
    Object existingELCtx = scriptCtx.getAttribute("elcontext");
    if (existingELCtx instanceof ELContext) {
        return (ELContext) existingELCtx;
    }
    scriptCtx.setAttribute("context", scriptCtx, ScriptContext.ENGINE_SCOPE);
    // Built-in function are added to ScriptCtx
    scriptCtx.setAttribute("out:print", getPrintMethod(), ScriptContext.ENGINE_SCOPE);
    SecurityManager securityManager = System.getSecurityManager();
    if (securityManager == null) {
        scriptCtx.setAttribute("lang:import", getImportMethod(), ScriptContext.ENGINE_SCOPE);
    }
    ELContext elContext = new ELContext() {

        ELResolver resolver = createElResolver();

        VariableMapper varMapper = new ScriptContextVariableMapper(scriptCtx);

        FunctionMapper funcMapper = new ScriptContextFunctionMapper(scriptCtx);

        @Override
        public ELResolver getELResolver() {
            return resolver;
        }

        @Override
        public VariableMapper getVariableMapper() {
            return varMapper;
        }

        @Override
        public FunctionMapper getFunctionMapper() {
            return funcMapper;
        }
    };
    // Store the elcontext in the scriptContext to be able to reuse
    scriptCtx.setAttribute("elcontext", elContext, ScriptContext.ENGINE_SCOPE);
    return elContext;
}
Also used : ELContext(javax.el.ELContext) BeanELResolver(javax.el.BeanELResolver) JsonNodeELResolver(org.activiti.engine.impl.el.JsonNodeELResolver) MapELResolver(javax.el.MapELResolver) ArrayELResolver(javax.el.ArrayELResolver) CompositeELResolver(javax.el.CompositeELResolver) DynamicBeanPropertyELResolver(org.activiti.engine.impl.el.DynamicBeanPropertyELResolver) ListELResolver(javax.el.ListELResolver) ELResolver(javax.el.ELResolver) ResourceBundleELResolver(javax.el.ResourceBundleELResolver) VariableMapper(javax.el.VariableMapper) FunctionMapper(javax.el.FunctionMapper)

Example 9 with VariableMapper

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

the class StatefulConversationScopedTOMEE1138Test method el.

@Test
public void el() {
    final BeanELResolver elResolver = new BeanELResolver();
    assertEquals("John", elResolver.getValue(new ELContext() {

        @Override
        public ELResolver getELResolver() {
            return elResolver;
        }

        @Override
        public FunctionMapper getFunctionMapper() {
            return new FunctionMapper() {

                @Override
                public Method resolveFunction(final String prefix, final String localName) {
                    return null;
                }
            };
        }

        @Override
        public VariableMapper getVariableMapper() {
            return new VariableMapper() {

                @Override
                public ValueExpression resolveVariable(final String variable) {
                    return null;
                }

                @Override
                public ValueExpression setVariable(final String variable, final ValueExpression expression) {
                    return null;
                }
            };
        }
    }, conversationByName, "name"));
}
Also used : ELContext(javax.el.ELContext) VariableMapper(javax.el.VariableMapper) ValueExpression(javax.el.ValueExpression) BeanELResolver(javax.el.BeanELResolver) FunctionMapper(javax.el.FunctionMapper) Test(org.junit.Test)

Example 10 with VariableMapper

use of javax.el.VariableMapper in project tomcat70 by apache.

the class AstIdentifier method getValue.

@Override
public Object getValue(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getValue(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Object result = ctx.getELResolver().getValue(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)

Aggregations

VariableMapper (javax.el.VariableMapper)13 ValueExpression (javax.el.ValueExpression)7 VariableMapperWrapper (com.sun.faces.facelets.el.VariableMapperWrapper)4 PropertyNotFoundException (javax.el.PropertyNotFoundException)4 IOException (java.io.IOException)3 URL (java.net.URL)3 FunctionMapper (javax.el.FunctionMapper)3 BeanELResolver (javax.el.BeanELResolver)2 ELContext (javax.el.ELContext)2 ELResolver (javax.el.ELResolver)2 LocatedWidget (fi.otavanopisto.muikku.model.widgets.LocatedWidget)1 ArrayELResolver (javax.el.ArrayELResolver)1 CompositeELResolver (javax.el.CompositeELResolver)1 ELException (javax.el.ELException)1 ListELResolver (javax.el.ListELResolver)1 MapELResolver (javax.el.MapELResolver)1 MethodExpression (javax.el.MethodExpression)1 MethodNotFoundException (javax.el.MethodNotFoundException)1 ResourceBundleELResolver (javax.el.ResourceBundleELResolver)1 TagAttributeException (javax.faces.view.facelets.TagAttributeException)1