/** * Returns the reference to the implementation of the specified service. * * @param serviceClass service class * @param <T> type of service * @return service implementation */ public static <T> T getService(Class<T> serviceClass) { Bundle bundle = FrameworkUtil.getBundle(serviceClass); if (bundle != null) { BundleContext bc = bundle.getBundleContext(); if (bc != null) { ServiceReference<T> reference = bc.getServiceReference(serviceClass); if (reference != null) { T impl = bc.getService(reference); if (impl != null) { return impl; } } } } throw new ServiceNotFoundException("Service " + serviceClass.getName() + " not found"); }
@Override public final Object execute() throws Exception { try { auditCommand(); doExecute(); } catch (ServiceNotFoundException e) { error(e.getMessage()); } return null; }