}
public static boolean updateHandler(Registry configSystemRegistry, String oldName, String payload) throws RegistryException,
XMLStreamException {
if (isHandlerNameInUse(oldName))
throw new RegistryException("Could not update handler since it is already in use!");
String newName = null;
OMElement element = AXIOMUtil.stringToOM(payload);
if (element != null) {
newName = element.getAttributeValue(new QName("class"));
}
if (newName == null || newName.equals(""))
return false; // invalid configuration
if (oldName == null || oldName.equals("")) {
String path = getContextRoot() + newName;
Resource resource;
if (handlerExists(configSystemRegistry, newName)) {
return false; // we are adding a new handler
}
else {
resource = new ResourceImpl();
}
resource.setContent(payload);
try {
configSystemRegistry.beginTransaction();
configSystemRegistry.put(path, resource);
generateHandler(configSystemRegistry, path);
configSystemRegistry.commitTransaction();
} catch (Exception e) {
configSystemRegistry.rollbackTransaction();
throw new RegistryException("Unable to generate handler", e);
}
return true;
}
if (newName.equals(oldName)) {
//updating the rest of the content
String oldPath = getContextRoot() + oldName;
Resource resource;
if (handlerExists(configSystemRegistry, oldName)) {
resource = configSystemRegistry.get(oldPath);
}
else {
resource = new ResourceImpl(); // will this ever happen?
}
resource.setContent(payload);
try {
configSystemRegistry.beginTransaction();
configSystemRegistry.put(oldPath, resource);
generateHandler(configSystemRegistry, oldPath);
configSystemRegistry.commitTransaction();
} catch (Exception e) {
configSystemRegistry.rollbackTransaction();
throw new RegistryException("Unable to generate handler", e);
}
return true;
}
else {
String oldPath = getContextRoot() + oldName;
String newPath = getContextRoot() + newName;
if (handlerExists(configSystemRegistry, newName)) {
return false; // we are trying to use the name of a existing handler
}
Resource resource;
if (handlerExists(configSystemRegistry, oldName)) {
resource = configSystemRegistry.get(oldPath);
}
else {
resource = new ResourceImpl(); // will this ever happen?
}
resource.setContent(payload);
try {
configSystemRegistry.beginTransaction();
configSystemRegistry.put(newPath, resource);
generateHandler(configSystemRegistry, newPath);
configSystemRegistry.delete(oldPath);
removeHandler(configSystemRegistry, oldName);
configSystemRegistry.commitTransaction();
} catch (Exception e) {
configSystemRegistry.rollbackTransaction();
throw new RegistryException("Unable to renew handler", e);
}
return true;
}
}