package eu.dnetlib.enabling.is.sn;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import eu.dnetlib.common.rmi.BaseService;

/**
 * This class is used to delegate incoming notifications to a callback.
 * 
 * It can be used as a service and registered to the ISSN service with a real endpoint. Notifications are then fowarded
 * to the real consumer which will usually be an anonymous class within a test unit.
 * 
 * @author marko
 * 
 */
public class TestNotificationDelegator implements BaseService {
	/**
	 * logger.
	 */
	private static final Log log = LogFactory.getLog(TestNotificationDelegator.class); 

	/**
	 * delgates all incoming notifications to this listener.
	 */
	private NotificationDelegatorListener listener;

	/**
	 * {@inheritDoc}
	 * 
	 * @see eu.dnetlib.common.rmi.BaseService#identify()
	 */
	public String identify() {
		return "test notification delegator";
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see eu.dnetlib.common.rmi.BaseService#notify(java.lang.String, java.lang.String, java.lang.String,
	 *      java.lang.String)
	 */
	public void notify(final String subscriptionId, final String topic, final String isId, final String message) {
		log.debug("delegating notificatoin for " + subscriptionId);
		if (listener != null)
			listener.notify(subscriptionId, topic, isId, message);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see eu.dnetlib.common.rmi.BaseService#start()
	 */
	public void start() {
		// no operation
	}

	public void setListener(final NotificationDelegatorListener listener) {
		this.listener = listener;
	}

	public NotificationDelegatorListener getListener() {
		return listener;
	}

}
