1 45 package org.openejb.core; 46 47 import java.util.HashMap ; 48 49 import org.openejb.Container; 50 import org.openejb.DeploymentInfo; 51 import org.openejb.core.ivm.naming.IvmContext; 52 import org.openejb.core.ivm.naming.ObjectReference; 53 import org.openejb.core.ivm.naming.Reference; 54 55 public class ContainerSystem implements org.openejb.spi.ContainerSystem{ 56 57 HashMap deployments = new HashMap (); 58 HashMap containers = new HashMap (); 59 IvmContext jndiRootContext = null; 60 61 62 public ContainerSystem( ){ 63 try { 65 jndiRootContext = IvmContext.createRootContext(); 67 jndiRootContext.createSubcontext("java:openejb/ejb"); 69 } 70 catch( javax.naming.NamingException exception) { 71 throw new RuntimeException (); 72 } 73 } 74 75 84 public DeploymentInfo getDeploymentInfo(Object id){ 85 return (DeploymentInfo)deployments.get(id); 86 } 87 88 95 public DeploymentInfo [] deployments( ){ 96 return (DeploymentInfo [])deployments.values().toArray(new DeploymentInfo [deployments.size()]); 97 } 98 99 106 public Container getContainer(Object id){ 107 return (Container)containers.get(id); 108 } 109 110 116 public Container [] containers( ){ 117 return (Container [])containers.values().toArray(new Container [containers.size()]); 118 } 119 120 127 public void addContainer(Object id, Container c){ 128 containers.put(id,c); 129 } 130 131 132 151 public void addDeployment(org.openejb.core.DeploymentInfo deployment){ 152 153 this.deployments.put(deployment.getDeploymentID(),deployment); 155 156 if (deployment.getHomeInterface() != null){ 158 bindProxy(deployment, deployment.getEJBHome(), false); 159 } 160 if (deployment.getLocalHomeInterface() != null){ 161 bindProxy(deployment, deployment.getEJBLocalHome(), true); 162 } 163 } 164 165 private void bindProxy(org.openejb.core.DeploymentInfo deployment, Object proxy, boolean isLocal) { 166 Reference ref = new ObjectReference( proxy ); 167 168 if(deployment.getComponentType()== DeploymentInfo.STATEFUL){ 169 ref = new org.openejb.core.stateful.EncReference( ref ); 170 } else if(deployment.getComponentType()== DeploymentInfo.STATELESS){ 171 ref = new org.openejb.core.stateless.EncReference( ref ); 172 } else{ 173 ref = new org.openejb.core.entity.EncReference( ref ); 174 } 175 176 try{ 177 178 String bindName = deployment.getDeploymentID().toString(); 179 180 if(bindName.charAt(0)== '/') { 181 bindName = bindName.substring(1); 182 } 183 184 bindName = "openejb/ejb/"+bindName; 185 if (isLocal){ 186 bindName += "Local"; 187 } 188 jndiRootContext.bind(bindName, ref); 189 190 }catch(Exception e){ e.printStackTrace();throw new RuntimeException ();} 191 } 192 193 203 public javax.naming.Context getJNDIContext(){ 204 return jndiRootContext; 205 } 206 } 207 | Popular Tags |