01: /*
02: * $Id: ListCommand.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: import org.concern.Controller;
17:
18: import java.util.Iterator;
19: import java.util.List;
20:
21: /**
22: * <b>Example</b>: list all subjects that are enlisted for the asynchronous Implementation activity<br>
23: * <pre>
24: * concern.sh Project list org.concern.test.project.Implementation
25: * </pre>
26: *
27: * @author hengels
28: */
29: public class ListCommand extends Command {
30: private String[] activities;
31:
32: public ListCommand() {
33: usage = "[ACTIVITY]...\n Show enlistments of activities.";
34: }
35:
36: public String[] getActivities() {
37: return activities;
38: }
39:
40: public void setActivities(String[] activities) {
41: this .activities = activities;
42: }
43:
44: public void setArguments(String[] args) {
45: activities = new String[args.length];
46: for (int i = 0; i < args.length; i++) {
47: activities[i] = args[i];
48: }
49: }
50:
51: public void run() {
52: if (activities != null && activities.length != 0) {
53: for (int i = 0; i < activities.length; i++) {
54: String activity = activities[i];
55: try {
56: System.out.println("list " + activity + ":");
57:
58: List list = controller.getSubjects(activity);
59: for (Iterator iterator = list.iterator(); iterator
60: .hasNext();) {
61: String subject = (String) iterator.next();
62: System.out.println(subject);
63: }
64: } catch (Exception e) {
65: System.out.println("list " + activity + ": ERROR");
66: e.printStackTrace();
67: }
68: }
69: } else {
70: try {
71: System.out.println("list:");
72:
73: List list = controller
74: .getSubjects(Controller.STATE_RUNNING);
75: for (Iterator iterator = list.iterator(); iterator
76: .hasNext();) {
77: String subject = (String) iterator.next();
78: System.out.println(subject);
79: }
80: } catch (Exception e) {
81: System.out.println("list: ERROR");
82: e.printStackTrace();
83: }
84:
85: }
86: }
87: }
|