Search in sources :

Example 1 with AlternativeKeys

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

the class RestLiAnnotationReader method addAlternativeKeys.

/**
   * Add alternative keys, if there are any, to the given model.
   *
   * @param model The {@link com.linkedin.restli.internal.server.model.ResourceModel} that we are building.
   * @param resourceClass The resource {@link java.lang.Class}.
   */
private static void addAlternativeKeys(ResourceModel model, Class<?> resourceClass) {
    if (resourceClass.isAnnotationPresent(AlternativeKey.class) || resourceClass.isAnnotationPresent(AlternativeKeys.class)) {
        AlternativeKey[] alternativeKeyAnnotations;
        if (resourceClass.isAnnotationPresent(AlternativeKeys.class)) {
            alternativeKeyAnnotations = resourceClass.getAnnotation(AlternativeKeys.class).alternativeKeys();
        } else //(resourceClass.isAnnotationPresent(AlternativeKey.class) == true)
        {
            alternativeKeyAnnotations = new AlternativeKey[] { resourceClass.getAnnotation(AlternativeKey.class) };
        }
        Map<String, com.linkedin.restli.server.AlternativeKey<?, ?>> alternativeKeyMap = new HashMap<String, com.linkedin.restli.server.AlternativeKey<?, ?>>(alternativeKeyAnnotations.length);
        for (AlternativeKey altKeyAnnotation : alternativeKeyAnnotations) {
            @SuppressWarnings("unchecked") com.linkedin.restli.server.AlternativeKey<?, ?> altKey = buildAlternativeKey(model.getName(), altKeyAnnotation);
            alternativeKeyMap.put(altKeyAnnotation.name(), altKey);
        }
        model.putAlternativeKeys(alternativeKeyMap);
    } else {
        model.putAlternativeKeys(new HashMap<String, com.linkedin.restli.server.AlternativeKey<?, ?>>());
    }
}
Also used : HashMap(java.util.HashMap) AlternativeKeys(com.linkedin.restli.server.annotations.AlternativeKeys) AlternativeKey(com.linkedin.restli.server.annotations.AlternativeKey)

Aggregations

AlternativeKey (com.linkedin.restli.server.annotations.AlternativeKey)1 AlternativeKeys (com.linkedin.restli.server.annotations.AlternativeKeys)1 HashMap (java.util.HashMap)1