KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > common > commands > TestCommand


1 package org.objectweb.celtix.common.commands;
2
3 public class TestCommand {
4     
5     private int result;
6     private int duration;
7     private String JavaDoc err;
8     private String JavaDoc out;
9     
10     public TestCommand(String JavaDoc[] args) {
11         int i = 0;
12         while (i < args.length) {
13             if ("-duration".equals(args[i]) && i < (args.length - 1)) {
14                 i++;
15                 try {
16                     duration = Integer.parseInt(args[i]);
17                 } catch (NumberFormatException JavaDoc ex) {
18                     // leave at default
19
}
20             } else if ("-result".equals(args[i]) && i < (args.length - 1)) {
21                 i++;
22                 try {
23                     result = Integer.parseInt(args[i]);
24                 } catch (NumberFormatException JavaDoc ex) {
25                     // leave at default
26
}
27             } else if ("-err".equals(args[i]) && i < (args.length - 1)) {
28                 i++;
29                 err = args[i];
30             } else if ("-out".equals(args[i]) && i < (args.length - 1)) {
31                 i++;
32                 out = args[i];
33             } else {
34                 result = -1;
35                 System.err.println("Usage: TestCommand [-duration <duration>] [-result <result>]"
36                                    + " [-out <out>] [-err <err>]");
37                 break;
38             }
39             i++;
40         }
41     }
42     
43     void execute() {
44        
45         if (null != out) {
46             System.out.println(out);
47         }
48         if (null != err) {
49             System.err.println(err);
50         }
51         try {
52             Thread.sleep(duration * 1000);
53         } catch (InterruptedException JavaDoc ex) {
54             // ignore
55
}
56         System.exit(result);
57     }
58     
59     public static void main(String JavaDoc[] args) {
60         TestCommand tc = new TestCommand(args);
61         tc.execute();
62     }
63 }
64
Popular Tags