1 22 package org.jboss.ejb3.enc; 23 24 import org.jboss.ejb3.EJBContainer; 25 import org.jboss.ejb3.Ejb3Deployment; 26 import org.jboss.ejb3.Ejb3Registry; 27 import org.jboss.ejb3.ProxyFactoryHelper; 28 import org.jboss.ejb3.Container; 29 import org.jboss.ejb3.DeploymentScope; 30 31 import javax.naming.NameNotFoundException ; 32 import java.util.Iterator ; 33 34 44 public abstract class DeploymentEjbResolver 45 { 46 protected DeploymentScope deploymentScope; 47 protected String errorName; 48 49 protected DeploymentEjbResolver(DeploymentScope deploymentScope, String errorName) 50 { 51 this.deploymentScope = deploymentScope; 52 this.errorName = errorName; 53 } 54 55 protected abstract EJBContainer searchDeploymentInternally(String ejbLink, Class businessIntf); 56 57 public EJBContainer getEjbContainer(String ejbLink, Class businessIntf) 58 { 59 int hashIndex = ejbLink.indexOf('#'); 60 if (hashIndex != -1) 61 { 62 if (deploymentScope == null) return null; 63 String relativePath = ejbLink.substring(0, hashIndex); 64 Ejb3Deployment dep = deploymentScope.findRelativeDeployment(relativePath); 65 if (dep == null) return null; 66 String ejbName = ejbLink.substring(hashIndex); 67 return dep.getEjbContainer(ejbName, businessIntf); 68 } 69 EJBContainer ejb = searchDeploymentInternally(ejbLink, businessIntf); 71 if (ejb != null) return ejb; 72 for (Object obj : Ejb3Registry.getContainers()) 73 { 74 EJBContainer container = (EJBContainer) obj; 75 if (container.getEjbName().equals(ejbLink)) 76 { 77 return container; 78 } 79 } 80 return null; 81 } 82 83 public String getEjbJndiName(String ejbLink, Class businessIntf) 84 { 85 EJBContainer container = getEjbContainer(ejbLink, businessIntf); 86 if (container == null) 87 { 88 return null; 89 } 90 return ProxyFactoryHelper.getJndiName(container, businessIntf); 91 } 92 93 public EJBContainer getEjbContainer(Ejb3Deployment deployment, Class businessIntf) throws NameNotFoundException ![JavaDoc](../../../../../cmn/javadoc.gif) 94 { 95 EJBContainer container = null; 96 for (Object obj : deployment.getEjbContainers().values()) 98 { 99 EJBContainer newContainer = (EJBContainer) obj; 100 if (container == newContainer) continue; 101 if (ProxyFactoryHelper.publishesInterface(newContainer, businessIntf)) 102 { 103 if (container != null) throw new NameNotFoundException ("duplicated in " + errorName); 104 container = newContainer; 105 } 106 } 107 return container; 108 } 109 110 public EJBContainer getEjbContainer(Class businessIntf) throws NameNotFoundException ![JavaDoc](../../../../../cmn/javadoc.gif) 111 { 112 EJBContainer rtnContainer = null; 113 rtnContainer = searchForEjbContainerInternally(businessIntf); 115 if (rtnContainer != null) return rtnContainer; 116 String jarName = null; 118 if (deploymentScope != null) 119 { 120 for (Ejb3Deployment deployment : deploymentScope.getEjbDeployments()) 121 { 122 EJBContainer newContainer = getEjbContainer(deployment, businessIntf); 123 if (rtnContainer == newContainer) continue; if (rtnContainer != null && newContainer != null) 125 { 126 throw new NameNotFoundException ("duplicated in .ear within " + jarName + 127 " and " + deployment.getDeploymentUnit().getShortName()); 128 } 129 if (newContainer != null) 130 { 131 rtnContainer = newContainer; 132 jarName = deployment.getDeploymentUnit().getShortName(); 133 } 134 } 135 } 136 if (rtnContainer != null) 137 { 138 return rtnContainer; 139 } 140 Iterator containers = Ejb3Registry.getContainers().iterator(); 142 while (containers.hasNext()) 143 { 144 Container container = (Container)containers.next(); 145 EJBContainer ejbContainer = (EJBContainer) container; 146 if (ejbContainer == rtnContainer) continue; 147 if (ProxyFactoryHelper.publishesInterface(container, businessIntf)) 148 { 149 if (rtnContainer != null) 150 { 151 throw new NameNotFoundException ("duplicated in " + ejbContainer.getDeployment().getDeploymentUnit().getShortName() 152 + " and " + jarName); 153 } 154 rtnContainer = ejbContainer; 155 jarName = ejbContainer.getDeployment().getDeploymentUnit().getShortName(); 156 } 157 } 158 if (rtnContainer != null) return rtnContainer; 159 throw new NameNotFoundException ("not used by any EJBs"); 160 } 161 162 protected abstract EJBContainer searchForEjbContainerInternally(Class businessIntf) throws NameNotFoundException ; 163 164 public String getEjbJndiName(Class businessIntf) throws NameNotFoundException ![JavaDoc](../../../../../cmn/javadoc.gif) 165 { 166 EJBContainer container = getEjbContainer(businessIntf); 167 String jndiName = ProxyFactoryHelper.getJndiName(container, businessIntf); 168 if (jndiName == null) throw new NameNotFoundException ("not used by any EJBs"); 169 return jndiName; 170 } 171 } 172 | Popular Tags |