From 7b90e0715c058aa5a5b07ed6bfc0b4521d089281 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 12 Jan 2007 15:46:10 +0000 Subject: [PATCH] extended to test against SimpleClient implementation git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@339 be28352e-c001-0410-b1a7-c7978e42abec --- src/uk/ac/vamsas/test/ExampleApplication.java | 59 ++++++++++++++++++++----- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/src/uk/ac/vamsas/test/ExampleApplication.java b/src/uk/ac/vamsas/test/ExampleApplication.java index 186e51e..684bdf3 100644 --- a/src/uk/ac/vamsas/test/ExampleApplication.java +++ b/src/uk/ac/vamsas/test/ExampleApplication.java @@ -7,6 +7,8 @@ package uk.ac.vamsas.test; import uk.ac.vamsas.client.*; +import uk.ac.vamsas.objects.core.VAMSAS; +import uk.ac.vamsas.test.objects.Core; import java.awt.Event; import java.beans.PropertyChangeEvent; @@ -15,7 +17,9 @@ import java.io.IOException; import java.util.Vector; /** * Toy vamsas command line client application demonstrating the API. - * + * TODO: test appData get/set methods + * TODO: verify and test pickManager and interaction between it and other session events + * TODO: add more session interaction events (currently: modifies document on start up, then modifies every 2 updates before finalizing after 5 updates. * @author jimp */ @@ -30,6 +34,8 @@ public class ExampleApplication { private static boolean isShuttingdown = false; private static boolean isFinalizing = false; private static void processVamsasDocument(IClientDocument doc) { + doc.addVamsasRoot(Core.getDemoVamsas()); + vorbaclient.updateDocument(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. @@ -43,6 +49,15 @@ public class ExampleApplication { System.out.println("Vamsas document update for "+evt.getPropertyName() +": "+evt.getOldValue()+" to "+evt.getNewValue()); // merge new data into ours. + // example - output doc + try { + IClientDocument cdoc = vorbaclient.getClientDocument(); + uk.ac.vamsas.test.simpleclient.ArchiveReports.rootReport(cdoc.getVamsasRoots(), true, System.out); + vorbaclient.updateDocument(cdoc); + } catch (Exception e) { + System.err.println("Exception whilst dumping document tree after an update."); + e.printStackTrace(System.err); + } isUpdated=true; // tell main thread to reflect change... } }); @@ -92,20 +107,26 @@ public class ExampleApplication { } public static String - Usage="ExampleApplication [+]\n" + Usage="ExampleApplication [session urn] watch/n( future usage is :/n [+]\n" +" is one of :\n\tsave,update,close,watch"; - + static String sess=null; private static boolean parseArgs(String args[]) { - return true; // incorrect arguments. + if (args.length==0) { + return false; + } + if (!args[0].toLowerCase().equals("watch")) { + sess=args[0]; + } + return true; } public static void main(String[] args) { - if ((args.length<=2) || !parseArgs(args)) { + + if (!parseArgs(args)) { System.err.print(Usage); } - // get IClientFactory try { - clientfactory = new uk.ac.vamsas.client.simpleclient.SimpleClientFactory(args[0]); + clientfactory = new uk.ac.vamsas.client.simpleclient.SimpleClientFactory(); } catch (IOException e) { System.err.println(e+"\n"+Usage); System.exit(1); @@ -142,15 +163,31 @@ public class ExampleApplication { e.printStackTrace(System.err); System.exit(1); } - + int update=0; // Main application event loop - wait around and do stuff... - while (!isShuttingdown) { + while (!isShuttingdown && update<5) { // do something with data // , update document, or something. // .. - + if (isUpdated) { + System.out.println("Update handler called "+(++update)+" times"); + System.out.println("******************************************"); + isUpdated=false; // TODO: saner update det method. + if (update % 2==1) { + try { + IClientDocument cdoc = vorbaclient.getClientDocument(); + processVamsasDocument(cdoc); + } + catch (Exception e) { + System.err.println("Error when updating document after an even numbered update."); + e.printStackTrace(System.err); + } + } + } + try { Thread.sleep(15); } catch (Exception e) {}; } - // call finalizeClient + System.out.println("Finalizing."); + // 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. -- 1.7.10.2