1 package org.openejb.core.ivm; 2 3 import javax.ejb.EJBHome ; 4 import javax.ejb.EJBMetaData ; 5 import javax.ejb.EJBObject ; 6 import javax.ejb.Handle ; 7 import javax.ejb.HomeHandle ; 8 9 import org.openejb.ProxyInfo; 10 import org.openejb.core.entity.EntityEjbHomeHandler; 11 import org.openejb.core.stateful.StatefulEjbHomeHandler; 12 import org.openejb.core.stateless.StatelessEjbHomeHandler; 13 import org.openejb.util.proxy.ProxyManager; 14 15 60 public class IntraVmServer implements org.openejb.spi.ApplicationServer{ 61 62 63 public EJBMetaData getEJBMetaData(ProxyInfo pi) { 64 org.openejb.DeploymentInfo di = pi.getDeploymentInfo(); 65 IntraVmMetaData metaData = new IntraVmMetaData(di.getHomeInterface(), di.getRemoteInterface(),di.getComponentType()); 66 67 metaData.setEJBHome( getEJBHome(pi) ); 68 return metaData; 69 } 70 71 72 public Handle getHandle(ProxyInfo pi) { 73 return new IntraVmHandle(getEJBObject(pi)); 74 } 75 76 public HomeHandle getHomeHandle(ProxyInfo pi) { 77 return new IntraVmHandle(getEJBHome(pi)); 78 } 79 80 public EJBObject getEJBObject(ProxyInfo pi) { 81 EjbHomeProxyHandler handler = null; 82 return (EJBObject )getEjbHomeHandler(pi).createProxy(pi); 83 } 84 85 86 public EJBHome getEJBHome(ProxyInfo pi) { 87 88 if (pi.getDeploymentInfo() instanceof org.openejb.core.DeploymentInfo) { 89 org.openejb.core.DeploymentInfo coreDeployment = (org.openejb.core.DeploymentInfo) pi.getDeploymentInfo(); 90 return coreDeployment.getEJBHome(); 91 92 } else { 93 try{ 94 Class [] interfaces = new Class []{ pi.getDeploymentInfo().getHomeInterface(), org.openejb.core.ivm.IntraVmProxy.class }; 95 return (javax.ejb.EJBHome )ProxyManager.newProxyInstance( interfaces , getEjbHomeHandler(pi) ); 96 }catch(Exception e){ 97 throw new RuntimeException ("Can't create EJBHome stub" + e.getMessage()); 98 } 99 } 100 } 101 102 private EjbHomeProxyHandler getEjbHomeHandler(ProxyInfo pi){ 103 104 switch (pi.getDeploymentInfo().getComponentType()) { 105 106 case org.openejb.DeploymentInfo.BMP_ENTITY: 107 case org.openejb.DeploymentInfo.CMP_ENTITY: 108 return new EntityEjbHomeHandler(pi.getBeanContainer(),pi.getPrimaryKey(),pi.getDeploymentInfo().getDeploymentID()); 109 110 case org.openejb.DeploymentInfo.STATEFUL: 111 return new StatefulEjbHomeHandler(pi.getBeanContainer(),pi.getPrimaryKey(),pi.getDeploymentInfo().getDeploymentID()); 112 113 case org.openejb.DeploymentInfo.STATELESS: 114 return new StatelessEjbHomeHandler(pi.getBeanContainer(),pi.getPrimaryKey(),pi.getDeploymentInfo().getDeploymentID()); 115 default: 116 throw new RuntimeException ("Unknown EJB type: "+pi.getDeploymentInfo()); 117 } 118 } 119 } 120 | Popular Tags |