Search in sources :

Example 1 with ServiceNotFoundException

use of org.motechproject.mds.exception.entity.ServiceNotFoundException in project motech by motech.

the class DataServiceHelper method getDataService.

/**
 * Retrieves {@link org.motechproject.mds.service.MotechDataService} implementation for the
 * given entity class. It will throw {@link org.motechproject.mds.exception.entity.ServiceNotFoundException}, in
 * case a service for the given entity class cannot be found.
 *
 * @param bundleContext context of a bundle
 * @param entityClass fully qualified class name of an entity
 * @return generated {@link org.motechproject.mds.service.MotechDataService} implementation
 */
public static MotechDataService getDataService(BundleContext bundleContext, String entityClass) {
    String interfaceName = MotechClassPool.getInterfaceName(entityClass);
    MotechDataService dataService = OSGiServiceUtils.findService(bundleContext, interfaceName);
    if (dataService == null) {
        throw new ServiceNotFoundException(interfaceName);
    }
    return dataService;
}
Also used : ServiceNotFoundException(org.motechproject.mds.exception.entity.ServiceNotFoundException) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 2 with ServiceNotFoundException

use of org.motechproject.mds.exception.entity.ServiceNotFoundException in project motech by motech.

the class MdsDummyDataGeneratorImpl method getService.

@Override
public MotechDataService getService(BundleContext bundleContext, String className) {
    String interfaceName = MotechClassPool.getInterfaceName(className);
    ServiceReference ref = bundleContext.getServiceReference(interfaceName);
    if (ref == null) {
        throw new ServiceNotFoundException(interfaceName);
    }
    return (MotechDataService) bundleContext.getService(ref);
}
Also used : ServiceNotFoundException(org.motechproject.mds.exception.entity.ServiceNotFoundException) MotechDataService(org.motechproject.mds.service.MotechDataService) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

ServiceNotFoundException (org.motechproject.mds.exception.entity.ServiceNotFoundException)2 MotechDataService (org.motechproject.mds.service.MotechDataService)2 ServiceReference (org.osgi.framework.ServiceReference)1