use of org.camunda.bpm.engine.delegate.CaseVariableListener in project camunda-bpm-platform by camunda.
the class ItemHandler method initializeVariableListeners.
protected void initializeVariableListeners(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context) {
PlanItemDefinition definition = getDefinition(element);
List<CamundaVariableListener> listeners = queryExtensionElementsByClass(definition, CamundaVariableListener.class);
for (CamundaVariableListener listener : listeners) {
CaseVariableListener variableListener = initializeVariableListener(element, activity, context, listener);
String eventName = listener.getCamundaEvent();
if (eventName != null) {
activity.addVariableListener(eventName, variableListener);
} else {
for (String event : DEFAULT_VARIABLE_EVENTS) {
activity.addVariableListener(event, variableListener);
}
}
}
}
use of org.camunda.bpm.engine.delegate.CaseVariableListener in project camunda-bpm-platform by camunda.
the class CmmnExecution method invokeVariableListeners.
protected void invokeVariableListeners(boolean includeCustomerListeners) {
Queue<VariableEvent> variableEventsQueue = getVariableEventQueue();
while (!variableEventsQueue.isEmpty()) {
// do not remove the event yet, as otherwise new events will immediately be dispatched
VariableEvent nextEvent = variableEventsQueue.peek();
CmmnExecution sourceExecution = (CmmnExecution) nextEvent.getSourceScope();
DelegateCaseVariableInstanceImpl delegateVariable = DelegateCaseVariableInstanceImpl.fromVariableInstance(nextEvent.getVariableInstance());
delegateVariable.setEventName(nextEvent.getEventName());
delegateVariable.setSourceExecution(sourceExecution);
Map<String, List<VariableListener<?>>> listenersByActivity = sourceExecution.getActivity().getVariableListeners(delegateVariable.getEventName(), includeCustomerListeners);
CmmnExecution currentExecution = sourceExecution;
while (currentExecution != null) {
if (currentExecution.getActivityId() != null) {
List<VariableListener<?>> listeners = listenersByActivity.get(currentExecution.getActivityId());
if (listeners != null) {
delegateVariable.setScopeExecution(currentExecution);
for (VariableListener<?> listener : listeners) {
try {
CaseVariableListener caseVariableListener = (CaseVariableListener) listener;
CaseVariableListenerInvocation invocation = new CaseVariableListenerInvocation(caseVariableListener, delegateVariable, currentExecution);
Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(invocation);
} catch (Exception e) {
throw LOG.invokeVariableListenerException(e);
}
}
}
}
currentExecution = currentExecution.getParent();
}
// finally remove the event from the queue
variableEventsQueue.remove();
}
}
use of org.camunda.bpm.engine.delegate.CaseVariableListener in project camunda-bpm-platform by camunda.
the class DelegateExpressionCaseVariableListener method notify.
public void notify(DelegateCaseVariableInstance variableInstance) throws Exception {
Object delegate = expression.getValue(variableInstance.getSourceExecution());
applyFieldDeclaration(fieldDeclarations, delegate);
if (delegate instanceof CaseVariableListener) {
CaseVariableListener listenerInstance = (CaseVariableListener) delegate;
Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new CaseVariableListenerInvocation(listenerInstance, variableInstance));
} else {
throw new ProcessEngineException("Delegate expression " + expression + " did not resolve to an implementation of " + CaseVariableListener.class);
}
}
use of org.camunda.bpm.engine.delegate.CaseVariableListener in project camunda-bpm-platform by camunda.
the class ClassDelegateCaseVariableListener method notify.
public void notify(DelegateCaseVariableInstance variableInstance) throws Exception {
CaseVariableListener variableListenerInstance = getVariableListenerInstance();
Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new CaseVariableListenerInvocation(variableListenerInstance, variableInstance));
}
use of org.camunda.bpm.engine.delegate.CaseVariableListener in project camunda-bpm-platform by camunda.
the class ItemHandler method initializeVariableListener.
protected CaseVariableListener initializeVariableListener(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, CamundaVariableListener listener) {
Collection<CamundaField> fields = listener.getCamundaFields();
List<FieldDeclaration> fieldDeclarations = initializeFieldDeclarations(element, activity, context, fields);
ExpressionManager expressionManager = context.getExpressionManager();
String className = listener.getCamundaClass();
String expression = listener.getCamundaExpression();
String delegateExpression = listener.getCamundaDelegateExpression();
CamundaScript scriptElement = listener.getCamundaScript();
CaseVariableListener variableListener = null;
if (className != null) {
variableListener = new ClassDelegateCaseVariableListener(className, fieldDeclarations);
} else if (expression != null) {
Expression expressionExp = expressionManager.createExpression(expression);
variableListener = new ExpressionCaseVariableListener(expressionExp);
} else if (delegateExpression != null) {
Expression delegateExp = expressionManager.createExpression(delegateExpression);
variableListener = new DelegateExpressionCaseVariableListener(delegateExp, fieldDeclarations);
} else if (scriptElement != null) {
ExecutableScript executableScript = initializeScript(element, activity, context, scriptElement);
if (executableScript != null) {
variableListener = new ScriptCaseVariableListener(executableScript);
}
}
return variableListener;
}
Aggregations