use of org.eclipse.epp.mpc.core.service.IUserFavoritesService 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);
}
}
use of org.eclipse.epp.mpc.core.service.IUserFavoritesService in project epp.mpc by eclipse.
the class ServiceLocator method createMarketplaceService.
protected IMarketplaceService createMarketplaceService(String baseUrl) {
IMarketplaceService service;
URL base;
try {
base = URLUtil.toURL(baseUrl);
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
DefaultMarketplaceService defaultService = new DefaultMarketplaceService(base);
Map<String, String> requestMetaParameters = computeDefaultRequestMetaParameters();
defaultService.setRequestMetaParameters(requestMetaParameters);
IUserFavoritesService favoritesService = getFavoritesService(baseUrl);
// FIXME this should be a service reference!
defaultService.setUserFavoritesService(favoritesService);
service = new CachingMarketplaceService(defaultService);
return service;
}
use of org.eclipse.epp.mpc.core.service.IUserFavoritesService in project epp.mpc by eclipse.
the class DefaultCatalogService method registerDynamicFavoritesService.
private void registerDynamicFavoritesService(String catalogUrl, String favoritesApiServer, String favoritesApiKey) {
IMarketplaceServiceLocator marketplaceServiceLocator = ServiceHelper.getMarketplaceServiceLocator();
IUserFavoritesService favoritesService = marketplaceServiceLocator.getFavoritesService(catalogUrl);
if (favoritesService != null) {
return;
}
((ServiceLocator) marketplaceServiceLocator).registerFavoritesService(catalogUrl, favoritesApiServer, favoritesApiKey);
}
use of org.eclipse.epp.mpc.core.service.IUserFavoritesService 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);
}
use of org.eclipse.epp.mpc.core.service.IUserFavoritesService 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;
}
Aggregations