uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

HRClient.java (1855B)


      1 import java.rmi.Naming;
      2 import java.rmi.RemoteException;
      3 import java.rmi.NotBoundException;
      4 import java.util.Scanner;
      5 
      6 public class HRClient {
      7 	public static void usage() {
      8 		System.err.println("usage: java HRClient list <hostname>");
      9 		System.err.println("       java HRClient book <type> <number> <name> <hostname>");
     10 		System.err.println("       java HRClient guests <hostname>");
     11 		System.err.println("       java HRClient cancel <type> <number> <name> <hostname>");
     12 		System.exit(1);
     13 	}
     14 
     15 	public static void main(String[] args) {
     16 		Scanner sc = new Scanner(System.in);
     17 		String str = "";
     18 
     19 		try {
     20 			if (args.length != 2 && args.length != 5)
     21 				usage();
     22 			String host = args[args.length-1];
     23 			HRInterface stub = (HRInterface)Naming.lookup(host);
     24 
     25 			if (args[0].equals("list") && args.length == 2)
     26 				str = stub.list();
     27 			else if (args[0].equals("book") && args.length == 5) {
     28 				str = stub.book(args[1], Integer.parseInt(args[2]), args[3]);
     29 				if (str.equals("fail: no rooms available")) {
     30 					System.out.println("the room is currently unavailable");
     31 					System.out.print("do you want to be notified (y/n)? ");
     32 					if (sc.next().equals("y")) {
     33 						stub.addListSub(args[3], args[1]);
     34 						System.out.println("thank you");
     35 						return;
     36 					}
     37 				}
     38 			} else if (args[0].equals("guests") && args.length == 2)
     39 				str = stub.guests();
     40 			else if (args[0].equals("cancel") && args.length == 5)
     41 				str = stub.cancel(args[1], Integer.parseInt(args[2]), args[3]);
     42 			else
     43 				usage();
     44 		} catch (RemoteException e) {
     45 			System.err.println("RemoteException: " + e.toString());
     46 		} catch (NotBoundException e) {
     47 			System.err.println("NotBoundException: " + e.toString());
     48 		} catch (IndexOutOfBoundsException e) {
     49 			usage();
     50 		} catch (Exception e) {
     51 			System.err.println("Exception: " + e.toString());
     52 		}
     53 
     54 		System.out.println(str);
     55 	}
     56 }