Search in sources :

Example 1 with ELContext

use of org.camunda.bpm.engine.impl.javax.el.ELContext in project camunda-bpm-platform by camunda.

the class ExpressionManager method getElContext.

public ELContext getElContext(VariableScope variableScope) {
    ELContext elContext = null;
    if (variableScope instanceof AbstractVariableScope) {
        AbstractVariableScope variableScopeImpl = (AbstractVariableScope) variableScope;
        elContext = variableScopeImpl.getCachedElContext();
    }
    if (elContext == null) {
        elContext = createElContext(variableScope);
        if (variableScope instanceof AbstractVariableScope) {
            ((AbstractVariableScope) variableScope).setCachedElContext(elContext);
        }
    }
    return elContext;
}
Also used : ELContext(org.camunda.bpm.engine.impl.javax.el.ELContext) AbstractVariableScope(org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope)

Example 2 with ELContext

use of org.camunda.bpm.engine.impl.javax.el.ELContext in project camunda-bpm-platform by camunda.

the class JuelExpression method setValue.

public void setValue(Object value, VariableScope variableScope, BaseDelegateExecution contextExecution) {
    ELContext elContext = expressionManager.getElContext(variableScope);
    try {
        ExpressionSetInvocation invocation = new ExpressionSetInvocation(valueExpression, elContext, value, contextExecution);
        Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(invocation);
    } catch (Exception e) {
        throw new ProcessEngineException("Error while evaluating expression: " + expressionText + ". Cause: " + e.getMessage(), e);
    }
}
Also used : ELContext(org.camunda.bpm.engine.impl.javax.el.ELContext) ExpressionSetInvocation(org.camunda.bpm.engine.impl.delegate.ExpressionSetInvocation) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) MethodNotFoundException(org.camunda.bpm.engine.impl.javax.el.MethodNotFoundException) PropertyNotFoundException(org.camunda.bpm.engine.impl.javax.el.PropertyNotFoundException) ELException(org.camunda.bpm.engine.impl.javax.el.ELException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 3 with ELContext

use of org.camunda.bpm.engine.impl.javax.el.ELContext in project camunda-bpm-platform by camunda.

the class JuelExpression method getValue.

public Object getValue(VariableScope variableScope, BaseDelegateExecution contextExecution) {
    ELContext elContext = expressionManager.getElContext(variableScope);
    try {
        ExpressionGetInvocation invocation = new ExpressionGetInvocation(valueExpression, elContext, contextExecution);
        Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(invocation);
        return invocation.getInvocationResult();
    } catch (PropertyNotFoundException pnfe) {
        throw new ProcessEngineException("Unknown property used in expression: " + expressionText + ". Cause: " + pnfe.getMessage(), pnfe);
    } catch (MethodNotFoundException mnfe) {
        throw new ProcessEngineException("Unknown method used in expression: " + expressionText + ". Cause: " + mnfe.getMessage(), mnfe);
    } catch (ELException ele) {
        throw new ProcessEngineException("Error while evaluating expression: " + expressionText + ". Cause: " + ele.getMessage(), ele);
    } catch (Exception e) {
        throw new ProcessEngineException("Error while evaluating expression: " + expressionText + ". Cause: " + e.getMessage(), e);
    }
}
Also used : ELContext(org.camunda.bpm.engine.impl.javax.el.ELContext) PropertyNotFoundException(org.camunda.bpm.engine.impl.javax.el.PropertyNotFoundException) ELException(org.camunda.bpm.engine.impl.javax.el.ELException) MethodNotFoundException(org.camunda.bpm.engine.impl.javax.el.MethodNotFoundException) ExpressionGetInvocation(org.camunda.bpm.engine.impl.delegate.ExpressionGetInvocation) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) MethodNotFoundException(org.camunda.bpm.engine.impl.javax.el.MethodNotFoundException) PropertyNotFoundException(org.camunda.bpm.engine.impl.javax.el.PropertyNotFoundException) ELException(org.camunda.bpm.engine.impl.javax.el.ELException)

Example 4 with ELContext

use of org.camunda.bpm.engine.impl.javax.el.ELContext in project camunda-bpm-platform by camunda.

the class Builder method main.

/**
 * Dump out abstract syntax tree for a given expression
 *
 * @param args array with one element, containing the expression string
 */
public static void main(String[] args) {
    if (args.length != 1) {
        System.err.println("usage: java " + Builder.class.getName() + " <expression string>");
        System.exit(1);
    }
    PrintWriter out = new PrintWriter(System.out);
    Tree tree = null;
    try {
        tree = new Builder(Feature.METHOD_INVOCATIONS).build(args[0]);
    } catch (TreeBuilderException e) {
        System.out.println(e.getMessage());
        System.exit(0);
    }
    NodePrinter.dump(out, tree.getRoot());
    if (!tree.getFunctionNodes().iterator().hasNext() && !tree.getIdentifierNodes().iterator().hasNext()) {
        ELContext context = new ELContext() {

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

            @Override
            public FunctionMapper getFunctionMapper() {
                return null;
            }

            @Override
            public ELResolver getELResolver() {
                return null;
            }
        };
        out.print(">> ");
        try {
            out.println(tree.getRoot().getValue(new Bindings(null, null), context, null));
        } catch (ELException e) {
            out.println(e.getMessage());
        }
    }
    out.flush();
}
Also used : ELContext(org.camunda.bpm.engine.impl.javax.el.ELContext) ELException(org.camunda.bpm.engine.impl.javax.el.ELException) PrintWriter(java.io.PrintWriter)

Example 5 with ELContext

use of org.camunda.bpm.engine.impl.javax.el.ELContext in project camunda-bpm-platform by camunda.

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(org.camunda.bpm.engine.impl.javax.el.ELContext) BeanELResolver(org.camunda.bpm.engine.impl.javax.el.BeanELResolver) ResourceBundleELResolver(org.camunda.bpm.engine.impl.javax.el.ResourceBundleELResolver) ListELResolver(org.camunda.bpm.engine.impl.javax.el.ListELResolver) CompositeELResolver(org.camunda.bpm.engine.impl.javax.el.CompositeELResolver) ELResolver(org.camunda.bpm.engine.impl.javax.el.ELResolver) ArrayELResolver(org.camunda.bpm.engine.impl.javax.el.ArrayELResolver) MapELResolver(org.camunda.bpm.engine.impl.javax.el.MapELResolver) VariableMapper(org.camunda.bpm.engine.impl.javax.el.VariableMapper) FunctionMapper(org.camunda.bpm.engine.impl.javax.el.FunctionMapper)

Aggregations

ELContext (org.camunda.bpm.engine.impl.javax.el.ELContext)5 ELException (org.camunda.bpm.engine.impl.javax.el.ELException)3 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 MethodNotFoundException (org.camunda.bpm.engine.impl.javax.el.MethodNotFoundException)2 PropertyNotFoundException (org.camunda.bpm.engine.impl.javax.el.PropertyNotFoundException)2 PrintWriter (java.io.PrintWriter)1 AbstractVariableScope (org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope)1 ExpressionGetInvocation (org.camunda.bpm.engine.impl.delegate.ExpressionGetInvocation)1 ExpressionSetInvocation (org.camunda.bpm.engine.impl.delegate.ExpressionSetInvocation)1 ArrayELResolver (org.camunda.bpm.engine.impl.javax.el.ArrayELResolver)1 BeanELResolver (org.camunda.bpm.engine.impl.javax.el.BeanELResolver)1 CompositeELResolver (org.camunda.bpm.engine.impl.javax.el.CompositeELResolver)1 ELResolver (org.camunda.bpm.engine.impl.javax.el.ELResolver)1 FunctionMapper (org.camunda.bpm.engine.impl.javax.el.FunctionMapper)1 ListELResolver (org.camunda.bpm.engine.impl.javax.el.ListELResolver)1 MapELResolver (org.camunda.bpm.engine.impl.javax.el.MapELResolver)1 ResourceBundleELResolver (org.camunda.bpm.engine.impl.javax.el.ResourceBundleELResolver)1 VariableMapper (org.camunda.bpm.engine.impl.javax.el.VariableMapper)1