use of org.activiti.engine.delegate.ExecutionListener in project Activiti by Activiti.
the class DelegateExpressionExecutionListener method notify.
public void notify(DelegateExecution execution) throws Exception {
// Note: we can't cache the result of the expression, because the
// execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
Object delegate = expression.getValue(execution);
ClassDelegate.applyFieldDeclaration(fieldDeclarations, delegate);
if (delegate instanceof ExecutionListener) {
Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new ExecutionListenerInvocation((ExecutionListener) delegate, execution));
} else if (delegate instanceof JavaDelegate) {
Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution));
} else {
throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + ExecutionListener.class + " nor " + JavaDelegate.class);
}
}
use of org.activiti.engine.delegate.ExecutionListener in project Activiti by Activiti.
the class MultiInstanceActivityBehavior method callCustomActivityStartListeners.
/**
* Since the first loop of the multi instance is not executed as a regular activity,
* it is needed to call the start listeners yourself.
*/
protected void callCustomActivityStartListeners(ActivityExecution execution) {
List<ExecutionListener> listeners = activity.getExecutionListeners(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START);
List<ExecutionListener> filteredExecutionListeners = new ArrayList<ExecutionListener>(listeners.size());
if (listeners != null) {
for (ExecutionListener executionListener : listeners) {
if (!(executionListener instanceof ActivityInstanceStartHandler)) {
filteredExecutionListeners.add(executionListener);
}
}
CallActivityListenersOperation atomicOperation = new CallActivityListenersOperation(filteredExecutionListeners);
Context.getCommandContext().performOperation(atomicOperation, (InterpretableExecution) execution);
}
}
use of org.activiti.engine.delegate.ExecutionListener in project Activiti by Activiti.
the class AbstractEventAtomicOperation method execute.
public void execute(InterpretableExecution execution) {
ScopeImpl scope = getScope(execution);
List<ExecutionListener> exectionListeners = scope.getExecutionListeners(getEventName());
int executionListenerIndex = execution.getExecutionListenerIndex();
if (exectionListeners.size() > executionListenerIndex) {
execution.setEventName(getEventName());
execution.setEventSource(scope);
ExecutionListener listener = exectionListeners.get(executionListenerIndex);
try {
listener.notify(execution);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new PvmException("couldn't execute event listener : " + e.getMessage(), e);
}
execution.setExecutionListenerIndex(executionListenerIndex + 1);
execution.performOperation(this);
} else {
execution.setExecutionListenerIndex(0);
execution.setEventName(null);
execution.setEventSource(null);
eventNotificationsCompleted(execution);
}
}
use of org.activiti.engine.delegate.ExecutionListener in project Activiti by Activiti.
the class AtomicOperationTransitionNotifyListenerTake method execute.
public void execute(InterpretableExecution execution) {
TransitionImpl transition = execution.getTransition();
List<ExecutionListener> executionListeners = transition.getExecutionListeners();
int executionListenerIndex = execution.getExecutionListenerIndex();
if (executionListeners.size() > executionListenerIndex) {
execution.setEventName(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_TAKE);
execution.setEventSource(transition);
ExecutionListener listener = executionListeners.get(executionListenerIndex);
try {
listener.notify(execution);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new PvmException("couldn't execute event listener : " + e.getMessage(), e);
}
execution.setExecutionListenerIndex(executionListenerIndex + 1);
execution.performOperation(this);
} else {
if (log.isDebugEnabled()) {
log.debug("{} takes transition {}", execution, transition);
}
execution.setExecutionListenerIndex(0);
execution.setEventName(null);
execution.setEventSource(null);
ActivityImpl activity = (ActivityImpl) execution.getActivity();
ActivityImpl nextScope = findNextScope(activity.getParent(), transition.getDestination());
execution.setActivity(nextScope);
// Firing event that transition is being taken
if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createSequenceFlowTakenEvent(ActivitiEventType.SEQUENCEFLOW_TAKEN, transition.getId(), activity.getId(), (String) activity.getProperties().get("name"), (String) activity.getProperties().get("type"), activity.getActivityBehavior().getClass().getCanonicalName(), nextScope.getId(), (String) nextScope.getProperties().get("name"), (String) nextScope.getProperties().get("type"), nextScope.getActivityBehavior().getClass().getCanonicalName()));
}
execution.performOperation(TRANSITION_CREATE_SCOPE);
}
}
Aggregations