1 package org.vamsas.test.simpleclient;
3 import java.util.Iterator;
4 import java.util.Vector;
6 import org.vamsas.client.ClientHandle;
7 import org.vamsas.client.simpleclient.ClientsFile;
9 public class ClientsFileTest {
10 private static 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"));
18 private static void complainArgs(int argl, int argpos, String cmd, int argneed, String msg) {
19 if (argl-argpos<argneed)
20 throw new Error(cmd+" needs "+argneed+" arguments : "+msg);
22 public static void main(String[] args) {
23 java.io.File cf = new java.io.File(args[0]);
24 System.out.println("Connecting to clientFile "+args[0]);
27 cfhand = new ClientsFile(cf);
30 e.printStackTrace(System.err);
34 while (argc<args.length) {
36 Iterator coms = commands.iterator();
38 while ((coms!=null) && coms.hasNext()) {
40 if (args[argc].toLowerCase().equals((String) coms.next())) {
41 System.out.println("Doing "+args[argc]);
47 ClientsFileTest.complainArgs(args.length, argc, "add", 2, "for the Client's 'Name' and 'Version'");
48 int pos = cfhand.addClient(ch=new ClientHandle(args[argc],args[argc+1]));
51 System.out.println("Client added at "+pos+" as urn:"+ch.getClientUrn());
53 System.out.println("Client was not added.");
57 ClientsFileTest.complainArgs(args.length, argc, "remove", 3, "for the Client's 'Name', Version and URN");
58 ch=new ClientHandle(args[argc], args[argc+1]);
59 ch.setClientUrn(args[argc+2]);
61 cfhand.removeClient(ch);
62 System.out.println("Client removed (apparently)");
66 ClientHandle[] chlist = cfhand.retrieveClientList();
68 for (int chi=0,che=chlist.length; chi<che; chi++) {
69 System.out.println("Client "+chi+" ("+chlist[chi].getClientName()+" "+chlist[chi].getVersion()+" "+chlist[chi].getClientUrn()+")");
72 System.out.println("Client list is empty.");
81 cfhand = new ClientsFile(cf);
84 System.err.println("Failed on new empty clientfile creation!");
85 e.printStackTrace(System.err);
93 System.err.println("Unknown command : "+args[argc] + "*Ignored!*");