/* 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;

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

public class BucketFactory {

    private static BucketFactory instance = new BucketFactory();

    private BucketFactory() {

    }

    public static BucketFactory getInstance() {
        return instance;
    }

    public Bucket createBucket(BucketMetaData meta) {

/*
    在 EJBDeployer 的时候，肯定会设置好 protocol 的值
    EJBDescriptor ejbDescriptor = meta.getEJBDescriptor();
    // 如果 EJBMetaInfo 没有设置默认的协议，使用 Container 的默认协议
    if(ejbDescriptor.getRemoteProtocol() == null || ejbDescriptor.getRemoteProtocol().equals("")){
      ejbDescriptor.setRemoteProtocol(ContainerImpl.getInstance().getRemoteProtocol());
    }
    if(ejbDescriptor.getLocalProtocol() == null || ejbDescriptor.getLocalProtocol().equals("")){
      ejbDescriptor.setLocalProtocol(ContainerImpl.getInstance().getLocalProtocol());
    }
*/

        if(meta.getEJBMetaData().isSession()) {
            if(meta.getEJBMetaData().isStatelessSession()) {
                return new StatelessSessionBucket(meta);
            }
            else {
                return new StatefulSessionBucket(meta);
            }
        }
        else {
            throw new RuntimeException("not support EntityBean now!");
        }
    }

    public static void main(String[] args) {

    }
}