if (!(toplevel instanceof CompositeActor)) {
throw new IllegalActionException(toplevel,
"Cannot get a manager because the model is not a CompositeActor.");
}
Manager manager = ((CompositeActor) toplevel).getManager();
if (manager == null) {
try {
manager = new Manager(toplevel.workspace(), "manager");
((CompositeActor) toplevel).setManager(manager);
} catch (IllegalActionException ex) {
// Should not occur.
throw new InternalErrorException(ex);
}
}
if (manager != _manager) {
// If there was a previous manager, unlisten.
if (_manager != null) {
_manager.removeExecutionListener(this);
}
manager.addExecutionListener(this);
_manager = manager;
}
return manager;
}