package net.sourceforge.javautil.deployer.artifact.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.sourceforge.javautil.common.io.IVirtualArtifact;
import net.sourceforge.javautil.common.io.IVirtualDirectory;
import net.sourceforge.javautil.common.io.IVirtualFile;
import net.sourceforge.javautil.common.io.impl.Directory;
import net.sourceforge.javautil.common.io.impl.DirectoryRoot;
import net.sourceforge.javautil.deployer.artifact.LinkedDeployment;
import net.sourceforge.javautil.deployer.artifact.IVirtualArtifactDeployer;
import net.sourceforge.javautil.deployer.artifact.IVirtualArtifactDeployment;
/**
* Used by the {@link VirtualArtifactDeployerComposite} to return a composite
* deployment of possibly more than one deployments by different deployers.
*
* @author elponderador
* @author $Author$
* @version $Id$
*/
public class VirtualArtifactDeploymentComposite extends VirtualArtifactDeploymentAbstract<IVirtualArtifact> {
protected List<IVirtualArtifactDeployment> deployments;
public VirtualArtifactDeploymentComposite(IVirtualArtifact deploymentStructure, IVirtualArtifactDeployer deployer, IVirtualArtifact artifact) {
super(deployer, artifact);
}
public void link(IVirtualArtifactDeployment deployment, boolean circular) {
for (IVirtualArtifactDeployment depl : this.deployments) {
depl.link(deployment, circular);
}
}
public void unlink(IVirtualArtifactDeployment deployment) {
for (IVirtualArtifactDeployment depl : this.deployments) {
depl.unlink(deployment);
}
}
public List<LinkedDeployment> getLinkedDeployments() {
List<LinkedDeployment> linked = new ArrayList<LinkedDeployment>();
for (IVirtualArtifactDeployment depl : this.deployments) linked.addAll(depl.getLinkedDeployments());
return linked;
}
public LinkedDeployment getLinkedDeployment(IVirtualArtifactDeployment deployment) {
for (IVirtualArtifactDeployment depl : this.deployments) if (depl.isLinked(deployment)) return depl.getLinkedDeployment(deployment);
return null;
}
public Directory getDeploymentStructure() {
Directory composite = new DirectoryRoot();
for (IVirtualArtifactDeployment depl : this.deployments) {
if (depl.getDeploymentStructure() instanceof IVirtualDirectory) {
composite.link((IVirtualDirectory) depl.getDeploymentStructure());
} else {
composite.link((IVirtualFile) depl.getDeploymentStructure(), depl.getDeploymentStructure().getName());
}
}
return composite;
}
public boolean isLinked(IVirtualArtifactDeployment deployment) {
for (IVirtualArtifactDeployment depl : this.deployments) {
if (depl.isLinked(deployment)) return true;
}
return false;
}
/**
* @return The deployments that make up this composite
*/
public List<IVirtualArtifactDeployment> getDeployments() { return deployments; }
/**
* @param deployments The deployments deployed for this composite
*/
protected VirtualArtifactDeploymentComposite setDeployments (List<IVirtualArtifactDeployment> deployments) {
this.deployments = Collections.unmodifiableList(deployments); return this;
}
}