}
public String Usage = "ExampleApplication :/n [-arena <vamsasFileDirectory>][-session <vamsasSessionURN>] <action> [+<arguments>]\n"
- + "<action> is one of :\n\tsave,update,close,watch";
+ + "<action> is one of :\n\tsave,new,watch\n"+
+ "-arena and -session are not yet supported"; // TODO for release
String sess = null;
String importFile = null;
String outputFile = null;
-
+ boolean newSession=false;
+ boolean imported=false;
private boolean parseArgs(String args[]) {
if (args.length == 0) {
return false;
int cpos = 0;
boolean parsed = false;
while (!parsed && cpos < args.length) {
- if (args[cpos].toLowerCase().equals("load") && cpos + 1 < args.length) {
+ // TODO: note importDocument not yet supported.
+ //if (args[cpos].toLowerCase().equals("load") && cpos + 1 < args.length) {
+ // importFile = args[cpos + 1];
+ // cpos += 2;
+ // continue;
+ //}
+ if (args[cpos].toLowerCase().equals("new") && cpos + 1 < args.length) {
importFile = args[cpos + 1];
+ newSession=true;
cpos += 2;
continue;
}
// get an Iclient with session data
app = new ClientHandle("uk.ac.vamsas.test.ExampleApplication", "0.1");
user = new UserHandle("arnolduser", "deathsdoor");
+ if (sess!=null && importFile!=null)
+ {
+ System.err.println("Import of an existing document into an existing session is not fully supported yet.");
+ System.exit(3);
+ }
try {
if (sess != null) {
System.out.println("Connecting to " + sess);
vorbaclient = clientfactory.getIClient(app, user, sess);
} else {
- vorbaclient = clientfactory.getIClient(app, user);
+ if (newSession)
+ {
+ if (importFile==null)
+ {
+ System.out.println("Connecting to a new VAMSAS Session.");
+ vorbaclient = clientfactory.getNewSessionIClient(app, user);
+ } else {
+ System.out.println("Connecting to a new VAMSAS Session to share data in existing document:"+importFile);
+ File vfile = new File(importFile);
+ vorbaclient = clientfactory.openAsNewSessionIClient(app, user, vfile);
+ System.out.println("Succesfully imported document into new session.");
+ imported = true;
+ importFile=null;
+ }
+ } else {
+ vorbaclient = clientfactory.getIClient(app, user);
+ }
}
- } catch (NoDefaultSessionException e) {
+ }
+ catch (InvalidSessionDocumentException e) {
+ System.err.println("Failed to create a session to share "+importFile);
+ System.err.println("Sorry it didn't work out. This is what went wrong:");
+ e.printStackTrace(System.err);
+ System.exit(3);
+ }
+ catch (NoDefaultSessionException e) {
System.err
.println("There appear to be several sessions to choose from :");
String[] sessions = clientfactory.getCurrentSessions();
File vfile = new File(importFile);
try {
vorbaclient.importDocument(vfile);
+ imported=true;
} catch (Exception e) {
System.err.println("Failed to import file " + importFile);
System.err.println("Exception received was " + e);
// get document data
try {
IClientDocument cdoc = vorbaclient.getClientDocument();
+ if (imported)
+ {
+ if (cdoc.getVamsasRoots()==null || cdoc.getVamsasRoots()[0].getDataSetCount()<1)
+ {
+ System.err.println("Imported an Empty vamsas document. Is this correct ?");
+ }
+ }
processVamsasDocument(cdoc);
} catch (Exception e) {
System.err