1 /* JFox, the OpenSource J2EE Application Server2 *3 * Distributable under GNU LGPL license by gun.org4 * more details please visit http://www.huihoo.org/jfox5 */6 7 package org.jfox.ejb.naming;8 9 import javax.naming.Context ;10 11 import org.jfox.ejb.connector.EJBContainerImpl;12 import org.jfox.ioc.ComponentName;13 import org.jfox.ioc.Registry;14 import org.jfox.ioc.connector.Container;15 import org.jfox.jndi.enc.AbstractEnterpriseContextContainer;16 import org.jfox.jndi.enc.EnterpriseContext;17 import org.jfox.jndi.enc.EnterpriseContextInvocationHandler;18 19 /**20 * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>21 */22 23 public class EJBEnterpriseContextContainer extends AbstractEnterpriseContextContainer {24 private static EJBEnterpriseContextContainer intstance = new EJBEnterpriseContextContainer();25 26 private EJBEnterpriseContextContainer() {27 }28 29 public static EJBEnterpriseContextContainer getInstance() {30 return intstance;31 }32 33 public Context getCurrentEnterpriseContext() {34 String ejbName = (String ) currName.get();35 if(ejbName == null) {36 return new EnterpriseContext();37 }38 try {39 return ((EJBContainerImpl) Registry.getInstance().getComponentInstance(ComponentName.parseString(Container.class.getName() + "@EJB"))).getBucket(ejbName).getEnterpriseContext();40 }41 catch(Exception e){42 e.printStackTrace();43 return null;44 }45 }46 47 public EnterpriseContextInvocationHandler getEnterpriseContextInvocationHandler() {48 return new EnterpriseContextInvocationHandler(getCurrentEnterpriseContext());49 }50 51 public static void main(String [] args) {52 53 }54 }55