/*
 * JBoss, the OpenSource J2EE WebOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.test.cts.service;

import javax.naming.InitialContext;

import org.jboss.system.ServiceMBeanSupport;
import org.jboss.test.cts.interfaces.CtsCmp2Local;
import org.jboss.test.cts.interfaces.CtsCmp2LocalHome;
import org.jboss.test.util.Debug;

/** Version 1 of the MBean service that uses the version 1 of the
 * CtsCmp2Local EJB interface.
 *
 * @author Scott.Stark@jboss.org
 * @version $Revision: 1.1.4.2 $
 */
public class CtsCmpService extends ServiceMBeanSupport
   implements CtsCmpServiceMBean
{
   private CtsCmp2LocalHome home;
   private String homeJndiName = "v1/local/CtsCmp2Bean";

   public CtsCmpService()
   {
      log.info("CtsCmpService V1 ctor");
   }

   public void setHomeJndiName(String jndiName)
   {
      this.homeJndiName = jndiName;
   }

   protected void startService() throws Exception
   {
      InitialContext ctx = new InitialContext();
      Object obj = new InitialContext().lookup(homeJndiName);
      Class homeClass = obj.getClass();
      StringBuffer results = new StringBuffer();
      results.append("CtsCmpService V1 class info:\n");
      Debug.displayClassInfo(getClass(), results);
      results.append("CtsCmp2LocalHome Proxy class info:\n");
      Debug.displayClassInfo(homeClass, results);
      results.append("\nLocal CtsCmp2LocalHome.class info:\n");
      Debug.displayClassInfo(CtsCmp2LocalHome.class, results);
      log.info(results.toString());
      home = (CtsCmp2LocalHome) obj;

      CtsCmp2Local bean = home.create("V1key", "V1data");
      log.info("CtsCmp2Local.key = "+bean.getKey());
      log.info("CtsCmp2Local.data = "+bean.getData());
   }
}
