refactoring org to uk - never use f**ng eclipse
[vamsas.git] / src / org / vamsas / test / ExampleApplication.java
index e8bce3c..b6597be 100644 (file)
@@ -6,7 +6,7 @@
  */
 package org.vamsas.test;
 
-import org.vamsas.client.*;
+import uk.ac.vamsas.client.*;
 
 import java.awt.Event;
 import java.beans.PropertyChangeEvent;
@@ -21,7 +21,7 @@ import java.util.Vector;
 
 public class ExampleApplication {
   private static ClientHandle app;
-  private static UserHandle user;
+  private static UserHandle user; // TODO: make this something defined by the api
   private static IClientFactory clientfactory;
   private static IClient vorbaclient;
   private static byte[] mydata;
@@ -99,13 +99,13 @@ public class ExampleApplication {
     return true; // incorrect arguments.
   }
   public static void main(String[] args) {
-    if ((args.length<=2) || parseArgs(args)) {
+    if ((args.length<=2) || !parseArgs(args)) {
       System.err.print(Usage);
     }
 
     // get IClientFactory
     try {
-      clientfactory = new org.vamsas.client.SimpleClientFactory(args[0]);
+      clientfactory = new uk.ac.vamsas.client.simpleclient.SimpleClientFactory(args[0]);
     } catch (IOException e) {
       System.err.println(e+"\n"+Usage);
       System.exit(1);
@@ -114,7 +114,15 @@ public class ExampleApplication {
     // get an Iclient with session data
     app = new ClientHandle("org.vamsas.test.ExampleApplication","0.1");
     user = new UserHandle("arnolduser","deathsdoor");
-    vorbaclient = clientfactory.getIClient(app, user);
+    try {
+      vorbaclient = clientfactory.getIClient(app, user);
+    } catch (NoDefaultSessionException e) {
+      System.err.println("There appear to be several sessions to choose from :");
+      String[] sessions = clientfactory.getCurrentSessions();
+      for (int s=0;s<sessions.length; s++)
+        System.err.println(sessions[s]);
+      System.exit(2);
+    }
     addHandlers(vorbaclient);
     try {
       vorbaclient.joinSession();
@@ -126,7 +134,14 @@ public class ExampleApplication {
     }
     // register an update listener and a close listener.
     // get document data
-    processVamsasDocument(vorbaclient.getClientDocument());
+    try {
+      IClientDocument cdoc = vorbaclient.getClientDocument();
+      processVamsasDocument(cdoc);
+    } catch (Exception e) {
+      System.err.println("Unexpected exception when retrieving the client document for the first time!");
+      e.printStackTrace(System.err);
+      System.exit(1);
+    }
 
     // Main application event loop - wait around and do stuff...
     while (!isShuttingdown) {