blob: 79daa1688845337de2d3a63bceb87fa6985f8cbc [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.mondrian;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.osbp.mondrian.api.IMondrianManager;
import org.eclipse.osbp.mondrian.api.IMondrianService;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
@Component
public class MondrianManager implements IMondrianManager {
private final Set<ServiceReference<IMondrianService>> services = new HashSet<>();
private ComponentContext context;
@Activate
void activate(ComponentContext context) {
this.context = context;
}
@Deactivate
void deactivate() {
this.context = null;
services.clear();
}
@Override
public List<IMondrianService> getAllServices() {
List<IMondrianService> result = new ArrayList<IMondrianService>();
for (ServiceReference<IMondrianService> reference : services) {
result.add(context.getBundleContext().getService(reference));
}
return result;
}
@Override
public IMondrianService getService(String packageName) {
// iterate over all service references and try to find a reference with
// matching package name
for (ServiceReference<IMondrianService> reference : services) {
String prop_Package = (String) reference
.getProperty(IMondrianService.PROP__PACKAGE_NAME);
if (packageName.equals(prop_Package)) {
return context.getBundleContext().getService(reference);
}
}
return null;
}
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, service = IMondrianService.class)
void addIMondrianService(ServiceReference<IMondrianService> ref) {
services.add(ref);
}
void removeIMondrianService(ServiceReference<IMondrianService> ref) {
if (services != null) {
services.remove(ref);
}
}
}