1 22 package org.jboss.deployers.plugins.deployers.helpers; 23 24 import java.util.Set ; 25 26 import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer; 27 import org.jboss.deployers.spi.DeploymentException; 28 import org.jboss.deployers.spi.deployer.DeploymentUnit; 29 30 37 public abstract class AbstractRealDeployer<T> extends AbstractSimpleDeployer 38 { 39 40 private SimpleDeploymentVisitor<T> visitor; 41 42 43 private Class <T> deploymentType; 44 45 46 private boolean warned; 47 48 52 public AbstractRealDeployer() 53 { 54 setRelativeOrder(REAL_DEPLOYER); 55 } 56 57 63 protected void setDeploymentVisitor(SimpleDeploymentVisitor<T> visitor) 64 { 65 if (visitor == null) 66 throw new IllegalArgumentException ("Null visitor"); 67 this.visitor = visitor; 68 deploymentType = visitor.getVisitorType(); 69 if (deploymentType == null) 70 throw new IllegalArgumentException ("Null visitor type"); 71 } 72 73 public void deploy(DeploymentUnit unit) throws DeploymentException 74 { 75 if (visitor == null) 76 { 77 if (warned == false) 78 { 79 log.error("INTERNAL ERROR: Visitor is null for " + getClass().getName()); 80 warned = true; 81 } 82 return; 83 } 84 85 try 86 { 87 Set <? extends T> deployments = unit.getAllMetaData(deploymentType); 88 for (T deployment : deployments) 89 visitor.deploy(unit, deployment); 90 } 91 catch (Throwable t) 92 { 93 undeploy(unit); 94 throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + unit.getName(), t); 95 } 96 } 97 98 public void undeploy(DeploymentUnit unit) 99 { 100 if (visitor == null) 101 return; 102 Set <? extends T> deployments = unit.getAllMetaData(deploymentType); 103 for (T deployment : deployments) 104 visitor.undeploy(unit, deployment); 105 } 106 107 } 108 | Popular Tags |