package net.sourceforge.javautil.deployer.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sourceforge.javautil.common.event.IEventPropagator;
import net.sourceforge.javautil.common.io.IVirtualArtifact;
import net.sourceforge.javautil.common.proxy.CollectionTargetProxy;
import net.sourceforge.javautil.deployer.IDeployer;
import net.sourceforge.javautil.deployer.DeployerEvent;
import net.sourceforge.javautil.deployer.DeployerException;
import net.sourceforge.javautil.deployer.IDeployerListener;
import net.sourceforge.javautil.deployer.IDeployment;
import net.sourceforge.javautil.deployer.IDeploymentContext;
import net.sourceforge.javautil.deployer.DeployerEvent.Type;
/**
* The base for most deployer implementations.
*
* @author elponderador
* @author $Author$
* @version $Id$
*/
public abstract class DeployerAbstract<D,
DU extends IDeployment<D>,
DC extends IDeploymentContext<DU, D>,
DL extends IDeployerListener>
implements IDeployer<D, DU, DC, DL> {
protected final Logger log = LoggerFactory.getLogger(getClass());
protected final IEventPropagator<? extends DeployerEvent, DL> propagator = this.createEventPropagator();
public void addListener(DL listener) {
propagator.addListener(listener);
}
public void removeListener(DL listener) {
propagator.removeListener(listener);
}
public void addListener(Object listener) {
propagator.addListener(listener);
}
public void removeListener(Object listener) {
propagator.removeListener(listener);
}
/**
* @param deployment The deployment for which to create unique id
* @return The unique id for the deployment
*/
protected abstract String createUniqueId (D artifact);
/**
* This assumes no related exception.
*
* @see #fireEvent(IVirtualArtifact, Type, Throwable)
*/
protected DeployerEvent fireEvent (DU deployment, Type type) { return this.fireEvent(deployment, type, null); }
/**
* This assumes this deployer is the origin.
*
* @see #fireEvent(VirtualArtifactDeployer, IVirtualArtifact, Type, Throwable)
*/
protected DeployerEvent fireEvent (DU deployment, Type type, Throwable throwable) {
return this.fireEvent(this, deployment, type, throwable);
}
/**
* Implementations can use this facility for propagating events.
*
* @param deployer The deployer that is related to this event
* @param artifact The artifact in question
* @param type The type of event to fire
* @param throwable The exception, if any, related to the event
*
* @return The event object that was generated
*/
protected DeployerEvent fireEvent (IDeployer deployer, DU deployment, Type type, Throwable throwable) {
DeployerEvent evt = this.createEvent(deployer, deployment, type, throwable);
((IDeployerListener)propagator).handle( evt );
return evt;
}
protected abstract DeployerEvent createEvent (IDeployer deployer, DU deployment, Type type, Throwable throwable);
protected abstract IEventPropagator<? extends DeployerEvent, DL> createEventPropagator ();
}