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