1 package org.vamsas.test.simpleclient;
3 import java.util.Iterator;
4 import java.util.Vector;
6 public class CommandProcessor {
8 * this is not getOPT!!!! - processes a *series* of space separated commands - some of which take arguments.
10 private Vector commands;
12 ClientsFileTest.commands=new Vector();
13 ClientsFileTest.commands.add(new String("add"));
14 ClientsFileTest.commands.add(new String("remove"));
15 ClientsFileTest.commands.add(new String("list"));
16 ClientsFileTest.commands.add(new String("clear"));
17 ClientsFileTest.commands.add(new String("watch"));
18 ClientsFileTest.commands.add(new String("monitor"));
21 public int addCommand(String cmd, int argneed, String complainString) {
24 commands = new Vector();
26 cnum = commands.size();
27 Vector cv = new Vector();
28 cv.add(new String(cmd));
29 cv.add(new Integer(argneed));
30 cv.add(new String(complainString));
36 * Integer argl, Integer argpos, String cmd, Integer argneed, String msg in vector
38 public void complainArgs(int argl, int argpos, Vector ca) {
39 int argneed = ((Integer) ca.get(1)).intValue();
40 if (argl-argpos<argneed)
41 throw new Error(((String) ca.get(0))+" at position "+argpos+" needs "+argneed+" arguments : "+(String) ca.get(2));
44 * find and verify a command
45 * @param args argstring
46 * @param argpos position to check for command
47 * @return matching command or -1
49 public int getCommand(String[]args, int argpos) {
50 Iterator coms = commands.iterator();
53 while ((coms!=null) && coms.hasNext()) {
55 Vector comnext = (Vector) coms.next();
56 if (args[argc].toLowerCase().equals((String) comnext.get(0))) {
58 complainArgs(args.length, argc+1, comnext);