1 22 package org.jboss.ejb.deployers; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import javax.management.MalformedObjectNameException ; 28 import javax.management.ObjectName ; 29 30 import org.jboss.deployers.plugins.deployers.helpers.AbstractSimpleRealDeployer; 31 import org.jboss.deployers.spi.DeploymentException; 32 import org.jboss.deployers.spi.deployer.DeploymentUnit; 33 import org.jboss.ejb.EjbModule; 34 import org.jboss.metadata.ApplicationMetaData; 35 import org.jboss.mx.util.ObjectNameConverter; 36 import org.jboss.system.metadata.ServiceAttributeMetaData; 37 import org.jboss.system.metadata.ServiceConstructorMetaData; 38 import org.jboss.system.metadata.ServiceDependencyValueMetaData; 39 import org.jboss.system.metadata.ServiceMetaData; 40 41 48 public class EjbDeployer extends AbstractSimpleRealDeployer<ApplicationMetaData> 49 { 50 private String transactionManagerServiceName; 51 private String webServiceName; 52 53 58 public static String shortNameFromDeploymentName(String name) 59 { 60 String shortName = name; 61 String [] parts = name.split("/|\\."); 62 if( parts.length > 1 ) 63 { 64 if( parts[parts.length-1].equals("war") ) 66 shortName = parts[parts.length-2]; 67 else 69 shortName = parts[parts.length-1]; 70 } 71 return shortName; 72 } 73 74 public EjbDeployer() 75 { 76 super(ApplicationMetaData.class); 77 } 78 79 public String getTransactionManagerServiceName() 80 { 81 return transactionManagerServiceName; 82 } 83 84 public void setTransactionManagerServiceName( 85 String transactionManagerServiceName) 86 { 87 this.transactionManagerServiceName = transactionManagerServiceName; 88 } 89 90 public String getWebServiceName() 91 { 92 return webServiceName; 93 } 94 95 public void setWebServiceName(String webServiceName) 96 { 97 this.webServiceName = webServiceName; 98 } 99 100 @Override 101 public void deploy(DeploymentUnit unit, ApplicationMetaData deployment) 102 throws DeploymentException 103 { 104 if (deployment.getEjbVersion() > 2) return; 107 ServiceMetaData ejbModule = new ServiceMetaData(); 108 ejbModule.setCode(EjbModule.class.getName()); 109 110 String moduleName = deployment.getJmxName(); 111 if( moduleName == null ) 112 { 113 String unitShortName = unit.getName(); 114 if (unitShortName.endsWith("/")) 115 { 116 unitShortName = unitShortName.substring(0, unitShortName.length() - 1); 117 } 118 119 if(unitShortName.endsWith("!")) 120 { 121 unitShortName = unitShortName.substring(0, unitShortName.length() - 1); 122 } 123 124 unitShortName = unitShortName.substring(unitShortName.lastIndexOf("/") + 1); 125 126 moduleName = EjbModule.BASE_EJB_MODULE_NAME + ",module=" + unitShortName; 127 } 128 129 ObjectName moduleObjectName = null; 131 try 132 { 133 moduleObjectName = ObjectNameConverter.convert(moduleName); 134 } 135 catch(MalformedObjectNameException e) 136 { 137 throw new DeploymentException("Failed to create EJB module " + unit.getName() + 138 ": malformed EjbModule name " + moduleName, e); 139 } 140 141 ejbModule.setObjectName(moduleObjectName); 142 143 ServiceConstructorMetaData ctor = new ServiceConstructorMetaData(); 144 ctor.setSignature( 145 new String []{DeploymentUnit.class.getName(), ApplicationMetaData.class.getName()} 146 ); 147 ctor.setParameters(new Object []{unit, deployment}); 148 ejbModule.setConstructor(ctor); 149 150 List <ServiceAttributeMetaData> attrs = new ArrayList <ServiceAttributeMetaData>(); 152 ServiceAttributeMetaData attr = new ServiceAttributeMetaData(); 153 attr.setName("TransactionManagerFactory"); 154 ServiceDependencyValueMetaData dependencyValue = new ServiceDependencyValueMetaData(); 155 dependencyValue.setDependency(getTransactionManagerServiceName()); 156 dependencyValue.setProxyType("attribute"); 157 attr.setValue(dependencyValue); 158 attrs.add(attr); 159 160 ejbModule.setAttributes(attrs); 161 162 unit.addAttachment(ServiceMetaData.class, ejbModule); 163 } 164 165 @Override 166 public void undeploy(DeploymentUnit unit, ApplicationMetaData deployment) 167 { 168 170 } 171 172 181 protected ObjectName getObjectName(DeploymentUnit unit, ApplicationMetaData metaData) 182 throws MalformedObjectNameException 183 { 184 String name = metaData.getJmxName(); 185 if( name == null ) 186 { 187 name = EjbModule.BASE_EJB_MODULE_NAME + ",module=" 188 + shortNameFromDeploymentName(unit.getName()); 189 } 190 191 ObjectName ejbModuleName = ObjectNameConverter.convert(name); 193 return ejbModuleName; 194 } 195 196 protected void deployEjbModule(DeploymentUnit unit, ApplicationMetaData metaData) 197 throws Exception 198 { 199 log.debug("deployWebModule"); 200 try 201 { 202 ServiceMetaData ejbModule = new ServiceMetaData(); 203 ObjectName objectName = getObjectName(unit, metaData); 204 ejbModule.setObjectName(objectName); 205 ejbModule.setCode(EjbModule.class.getName()); 206 ServiceConstructorMetaData constructor = new ServiceConstructorMetaData(); 208 constructor.setSignature(new String [] { DeploymentUnit.class.getName()}); 209 constructor.setParameters(new Object [] {unit, this, metaData}); 210 ejbModule.setConstructor(constructor); 211 212 List <ServiceAttributeMetaData> attributes = new ArrayList <ServiceAttributeMetaData>(); 213 ServiceAttributeMetaData tm = new ServiceAttributeMetaData(); 215 tm.setName("txMgr"); 216 String tmProxyType = "javax.transaction.TransactionManager"; 217 ServiceDependencyValueMetaData tmDepends = new ServiceDependencyValueMetaData(transactionManagerServiceName, tmProxyType); 218 tm.setValue(tmDepends); 219 attributes.add(tm); 220 ServiceAttributeMetaData ws = new ServiceAttributeMetaData(); 222 ws.setName("webServiceName"); 223 ServiceDependencyValueMetaData wsDepends = new ServiceDependencyValueMetaData(); 224 wsDepends.setDependency(webServiceName); 225 attributes.add(ws); 226 ejbModule.setAttributes(attributes); 227 228 unit.addAttachment(ServiceMetaData.class, ejbModule); 230 } 231 catch (Exception e) 232 { 233 throw DeploymentException.rethrowAsDeploymentException("Error creating rar deployment " + unit.getName(), e); 234 } 235 236 } 237 } 238 | Popular Tags |