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;
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
*/
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.
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...
}
});
}
public static String
- Usage="ExampleApplication <vamsasFileDirectory> <vamsasSessionURN> <action> [+<arguments>]\n"
+ Usage="ExampleApplication [session urn] watch/n( future usage is :/n <vamsasFileDirectory> <vamsasSessionURN> <action> [+<arguments>]\n"
+"<action> 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);
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.