protected void initExpressionManager() { if (expressionManager == null) { expressionManager = new ExpressionManager(beans); } // add function mapper for command context (eg currentUser(), currentUserGroups()) expressionManager.addFunctionMapper(new CommandContextFunctionMapper()); // add function mapper for date time (eg now(), dateTime()) expressionManager.addFunctionMapper(new DateTimeFunctionMapper()); }
/** * Checks whether a {@link String} seams to be a composite expression or not. In contrast to an eval expression * is the composite expression also allowed to consist of a combination of literal and eval expressions, e.g., * "Welcome ${customer.name} to our site". * * Note: If you just want to allow eval expression, then the expression must always start with "#{" or "${". * Use {@link #isExpression(String)} to conduct these kind of checks. * */ public static boolean isCompositeExpression(String text, ExpressionManager expressionManager) { return !expressionManager.createExpression(text).isLiteralText(); }
public Expression createExpression(String expression) { ValueExpression valueExpression = createValueExpression(expression); return new JuelExpression(valueExpression, this, expression); }
synchronized public static Object evaluateJuelWithGenerator(String expression, ContentGenerator contentGenerator, VariableScope scope) { currentEvaluationWrapperClass = getWrapperClass(contentGenerator); try { if (cachedExpressionManager == null) { cachedExpressionManager = getExpressionManager(Context.getProcessEngineConfiguration()); } ELContext elContext = cachedExpressionManager.getElContext(scope == null ? new ExecutionEntity() : scope); ExpressionGetInvocation invocation = new ExpressionGetInvocation(cachedExpressionManager.createValueExpression(expression), elContext, null); invocation.proceed(); return invocation.getInvocationResult(); } catch (Exception e) { throw new RuntimeException("Could not evaluate JUEL expression '" + expression + "'", e); } finally { currentEvaluationWrapperClass = null; } }
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); } }
protected void registerFunctionMapper(ProcessEngineConfigurationImpl processEngineConfiguration) { processEngineConfiguration.getExpressionManager().addFunctionMapper(new SpinFunctionMapper()); }
protected ProcessEngineElContext createElContext(VariableScope variableScope) { ELResolver elResolver = getCachedElResolver(); ProcessEngineElContext elContext = new ProcessEngineElContext(functionMappers, elResolver); elContext.putContext(ExpressionFactory.class, expressionFactory); elContext.putContext(VariableScope.class, variableScope); return elContext; }
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; }
@Before public void setup() { modelInstance = Cmmn.createEmptyModel(); definitions = modelInstance.newInstance(Definitions.class); definitions.setTargetNamespace("http://camunda.org/examples"); modelInstance.setDefinitions(definitions); caseDefinition = createElement(definitions, "aCaseDefinition", Case.class); casePlanModel = createElement(caseDefinition, "aCasePlanModel", CasePlanModel.class); context = new CmmnHandlerContext(); CaseDefinitionEntity caseDefinition = new CaseDefinitionEntity(); caseDefinition.setTaskDefinitions(new HashMap<String, TaskDefinition>()); context.setCaseDefinition(caseDefinition); ExpressionManager expressionManager = new ExpressionManager(); context.setExpressionManager(expressionManager); DeploymentEntity deployment = new DeploymentEntity(); deployment.setId("foo"); context.setDeployment(deployment); }
protected ELResolver getCachedElResolver() { if (elResolver == null) { synchronized(this) { if (elResolver == null) { elResolver = createElResolver(); } } } return elResolver; }
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); } }
private static ExpressionManager getExpressionManager(ProcessEngineConfigurationImpl processEngineConfigurationImpl) { ExpressionManager em = processEngineConfigurationImpl.getExpressionManager(); em.addFunctionMapper(new FunctionMapper() { @Override public Method resolveFunction(String prefix, String localName) { if (currentEvaluationWrapperClass == null || !"g".equals(prefix)) return null; return Arrays.stream(currentEvaluationWrapperClass.getMethods()).filter(m -> localName.equals(m.getName())).findFirst().orElse(null); } }); return em; }
protected ProcessEngineElContext createElContext(VariableScope variableScope) { ELResolver elResolver = getCachedElResolver(); ProcessEngineElContext elContext = new ProcessEngineElContext(functionMappers, elResolver); elContext.putContext(ExpressionFactory.class, expressionFactory); elContext.putContext(VariableScope.class, variableScope); return elContext; }
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; }
@Before public void setup() { modelInstance = Cmmn.createEmptyModel(); definitions = modelInstance.newInstance(Definitions.class); definitions.setTargetNamespace("http://camunda.org/examples"); modelInstance.setDefinitions(definitions); caseDefinition = createElement(definitions, "aCaseDefinition", Case.class); casePlanModel = createElement(caseDefinition, "aCasePlanModel", CasePlanModel.class); context = new CmmnHandlerContext(); CaseDefinitionEntity caseDefinition = new CaseDefinitionEntity(); caseDefinition.setTaskDefinitions(new HashMap<String, TaskDefinition>()); context.setCaseDefinition(caseDefinition); ExpressionManager expressionManager = new ExpressionManager(); context.setExpressionManager(expressionManager); DeploymentEntity deployment = new DeploymentEntity(); deployment.setId("foo"); context.setDeployment(deployment); }
protected ELResolver getCachedElResolver() { if (elResolver == null) { synchronized(this) { if (elResolver == null) { elResolver = createElResolver(); } } } return elResolver; }
/** * Checks whether a {@link String} seams to be a composite expression or not. In contrast to an eval expression * is the composite expression also allowed to consist of a combination of literal and eval expressions, e.g., * "Welcome ${customer.name} to our site". * * Note: If you just want to allow eval expression, then the expression must always start with "#{" or "${". * Use {@link #isExpression(String)} to conduct these kind of checks. * */ public static boolean isCompositeExpression(String text, ExpressionManager expressionManager) { return !expressionManager.createExpression(text).isLiteralText(); }
protected void initExpressionManager() { if (expressionManager == null) { expressionManager = new ExpressionManager(beans); } // add function mapper for command context (eg currentUser(), currentUserGroups()) expressionManager.addFunctionMapper(new CommandContextFunctionMapper()); // add function mapper for date time (eg now(), dateTime()) expressionManager.addFunctionMapper(new DateTimeFunctionMapper()); }
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); } }
public Expression createExpression(String expression) { ValueExpression valueExpression = createValueExpression(expression); return new JuelExpression(valueExpression, this, expression); }