Search in sources :

Example 1 with RestLiSimpleResource

use of com.linkedin.restli.server.annotations.RestLiSimpleResource in project rest.li by linkedin.

the class RestLiAnnotationReader method getResourceType.

private static ResourceType getResourceType(final Class<?> resourceClass) {
    RestLiCollection collAnno = resourceClass.getAnnotation(RestLiCollection.class);
    RestLiAssociation assocAnno = resourceClass.getAnnotation(RestLiAssociation.class);
    RestLiSimpleResource simpleResourceAnno = resourceClass.getAnnotation(RestLiSimpleResource.class);
    if (resourceClass.isAnnotationPresent(RestLiActions.class)) {
        throw new ResourceConfigException("Resource class '" + resourceClass.getName() + "' cannot have both @RestLiCollection and @RestLiActions annotations.");
    }
    int annoCount = 0;
    annoCount += collAnno != null ? 1 : 0;
    annoCount += assocAnno != null ? 1 : 0;
    annoCount += simpleResourceAnno != null ? 1 : 0;
    if (annoCount > 1) {
        throw new ResourceConfigException("Class '" + resourceClass.getName() + "' is annotated " + "with too many RestLi annotations");
    } else if (collAnno != null) {
        return ResourceType.COLLECTION;
    } else if (assocAnno != null) {
        return ResourceType.ASSOCIATION;
    } else if (simpleResourceAnno != null) {
        return ResourceType.SIMPLE;
    } else {
        throw new ResourceConfigException("Class '" + resourceClass.getName() + "' should be annotated " + "with '" + RestLiAssociation.class.getName() + "'" + " or '" + RestLiCollection.class.getName() + "'" + " or '" + RestLiSimpleResource.class.getName() + "'");
    }
}
Also used : RestLiCollection(com.linkedin.restli.server.annotations.RestLiCollection) RestLiSimpleResource(com.linkedin.restli.server.annotations.RestLiSimpleResource) RestLiAssociation(com.linkedin.restli.server.annotations.RestLiAssociation) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException)

Aggregations

ResourceConfigException (com.linkedin.restli.server.ResourceConfigException)1 RestLiAssociation (com.linkedin.restli.server.annotations.RestLiAssociation)1 RestLiCollection (com.linkedin.restli.server.annotations.RestLiCollection)1 RestLiSimpleResource (com.linkedin.restli.server.annotations.RestLiSimpleResource)1