boolean matchingParentFound = false;
ActivityExecution leavingExecution = execution;
ActivityImpl currentActivity = (ActivityImpl) execution.getActivity();
ScopeImpl catchingScope = errorHandler.getParent();
if (catchingScope instanceof ActivityImpl) {
ActivityImpl catchingScopeActivity = (ActivityImpl) catchingScope;
if (!catchingScopeActivity.isScope()) { // event subprocesses
catchingScope = catchingScopeActivity.getParent();
}
}
if (catchingScope instanceof PvmProcessDefinition) {
executeEventHandler(errorHandler, ((ExecutionEntity) execution).getProcessInstance());
} else {
if (currentActivity.getId().equals(catchingScope.getId())) {
matchingParentFound = true;
} else {
// boundary events are always defined on scopes, so we have to
// find the next parent activity that is a scope
currentActivity = currentActivity.getParentScopeActivity();
// Traverse parents until one is found that is a scope
// and matches the activity the boundary event is defined on.
//
// This loop attempts attempts to find the execution that matches
// currentActivity and then checks whether this is the scope that
// is responsible for catching the error (i.e. currentActivity == catchingScope).
// If not, search is continued in the parent activities and executions.
while (!matchingParentFound && leavingExecution != null && currentActivity != null) {
if (!leavingExecution.isConcurrent() && currentActivity.getId().equals(catchingScope.getId())) {
matchingParentFound = true;
} else if (leavingExecution.isConcurrent()) {
leavingExecution = leavingExecution.getParent();
} else {
currentActivity = currentActivity.getParentScopeActivity();
leavingExecution = leavingExecution.getParent();
}
}
// Follow parents up until matching scope can't be found anymore (needed to support for multi-instance)
while (leavingExecution != null
&& leavingExecution.getParent() != null
&& leavingExecution.getParent().getActivity() != null
&& leavingExecution.getParent().getActivity().getId().equals(catchingScope.getId())) {
leavingExecution = leavingExecution.getParent();
}
}
if (matchingParentFound && leavingExecution != null) {