2 * This file is part of the Vamsas Client version 0.2.
\r
3 * Copyright 2010 by Jim Procter, Iain Milne, Pierre Marguerite,
\r
4 * Andrew Waterhouse and Dominik Lindner.
\r
6 * Earlier versions have also been incorporated into Jalview version 2.4
\r
7 * since 2008, and TOPALi version 2 since 2007.
\r
9 * The Vamsas Client is free software: you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation, either version 3 of the License, or
\r
12 * (at your option) any later version.
\r
14 * The Vamsas Client is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public License
\r
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
\r
22 package uk.ac.vamsas.test.simpleclient;
\r
24 import java.util.Iterator;
\r
25 import java.util.Vector;
\r
27 public class CommandProcessor {
\r
29 * this is not getOPT!!!! - processes a *series* of space separated commands -
\r
30 * some of which take arguments.
\r
32 private Vector commands;
\r
35 * static { ClientsFileTest.commands=new Vector();
\r
36 * ClientsFileTest.commands.add(new String("add"));
\r
37 * ClientsFileTest.commands.add(new String("remove"));
\r
38 * ClientsFileTest.commands.add(new String("list"));
\r
39 * ClientsFileTest.commands.add(new String("clear"));
\r
40 * ClientsFileTest.commands.add(new String("watch"));
\r
41 * ClientsFileTest.commands.add(new String("monitor")); }
\r
44 public int addCommand(String cmd, int argneed, String complainString) {
\r
46 if (commands == null)
\r
47 commands = new Vector();
\r
49 cnum = commands.size();
\r
50 Vector cv = new Vector();
\r
51 cv.add(new String(cmd));
\r
52 cv.add(new Integer(argneed));
\r
53 cv.add(new String(complainString));
\r
59 * Integer argl, Integer argpos, String cmd, Integer argneed, String msg in
\r
62 public void complainArgs(int argl, int argpos, Vector ca) {
\r
63 int argneed = ((Integer) ca.get(1)).intValue();
\r
64 if (argl - argpos < argneed)
\r
65 throw new Error(((String) ca.get(0)) + " at position " + argpos
\r
66 + " needs " + argneed + " arguments : " + (String) ca.get(2));
\r
70 * find and verify a command
\r
75 * position to check for command
\r
76 * @return matching command or -1
\r
78 public int getCommand(String[] args, int argpos) {
\r
79 Iterator coms = commands.iterator();
\r
82 while ((coms != null) && coms.hasNext()) {
\r
84 Vector comnext = (Vector) coms.next();
\r
85 if (args[argc].toLowerCase().equals((String) comnext.get(0))) {
\r
86 if (comnext.size() > 2)
\r
87 complainArgs(args.length, argc + 1, comnext);
\r