org.osgi.framework.ServiceException Java Examples

The following examples show how to use org.osgi.framework.ServiceException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceReferenceImpl.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
S factorService(final Bundle theBundle, boolean count){
	@SuppressWarnings("unchecked")
	final ServiceFactory<S> factory = (ServiceFactory<S>) service;
	final S factoredService;
	try {
		if(count)
			incrementCounter(theBundle);
		marker = true;
		factoredService = factory.getService(theBundle,
				registration);
		marker = false;
		checkService(factoredService,
				(String[]) properties.get(Constants.OBJECTCLASS));
		// catch failed check and exceptions thrown in factory
	} catch (final IllegalArgumentException iae) {
		if(count)
			decrementCounter(theBundle);
		framework.notifyFrameworkListeners(FrameworkEvent.ERROR,
				bundle, new ServiceException(
						"Invalid service object",
						ServiceException.FACTORY_ERROR));
		return null;
	} catch (final Throwable t) {
		if(count)
			decrementCounter(theBundle);
		framework.notifyFrameworkListeners(FrameworkEvent.ERROR,
				bundle, new ServiceException(
						"Exception while factoring the service",
						ServiceException.FACTORY_EXCEPTION, t));
		return null;
	}
	
	return factoredService;
}
 
Example #2
Source File: BticinoDevice.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
private State getItemState(String itemId) throws ServiceException {
    ItemRegistry itemRegistry = getItemRegistry();
    State itemState = null;

    try {
        Item item = itemRegistry.getItem(itemId);
        itemState = item.getState();
        logger.debug("{}: State: {}", itemId, itemState);
    } catch (ItemNotFoundException ex) {
        logger.info("{} not found {}", itemId, ex.getMessage());
    }

    return itemState;
}
 
Example #3
Source File: BticinoDevice.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
private ItemRegistry getItemRegistry() throws ServiceException {
    BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
    if (bundleContext != null) {
        ServiceReference<?> serviceReference = bundleContext.getServiceReference(ItemRegistry.class.getName());
        if (serviceReference != null) {
            ItemRegistry itemregistry = (ItemRegistry) bundleContext.getService(serviceReference);
            return itemregistry;
        }
    }
    throw new ServiceException("Cannot get ItemRegistry");
}