if (scopeActivity instanceof PvmProcessDefinition) {
return execution.getProcessInstance();
} else {
ActivityImpl currentActivity = execution.getActivity();
ExecutionEntity candiadateExecution = null;
ExecutionEntity originalExecution = execution;
while (execution != null) {
currentActivity = execution.getActivity();
if (scopeActivity.getActivities().contains(currentActivity) /* does not search rec*/
|| scopeActivity.equals(currentActivity)) {
// found a candidate execution; lets still check whether we find an
// execution which is also sitting in an activity part of this scope
// higher up the hierarchy
candiadateExecution = execution;
} else if (currentActivity!= null
&& currentActivity.contains((ActivityImpl)scopeActivity) /*searches rec*/) {
// now we're too "high", the candidate execution is the one.
break;
}
execution = execution.getParent();