Skip to content

Instantly share code, notes, and snippets.

@gayanW
Created June 7, 2017 06:24
Show Gist options
  • Save gayanW/2df142a6bddffd59b04b8982c10d1985 to your computer and use it in GitHub Desktop.
Save gayanW/2df142a6bddffd59b04b8982c10d1985 to your computer and use it in GitHub Desktop.
private String getResourceName(DelegatingResourceHandler resourceHandler, boolean getParent) {
Resource annotation = resourceHandler.getClass().getAnnotation(Resource.class);
String resourceName = null;
if (annotation != null) {
// top level resource
resourceName = annotation.name();
} else {
// sub resource
SubResource subResourceAnnotation = resourceHandler.getClass().getAnnotation(SubResource.class);
if (subResourceAnnotation != null) {
if (getParent) {
Resource parentResourceAnnotation = subResourceAnnotation.parent().getAnnotation(Resource.class);
resourceName = parentResourceAnnotation.name();
} else {
resourceName = subResourceAnnotation.path();
}
}
}
return resourceName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment