package com.collab.examples;


import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.collab.util.TeamForgeConnection;




public class Example1
{
   private static final Logger
      logger = Logger.getLogger(Example1.class.getName());


  /**
   * Example 1 is the prototypical "Hello World" example which connects to a
   * TeamForge server using the TeamForgeConnection utility object.
   * <p>
   * The program expects the following arguments:
   * <p>
   *    teamforge-url: the URL of the TeamForge server
   * <p>
   *    username:        a valid TeamForge user
   * <p>
   *    password:        the password of the TeamForge user
   * <p>
   * @param args command line arguments passed into main().
   * <p>
   * @throws RemoteException any errors logging in or out of TeamForge will
   *                         be thrown from this method
   */
   public static void main(String args[])
		throws RemoteException
	{
      //BasicConfigurator.configure();

      logger.log(Level.INFO, "running Example1");

      String sfUrl;
      String sfUser;
      String sfPass;

      if (args.length != 3)
      {
         logger.log(Level.SEVERE, "Usage: teamforge-url username password");
      }
      else
      {
         sfUrl  = args[0];
         sfUser = args[1];
         sfPass = args[2];

         TeamForgeConnection sfc = new TeamForgeConnection(sfUrl);

         String sessionId = sfc.login(sfUser,sfPass);

         logger.log(Level.INFO, "Hello World! successfully connected to TeamForge");

         sfc.logoff(sessionId);

         logger.log(Level.INFO, "successfully disconnected from TeamForge");
      }

      logger.log(Level.INFO, "exiting Example1");
   }
}
