/* JFox, the OpenSource J2EE Application Server
 *
 * Copyright (C) 2002 huihoo.com
 * Distributable under GNU LGPL license
 * See the GNU Lesser General Public License for more details.
 */

package org.jfox.ejb;

import org.jfox.ejb.meta.EJBDescriptor;

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

public class BulkFactory {

  private static BulkFactory instance = new BulkFactory();

  private BulkFactory() {

  }

  public static BulkFactory getInstance(){
    return instance;
  }

  public Bulk createBulk(BulkMetaData meta) {
    EJBDescriptor mi = meta.getEJBDescriptor();
    // 如果 EJBMetaInfo 没有设置默认的协议,使用 Container 的默认协议
    if(mi.getRemoteProtocol() == null || mi.getRemoteProtocol().equals("")){
      mi.setRemoteProtocol(ContainerImpl.getInstance().getRemoteProtocol());
    }
    if(mi.getLocalProtocol() == null || mi.getLocalProtocol().equals("")){
      mi.setLocalProtocol(ContainerImpl.getInstance().getLocalProtocol());
    }

    if(meta.getEJBMetaData().isSession()) {
      if(meta.getEJBMetaData().isStatelessSession()) {
        return new StatelessSessionBulk(meta);
      }
      else {
        return new StatefulSessionBulk(meta);
      }

    }
    else {
      throw new RuntimeException("not support EntityBean now!");
    }
  }

  public static void main(String[] args) {

  }
}