public void remove(NamespaceInfo namespace) {
if (!catalogDAO.getResourcesByNamespace(namespace, ResourceInfo.class).isEmpty()) {
throw new IllegalArgumentException("Unable to delete non-empty namespace.");
}
NamespaceInfoImpl realns = catalogDAO.getNamespaceByPrefix(namespace.getPrefix());
if (realns == null) {
throw new IllegalArgumentException("Can't find namespace '" + namespace.getPrefix()
+ "' for deletion.");
}
catalogDAO.delete(realns);
if (realns.isDefault()) {
LOGGER.warning("Removing default namespace '" + namespace.getName() + "'");
// elect a random ns as default
List<NamespaceInfo> nslist = catalogDAO.getNamespaces();
if (!nslist.isEmpty()) {
NamespaceInfoImpl ns0 = (NamespaceInfoImpl) nslist.get(0);
LOGGER.warning("Electing '" + namespace.getName() + "' to default namespace.");
ns0.setDefault(true);
catalogDAO.update(ns0);
}
}
removed(namespace);
}