View Javadoc

1   package com.atlassian.plugins.rest.common.expand.resolver;
2   
3   import com.atlassian.plugins.rest.common.expand.EntityExpander;
4   import com.atlassian.plugins.rest.common.expand.Expander;
5   
6   import static com.google.common.base.Preconditions.checkNotNull;
7   
8   /**
9    * <p>An {@link EntityExpander} resolver that uses the {@link Expander} annotation for resolution.</p>
10   * <p>Implementation must implement {@link #getEntityExpander(Expander)}</p>
11   */
12  public abstract class AbstractAnnotationEntityExpanderResolver implements EntityExpanderResolver {
13      public boolean hasExpander(Class<?> type) {
14          return checkNotNull(type).getAnnotation(Expander.class) != null;
15      }
16  
17      public final <T> EntityExpander<T> getExpander(Class<? extends T> type) {
18          final Expander expander = checkNotNull(type).getAnnotation(Expander.class);
19          return expander != null ? (EntityExpander<T>) getEntityExpander(expander) : null;
20      }
21  
22      /**
23       * Retrieves the {@link EntityExpander} associated to the {@link Expander} annotation. The entity expander is created if necessary.
24       *
25       * @param expander the annotation
26       * @return an instance of {@link EntityExpander}
27       */
28      protected abstract EntityExpander<?> getEntityExpander(Expander expander);
29  }