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.deployment.web;8 9 import javax.naming.Context ;10 11 import org.jfox.ioc.Registry;12 import org.jfox.ioc.exception.ComponentException;13 import org.jfox.jndi.enc.AbstractEnterpriseContextContainer;14 import org.jfox.jndi.enc.EnterpriseContext;15 import org.jfox.jndi.enc.EnterpriseContextInvocationHandler;16 17 /**18 * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>19 */20 21 public class WebEnterpriseContextContainer extends AbstractEnterpriseContextContainer {22 private static WebEnterpriseContextContainer instance = new WebEnterpriseContextContainer();23 24 private WebDeployer webDeployer = null;25 26 public WebEnterpriseContextContainer() {27 try {28 webDeployer = (WebDeployer)(Registry.getInstance().getComponentInstance(WebDeployer.class));29 }30 catch(ComponentException e) {31 e.printStackTrace();32 throw new RuntimeException ("Web container instance error");33 }34 }35 36 public static WebEnterpriseContextContainer getInstance() {37 return instance;38 }39 40 41 public Context getCurrentEnterpriseContext() {42 String webContext = (String ) currName.get();43 if(webContext == null) {44 return new EnterpriseContext();45 }46 return ((NestedWebModule) webDeployer.getWebModule(webContext)).getEnterpriseContext();47 }48 49 public EnterpriseContextInvocationHandler getEnterpriseContextInvocationHandler() {50 return new EnterpriseContextInvocationHandler(getCurrentEnterpriseContext());51 }52 53 public static void main(String [] args) {54 55 }56 }57