basic example application skeleton and SimpleClientFactory .
authorjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 16 Sep 2005 15:26:43 +0000 (15:26 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 16 Sep 2005 15:26:43 +0000 (15:26 +0000)
git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@12 be28352e-c001-0410-b1a7-c7978e42abec

src/org/vamsas/client/Client.java [new file with mode: 0644]
src/org/vamsas/client/ClientHandle.java
src/org/vamsas/client/IClientDocument.java
src/org/vamsas/client/IClientFactory.java [new file with mode: 0644]
src/org/vamsas/client/SimpleClientFactory.java [new file with mode: 0644]
src/org/vamsas/client/UserHandle.java
src/org/vamsas/test/ExampleApplication.java

diff --git a/src/org/vamsas/client/Client.java b/src/org/vamsas/client/Client.java
new file mode 100644 (file)
index 0000000..78cafd7
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Created on 15-Sep-2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.vamsas.client;
+
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.util.EventListener;
+
+/**
+ * @author jimp
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class Client implements IClient {
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClient#getAbout()
+   */
+  public String getAbout() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClient#getSessionUrn()
+   */
+  public String getSessionUrn() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClient#getSessionHandle()
+   */
+  public SessionHandle getSessionHandle() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClient#getClientHandle()
+   */
+  public ClientHandle getClientHandle() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClient#getUserHandle()
+   */
+  public UserHandle getUserHandle() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClient#finalizeClient()
+   */
+  public void finalizeClient() {
+    // TODO Auto-generated method stub
+
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClient#addDocumentUpdateHandler(java.util.EventListener)
+   */
+  public void addDocumentUpdateHandler(EventListener evt) {
+    // TODO Auto-generated method stub
+
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClient#getClientDocument()
+   */
+  public IClientDocument getClientDocument() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClient#updateDocument(org.vamsas.client.IClientDocument)
+   */
+  public void updateDocument(IClientDocument newdoc) {
+    // TODO Auto-generated method stub
+
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClient#storeDocument(java.io.File)
+   */
+  public void storeDocument(File location) {
+    // TODO Auto-generated method stub
+
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClient#addVorbaEventHandler(java.lang.String, java.beans.PropertyChangeListener)
+   */
+  public void addVorbaEventHandler(String EventChain, PropertyChangeListener evt) {
+    // TODO Auto-generated method stub
+
+  }
+
+  public static void main(String[] args) {
+  }
+}
index 0269af4..031469a 100644 (file)
@@ -8,12 +8,25 @@ package org.vamsas.client;
  */
 public class ClientHandle {
   /**
+   * @param clientName
+   * @param version
+   */
+  public ClientHandle(String clientName, String version) {
+    super();
+    this.clientName = clientName;
+    this.version = version;
+  }
+  /**
    * (non-unique) human readable vamsas client name
    */
   String clientName;
 
   /**
    * the unambiguous client identifier
+   * This may be rewritten by the Vorba object if
+   * other clients with the same name, version 
+   * and user are involved in a session.
+   * 
    */
   String clientUrn;
 
@@ -30,6 +43,7 @@ public class ClientHandle {
   }
 
   /**
+   * May become protected - should only be set by a Vorba object.
    * @param clientUrn
    *          The clientUrn to set.
    */
index 26223fb..c0887bc 100644 (file)
@@ -6,7 +6,6 @@
  */
 package org.vamsas.client;
 
-import java.util.Vector;
 
 /**
  * Defines the API for the Vamsas XML Document 
diff --git a/src/org/vamsas/client/IClientFactory.java b/src/org/vamsas/client/IClientFactory.java
new file mode 100644 (file)
index 0000000..5f203ef
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Created on 13-Sep-2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.vamsas.client;
+
+/**
+ * Defines methods for instantiating Vorba client application agents
+ * @author jimp
+ *
+ * (it's VORBA, not CORBA!)
+ */
+
+public interface IClientFactory {
+
+     /**
+      * Create a new Vorba Session
+      * @param applicationHandle is the application's VAMSAS handle string
+      */
+       IClient getIClient(ClientHandle applicationHandle);
+       /**
+        * returns new Vorba for a given session.
+        * @param applicationHandle
+        * @param sessionUrn locates the session that the client should attach to
+        * @return
+        */
+       IClient getIClient(ClientHandle applicationHandle, String sessionUrn);
+       /**
+        * returns new vorba for a  given session acting as a particular identity
+        * @param applicationHandle
+        * @param userId
+        * @param sessionUrn
+        * @return
+        */
+       IClient getIClient(ClientHandle applicationHandle, UserHandle userId, String sessionUrn);
+       /**
+        * New session for application and specific user
+        * @param applicationHandle
+        * @param userId
+        * @return
+        */
+       IClient getIClient(ClientHandle applicationHandle, UserHandle userId);
+       
+
+}
diff --git a/src/org/vamsas/client/SimpleClientFactory.java b/src/org/vamsas/client/SimpleClientFactory.java
new file mode 100644 (file)
index 0000000..5a53bd2
--- /dev/null
@@ -0,0 +1,72 @@
+package org.vamsas.client;
+/**
+ * TODO document type SimpleClientFactory
+ * @author jimp
+ *
+ */
+public class SimpleClientFactory implements IClientFactory {
+  static SimpleClientFactory singleton = null;
+
+  static private void CreateClientFactory() {
+    if (singleton != null) {
+
+    } else {
+      // Create singleton class.
+
+    }
+  }
+  /**
+   * Create a client factory that works with sessions at the given
+   * path.
+   * @param path
+   */
+  public SimpleClientFactory(String path) {
+    // Check path is valid and read/writeable.
+    // make housekeeping files...
+  }
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClientFactory#getIClient(org.vamsas.client.ClientHandle)
+   */
+  public IClient getIClient(ClientHandle applicationHandle) {
+    // create a new session
+    // register new ClientHandle in session
+    // create Client instance
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClientFactory#getIClient(org.vamsas.client.ClientHandle, java.lang.String)
+   */
+  public IClient getIClient(ClientHandle applicationHandle, String sessionUrn) {
+    // locate session from Urn
+    // check that clientHandle is unique (with default user) - if not update the clientHandle urn to make it unique.
+    // wait for lock and attach to session
+    // create Client instance
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClientFactory#getIClient(org.vamsas.client.ClientHandle, org.vamsas.client.UserHandle, java.lang.String)
+   */
+  public IClient getIClient(ClientHandle applicationHandle, UserHandle userId,
+      String sessionUrn) {
+    // locate session from Urn
+    // check Uniqueness of user + ClientHandle in the session. Update clientHandle urn accordingly.
+    // wait for lock, attach to session
+    // create client instance
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see org.vamsas.client.IClientFactory#getIClient(org.vamsas.client.ClientHandle, org.vamsas.client.UserHandle)
+   */
+  public IClient getIClient(ClientHandle applicationHandle, UserHandle userId) {
+    // create new session
+    // register Client and UserHandles in session
+    // create client instance
+    return null;
+  }
+
+  public static void main(String[] args) {
+  }
+}
index 0408ae2..8bfe16c 100644 (file)
@@ -13,6 +13,14 @@ package org.vamsas.client;
  * @author jimp
  */
 public class UserHandle {
+  /**
+   * @param fullName
+   * @param organization
+   */
+  public UserHandle(String fullName, String organization) {
+    this.fullName = fullName;
+    Organization = organization;
+  }
   String fullName;
   String Organization;
   /**
index a0c1ec2..297d48d 100644 (file)
  */
 package org.vamsas.test;
 
+import org.vamsas.client.*;
+
+import java.awt.Event;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Vector;
 /**
- * Toy vamsas client application demonstrating the API.
+ * Toy vamsas command line client application demonstrating the API.
  * 
  * @author jimp
  */
 
 public class ExampleApplication {
-  public static String Usage="ExampleApplication <vamsasSessionURN> <action> [+<arguments>]\n<action> is one of :";
+  private static ClientHandle app;
+  private static UserHandle user;
+  private static IClientFactory clientfactory;
+  private static IClient vorbaclient;
+  private static byte[] mydata;
+  private static Vector vamsasObjects;
+  private static boolean isUpdated = false;
+  private static boolean isShuttingdown = false;
+  private static boolean isFinalizing = false;
+  private static void processVamsasDocument(IClientDocument doc) {
+    // merge vamsasObjects with vamsas objects in document
+    // get this apps 'mydata' if it hasn't got it already.
+    // .. access this application's 'public' mydata' if there is any.
+  }
+  private static void addHandlers(IClient avorbaclient) {
+    // make a non-volatile reference to the client instance.
+    final IClient vorbaclient = avorbaclient;
+    // register update handler
+    vorbaclient.addDocumentUpdateHandler(new PropertyChangeListener() {
+      public void propertyChange(PropertyChangeEvent evt) {
+        System.out.println("Vamsas document update for "+evt.getPropertyName()
+            +": "+evt.getOldValue()+" to "+evt.getNewValue());
+        // merge new data into ours.
+        isUpdated=true; // tell main thread to reflect change...
+      }
+    });
+    // register close handler
+    vorbaclient.addVorbaEventHandler(Events.DOCUMENT_REQUESTTOCLOSE, 
+        new PropertyChangeListener() {
+       public void propertyChange(PropertyChangeEvent evt) {
+         System.out.println("Received request to close vamsas document.");
+         // ask user for a filename to save it to. 
+         // Then pass it to the vorba object...
+         vorbaclient.storeDocument(new java.io.File("UserLocation"));
+       }
+    });
+    
+    // register some more handlers to monitor the session :
+    
+    vorbaclient.addVorbaEventHandler(Events.CLIENT_CREATION, 
+        new PropertyChangeListener() {
+      public void propertyChange(PropertyChangeEvent evt) {
+        System.out.println("New Vamsas client for "+evt.getPropertyName()
+            +": "+evt.getOldValue()+" to "+evt.getNewValue());
+        // tell app add new client to its list of clients.
+      }
+    });
+    vorbaclient.addVorbaEventHandler(Events.CLIENT_FINALIZATION, 
+        new PropertyChangeListener() {
+      public void propertyChange(PropertyChangeEvent evt) {
+        System.out.println("Vamsas client finalizing for "+evt.getPropertyName()
+            +": "+evt.getOldValue()+" to "+evt.getNewValue());
+        // tell app to update its list of clients to communicate with.
+      }
+    });
+    vorbaclient.addVorbaEventHandler(Events.SESSION_SHUTDOWN, 
+        new PropertyChangeListener() {
+      public void propertyChange(PropertyChangeEvent evt) {
+        System.out.println("Session "+evt.getPropertyName()+" is shutting down.");
+        // tell app to finalize its session data before shutdown.
+      }
+    });        
+  }
+  public static String 
+       Usage="ExampleApplication <vamsasFileDirectory> <vamsasSessionURN> <action> [+<arguments>]\n"
+         +"<action> is one of :\n\tsave,update,close,watch";
+  
   private static boolean parseArgs(String args[]) {
     return true; // incorrect arguments.
   }
   public static void main(String[] args) {
-    if ((args.length<=1) || parseArgs(args)) {
+    if ((args.length<=2) || parseArgs(args)) {
       System.err.print(Usage);
     }
+
     // get IClientFactory
+    clientfactory = new org.vamsas.client.SimpleClientFactory(args[0]);
+    
     // 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);
+    addHandlers(vorbaclient);
     // register an update listener and a close listener.
     // get document data
-    // do something with data
-    // , update document, or something.
-    // ..
+    processVamsasDocument(vorbaclient.getClientDocument());
+
+    // Main application event loop - wait around and do stuff...
+    while (!isShuttingdown) {
+      // do something with data
+      // , update document, or something.
+      // ..
+      
+    }
     // call finalizeClient
+    vorbaclient.finalizeClient();
     // { meanwhile, eventHandlers are called to do any saves if need be }
+    // and all registered listeners will be deregistered to avoid deadlock.
+    
     // finish
   }
 }