use of com.linkedin.restli.server.annotations.RestLiTemplate in project rest.li by linkedin.
the class RestLiAnnotationReader method checkAnnotation.
/**
* Check if resourceClass is annotated with the expected annotation of its template class,
* expressed in the {@link RestLiTemplate} annotation.
*/
private static void checkAnnotation(final Class<?> resourceClass) {
Class templateClass = resourceClass;
while (templateClass != Object.class) {
templateClass = templateClass.getSuperclass();
final RestLiTemplate templateAnnotation = (RestLiTemplate) templateClass.getAnnotation(RestLiTemplate.class);
if (templateAnnotation != null) {
final Class<? extends Annotation> currentExpect = templateAnnotation.expectedAnnotation();
if (currentExpect == RestLiCollection.class || currentExpect == RestLiAssociation.class || currentExpect == RestLiSimpleResource.class) {
if (resourceClass.getAnnotation(currentExpect) == null) {
throw new ResourceConfigException(resourceClass.getName() + " is not annotated with " + currentExpect.getName() + ", expected by " + templateClass.getName());
} else {
return;
}
} else {
throw new ResourceConfigException("Unknown expected annotation " + currentExpect.getName() + " from " + templateClass.getName());
}
}
}
}
Aggregations