FileDocCategorySizeDatePackage
DeploymentEjbResolver.javaAPI DocJBoss 4.2.16980Fri Jul 13 20:53:50 BST 2007org.jboss.ejb3.enc

DeploymentEjbResolver

public abstract class DeploymentEjbResolver extends Object
Class to resolve EJB containers from ejb-ref or @EJB metadata This class is overriden for specific behaviors, specifically whether or not to resolve the EJB internally in a specific deployment or not. There will be one for an EJB jar deployment and a WAR deployment and any other deployment package that needs to use @EJB.
author
Bill Burke
version
$Revision: 62501 $

Fields Summary
private static final Logger
log
protected org.jboss.ejb3.DeploymentScope
deploymentScope
protected String
errorName
Constructors Summary
protected DeploymentEjbResolver(org.jboss.ejb3.DeploymentScope deploymentScope, String errorName)


       
   
      this.deploymentScope = deploymentScope;
      this.errorName = errorName;
   
Methods Summary
public org.jboss.ejb3.EJBContainergetEjbContainer(java.lang.String ejbLink, java.lang.Class businessIntf)

      int hashIndex = ejbLink.indexOf('#");
      if (hashIndex != -1)
      {
         if (deploymentScope == null)
         {
            log.warn("ejb link '" + ejbLink + "' is relative, but no deployment scope found");
            return null;
         }
         String relativePath = ejbLink.substring(0, hashIndex);
         Ejb3Deployment dep = deploymentScope.findRelativeDeployment(relativePath);
         if (dep == null)
         {
            log.warn("can't find a deployment for path '" + relativePath + "' of ejb link '" + ejbLink + "'");
            return null;
         }
         String ejbName = ejbLink.substring(hashIndex + 1);
         return dep.getEjbContainer(ejbName, businessIntf);
      }
      // look internally
      EJBContainer ejb = searchDeploymentInternally(ejbLink, businessIntf);
      if (ejb != null) return ejb;
      for (Object obj : Ejb3Registry.getContainers())
      {
         EJBContainer container = (EJBContainer) obj;
         if (container.getEjbName().equals(ejbLink))
         {
            return container;
         }
      }
      return null;
   
public org.jboss.ejb3.EJBContainergetEjbContainer(org.jboss.ejb3.Ejb3Deployment deployment, java.lang.Class businessIntf)

      EJBContainer container = null;
      // search in myself
      for (Object obj : deployment.getEjbContainers().values())
      {
         EJBContainer newContainer = (EJBContainer) obj;
         if (container == newContainer) continue;
         if (ProxyFactoryHelper.publishesInterface(newContainer, businessIntf))
         {
            if (container != null) throw new NameNotFoundException("duplicated in " + errorName);
            container = newContainer;
         }
      }
      return container;
   
public org.jboss.ejb3.EJBContainergetEjbContainer(java.lang.Class businessIntf)

      EJBContainer rtnContainer = null;
      // search in deployment first
      rtnContainer = searchForEjbContainerInternally(businessIntf);
      if (rtnContainer != null) return rtnContainer;
      // search in EAR
      String jarName = null;
      if (deploymentScope != null)
      {
         for (Ejb3Deployment deployment : deploymentScope.getEjbDeployments())
         {
            EJBContainer newContainer = getEjbContainer(deployment, businessIntf);
            if (rtnContainer == newContainer) continue; // don't check self
            if (rtnContainer != null && newContainer != null)
            {
               throw new NameNotFoundException("duplicated in .ear within " + jarName +
                       " and " + deployment.getDeploymentUnit().getShortName());
            }
            if (newContainer != null)
            {
               rtnContainer = newContainer;
               jarName = deployment.getDeploymentUnit().getShortName();
            }
         }
      }
      if (rtnContainer != null)
      {
         return rtnContainer;
      }
      // search everywhere
      Iterator containers = Ejb3Registry.getContainers().iterator();
      while (containers.hasNext())
      {
         Container container = (Container)containers.next();
         EJBContainer ejbContainer = (EJBContainer) container;
         if (ejbContainer == rtnContainer) continue;
         if (ProxyFactoryHelper.publishesInterface(container, businessIntf))
         {
            if (rtnContainer != null)
            {
               throw new NameNotFoundException("duplicated in " + ejbContainer.getDeployment().getDeploymentUnit().getShortName()
                       + " and " + jarName);
            }
            rtnContainer = ejbContainer;
            jarName = ejbContainer.getDeployment().getDeploymentUnit().getShortName();
         }
      }
      if (rtnContainer != null) return rtnContainer;
      throw new NameNotFoundException("not used by any EJBs");
   
public java.lang.StringgetEjbJndiName(java.lang.String ejbLink, java.lang.Class businessIntf)

      EJBContainer container = getEjbContainer(ejbLink, businessIntf);
      if (container == null)
      {
         return null;
      }
      return ProxyFactoryHelper.getJndiName(container, businessIntf);
   
public java.lang.StringgetEjbJndiName(java.lang.Class businessIntf)

      EJBContainer container = getEjbContainer(businessIntf);
      String jndiName = ProxyFactoryHelper.getJndiName(container, businessIntf);
      if (jndiName == null) throw new NameNotFoundException("not used by any EJBs");
      return jndiName;
   
protected abstract org.jboss.ejb3.EJBContainersearchDeploymentInternally(java.lang.String ejbLink, java.lang.Class businessIntf)

protected abstract org.jboss.ejb3.EJBContainersearchForEjbContainerInternally(java.lang.Class businessIntf)