FileDocCategorySizeDatePackage
Ejb3AnnotationHandler.javaAPI DocJBoss 4.2.112798Fri Jul 13 20:53:58 BST 2007org.jboss.ejb3

Ejb3AnnotationHandler

public class Ejb3AnnotationHandler extends Object implements Ejb3Handler
author
William DeCoste
author
Bill Burke
version
$Revision: 61346 $

Fields Summary
private static final Logger
log
protected DeploymentUnit
di
protected ClassFile
cf
protected List
ejbNames
protected Class
ejbClass
protected String
className
protected EJB_TYPE
ejbType
protected Annotation
annotation
protected AnnotationsAttribute
visible
protected Hashtable
ctxProperties
protected String
defaultSLSBDomain
protected String
defaultSFSBDomain
protected String
defaultMDBDomain
protected String
defaultServiceDomain
protected String
defaultConsumerDomain
protected Ejb3Deployment
deployment
Constructors Summary
public Ejb3AnnotationHandler(Ejb3Deployment deployment)

   
     
   
      this.deployment = deployment;
      this.di = deployment.getDeploymentUnit();
      defaultSLSBDomain = deployment.getDefaultSLSBDomain();
      defaultSFSBDomain = deployment.getDefaultSFSBDomain();
      defaultMDBDomain = deployment.getDefaultMDBDomain();
      defaultServiceDomain = deployment.getDefaultServiceDomain();
      defaultConsumerDomain = deployment.getDefaultConsumerDomain();
   
public Ejb3AnnotationHandler(Ejb3Deployment deployment, ClassFile cf)

      this.deployment = deployment;
      this.di = deployment.getDeploymentUnit();
      defaultSLSBDomain = deployment.getDefaultSLSBDomain();
      defaultSFSBDomain = deployment.getDefaultSFSBDomain();
      defaultMDBDomain = deployment.getDefaultMDBDomain();
      defaultServiceDomain = deployment.getDefaultServiceDomain();
      defaultConsumerDomain = deployment.getDefaultConsumerDomain();
      
      this.cf = cf;
      className = cf.getName();
      visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
   
Methods Summary
protected voidcreateProxyFactories()


   
protected java.lang.StringgetAspectDomain(int ejbIndex, java.lang.String defaultDomain)

      return EJB3Util.getAspectDomain(visible, defaultDomain);
   
protected org.jboss.ejb3.mdb.ConsumerContainergetConsumerContainer(int ejbIndex)

      String containerName = getAspectDomain(ejbIndex, defaultConsumerDomain);
      DomainDefinition domain = AspectManager.instance().getContainer(containerName);

      if (domain == null)
         throw new RuntimeException("No container configured with name '"
                 + containerName + "''");

      return new ConsumerContainer(ejbNames.get(ejbIndex), (AspectManager) domain.getManager(),
              di.getClassLoader(), className, ctxProperties,
              di.getInterceptorInfoRepository(), deployment);

   
public java.util.ListgetContainers(Ejb3Deployment deployment)

      List containers = new ArrayList();

      populateBaseInfo();

      for (int ejbIndex = 0; ejbIndex < ejbNames.size(); ++ejbIndex)
      {
         String ejbName = ejbNames.get(ejbIndex);
         if (ejbType == EJB_TYPE.STATELESS)
         {
            EJBContainer container = getStatelessContainer(ejbIndex);
            container.setJaccContextId(getJaccContextId());
            containers.add(container);
         }
         else if (ejbType == EJB_TYPE.STATEFUL)
         {
            StatefulContainer container = getStatefulContainer(ejbIndex);
            container.setJaccContextId(getJaccContextId());
            containers.add(container);
         }
         else if (ejbType == EJB_TYPE.MESSAGE_DRIVEN)
         {
            MDB container = getMDB(ejbIndex);
            validateMDBTransactionAttribute(container);
            container.setJaccContextId(getJaccContextId());
            containers.add(container);
         }
         else if (ejbType == EJB_TYPE.SERVICE)
         {
            ServiceContainer container = getServiceContainer(ejbIndex);
            container.setJaccContextId(getJaccContextId());
            containers.add(container);
         }
         else if (ejbType == EJB_TYPE.CONSUMER)
         {
            ConsumerContainer container = getConsumerContainer(ejbIndex);
            container.setJaccContextId(getJaccContextId());
            containers.add(container);
         }
         log.debug("found EJB3: ejbName=" + ejbName + ", class=" + className + ", type=" + ejbType);
      }

      return containers;
   
protected java.lang.StringgetJaccContextId()

      return di.getShortName();
   
protected org.jboss.ejb3.mdb.MDBgetMDB(int ejbIndex)

      return getMDB(ejbIndex, null);
   
protected org.jboss.ejb3.mdb.MDBgetMDB(int ejbIndex, org.jboss.ejb3.metamodel.EnterpriseBean xml)

      String domainName = getMDBDomainName(ejbIndex);
      
      String containerName = getAspectDomain(ejbIndex, domainName);
      DomainDefinition domain = AspectManager.instance().getContainer(containerName);

      if (domain == null)
         throw new RuntimeException("No container configured with name '"
                 + containerName + "''");

      MDB container = new MDB(ejbNames.get(ejbIndex), (AspectManager) domain.getManager(), di.getClassLoader(), className,
              ctxProperties, di.getInterceptorInfoRepository(), deployment);

      return container;
   
protected java.lang.StringgetMDBDomainName(int ejbIndex)

      return defaultMDBDomain;
   
protected org.jboss.ejb3.service.ServiceContainergetServiceContainer(int ejbIndex)

      String containerName = getAspectDomain(ejbIndex, defaultServiceDomain);
      DomainDefinition domain = AspectManager.instance().getContainer(containerName);

      if (domain == null)
         throw new RuntimeException("No container configured with name '"
                 + containerName + "''");

      return new ServiceContainer(deployment.getMbeanServer(), di.getClassLoader(), className,
              ejbNames.get(ejbIndex), (AspectManager) domain.getManager(), ctxProperties,
              di.getInterceptorInfoRepository(), deployment);

   
protected org.jboss.ejb3.stateful.StatefulContainergetStatefulContainer(int ejbIndex)

      String containerName = getAspectDomain(ejbIndex, defaultSFSBDomain);
      DomainDefinition domain = AspectManager.instance().getContainer(containerName);

      if (domain == null)
         throw new RuntimeException("No container configured with name '"
                 + containerName + "''");

      return new StatefulContainer(di.getClassLoader(), className,
              ejbNames.get(ejbIndex), (AspectManager) domain.getManager(), ctxProperties,
              di.getInterceptorInfoRepository(), deployment);

   
protected EJBContainergetStatelessContainer(int ejbIndex)

      String containerName = getAspectDomain(ejbIndex, defaultSLSBDomain);
      
      DomainDefinition domain = AspectManager.instance().getContainer(containerName);

      if (domain == null)
         throw new RuntimeException("No container configured with name '"
                 + containerName + "''");

      return new StatelessContainer(di.getClassLoader(), className,
              ejbNames.get(ejbIndex), (AspectManager) domain.getManager(),
              ctxProperties, di.getInterceptorInfoRepository(),
              deployment);
   
public booleanisEjb()

      if (visible == null) return false;

      if (EJB3Util.isStateless(visible)) return true;
      if (EJB3Util.isMessageDriven(visible)) return true;
      if (EJB3Util.isStatefulSession(visible)) return true;
      return false;
   
public booleanisJBossBeanType()

      if (visible == null) return false;

      if (EJB3Util.isService(visible)) return true;
      if (EJB3Util.isConsumer(visible)) return true;
      return false;
   
protected voidpopulateBaseInfo()

      String ejbName = null;
      ejbClass = di.getClassLoader().loadClass(className);

      visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);

      if (visible != null)
      {
         annotation = visible.getAnnotation(javax.ejb.Stateless.class.getName());
         if (annotation != null)
         {
            ejbType = EJB_TYPE.STATELESS;
         }
         else
         {
            annotation = visible.getAnnotation(javax.ejb.Stateful.class.getName());
            if (annotation != null)
            {
               ejbType = EJB_TYPE.STATEFUL;
            }
            else
            {
               annotation = visible.getAnnotation(javax.persistence.Entity.class.getName());
               if (annotation != null)
               {
                  ejbType = EJB_TYPE.ENTITY;
               }
               else
               {
                  annotation = visible.getAnnotation(javax.ejb.MessageDriven.class.getName());
                  if (annotation != null)
                  {
                     ejbType = EJB_TYPE.MESSAGE_DRIVEN;
                  }
                  else
                  {
                     annotation = visible.getAnnotation(org.jboss.annotation.ejb.Service.class.getName());
                     if (annotation != null)
                     {
                        ejbType = EJB_TYPE.SERVICE;
                     }
                     else
                     {
                        annotation = visible.getAnnotation(org.jboss.annotation.ejb.Consumer.class.getName());
                        if (annotation != null)
                        {
                           ejbType = EJB_TYPE.CONSUMER;
                        }
                     }
                  }
               }
            }
         }

         if (annotation != null)
         {
            StringMemberValue mv = (StringMemberValue) annotation.getMemberValue("name");
            if (mv != null)
               ejbName = mv.getValue();
            else
               ejbName = ejbClass.getSimpleName();
         }
      }

      if (ejbName != null)
      {
         ejbNames.add(ejbName);
      }
   
public voidsetCtxProperties(java.util.Hashtable ctxProperties)

      this.ctxProperties = ctxProperties;
   
protected voidvalidateMDBTransactionAttribute(org.jboss.ejb3.mdb.MDB mdb)

      TransactionAttribute tx = (TransactionAttribute)mdb.resolveAnnotation(TransactionAttribute.class); 
      if (tx != null)
      {
         TransactionAttributeType type = tx.value();
         if (type != TransactionAttributeType.REQUIRED && type != TransactionAttributeType.NOT_SUPPORTED)
            throw new RuntimeException("MDB " + mdb.getEjbName() + " has an invalid TransactionAttribute: " + type + 
                  ". Only REQUIRED and NOT_SUPPORTED are valid");
      }