ModificationExtractor calculator, String moduleToRemove) {
RootModuleDefinition oldRootDefinition = moduleStateHolder.getRootModuleDefinition();
if (oldRootDefinition == null) {
return new TransitionResultSet();
}
RootModuleDefinition newRootDefinition = moduleStateHolder.cloneRootModuleDefinition();
ModuleDefinition definitionToRemove = newRootDefinition.findChildDefinition(moduleToRemove, true);
if (definitionToRemove != null) {
if (definitionToRemove instanceof RootModuleDefinition) {
//we're removing the rootModuleDefinition
TransitionSet transitions = calculator.getTransitions(application, oldRootDefinition, null);
TransitionResultSet transitionResultSet = getTransitionManager().processTransitions(moduleStateHolder, application, transitions);
return transitionResultSet;
}
else {
ModuleDefinition parent = definitionToRemove.getParentDefinition();
if (parent != null) {
parent.removeChildModuleDefinition(moduleToRemove);
definitionToRemove.setParentDefinition(null);
TransitionSet transitions = calculator.getTransitions(application, oldRootDefinition, newRootDefinition);
TransitionResultSet transitionResultSet = getTransitionManager().processTransitions(moduleStateHolder, application, transitions);
return transitionResultSet;
}
else {
throw new InvalidStateException("Module to remove does not have a parent module. "
+ "This is unexpected state and may indicate a bug");
}
}
}
return new TransitionResultSet();
}