1 22 package org.jboss.ejb3.deployers; 23 24 import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer; 25 import org.jboss.deployers.spi.deployer.DeploymentUnit; 26 import org.jboss.deployers.spi.DeploymentException; 27 import org.jboss.deployers.spi.structure.DeploymentContext; 28 import org.jboss.ejb3.DeploymentScope; 29 import org.jboss.ejb3.Ejb3Deployment; 30 import org.jboss.ejb3.EJB3Deployer; 31 import org.jboss.kernel.Kernel; 32 import org.jboss.virtual.VirtualFile; 33 import org.jboss.logging.Logger; 34 35 import javax.management.MBeanServer ; 36 import java.util.HashSet ; 37 import java.util.Properties ; 38 import java.util.List ; 39 40 47 public class EJBRegistrationDeployer extends AbstractSimpleDeployer 48 { 49 private static final Logger log = Logger.getLogger(EJBRegistrationDeployer.class); 50 51 private HashSet ignoredJarsSet; 52 private MBeanServer mbeanServer; 53 private Kernel kernel; 54 private Properties defaultPersistenceProperties; 55 private List <String > allowedSuffixes; 56 57 public List <String > getAllowedSuffixes() 58 { 59 return allowedSuffixes; 60 } 61 62 public void setAllowedSuffixes(List <String > allowedSuffixes) 63 { 64 this.allowedSuffixes = allowedSuffixes; 65 } 66 67 public HashSet getIgnoredJarsSet() 68 { 69 return ignoredJarsSet; 70 } 71 72 public void setIgnoredJarsSet(HashSet ignoredJarsSet) 73 { 74 this.ignoredJarsSet = ignoredJarsSet; 75 } 76 77 public MBeanServer getMbeanServer() 78 { 79 return mbeanServer; 80 } 81 82 public void setMbeanServer(MBeanServer mbeanServer) 83 { 84 this.mbeanServer = mbeanServer; 85 } 86 87 public Kernel getKernel() 88 { 89 return kernel; 90 } 91 92 public void setKernel(Kernel kernel) 93 { 94 this.kernel = kernel; 95 } 96 97 public Properties getDefaultPersistenceProperties() 98 { 99 return defaultPersistenceProperties; 100 } 101 102 public void setDefaultPersistenceProperties(Properties defaultPersistenceProperties) 103 { 104 this.defaultPersistenceProperties = defaultPersistenceProperties; 105 } 106 107 public void deploy(DeploymentUnit unit) throws DeploymentException 108 { 109 try 110 { 111 if (unit.getDeploymentContext().isComponent()) return; 112 VirtualFile jar = unit.getDeploymentContext().getRoot(); 113 if (jar.isLeaf() || ignoredJarsSet.contains(jar.getName()) ) 114 { 115 log.trace("EJBRegistrationDeployer ignoring: " + jar.getName()); 116 return; 117 } 118 if (allowedSuffixes != null) 119 { 120 for (String suffix : allowedSuffixes) 121 { 122 if (jar.getName().endsWith(suffix)) 123 { 124 log.trace("EJBRegistrationDeployer ignoring: " + jar.getName()); 125 return; 126 } 127 } 128 } 129 log.debug("********* EJBRegistrationDepoyer Begin Unit: " + unit.getName() + " jar: " + jar.getName()); 130 VirtualFile ejbjar = unit.getMetaDataFile("ejb-jar.xml"); 131 if (ejbjar != null) 132 { 133 if (!EJB3Deployer.has30EjbJarXml(ejbjar.openStream())) return; 134 } 135 DeploymentScope scope = null; 136 DeploymentContext parent = unit.getDeploymentContext().getParent(); 137 if (parent != null && parent.getRoot().getName().endsWith(".ear")) { 139 scope = parent.getTransientAttachments().getAttachment(DeploymentScope.class); 140 if (scope == null) 141 { 142 scope = new JBoss5DeploymentScope(unit.getDeploymentContext().getParent()); 143 parent.getTransientAttachments().addAttachment(DeploymentScope.class, scope); 144 } 145 } 146 JBoss5DeploymentUnit du = new JBoss5DeploymentUnit(unit); 147 du.setDefaultPersistenceProperties(defaultPersistenceProperties); 148 Ejb3JBoss5Deployment deployment = new Ejb3JBoss5Deployment(du, kernel, mbeanServer, unit, scope); 149 if (scope != null) scope.register(deployment); 150 deployment.create(); 152 if (deployment.getEjbContainers().size() == 0 && deployment.getPersistenceUnitDeployments().size() == 0) 153 { 154 log.trace("EJBRegistrationDeployer no containers in scanned jar, consider adding it to the ignore list: " + jar.getName() + " url: " + jar.toURL() + " unit: " + unit.getName()); 155 return; 156 } 157 unit.addAttachment(Ejb3Deployment.class, deployment); 158 } 159 catch (Exception e) 160 { 161 throw new DeploymentException(e); 162 } 163 } 164 165 public void undeploy(DeploymentUnit unit) 166 { 167 Ejb3Deployment deployment = unit.getAttachment(Ejb3Deployment.class); 168 if (deployment == null) return; 169 try 170 { 171 deployment.stop(); 172 } 173 catch (Exception e) 174 { 175 log.error("failed to stop deployment", e); 176 } 177 try 178 { 179 deployment.destroy(); 180 } 181 catch (Exception e) 182 { 183 log.error("failed to destroy deployment", e); 184 } 185 } 186 187 } 188 | Popular Tags |