use of org.camunda.bpm.engine.impl.scripting.ExecutableScript in project camunda-bpm-platform by camunda.
the class HumanTaskItemHandler method initializeTaskListener.
protected TaskListener initializeTaskListener(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, CamundaTaskListener listener) {
Collection<CamundaField> fields = listener.getCamundaFields();
List<FieldDeclaration> fieldDeclarations = initializeFieldDeclarations(element, activity, context, fields);
ExpressionManager expressionManager = context.getExpressionManager();
TaskListener taskListener = null;
String className = listener.getCamundaClass();
String expression = listener.getCamundaExpression();
String delegateExpression = listener.getCamundaDelegateExpression();
CamundaScript scriptElement = listener.getCamundaScript();
if (className != null) {
taskListener = new ClassDelegateTaskListener(className, fieldDeclarations);
} else if (expression != null) {
Expression expressionExp = expressionManager.createExpression(expression);
taskListener = new ExpressionTaskListener(expressionExp);
} else if (delegateExpression != null) {
Expression delegateExp = expressionManager.createExpression(delegateExpression);
taskListener = new DelegateExpressionTaskListener(delegateExp, fieldDeclarations);
} else if (scriptElement != null) {
ExecutableScript executableScript = initializeScript(element, activity, context, scriptElement);
if (executableScript != null) {
taskListener = new ScriptTaskListener(executableScript);
}
}
return taskListener;
}
use of org.camunda.bpm.engine.impl.scripting.ExecutableScript in project camunda-bpm-platform by camunda.
the class JuelFormEngine method executeScript.
protected Object executeScript(String scriptSrc, VariableScope scope) {
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
ScriptFactory scriptFactory = processEngineConfiguration.getScriptFactory();
ExecutableScript script = scriptFactory.createScriptFromSource(ScriptingEngines.DEFAULT_SCRIPTING_LANGUAGE, scriptSrc);
ScriptInvocation invocation = new ScriptInvocation(script, scope);
try {
processEngineConfiguration.getDelegateInterceptor().handleInvocation(invocation);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new ProcessEngineException(e);
}
return invocation.getInvocationResult();
}
use of org.camunda.bpm.engine.impl.scripting.ExecutableScript in project camunda-bpm-platform by camunda.
the class ScriptingEnvironment method execute.
public Object execute(ExecutableScript script, VariableScope scope, Bindings bindings, ScriptEngine scriptEngine) {
final String scriptLanguage = script.getLanguage();
// first, evaluate the env scripts (if any)
List<ExecutableScript> envScripts = getEnvScripts(scriptLanguage);
for (ExecutableScript envScript : envScripts) {
envScript.execute(scriptEngine, scope, bindings);
}
// next evaluate the actual script
return script.execute(scriptEngine, scope, bindings);
}
use of org.camunda.bpm.engine.impl.scripting.ExecutableScript in project camunda-bpm-platform by camunda.
the class BpmnParseUtil method parseParamValueProvider.
/**
* @throws BpmnParseException if the parameter is invalid
*/
protected static ParameterValueProvider parseParamValueProvider(Element parameterElement) {
// LIST
if ("list".equals(parameterElement.getTagName())) {
List<ParameterValueProvider> providerList = new ArrayList<ParameterValueProvider>();
for (Element element : parameterElement.elements()) {
// parse nested provider
providerList.add(parseParamValueProvider(element));
}
return new ListValueProvider(providerList);
}
// MAP
if ("map".equals(parameterElement.getTagName())) {
TreeMap<ParameterValueProvider, ParameterValueProvider> providerMap = new TreeMap<ParameterValueProvider, ParameterValueProvider>();
for (Element entryElement : parameterElement.elements("entry")) {
// entry must provide key
String keyAttribute = entryElement.attribute("key");
if (keyAttribute == null || keyAttribute.isEmpty()) {
throw new BpmnParseException("Missing attribute 'key' for 'entry' element", entryElement);
}
// parse nested provider
providerMap.put(new ElValueProvider(getExpressionManager().createExpression(keyAttribute)), parseNestedParamValueProvider(entryElement));
}
return new MapValueProvider(providerMap);
}
// SCRIPT
if ("script".equals(parameterElement.getTagName())) {
ExecutableScript executableScript = parseCamundaScript(parameterElement);
if (executableScript != null) {
return new ScriptValueProvider(executableScript);
} else {
return new NullValueProvider();
}
}
String textContent = parameterElement.getText().trim();
if (!textContent.isEmpty()) {
// EL
return new ElValueProvider(getExpressionManager().createExpression(textContent));
} else {
// NULL value
return new NullValueProvider();
}
}
use of org.camunda.bpm.engine.impl.scripting.ExecutableScript in project camunda-bpm-platform by camunda.
the class ScriptExecutionListenerSpec method verifyListener.
public void verifyListener(DelegateListener<? extends BaseDelegateExecution> listener) {
assertTrue(listener instanceof ScriptCaseExecutionListener);
ScriptCaseExecutionListener scriptListener = (ScriptCaseExecutionListener) listener;
ExecutableScript executableScript = scriptListener.getScript();
assertNotNull(executableScript);
assertEquals(SCRIPT_FORMAT, executableScript.getLanguage());
}
Aggregations