1 22 package org.jboss.ejb3; 23 24 import javassist.bytecode.AnnotationsAttribute; 25 import javassist.bytecode.ClassFile; 26 import javassist.bytecode.annotation.Annotation; 27 import javassist.bytecode.annotation.StringMemberValue; 28 import org.jboss.annotation.ejb.ResourceAdapter; 29 import org.jboss.aop.AspectManager; 30 import org.jboss.aop.DomainDefinition; 31 import org.jboss.ejb3.metamodel.EnterpriseBean; 32 import org.jboss.ejb3.metamodel.MessageDrivenBean; 33 import org.jboss.ejb3.mdb.ConsumerContainer; 34 import org.jboss.ejb3.mdb.MDB; 35 import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory; 36 import org.jboss.ejb3.service.ServiceContainer; 37 import org.jboss.ejb3.stateful.StatefulContainer; 38 import org.jboss.ejb3.stateless.StatelessContainer; 39 import org.jboss.logging.Logger; 40 41 import java.util.ArrayList ; 42 import java.util.Hashtable ; 43 import java.util.List ; 44 45 50 public class Ejb3AnnotationHandler implements Ejb3Handler 51 { 52 private static final Logger log = Logger.getLogger(Ejb3AnnotationHandler.class); 53 54 protected static enum EJB_TYPE 55 { 56 STATELESS, STATEFUL, MESSAGE_DRIVEN, ENTITY, SERVICE, CONSUMER 57 } 58 59 protected DeploymentUnit di; 60 61 protected ClassFile cf; 62 protected List <String > ejbNames = new ArrayList <String >(); 63 protected Class ejbClass; 64 protected String className; 65 protected EJB_TYPE ejbType; 66 protected Annotation annotation; 67 protected AnnotationsAttribute visible; 68 protected Hashtable ctxProperties; 69 protected String defaultSLSBDomain; 70 protected String defaultSFSBDomain; 71 protected String defaultMDBDomain; 72 protected String defaultServiceDomain; 73 protected String defaultConsumerDomain; 74 protected Ejb3Deployment deployment; 75 76 public Ejb3AnnotationHandler(Ejb3Deployment deployment, ClassFile cf) 77 { 78 this.deployment = deployment; 79 this.di = deployment.getDeploymentUnit(); 80 this.cf = cf; 81 className = cf.getName(); 82 visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag); 83 defaultSLSBDomain = deployment.getDefaultSLSBDomain(); 84 defaultSFSBDomain = deployment.getDefaultSFSBDomain(); 85 defaultMDBDomain = deployment.getDefaultMDBDomain(); 86 defaultServiceDomain = deployment.getDefaultServiceDomain(); 87 defaultConsumerDomain = deployment.getDefaultConsumerDomain(); 88 } 89 90 public void setCtxProperties(Hashtable ctxProperties) 91 { 92 this.ctxProperties = ctxProperties; 93 } 94 95 private String getJaccContextId() 96 { 97 return di.getShortName(); 98 } 99 100 public boolean isEjb() 101 { 102 if (visible == null) return false; 103 104 if (EJB3Util.isStateless(visible)) return true; 105 if (EJB3Util.isMessageDriven(visible)) return true; 106 if (EJB3Util.isStatefulSession(visible)) return true; 107 return false; 108 } 109 110 public boolean isJBossBeanType() 111 { 112 if (visible == null) return false; 113 114 if (EJB3Util.isService(visible)) return true; 115 if (EJB3Util.isConsumer(visible)) return true; 116 return false; 117 } 118 119 public List getContainers(ClassFile cf, Ejb3Deployment deployment) throws Exception 120 { 121 List containers = new ArrayList (); 122 123 populateBaseInfo(); 124 125 for (int ejbIndex = 0; ejbIndex < ejbNames.size(); ++ejbIndex) 126 { 127 String ejbName = ejbNames.get(ejbIndex); 128 if (ejbType == EJB_TYPE.STATELESS) 129 { 130 StatelessContainer container = getStatelessContainer(ejbIndex); 131 container.setJaccContextId(getJaccContextId()); 132 containers.add(container); 133 } 134 else if (ejbType == EJB_TYPE.STATEFUL) 135 { 136 StatefulContainer container = getStatefulContainer(ejbIndex); 137 container.setJaccContextId(getJaccContextId()); 138 containers.add(container); 139 } 140 else if (ejbType == EJB_TYPE.MESSAGE_DRIVEN) 141 { 142 MDB container = getMDB(ejbIndex); 143 container.setJaccContextId(getJaccContextId()); 144 containers.add(container); 145 } 146 else if (ejbType == EJB_TYPE.SERVICE) 147 { 148 ServiceContainer container = getServiceContainer(ejbIndex); 149 container.setJaccContextId(getJaccContextId()); 150 containers.add(container); 151 } 152 else if (ejbType == EJB_TYPE.CONSUMER) 153 { 154 ConsumerContainer container = getConsumerContainer(ejbIndex); 155 container.setJaccContextId(getJaccContextId()); 156 containers.add(container); 157 } 158 log.debug("found EJB3: ejbName=" + ejbName + ", class=" + className + ", type=" + ejbType); 159 } 160 161 return containers; 162 } 163 164 protected String getAspectDomain(int ejbIndex, String defaultDomain) 165 { 166 return EJB3Util.getAspectDomain(visible, defaultDomain); 167 } 168 169 protected ServiceContainer getServiceContainer(int ejbIndex) throws Exception 170 { 171 String containerName = getAspectDomain(ejbIndex, defaultServiceDomain); 172 DomainDefinition domain = AspectManager.instance().getContainer(containerName); 173 174 if (domain == null) 175 throw new RuntimeException ("No container configured with name '" 176 + containerName + "''"); 177 178 return new ServiceContainer(deployment.getMbeanServer(), di.getClassLoader(), cf.getName(), 179 ejbNames.get(ejbIndex), (AspectManager) domain.getManager(), ctxProperties, 180 di.getInterceptorInfoRepository(), deployment); 181 182 } 183 184 protected ConsumerContainer getConsumerContainer(int ejbIndex) throws Exception 185 { 186 String containerName = getAspectDomain(ejbIndex, defaultConsumerDomain); 187 DomainDefinition domain = AspectManager.instance().getContainer(containerName); 188 189 if (domain == null) 190 throw new RuntimeException ("No container configured with name '" 191 + containerName + "''"); 192 193 return new ConsumerContainer(ejbNames.get(ejbIndex), (AspectManager) domain.getManager(), 194 di.getClassLoader(), cf.getName(), ctxProperties, 195 di.getInterceptorInfoRepository(), deployment); 196 197 } 198 199 protected StatefulContainer getStatefulContainer(int ejbIndex) throws Exception 200 { 201 String containerName = getAspectDomain(ejbIndex, defaultSFSBDomain); 202 DomainDefinition domain = AspectManager.instance().getContainer(containerName); 203 204 if (domain == null) 205 throw new RuntimeException ("No container configured with name '" 206 + containerName + "''"); 207 208 return new StatefulContainer(di.getClassLoader(), cf.getName(), 209 ejbNames.get(ejbIndex), (AspectManager) domain.getManager(), ctxProperties, 210 di.getInterceptorInfoRepository(), deployment); 211 212 } 213 214 protected StatelessContainer getStatelessContainer(int ejbIndex) throws Exception 215 { 216 String containerName = getAspectDomain(ejbIndex, defaultSLSBDomain); 217 218 DomainDefinition domain = AspectManager.instance().getContainer(containerName); 219 220 if (domain == null) 221 throw new RuntimeException ("No container configured with name '" 222 + containerName + "''"); 223 224 return new StatelessContainer(di.getClassLoader(), cf.getName(), 225 ejbNames.get(ejbIndex), (AspectManager) domain.getManager(), 226 ctxProperties, di.getInterceptorInfoRepository(), 227 deployment); 228 } 229 230 protected String getMDBDomainName(int ejbIndex) 231 { 232 return defaultMDBDomain; 233 } 234 235 protected void createProxyFactories() 236 { 237 238 } 239 240 protected MDB getMDB(int ejbIndex) throws Exception 241 { 242 return getMDB(ejbIndex, null); 243 } 244 245 protected MDB getMDB(int ejbIndex, EnterpriseBean xml) throws Exception 246 { 247 String domainName = getMDBDomainName(ejbIndex); 248 249 String containerName = getAspectDomain(ejbIndex, domainName); 250 DomainDefinition domain = AspectManager.instance().getContainer(containerName); 251 252 if (domain == null) 253 throw new RuntimeException ("No container configured with name '" 254 + containerName + "''"); 255 256 MDB container = new MDB(ejbNames.get(ejbIndex), (AspectManager) domain.getManager(), di.getClassLoader(), cf.getName(), 257 ctxProperties, di.getInterceptorInfoRepository(), deployment); 258 259 return container; 260 } 261 262 protected void populateBaseInfo() throws Exception 263 { 264 String ejbName = null; 265 ejbClass = di.getClassLoader().loadClass(className); 266 267 visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag); 268 269 if (visible != null) 270 { 271 annotation = visible.getAnnotation(javax.ejb.Stateless .class.getName()); 272 if (annotation != null) 273 { 274 ejbType = EJB_TYPE.STATELESS; 275 } 276 else 277 { 278 annotation = visible.getAnnotation(javax.ejb.Stateful .class.getName()); 279 if (annotation != null) 280 { 281 ejbType = EJB_TYPE.STATEFUL; 282 } 283 else 284 { 285 annotation = visible.getAnnotation(javax.persistence.Entity.class.getName()); 286 if (annotation != null) 287 { 288 ejbType = EJB_TYPE.ENTITY; 289 } 290 else 291 { 292 annotation = visible.getAnnotation(javax.ejb.MessageDriven .class.getName()); 293 if (annotation != null) 294 { 295 ejbType = EJB_TYPE.MESSAGE_DRIVEN; 296 } 297 else 298 { 299 annotation = visible.getAnnotation(org.jboss.annotation.ejb.Service.class.getName()); 300 if (annotation != null) 301 { 302 ejbType = EJB_TYPE.SERVICE; 303 } 304 else 305 { 306 annotation = visible.getAnnotation(org.jboss.annotation.ejb.Consumer.class.getName()); 307 if (annotation != null) 308 { 309 ejbType = EJB_TYPE.CONSUMER; 310 } 311 } 312 } 313 } 314 } 315 } 316 317 if (annotation != null) 318 { 319 StringMemberValue mv = (StringMemberValue) annotation.getMemberValue("name"); 320 if (mv != null) 321 ejbName = mv.getValue(); 322 else 323 ejbName = ejbClass.getSimpleName(); 324 } 325 } 326 327 if (ejbName != null) 328 { 329 ejbNames.add(ejbName); 330 } 331 } 332 } 333 | Popular Tags |