Search in sources :

Example 1 with UserFavoritesService

use of org.eclipse.epp.internal.mpc.core.service.UserFavoritesService in project epp.mpc by eclipse.

the class ServiceLocator method unbindFromUserFavoritesService.

private void unbindFromUserFavoritesService(ServiceReference<IUserFavoritesService> reference, ServiceReference<IMarketplaceStorageService> serviceReference, IMarketplaceStorageService serviceInstance) {
    ServiceRegistration<IUserFavoritesService> registration = getDynamicServiceInstance(reference);
    if (registration == null) {
        return;
    }
    Object binding = reference.getProperty(STORAGE_SERVICE_BINDING_ID);
    if (binding != null && serviceReference.equals(binding)) {
        if (registration != null) {
            Dictionary<String, Object> properties = ServiceUtil.getProperties(reference);
            properties.remove(STORAGE_SERVICE_BINDING_ID);
            registration.setProperties(properties);
        }
    }
    IUserFavoritesService service = ServiceUtil.getService(registration);
    if (service.getStorageService() == serviceInstance) {
        ((UserFavoritesService) service).unbindStorageService(serviceInstance);
    }
}
Also used : UserFavoritesService(org.eclipse.epp.internal.mpc.core.service.UserFavoritesService) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService)

Example 2 with UserFavoritesService

use of org.eclipse.epp.internal.mpc.core.service.UserFavoritesService in project epp.mpc by eclipse.

the class ServiceLocator method activate.

/**
 * OSGi service activation method. Activation will cause the locator to start managing individual marketplace
 * services and return the same instances per base url on subsequent calls to {@link #getMarketplaceService(String)}
 * .
 */
public synchronized void activate(BundleContext context, Map<?, ?> properties) {
    URL baseUrl = ServiceUtil.getUrl(properties, DEFAULT_URL, null);
    URL catalogUrl = ServiceUtil.getUrl(properties, CATALOG_URL, baseUrl);
    if (catalogUrl != null) {
        this.defaultCatalogUrl = catalogUrl;
    }
    // else the default value from the constructor is used
    URL marketplaceUrl = ServiceUtil.getUrl(properties, DEFAULT_MARKETPLACE_URL, baseUrl);
    if (marketplaceUrl != null) {
        this.defaultMarketplaceUrl = marketplaceUrl;
    }
    // else the default value from the constructor is used
    marketplaceServiceTracker = new ServiceTracker<IMarketplaceService, IMarketplaceService>(context, IMarketplaceService.class, null);
    marketplaceServiceTracker.open(true);
    catalogServiceTracker = new ServiceTracker<ICatalogService, ICatalogService>(context, ICatalogService.class, null);
    catalogServiceTracker.open(true);
    storageServiceTracker = new ServiceTracker<IMarketplaceStorageService, IMarketplaceStorageService>(context, IMarketplaceStorageService.class, new ServiceTrackerCustomizer<IMarketplaceStorageService, IMarketplaceStorageService>() {

        public IMarketplaceStorageService addingService(ServiceReference<IMarketplaceStorageService> reference) {
            IMarketplaceStorageService service = storageServiceTracker.addingService(reference);
            Object marketplaceUrl = ServiceUtil.getOverridablePropertyValue(reference, IMarketplaceService.BASE_URL);
            if (marketplaceUrl != null && service != null) {
                bindToUserFavoritesServices(marketplaceUrl.toString(), reference);
            }
            return service;
        }

        public void modifiedService(ServiceReference<IMarketplaceStorageService> reference, IMarketplaceStorageService service) {
            Object marketplaceUrl = ServiceUtil.getOverridablePropertyValue(reference, IMarketplaceService.BASE_URL);
            if (marketplaceUrl != null) {
                rebindToUserFavoritesServices(marketplaceUrl.toString(), reference, service);
            } else {
                unbindFromUserFavoritesServices(reference, service);
            }
        }

        public void removedService(ServiceReference<IMarketplaceStorageService> reference, IMarketplaceStorageService service) {
            unbindFromUserFavoritesServices(reference, service);
        }
    });
    storageServiceTracker.open(true);
    favoritesServiceTracker = new ServiceTracker<IUserFavoritesService, IUserFavoritesService>(context, IUserFavoritesService.class, new ServiceTrackerCustomizer<IUserFavoritesService, IUserFavoritesService>() {

        public IUserFavoritesService addingService(ServiceReference<IUserFavoritesService> reference) {
            return ServiceUtil.getService(reference);
        }

        public void modifiedService(ServiceReference<IUserFavoritesService> reference, IUserFavoritesService service) {
            if (!(service instanceof UserFavoritesService)) {
                return;
            }
            ServiceReference<?> storageServiceBinding = (ServiceReference<?>) reference.getProperty(STORAGE_SERVICE_BINDING_ID);
            if (storageServiceBinding != null && service.getStorageService() == null) {
                ((UserFavoritesService) service).bindStorageService((IMarketplaceStorageService) ServiceUtil.getService(storageServiceBinding));
            } else if (service.getStorageService() != null && getDynamicServiceInstance(reference) != null) {
                ((UserFavoritesService) service).setStorageService(null);
            }
        }

        public void removedService(ServiceReference<IUserFavoritesService> reference, IUserFavoritesService service) {
        // ignore
        }
    });
    favoritesServiceTracker.open(true);
}
Also used : ICatalogService(org.eclipse.epp.mpc.core.service.ICatalogService) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) URL(java.net.URL) ServiceReference(org.osgi.framework.ServiceReference) UserFavoritesService(org.eclipse.epp.internal.mpc.core.service.UserFavoritesService) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)

Example 3 with UserFavoritesService

use of org.eclipse.epp.internal.mpc.core.service.UserFavoritesService in project epp.mpc by eclipse.

the class ServiceLocator method registerFavoritesService.

public IUserFavoritesService registerFavoritesService(String marketplaceBaseUrl, String apiServerUrl, String apiKey) {
    IMarketplaceStorageService storageService = getStorageService(marketplaceBaseUrl);
    if (storageService == null) {
        storageService = registerStorageService(marketplaceBaseUrl, apiServerUrl, apiKey);
    }
    UserFavoritesService favoritesService = new UserFavoritesService();
    favoritesService.bindStorageService(storageService);
    registerService(marketplaceBaseUrl, IUserFavoritesService.class, favoritesService);
    return favoritesService;
}
Also used : UserFavoritesService(org.eclipse.epp.internal.mpc.core.service.UserFavoritesService) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)

Aggregations

UserFavoritesService (org.eclipse.epp.internal.mpc.core.service.UserFavoritesService)3 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)3 IMarketplaceStorageService (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)2 URL (java.net.URL)1 ICatalogService (org.eclipse.epp.mpc.core.service.ICatalogService)1 IMarketplaceService (org.eclipse.epp.mpc.core.service.IMarketplaceService)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1