/**
 * Sample client that tests some methods 
 * of a RemotePIMCollection 
 *
 * needs to be told the hostname of the server on
 * the command line:
 *  java TestClient monte.cs.rpi.edu
 *
 */

import java.util.*;
import java.io.*;
import java.rmi.*;

class TestClient {


  static public void main(String args[]) {

	if (args.length != 1) {
	  System.out.println("Usage: TestClient hostname");
	  System.exit(1);
	} else {
	  System.out.println("Client Starting");
	}
	  // Grab the command line parameters
	  String hostname = args[0];

	  try {
		Object o = Naming.lookup("rmi://"+hostname+"/RemotePIM");

		// need to cast the generic object as something that
		// supports the RemoteMath interface.

		RemotePIMCollection r = (RemotePIMCollection) o;

		System.out.println("Got a connection\n");

		// try them all
		System.out.println("=======ALL======");
		printCollection(r.getAll());

		// try a specific date
		System.out.println("=======DATE 5/10/2003=====");
		// (months start at 0!)
		printCollection( r.getItemsForDate(	new Date(103,4,10)));

		// try all Todos
		System.out.println("=======ALL TODOS=====");
		printCollection( r.getTodos());

		// try all Notes
		System.out.println("=======ALL NOTES=====");
		printCollection( r.getNotes());

		// try all Appointments
		System.out.println("=======ALL APPTS=====");
		printCollection( r.getAppointments());

		// try all Contacts
		System.out.println("=======ALL CONTACTS=====");
		printCollection( r.getContacts());

		// try private items
		System.out.println("=======ALL by Owner DaveH=====");
		printCollection( r.getAllByOwner("DaveH"));

		// try private items
		System.out.println("=======ALL by Owner Mary=====");
		printCollection( r.getAllByOwner("Mary"));


	  } catch (Exception e) {
		e.printStackTrace();
	  }

	}

  /**
   * prints out all records in a Collection
   */
  public static void printCollection(Collection p) {

	ArrayList a = new ArrayList(p);
	for (int i=0;i<a.size();i++) {
	  System.out.println(a.get(i));
	}
  }
}
  

