/* JFox, the OpenSource J2EE Application Server
 *
 * Distributable under GNU LGPL license by gun.org
 * more details please visit http://www.huihoo.org/jfox
 */

package org.jfox.ejb.naming;

import javax.naming.Context;

import org.jfox.ejb.ContainerImpl;
import org.jfox.jndi.enc.AbstractEnterpriseContextContainer;
import org.jfox.jndi.enc.EnterpriseContext;
import org.jfox.jndi.enc.EnterpriseContextInvocationHandler;

/**
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class EJBEnterpriseContextContainer extends AbstractEnterpriseContextContainer {
    private static EJBEnterpriseContextContainer intstance = new EJBEnterpriseContextContainer();

    private EJBEnterpriseContextContainer() {
    }

    public static EJBEnterpriseContextContainer getInstance() {
        return intstance;
    }

    public Context getCurrentEnterpriseContext() {
        String ejbName = (String) currName.get();
        if(ejbName == null) {
            return new EnterpriseContext();
        }
        return ContainerImpl.getInstance().getBucket(ejbName).getEnterpriseContext();
    }

    public EnterpriseContextInvocationHandler getEnterpriseContextInvocationHandler() {
        return new EnterpriseContextInvocationHandler(getCurrentEnterpriseContext());
    }

    public static void main(String[] args) {

    }
}
