blob: aeea4434f93f03428f48442662ad708071262429 [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001package org.onlab.onos.cli;
2
3import org.apache.karaf.shell.console.OsgiCommandSupport;
4import org.osgi.framework.BundleContext;
5import org.osgi.framework.FrameworkUtil;
6
7/**
8 * Base abstraction of Karaf shell commands.
9 */
10public abstract class AbstractShellCommand extends OsgiCommandSupport {
11
12 /**
13 * Returns the reference to the implementaiton of the specified service.
14 *
15 * @param serviceClass service class
16 * @param <T> type of service
17 * @return service implementation
18 */
19 static <T> T get(Class<T> serviceClass) {
20 BundleContext bc = FrameworkUtil.getBundle(AbstractShellCommand.class).getBundleContext();
21 return bc.getService(bc.getServiceReference(serviceClass));
22 }
23
24}