Search in sources :

Example 1 with RestLiTemplate

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());
            }
        }
    }
}
Also used : RestLiTemplate(com.linkedin.restli.server.annotations.RestLiTemplate) RestLiSimpleResource(com.linkedin.restli.server.annotations.RestLiSimpleResource) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException)

Aggregations

ResourceConfigException (com.linkedin.restli.server.ResourceConfigException)1 RestLiSimpleResource (com.linkedin.restli.server.annotations.RestLiSimpleResource)1 RestLiTemplate (com.linkedin.restli.server.annotations.RestLiTemplate)1