tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 1 | package org.onlab.rest; |
| 2 | |
| 3 | import org.onlab.osgi.DefaultServiceDirectory; |
| 4 | import org.onlab.osgi.ServiceDirectory; |
| 5 | |
| 6 | /** |
| 7 | * Base abstraction of a JAX-RS resource. |
| 8 | */ |
| 9 | public abstract class BaseResource { |
| 10 | |
| 11 | private static ServiceDirectory services = new DefaultServiceDirectory(); |
| 12 | |
| 13 | /** |
| 14 | * Sets alternate service directory to be used for lookups. |
| 15 | * <p> |
| 16 | * Intended to ease unit testing and not intended for use in production. |
| 17 | * </p> |
| 18 | * |
| 19 | * @param serviceDirectory alternate service directory |
| 20 | */ |
| 21 | public static void setServiceDirectory(ServiceDirectory serviceDirectory) { |
| 22 | services = serviceDirectory; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Returns reference to the specified service implementation. |
| 27 | * |
| 28 | * @param service service class |
| 29 | * @param <T> type of service |
| 30 | * @return service implementation |
| 31 | */ |
| 32 | protected static <T> T get(Class<T> service) { |
| 33 | return services.get(service); |
| 34 | } |
| 35 | |
| 36 | } |