use of com.linkedin.restli.server.resources.SingleObjectResource in project rest.li by linkedin.
the class RestLiAnnotationReader method processResource.
/**
* Processes an annotated resource class, producing a ResourceModel.
*
* @param resourceClass annotated resource class
* @return {@link ResourceModel} for the provided resource class
*/
public static ResourceModel processResource(final Class<?> resourceClass, ResourceModel parentResourceModel) {
final ResourceModel model;
checkAnnotation(resourceClass);
if ((resourceClass.isAnnotationPresent(RestLiCollection.class) || resourceClass.isAnnotationPresent(RestLiAssociation.class))) {
// If any of these annotations, a subclass of KeyValueResource is expected
if (!KeyValueResource.class.isAssignableFrom(resourceClass)) {
throw new RestLiInternalException("Resource class '" + resourceClass.getName() + "' declares RestLi annotation but does not implement " + KeyValueResource.class.getName() + " interface.");
}
@SuppressWarnings("unchecked") Class<? extends KeyValueResource<?, ?>> clazz = (Class<? extends KeyValueResource<?, ?>>) resourceClass;
model = processCollection(clazz, parentResourceModel);
} else if (resourceClass.isAnnotationPresent(RestLiActions.class)) {
model = processActions(resourceClass, parentResourceModel);
} else if (resourceClass.isAnnotationPresent(RestLiSimpleResource.class)) {
@SuppressWarnings("unchecked") Class<? extends SingleObjectResource<?>> clazz = (Class<? extends SingleObjectResource<?>>) resourceClass;
model = processSingleObjectResource(clazz, parentResourceModel);
} else {
throw new ResourceConfigException("Class '" + resourceClass.getName() + "' must be annotated with a valid @RestLi... annotation");
}
if (parentResourceModel != null) {
parentResourceModel.addSubResource(model.getName(), model);
}
if (!model.isActions()) {
checkRestLiDataAnnotations(resourceClass, (RecordDataSchema) getDataSchema(model.getValueClass(), null));
}
addAlternativeKeys(model, resourceClass);
DataMap annotationsMap = ResourceModelAnnotation.getAnnotationsMap(resourceClass.getAnnotations());
addDeprecatedAnnotation(annotationsMap, resourceClass);
model.setCustomAnnotation(annotationsMap);
return model;
}
Aggregations