String newDevicePath =
getXMLFilePath(deviceDirectory, newDeviceName);
if (!archive.rename(devicePath, newDevicePath)) {
// Should only happen if the device files are out of date
// wrt the hierarchy, which should not be often.
throw new RepositoryException(
exceptionLocalizer.format(
"device-rename-failed",
new Object[]{devicePath,
newDevicePath}));
}
// Then update it's contents to change the name internally.
Document deviceDoc = createNewDocument(
archive.getInputFrom(newDevicePath));
Element deviceElement = deviceDoc.getRootElement();
deviceElement.setAttribute(
DeviceRepositorySchemaConstants.DEVICE_NAME_ATTRIBUTE,
newDeviceName);
try {
writeDocument(deviceDoc, archive.getOutputTo(newDevicePath));
} catch (IOException e) {
throw new RepositoryException(
exceptionLocalizer.format(
"device-update-failure",
newDevicePath),
e);
}