clargs documentation, new vamsas session import and join args. apply gpl development...
[jalview.git] / src / jalview / bin / Jalview.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3  * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.bin;
20
21 import java.io.BufferedReader;
22 import java.io.File;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.io.OutputStreamWriter;
26 import java.io.PrintWriter;
27 import java.lang.reflect.Constructor;
28 import java.net.URL;
29 import java.util.*;
30
31 import javax.swing.*;
32
33 import jalview.gui.*;
34 import jalview.io.AppletFormatAdapter;
35
36 /**
37  * Main class for Jalview Application <br>
38  * <br>
39  * start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
40  * 
41  * @author $author$
42  * @version $Revision$
43  */
44 public class Jalview
45 {
46
47   /**
48    * main class for Jalview application
49    * 
50    * @param args
51    *                open <em>filename</em>
52    */
53   public static void main(String[] args)
54   {
55     System.out.println("Java version: "
56             + System.getProperty("java.version"));
57     System.out.println(System.getProperty("os.arch") + " "
58             + System.getProperty("os.name") + " "
59             + System.getProperty("os.version"));
60
61     ArgsParser aparser = new ArgsParser(args);
62     boolean headless = false;
63
64     if (aparser.contains("help") || aparser.contains("h"))
65     {
66       System.out
67               .println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
68                       + "-nodisplay\tRun Jalview without User Interface.\n"
69                       + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
70                       + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
71                       + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
72                       + "-features FILE\tUse the given file to mark features on the alignment.\n"
73                       + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
74                       + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
75                       + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
76                       + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
77                       + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
78                       + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
79                       + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
80                       + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
81                       + "-png FILE\tCreate PNG image FILE from alignment.\n"
82                       + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
83                       + "-eps FILE\tCreate EPS file FILE from alignment.\n"
84                       + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
85                       + "-noquestionnaire\tTurn off questionnaire check.\n"
86                       + "-nousagestats\tTurn off google analytics tracking for this session.\n"
87                       + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
88 //                      + "-setprop PROPERTY=VALUE\tSet the given Jalview property, after all other properties files have been read\n\t (quote the 'PROPERTY=VALUE' pair to ensure spaces are passed in correctly)"
89                       + "-dasserver nickname=URL\tAdd and enable a das server with given nickname (alphanumeric or underscores only) for retrieval of features for all alignments.\n"
90                       +"\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
91                       +"\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
92                       + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
93 //                      + "-vdoc vamsas-document\tImport vamsas document into new session or join existing session with same URN\n"
94 //                      + "-vses vamsas-session\tJoin session with given URN\n"
95                       + "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n"
96                       + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
97       System.exit(0);
98     }
99     Cache.loadProperties(aparser.getValue("props")); // must do this before
100     // anything else!
101     String defs = aparser.getValue("setprop");
102     while (defs!=null)
103     {
104       int p = defs.indexOf('=');
105       if ( p==-1 )
106       {
107         System.err.println("Ignoring invalid setprop argument : "+defs);
108       } else {
109         System.out.println("Executing setprop argument: "+defs);
110         // DISABLED FOR SECURITY REASONS
111         // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
112       }
113       defs = aparser.getValue("setprop");
114     }
115     if (aparser.contains("nodisplay"))
116     {
117       System.setProperty("java.awt.headless", "true");
118     }
119     if (System.getProperty("java.awt.headless") != null
120             && System.getProperty("java.awt.headless").equals("true"))
121     {
122       headless = true;
123     }
124
125     try
126     {
127       Cache.initLogger();
128     } catch (java.lang.NoClassDefFoundError error)
129     {
130       error.printStackTrace();
131       System.out
132               .println("\nEssential logging libraries not found."
133                       + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
134       System.exit(0);
135     }
136
137     Desktop desktop = null;
138
139     try
140     {
141       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()
142       // UIManager.getCrossPlatformLookAndFeelClassName()
143               // "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
144               // "javax.swing.plaf.metal.MetalLookAndFeel"
145               // "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
146               // "com.sun.java.swing.plaf.motif.MotifLookAndFeel"
147
148               
149               );
150     } catch (Exception ex)
151     {
152     }
153     if (!headless)
154     {
155       desktop = new Desktop();
156       desktop.setVisible(true);
157       desktop.discoverer.start();
158       if (!aparser.contains("nousagestats") && Cache.getDefault("USAGESTATS", true)) {
159         Cache.log.info("Initialising googletracker for usage stats.");
160         Cache.initGoogleTracker();
161         Cache.log.debug("Tracking enabled.");
162       } else {
163         Cache.log.info("Not enabling Google Tracking.");
164       }
165       if (!aparser.contains("noquestionnaire"))
166       {
167         String url = aparser.getValue("questionnaire");
168         if (url != null)
169         {
170           // Start the desktop questionnaire prompter with the specified
171           // questionnaire
172           Cache.log.debug("Starting questionnaire url at " + url);
173           desktop.checkForQuestionnaire(url);
174         }
175         else
176         {
177           if (Cache.getProperty("NOQUESTIONNAIRES") == null)
178           {
179             // Start the desktop questionnaire prompter with the specified
180             // questionnaire
181             // String defurl =
182             // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
183             // //
184             String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
185             Cache.log.debug("Starting questionnaire with default url: "
186                     + defurl);
187             desktop.checkForQuestionnaire(defurl);
188
189           }
190         }
191       }
192     }
193
194     String file = null, protocol = null, format = null, data = null;
195     jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
196     Vector getFeatures = null; // vector of das source nicknames to fetch
197                                 // features from
198     // loading is done.
199     String groovyscript = null; // script to execute after all loading is
200                                 // completed one way or another
201     // extract groovy argument and execute if necessary
202     groovyscript = aparser.getValue("groovy");
203     file = aparser.getValue("open");
204
205     if (file == null && desktop == null)
206     {
207       System.out.println("No files to open!");
208       System.exit(1);
209     }
210     String vamsasImport=aparser.getValue("vdoc"),vamsasSession=aparser.getValue("vsess");
211     if (vamsasImport!=null || vamsasSession!=null)
212     {
213       if (desktop==null || headless)
214       {
215         System.out.println("Headless vamsas sessions not yet supported. Sorry.");
216         System.exit(1);
217       }
218       // if we have a file, start a new session and import it.
219       boolean inSession = false;
220       if (vamsasImport!=null)
221       {
222         try {
223           inSession = desktop.vamsasImport(new File(vamsasImport));
224             
225           } catch (Exception e)
226           {
227             System.err.println("Exeption when importing "+vamsasImport+" as a vamsas document.");
228             e.printStackTrace();
229           }
230           if (!inSession) {
231             System.err.println("Failed to import "+vamsasImport+" as a vamsas document.");
232           } else {
233             System.out.println("Imported Successfully into new session "+desktop.getVamsasApplication().getCurrentSession());
234         }
235       } 
236       if (vamsasSession!=null) {
237         if (vamsasImport!=null) {
238        // close the newly imported session and import the Jalview specific remnants into the new session later on.
239           desktop.vamsasStop_actionPerformed(null);
240         }
241         // now join the new session
242         try {
243           if (desktop.joinVamsasSession(vamsasSession)) {
244             System.out.println("Successfully joined vamsas session "+vamsasSession);
245           } else {
246             System.err.println("WARNING: Failed to join vamsas session "+vamsasSession);
247           }
248         } catch (Exception e)
249         {
250           System.err.println("ERROR: Failed to join vamsas session "+vamsasSession);
251           e.printStackTrace();
252         }
253         if (vamsasImport!=null) {
254           // the Jalview specific remnants can now be imported into the new session at the user's leisure.
255           Cache.log.info("Skipping Push for import of data into existing vamsas session."); // TODO: enable this when debugged
256           // desktop.getVamsasApplication().push_update();
257         }
258       }
259     }
260     // Finally, deal with the remaining input data.
261     if (file != null)
262     {
263       System.out.println("Opening file: " + file);
264
265       if (!file.startsWith("http://"))
266       {
267         if (!(new java.io.File(file)).exists())
268         {
269           System.out.println("Can't find " + file);
270           if (headless)
271           {
272             System.exit(1);
273           }
274         }
275       }
276
277       protocol = checkProtocol(file);
278
279       format = new jalview.io.IdentifyFile().Identify(file, protocol);
280
281       AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
282               format);
283
284       if (af == null)
285       {
286         System.out.println("error");
287         return;
288       }
289
290       data = aparser.getValue("colour");
291       if (data != null)
292       {
293         data.replaceAll("%20", " ");
294
295         jalview.schemes.ColourSchemeI cs = jalview.schemes.ColourSchemeProperty
296                 .getColour(af.getViewport().getAlignment(), data);
297
298         if (cs == null)
299         {
300           jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
301                   "white");
302           ucs.parseAppletParameter(data);
303           cs = ucs;
304         }
305
306         System.out.println("colour is " + data);
307         af.changeColour(cs);
308       }
309
310       // Must maintain ability to use the groups flag
311       data = aparser.getValue("groups");
312       if (data != null)
313       {
314         af.parseFeaturesFile(data, checkProtocol(data));
315         System.out.println("Added " + data);
316       }
317       data = aparser.getValue("features");
318       if (data != null)
319       {
320         af.parseFeaturesFile(data, checkProtocol(data));
321         System.out.println("Added " + data);
322       }
323
324       data = aparser.getValue("annotations");
325       if (data != null)
326       {
327         af.loadJalviewDataFile(data);
328         System.out.println("Added " + data);
329       }
330       // set or clear the sortbytree flag.
331       if (aparser.contains("sortbytree"))
332       {
333         af.getViewport().setSortByTree(true);
334       }
335       if (aparser.contains("nosortbytree"))
336       {
337         af.getViewport().setSortByTree(false);
338       }
339       data = aparser.getValue("tree");
340       if (data != null)
341       {
342         jalview.io.NewickFile fin = null;
343         try
344         {
345           fin = new jalview.io.NewickFile(data, checkProtocol(data));
346           if (fin != null)
347           {
348             af.getViewport().setCurrentTree(
349                     af.ShowNewickTree(fin, data).getTree());
350             System.out.println("Added tree " + data);
351           }
352         } catch (IOException ex)
353         {
354           System.err.println("Couldn't add tree " + data);
355           ex.printStackTrace(System.err);
356         }
357       }
358       getFeatures = checkDasArguments(aparser);
359       if (af != null && getFeatures != null)
360       {
361         startFeatureFetching(getFeatures);
362         // need to block until fetching is complete.
363         while (af.operationInProgress())
364         {
365           // wait around until fetching is finished.
366           try
367           {
368             Thread.sleep(10);
369           } catch (Exception e)
370           {
371
372           }
373         }
374       }
375       if (groovyscript != null)
376       {
377         // Execute the groovy script after we've done all the rendering stuff
378         // and before any images or figures are generated.
379         if (jalview.bin.Cache.groovyJarsPresent())
380         {
381           System.out.println("Executing script " + groovyscript);
382           executeGroovyScript(groovyscript, desktop);
383         }
384         else
385         {
386           System.err
387                   .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
388                           + groovyscript);
389         }
390         groovyscript = null;
391       }
392       String imageName = "unnamed.png";
393       while (aparser.getSize() > 1)
394       {
395         format = aparser.nextValue();
396         file = aparser.nextValue();
397
398         if (format.equalsIgnoreCase("png"))
399         {
400           af.createPNG(new java.io.File(file));
401           imageName = (new java.io.File(file)).getName();
402           System.out.println("Creating PNG image: " + file);
403           continue;
404         }
405         else if (format.equalsIgnoreCase("imgMap"))
406         {
407           af.createImageMap(new java.io.File(file), imageName);
408           System.out.println("Creating image map: " + file);
409           continue;
410         }
411         else if (format.equalsIgnoreCase("eps"))
412         {
413           System.out.println("Creating EPS file: " + file);
414           af.createEPS(new java.io.File(file));
415           continue;
416         }
417
418         if (af.saveAlignment(file, format))
419         {
420           System.out.println("Written alignment in " + format
421                   + " format to " + file);
422         }
423         else
424         {
425           System.out.println("Error writing file " + file + " in " + format
426                   + " format!!");
427         }
428
429       }
430
431       while (aparser.getSize() > 0)
432       {
433         System.out.println("Unknown arg: " + aparser.nextValue());
434       }
435     }
436     AlignFrame startUpAlframe = null;
437     // We'll only open the default file if the desktop is visible.
438     // And the user
439     // ////////////////////
440     if (!headless && file == null && vamsasImport==null
441             && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
442     {
443       file = jalview.bin.Cache.getDefault("STARTUP_FILE",
444               "http://www.jalview.org/examples/exampleFile_2_3.jar");
445
446       protocol = "File";
447
448       if (file.indexOf("http:") > -1)
449       {
450         protocol = "URL";
451       }
452
453       if (file.endsWith(".jar"))
454       {
455         format = "Jalview";
456       }
457       else
458       {
459         format = new jalview.io.IdentifyFile().Identify(file, protocol);
460       }
461
462       startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
463               format);
464       getFeatures = checkDasArguments(aparser);
465       // extract groovy arguments before anything else.
466     }
467     // Once all loading is done. Retrieve features.
468     if (getFeatures != null)
469     {
470       if (startUpAlframe != null)
471       {
472         startFeatureFetching(getFeatures);
473       }
474     }
475     if (groovyscript != null)
476     {
477       if (jalview.bin.Cache.groovyJarsPresent())
478       {
479         System.out.println("Executing script " + groovyscript);
480         executeGroovyScript(groovyscript, desktop);
481       }
482       else
483       {
484         System.err
485                 .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
486                         + groovyscript);
487       }
488     }
489
490     // Once all other stuff is done, execute any groovy scripts (in order)
491   }
492
493   /**
494    * Locate the given string as a file and pass it to the groovy interpreter.
495    * 
496    * @param groovyscript
497    *                the script to execute
498    * @param jalviewContext
499    *                the Jalview Desktop object passed in to the groovy binding
500    *                as the 'Jalview' object.
501    */
502   private static void executeGroovyScript(String groovyscript,
503           Object jalviewContext)
504   {
505     if (jalviewContext == null)
506     {
507       System.err
508               .println("Sorry. Groovy support is currently only available when running with the Jalview GUI enabled.");
509     }
510     File sfile = null;
511     if (groovyscript.trim().equals("STDIN"))
512     {
513       // read from stdin into a tempfile and execute it
514       try
515       {
516         sfile = File.createTempFile("jalview", "groovy");
517         PrintWriter outfile = new PrintWriter(new OutputStreamWriter(
518                 new FileOutputStream(sfile)));
519         BufferedReader br = new BufferedReader(
520                 new java.io.InputStreamReader(System.in));
521         String line = null;
522         while ((line = br.readLine()) != null)
523         {
524           outfile.write(line + "\n");
525         }
526         br.close();
527         outfile.flush();
528         outfile.close();
529
530       } catch (Exception ex)
531       {
532         System.err.println("Failed to read from STDIN into tempfile "
533                 + ((sfile == null) ? "(tempfile wasn't created)" : sfile
534                         .toString()));
535         ex.printStackTrace();
536         return;
537       }
538     }
539     else
540     {
541       sfile = new File(groovyscript);
542     }
543     if (!sfile.exists())
544     {
545       System.err.println("File '" + groovyscript + "' does not exist.");
546       return;
547     }
548     if (!sfile.canRead())
549     {
550       System.err.println("File '" + groovyscript + "' cannot be read.");
551       return;
552     }
553     if (sfile.length() < 1)
554     {
555       System.err.println("File '" + groovyscript + "' is empty.");
556       return;
557     }
558     boolean success = false;
559     try
560     {
561       /*
562        * The following code performs the GroovyScriptEngine invocation using
563        * reflection, and is equivalent to this fragment from the embedding
564        * groovy documentation on the groovy site: <code> import
565        * groovy.lang.Binding; import groovy.util.GroovyScriptEngine;
566        * 
567        * String[] roots = new String[] { "/my/groovy/script/path" };
568        * GroovyScriptEngine gse = new GroovyScriptEngine(roots); Binding binding =
569        * new Binding(); binding.setVariable("input", "world");
570        * gse.run("hello.groovy", binding); </code>
571        */
572       ClassLoader cl = jalviewContext.getClass().getClassLoader();
573       Class gbindingc = cl.loadClass("groovy.lang.Binding");
574       Constructor gbcons = gbindingc.getConstructor(null);
575       Object gbinding = gbcons.newInstance(null);
576       java.lang.reflect.Method setvar = gbindingc.getMethod("setVariable",
577               new Class[]
578               { String.class, Object.class });
579       setvar.invoke(gbinding, new Object[]
580       { "Jalview", jalviewContext });
581       Class gsec = cl.loadClass("groovy.util.GroovyScriptEngine");
582       Constructor gseccons = gsec.getConstructor(new Class[]
583       { URL[].class }); // String[].class });
584       Object gse = gseccons.newInstance(new Object[]
585       { new URL[]
586       { sfile.toURL() } }); // .toString() } });
587       java.lang.reflect.Method run = gsec.getMethod("run", new Class[]
588       { String.class, gbindingc });
589       run.invoke(gse, new Object[]
590       { sfile.getName(), gbinding });
591       success = true;
592     } catch (Exception e)
593     {
594       System.err.println("Exception Whilst trying to execute file " + sfile
595               + " as a groovy script.");
596       e.printStackTrace(System.err);
597
598     }
599     if (success && groovyscript.equals("STDIN"))
600     {
601       // delete temp file that we made - but only if it was successfully
602       // executed
603       sfile.delete();
604     }
605   }
606
607   /**
608    * Check commandline for any das server definitions or any fetchfrom switches
609    * 
610    * @return vector of DAS source nicknames to retrieve from
611    */
612   private static Vector checkDasArguments(ArgsParser aparser)
613   {
614     Vector source = null;
615     String data;
616     String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
617     while ((data = aparser.getValue("dasserver")) != null)
618     {
619       String nickname = null;
620       String url = null;
621       boolean seq=false,feat=true;
622       int pos = data.indexOf('=');
623       // determine capabilities
624       if (pos > 0)
625       {
626         nickname = data.substring(0, pos);
627       }
628       url = data.substring(pos + 1);
629       if (url != null && (url.startsWith("http:") || url.startsWith("sequence:http:")))
630       {
631         if (nickname == null)
632         {
633           nickname = url;
634         }
635         if (locsources == null)
636         {
637           locsources = "";
638         }
639         else
640         {
641           locsources += "\t";
642         }
643         locsources = locsources + nickname + "|" + url;
644         System.err
645                 .println("NOTE! dasserver parameter not yet really supported (got args of "
646                         + nickname + "|" + url);
647         if (source == null)
648         {
649           source = new Vector();
650         }
651         source.addElement(nickname);
652       }
653     } // loop until no more server entries are found.
654     if (locsources != null && locsources.indexOf('|') > -1)
655     {
656       Cache.log.debug("Setting local source list in properties file to:\n"
657               + locsources);
658       Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
659     }
660     while ((data = aparser.getValue("fetchfrom")) != null)
661     {
662       System.out.println("adding source '" + data + "'");
663       if (source == null)
664       {
665         source = new Vector();
666       }
667       source.addElement(data);
668     }
669     return source;
670   }
671
672   /**
673    * start a feature fetcher for every alignment frame
674    * 
675    * @param dasSources
676    */
677   private static void startFeatureFetching(final Vector dasSources)
678   {
679     AlignFrame afs[] = Desktop.getAlignframes();
680     if (afs == null || afs.length == 0)
681     {
682       return;
683     }
684     for (int i = 0; i < afs.length; i++)
685     {
686       final AlignFrame af = afs[i];
687       SwingUtilities.invokeLater(new Runnable()
688       {
689
690         public void run()
691         {
692           af.featureSettings_actionPerformed(null);
693           af.featureSettings.fetchDasFeatures(dasSources);
694         }
695       });
696     }
697   }
698
699   private static String checkProtocol(String file)
700   {
701     String protocol = jalview.io.FormatAdapter.FILE;
702
703     if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
704     {
705       protocol = jalview.io.FormatAdapter.URL;
706     }
707     return protocol;
708   }
709 }
710
711 /**
712  * Notes: this argParser does not distinguish between parameter switches,
713  * parameter values and argument text. If an argument happens to be identical to
714  * a parameter, it will be taken as such (even though it didn't have a '-'
715  * prefixing it).
716  * 
717  * @author Andrew Waterhouse and JBP documented.
718  * 
719  */
720 class ArgsParser
721 {
722   Vector vargs = null;
723
724   public ArgsParser(String[] args)
725   {
726     vargs = new Vector();
727     for (int i = 0; i < args.length; i++)
728     {
729       String arg = args[i].trim();
730       if (arg.charAt(0) == '-')
731       {
732         arg = arg.substring(1);
733       }
734       vargs.addElement(arg);
735     }
736   }
737
738   /**
739    * check for and remove first occurence of arg+parameter in arglist.
740    * 
741    * @param arg
742    * @return return the argument following the given arg if arg was in list.
743    */
744   public String getValue(String arg)
745   {
746     int index = vargs.indexOf(arg);
747     String ret = null;
748     if (index != -1)
749     {
750       ret = vargs.elementAt(index + 1).toString();
751       vargs.removeElementAt(index);
752       vargs.removeElementAt(index);
753     }
754     return ret;
755   }
756
757   /**
758    * check for and remove first occurence of arg in arglist.
759    * 
760    * @param arg
761    * @return true if arg was present in argslist.
762    */
763   public boolean contains(String arg)
764   {
765     if (vargs.contains(arg))
766     {
767       vargs.removeElement(arg);
768       return true;
769     }
770     else
771     {
772       return false;
773     }
774   }
775
776   public String nextValue()
777   {
778     return vargs.remove(0).toString();
779   }
780
781   public int getSize()
782   {
783     return vargs.size();
784   }
785
786 }