public Resource get(RequestContext requestContext) throws RegistryException {
String path = requestContext.getResourcePath().getPath();
String stateKey = RegistryUtils.getResourceName(path);
if (!states.containsKey(stateKey)) {
throw new ResourceNotFoundException("The given key, " + stateKey + " does not " +
"correspond to a lifecycle state.");
}
String servicePath = RegistryUtils.getParentPath(path);
Registry registry = requestContext.getRegistry();
for (String majorVersion : getSortedChildrenList(servicePath, registry)) {
try {
Integer.parseInt(RegistryUtils.getResourceName(majorVersion));
for (String minorVersion : getSortedChildrenList(majorVersion, registry)) {
try {
Integer.parseInt(RegistryUtils.getResourceName(minorVersion));
for (String patchVersion : getSortedChildrenList(minorVersion, registry)) {
try {
Integer.parseInt(RegistryUtils.getResourceName(patchVersion));
String serviceResourcePath = patchVersion +
RegistryConstants.PATH_SEPARATOR + resourceKey;
Resource resource = registry.get(serviceResourcePath);
for (Object propKey : resource.getProperties().keySet()) {
if (((String)propKey).matches(
"^registry[.]lifecycle.*[.]state$")) {
if (states.get(stateKey).equals(
resource.getProperty((String)propKey))) {
resource.setProperty(RegistryConstants.REGISTRY_LINK,
"true");
resource.setProperty(
RegistryConstants.REGISTRY_MOUNT_POINT,
path);
resource.setProperty(
RegistryConstants.REGISTRY_TARGET_POINT,
serviceResourcePath);
resource.setProperty(RegistryConstants.REGISTRY_AUTHOR,
resource.getAuthorUserName());
resource.setProperty(
RegistryConstants.REGISTRY_ACTUAL_PATH,
serviceResourcePath);
requestContext.setProcessingComplete(true);
return resource;
}
break;
}
}
} catch (NumberFormatException ignored) {
break;
}
}
} catch (NumberFormatException ignored) {
break;
}
}
} catch (NumberFormatException ignored) {
break;
}
}
throw new ResourceNotFoundException("No Resources found to be in the given " +
"lifecycle state: " + stateKey);
}