blob: 78fa031305169b8155d10090f15d0314bf001110 [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001package org.onlab.rest;
2
3import org.onlab.osgi.DefaultServiceDirectory;
4import org.onlab.osgi.ServiceDirectory;
5
6/**
7 * Base abstraction of a JAX-RS resource.
8 */
9public 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}