// We cannot delete items from a URL repo
// First lets filter for jar resources
String repo = getAxisConfig().getRepository().getPath();
if (CarbonUtils.isURL(repo)) {
throw new ModuleMgtException(ModuleMgtException.WARNING, ModuleMgtMessageKeys.URL_REPO);
}
// We cannot remove the addressing module if at least one service is
// deployed in soapsession scope
if (moduleId.startsWith("addressing")) {
throw new ModuleMgtException(ModuleMgtException.WARNING,
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);
}
return "Module " + moduleId + " was successfully removed from system";
}