ModuleDefinition definitionToRemove = newRootDefinition.findChildDefinition(moduleToRemove, true);
if (definitionToRemove != null) {
if (definitionToRemove instanceof RootModuleDefinition) {
//we're removing the rootModuleDefinition
TransitionSet transitions = calculator.getTransitions(oldRootDefinition, null);
moduleStateHolder.processTransitions(transitions);
return true;
}
else {
ModuleDefinition parent = definitionToRemove.getParentDefinition();
if (parent != null) {
parent.remove(moduleToRemove);
definitionToRemove.setParentDefinition(null);
TransitionSet transitions = calculator.getTransitions(oldRootDefinition, newRootDefinition);
moduleStateHolder.processTransitions(transitions);
return true;
}
else {
throw new InvalidStateException("Module to remove does not have a parent module. "