X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Forg%2Fvamsas%2Ftest%2FExampleApplication.java;h=520f668a38e3980a4256e0cf7fdea5aaf8c703ce;hb=25174cde26bdba19676150341182d8dd75e31f4e;hp=a0c1ec2609751bc3aaccad18fb3dc8286b991dc0;hpb=bdf67676f72c1ec0730e07906ae52391d26bbd85;p=vamsas.git diff --git a/src/org/vamsas/test/ExampleApplication.java b/src/org/vamsas/test/ExampleApplication.java index a0c1ec2..520f668 100644 --- a/src/org/vamsas/test/ExampleApplication.java +++ b/src/org/vamsas/test/ExampleApplication.java @@ -1,4 +1,4 @@ -/* +/** * Created on 14-Sep-2005 * * TODO To change the template for this generated file go to @@ -6,30 +6,140 @@ */ package org.vamsas.test; +import org.vamsas.client.*; + +import java.awt.Event; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.IOException; +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 [+]\n 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. + } + }); + vorbaclient.addVorbaEventHandler(Events.DOCUMENT_FINALIZEAPPDATA, + new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + System.out.println("Application received a DOCUMENT_FINALIZEAPPDATA event."); + // tell app to finalize its session data prior to the storage of the current session as an archive. + } + }); + + } + public static String + Usage="ExampleApplication [+]\n" + +" 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 + try { + clientfactory = new org.vamsas.client.simpleclient.SimpleClientFactory(args[0]); + } catch (IOException e) { + System.err.println(e+"\n"+Usage); + System.exit(1); + } + // 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); + try { + vorbaclient.joinSession(); + } + catch (Exception se) { + se.printStackTrace(); + System.err.println(se+" when joining session.\n"+Usage); + System.exit(1); + } // 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 } }