for (Iterator it = stepsLocal().iterator(); it.hasNext();) {
ActivityLocal act = (ActivityLocal)it.next();
State s = act.typedState();
if (s.isSameOrSubState(NotRunningState.SUSPENDED)
|| s == ClosedState.ABORTED) {
throw new CannotStopException
(act.toString() + " is suspended.");
}
}
String unstoppable = null;
try {
setPaTypedState(RunningState.TERMINATING);
for (Iterator it = stepsLocal().iterator(); it.hasNext();) {
ActivityLocal act = (ActivityLocal)it.next();
if (act.workflowState() == State.OPEN
&& (!act.typedState().isSameOrSubState
(NotRunningState.NOT_STARTED))) {
try {
act.terminate();
} catch (CannotStopException e) {
unstoppable = act.toString()
+ " cannot be terminated: " + e.getMessage();
} catch (NotRunningException e) {
// cannot happen
logger.error (e.getMessage(), e);
}
}
}
} finally {
setPaTypedState(RunningState.RUNNING);
}
if (unstoppable != null) {
throw new CannotStopException (unstoppable);
}
}
updateState(ClosedState.TERMINATED);
}