01: /*
02: * $Id: LoadCommand.java 674 2006-10-06 12:15:59Z hengels $
03: * (c) Copyright 2004 con:cern development team.
04: *
05: * This file is part of con:cern (http://concern.sf.net).
06: *
07: * con:cern is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU Lesser General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.concern.client.commandline;
15:
16: /**
17: * <b>Example</b>: create touch, complete and log 100 projects<br>
18: * All arguments after the '-' are prefixe with [0-9]_<br>
19: * <pre>
20: * concern.sh Project load 10 create - a b c d e f g h i j
21: * concern.sh Project load 10 touch - a b c d e f g h i j
22: * concern.sh Project load 10 complete org.concern.test.project.Implementation - a b c d e f g h i j
23: * concern.sh Project load 10 log - a b c d e f g h i j
24: * </pre>
25: *
26: * @author hengels
27: */
28: public class LoadCommand extends Command {
29: public static final int OFFSET = 2;
30:
31: public void run() {
32:
33: try {
34: int count = Integer.parseInt(args[0]);
35: String commandName = args[1];
36:
37: for (int c = 0; c < count; c++) {
38: String prefix = c + "_";
39: String[] commandArgs = new String[args.length - OFFSET
40: - 1];
41: int offset = 0;
42: for (int i = OFFSET; i < args.length; i++) {
43: String arg = args[i];
44: if ("-".equals(arg)) {
45: offset = 1;
46: continue;
47: }
48: commandArgs[i - OFFSET - offset] = (arg
49: .startsWith("-") || offset == 0) ? arg
50: : prefix + arg;
51: }
52:
53: Command command = Concern.getCommand(commandName);
54: command.setController(controller);
55: command.setArguments(commandArgs);
56:
57: new Thread(command).start();
58: try {
59: Thread.sleep(1000);
60: } catch (InterruptedException e) {
61: e.printStackTrace();
62: }
63: }
64: } catch (InstantiationException e) {
65: e.printStackTrace();
66: } catch (IllegalAccessException e) {
67: e.printStackTrace();
68: }
69: }
70: }
|