/** * 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 * * 4/22 Updated to test add, update and remove methods */ 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+"/NewRemotePIM"); // 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 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")); // try them all System.out.println("=======ALL======"); PIMCollection all = r.getAll(); printCollection(all); System.out.println("=====Removing first item========"); Iterator i = all.iterator(); PIMEntity first = (PIMEntity) i.next(); r.remove(first); all = r.getAll(); printCollection(all); System.out.println("=====Adding item back========"); r.add(first); all = r.getAll(); printCollection(all); System.out.println("=====Changing priority of first item========"); // id has changed (it's really a new item), we need to get the entire list all = r.getAll(); i = all.iterator(); first = (PIMEntity) i.next(); first.setPriority("CHANGED PRIORITY"); r.update(first); all = r.getAll(); printCollection(all); } catch (Exception e) { e.printStackTrace(); } } /** * prints out all records in a Collection */ public static void printCollection(Collection p) { ArrayList a = new ArrayList(p); Collections.sort((List)a,new PIMComparator()); for (int i=0;i x2) return(1); else if (x1 < x2 ) return(-1); else return(0); } }