blob: bc8db505cdc6e0b6030a1ab8d5ef9fb7e9d25951 [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.authentication;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.eclipse.osbp.ui.api.complexdatacontainer.IComplexDataContainer;
import org.eclipse.osbp.ui.api.complexdatacontainer.IComplexDataContainerChangedListener;
import org.eclipse.osbp.ui.api.useraccess.IOrganizationService;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/**
* The listener interface for receiving service events. The class that is
* interested in processing a service event implements this interface, and the
* object created with that class is registered with a component using the
* component's <code>addServiceListener</code> method. When the service event
* occurs, that object's appropriate method is invoked.
*
*/
// TODO: check reference
/*
* reference not found
*
* @see ServiceEvent
*/
@Component
public class ServiceListener {
/** The Constant LOGGER. */
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceListener.class);
/** The Constant sOrganizationServices. */
public static final Map<String, IOrganizationService> sOrganizationServices = new HashMap<String, IOrganizationService>();
/** The listeners which are listening for changed complex data changes. */
public static final Set<IComplexDataContainerChangedListener> complexDataContainerChangedListeners = new HashSet<IComplexDataContainerChangedListener>();
/**
* Gets the organization services.
*
* @return the organization services
*/
public static Set<IOrganizationService> getOrganizationServices() {
return new HashSet<IOrganizationService>(sOrganizationServices.values());
}
/**
* Bind organization service.
*
* @param organization
* the organization
*/
@Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC)
public void bindOrganizationService(IOrganizationService organization) {
LOGGER.debug(ServiceListener.class.getCanonicalName() + ": " + organization.getClass().getCanonicalName() + " bound");
sOrganizationServices.put(organization.getClass().getCanonicalName(), organization);
triggerComplexDataContainerChangedListeners();
}
/**
* Unbind organization service.
*
* @param organization
* the organization
*/
public void unbindOrganizationService(IOrganizationService organization) {
LOGGER.debug(ServiceListener.class.getCanonicalName() + ": " + organization.getClass().getCanonicalName() + " unbound");
sOrganizationServices.remove(organization.getClass().getCanonicalName());
triggerComplexDataContainerChangedListeners();
}
public static void addComplexDataContainerChangedListener(IComplexDataContainerChangedListener listener) {
complexDataContainerChangedListeners.add(listener);
}
public static void removeComplexDataContainerChangedListener(IComplexDataContainerChangedListener listener) {
complexDataContainerChangedListeners.remove(listener);
}
public static void triggerComplexDataContainerChangedListeners() {
for (IComplexDataContainerChangedListener listener : complexDataContainerChangedListeners) {
listener.complexDataContainerChanged();
}
}
}