/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.ejb3;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
import org.jboss.logging.Logger;

/**
 * Responsible for creating an EJB proxy
 *
 * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
 */
public class JndiProxyFactory implements ObjectFactory
{
   private static final Logger log = Logger.getLogger(JndiProxyFactory.class);

   public static final String FACTORY = "FACTORY";

   public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception
   {
      Reference ref = (Reference) obj;
      String factoryName = (String) ref.get(FACTORY).getContent();
      ProxyFactory factory = (ProxyFactory) nameCtx.lookup(factoryName);
      return factory.createProxy();
   }
}
