ModuleMgtMessageKeys.DISENGAGE_ADDRESSING_GLOBALLY);
}
// Check whether this file can be deleted.
// We should proceed only if this file can be deleted.
AxisModule module = axisConfig.getModule(moduleId);
if (module == null) {
log.error("Module " + moduleId + "cannnot be found!");
throw new ModuleMgtException(ModuleMgtException.ERROR,
ModuleMgtMessageKeys.MODULE_NOT_FOUND);
}
if (module.getFileName() != null) {
String fileName = module.getFileName().getPath();
File file = new File(fileName);
if (!file.canWrite()) {
throw new ModuleMgtException(ModuleMgtException.WARNING,
ModuleMgtMessageKeys.MODULE_DELETE_ERROR);
}
if (isEngaged(module)) {
throw new ModuleMgtException(ModuleMgtException.WARNING,
ModuleMgtMessageKeys.ENGAGED_MODULE_REMOVE);
}
disengageModuleFromSystem(moduleId);
// Delete the MAR file
if (file.exists()) {
if (!(file.isDirectory() && FileManipulator.deleteDir(file))) {
if (!file.delete()) {
throw new ModuleMgtException(ModuleMgtException.WARNING,
ModuleMgtMessageKeys.MODULE_DELETE_ERROR);
}
}
} else {
throw new ModuleMgtException(ModuleMgtException.WARNING,
ModuleMgtMessageKeys.MODULE_FILE_NOT_FOUND);
}
} else {
throw new ModuleMgtException(ModuleMgtException.WARNING,
ModuleMgtMessageKeys.SYSTEM_MODULE_DELETE);
}
try {
pf.getModulePM().removeModule(module);
axisConfig.removeModule(module.getName(), module.getVersion());
} catch (Exception e) {
log.error("Error while removing module : " + moduleId, e);
throw new ModuleMgtException(ModuleMgtException.WARNING, ModuleMgtMessageKeys.ERROR_MODULE_REMOVE);
}